9 NetMsgs Generate C files module. 11 A pair of C .h header and .c source files are generated from a RoadNarrows 12 NetMsg XML specification. 80 """ RoadNarrows Net Messages C Source Generator Class. 82 The NetMsgsGenC class reads the post-parsed database of a NetMsgsXmlParser 83 class instance and generates a C .h and .c file pair. The C files expects 84 the libnetmsgs C library. 88 def __init__(self, xml, hfilepath, cfilepath, **kwargs):
89 """ Initialize NetMsgsGenC instance. 92 xml - NetMsgsXMLParser class instance. 93 hfilepath - Generated output h file. 94 cfilepath - Generated output c file. 95 kwargs - Optional keyword arguments. 96 debug - Set debugging level: 0 == off, 1, 2, 3. 97 incprefix - Generated .h include prefix in .c file. 128 """ Augument the XML database of parsed XML values with C generated 131 self.
mXml[
'genc'] = { }
132 encoding = self.
mXml[
'netmsgs'][
'encoding'].lower()
135 if encoding ==
'itv':
136 self.
mXml[
'genc'][
'encoding_prefix'] = encoding.upper()
138 self.
mXml[
'genc'][
'encoding_prefix'] = encoding.capitalize()
140 endian = self.
mXml[
'netmsgs'][
'endian'].lower()
143 self.
mXml[
'genc'][
'endian_desc'] = endian +
'-endian' 144 self.
mXml[
'genc'][
'endian_enum'] =
'NMEndian'+endian.capitalize()
152 """ Make initial pass through the XML database and augument with 153 specific C information. 155 No generated C code is written to file output. 157 for xid
in self.
mXml[
'field_types'][nmBase.NMKeyOrder]:
159 for xid
in self.
mXml[
'msg_types'][nmBase.NMKeyOrder]:
166 """ Process the given XmL definition and add C specific data. 168 No generated C code is written to file output. 171 pathXids - Path (list) of XML ftypedef, msgdef, or fielddef 173 xdef - XML ftypedef, msgdef, or fielddef XML specification. 174 depth - Recursive definition depth. 177 Maximum number of packed bytes required for this encoded definition. 179 ns = self.
mXml[
'meta'][
'ns']
182 ftype = xdef[
'ftype']
186 xdef[
'base_ftype'] = base_ftype
193 elif ftype ==
'struct':
197 elif ftype ==
'vector':
201 elif ftype ==
'string':
205 elif nmBase.NMBuiltInFieldTypes.has_key(ftype):
217 """ Process pad XML definition. 220 pathXids - Path (list) of XML ftypedef, msgdef, or fielddef 222 xdef - XML ftypedef, msgdef, or fielddef XML specification. 223 depth - Recursive definition depth. 226 Maximum number of packed bytes required for this encoded definition. 233 eq_sum = repr(nmBase.NMBuiltInFieldTypes[
'pad'][
'flen'])+
'*'+xdef[
'count']
237 xdef[
'genc'][
'type_spec'] =
None 238 xdef[
'genc'][
'id'] =
None 239 xdef[
'genc'][
'const_expr'] =
None 240 xdef[
'genc'][
'comment'] =
'message padding' 241 xdef[
'genc'][
'maxlen'] = maxlen
242 xdef[
'genc'][
'active_cnt'] = active_cnt
249 """ Process struct XML definition. 252 pathXids - Path (list) of XML ftypedef, msgdef, or fielddef 254 xdef - XML ftypedef, msgdef, or fielddef XML specification. 255 depth - Recursive definition depth. 258 Maximum number of packed bytes required for this encoded definition. 260 encoding = self.
mXml[
'netmsgs'][
'encoding']
261 eq_sum = [nmBase.NMFHdrLen[encoding][
'struct']]
268 for fname
in xdef[
'fields'][nmBase.NMKeyOrder]:
269 n = self.
Pass0XmlDef(pathXids+[fname], xdef[
'fields'][fname], depth+1)
275 ns = self.
mXml[
'meta'][
'ns']
278 cid = self.
MakeCId(xid, depth==0)
280 msgdef =
"%s%sMsgDef" % (ns,
''.join(pathXids))
283 xdef[
'genc'][
'type_spec'] = type_spec
284 xdef[
'genc'][
'id'] = cid
285 xdef[
'genc'][
'const_expr'] = const_expr
286 xdef[
'genc'][
'comment'] =
"%s structure" % (xid)
287 xdef[
'genc'][
'msgdef'] = msgdef
288 xdef[
'genc'][
'maxlen'] = maxlen
289 xdef[
'genc'][
'active_cnt'] = active_cnt
296 """ Process vector XML definition. 299 pathXids - Path (list) of XML ftypedef, msgdef, or fielddef 301 xdef - XML ftypedef, msgdef, or fielddef XML specification. 302 depth - Recursive definition depth. 305 Maximum number of packed bytes required for this encoded definition. 307 ns = self.
mXml[
'meta'][
'ns']
310 cid = self.
MakeCId(xid, depth==0)
311 vtype = xdef[
'vtype']
316 fsize = xdef.get(
'size',
'NMFVAL_LEN_MAX_VECTOR')
317 if nmBase.IsIdentifier(fsize)
and fsize !=
'NMFVAL_LEN_MAX_VECTOR':
324 nlist = pathXids + [
'len']
327 'token_seq':
'(' + fsize +
')',
328 'comment':
"%s maximum vector length" % (
' '.join(pathXids)),
330 const_expr = macro_len[
'name']
331 fielddef =
"%s%sFieldDef" % (ns,
''.join(pathXids))
334 encoding = self.
mXml[
'netmsgs'][
'encoding']
335 eq_sum = [nmBase.NMFHdrLen[encoding][
'vector']]
336 if macro_len[
'token_seq']:
337 maxcount = macro_len[
'token_seq']
339 maxcount = macro_len[
'name']
340 if base_vname ==
'this':
342 flen = repr(nmBase.NMBuiltInFieldTypes[base_vtype][
'flen'])
345 flen = repr(nmBase.NMBuiltInFieldTypes[base_vtype][
'flen'])
347 fhdrlen = repr(nmBase.NMFHdrLen[encoding][base_vtype])
348 flen = self.
mXml[
'field_types'][base_vname][
'genc'][
'maxlen']
354 eq_sum += [flen +
'*' + maxcount]
359 xdef[
'genc'][
'type_spec'] = type_spec
360 xdef[
'genc'][
'id'] = cid
361 xdef[
'genc'][
'const_expr'] = const_expr
362 xdef[
'genc'][
'comment'] =
"%s vector" % (xid)
363 xdef[
'genc'][
'vtype_spec'] = vtype_spec
364 xdef[
'genc'][
'base_vtype'] = base_vtype
365 xdef[
'genc'][
'base_vname'] = base_vname
366 xdef[
'genc'][
'macro_len'] = macro_len
367 xdef[
'genc'][
'fielddef'] = fielddef
368 xdef[
'genc'][
'maxlen'] = maxlen
369 xdef[
'genc'][
'active_cnt'] = active_cnt
376 """ Process string XML definition. 379 pathXids - Path (list) of XML ftypedef, msgdef, or fielddef 381 xdef - XML ftypedef, msgdef, or fielddef XML specification. 382 depth - Recursive definition depth. 385 Maximum number of packed bytes required for this encoded definition. 387 ns = self.
mXml[
'meta'][
'ns']
389 ftype = xdef[
'ftype']
390 type_spec = nmBase.NMBuiltInFieldTypes[ftype][
'T']
391 cid = self.
MakeCId(xid, depth==0)
393 fsize = xdef.get(
'size',
'NMFVAL_LEN_MAX_STRING')
394 if nmBase.IsIdentifier(fsize)
and fsize !=
'NMFVAL_LEN_MAX_STRING':
401 nlist = pathXids + [
'len']
404 'token_seq':
'(' + fsize +
')',
405 'comment':
"%s maximum string length" % (
' '.join(pathXids)),
408 const_expr = macro_len[
'name'] +
'+1' 411 encoding = self.
mXml[
'netmsgs'][
'encoding']
412 eq_sum = [nmBase.NMFHdrLen[encoding][
'string']]
413 if macro_len[
'token_seq']:
414 maxcount = macro_len[
'token_seq']
416 maxcount = macro_len[
'name']
427 xdef[
'genc'][
'type_spec'] = type_spec
428 xdef[
'genc'][
'id'] = cid
429 xdef[
'genc'][
'const_expr'] = const_expr
430 xdef[
'genc'][
'comment'] =
"%s string" % (xid)
431 xdef[
'genc'][
'macro_len'] = macro_len
432 xdef[
'genc'][
'maxlen'] = maxlen
433 xdef[
'genc'][
'active_cnt'] = active_cnt
440 """ Process simple XML definition. 443 pathXids - Path (list) of XML ftypedef, msgdef, or fielddef 445 xdef - XML ftypedef, msgdef, or fielddef XML specification. 446 depth - Recursive definition depth. 449 Maximum number of packed bytes required for this encoded definition. 451 ns = self.
mXml[
'meta'][
'ns']
453 ftype = xdef[
'ftype']
454 base_ftype = xdef[
'base_ftype']
455 type_spec = nmBase.NMBuiltInFieldTypes[ftype][
'T']
456 cid = self.
MakeCId(xid, depth==0)
460 encoding = self.
mXml[
'netmsgs'][
'encoding']
461 fhdr_len = nmBase.NMFHdrLen[encoding][
'simple']
462 flen = nmBase.NMBuiltInFieldTypes[base_ftype][
'flen']
468 eq_sum = [fhdr_len, flen]
473 xdef[
'genc'][
'type_spec'] = type_spec
474 xdef[
'genc'][
'id'] = cid
475 xdef[
'genc'][
'const_expr'] = const_expr
476 xdef[
'genc'][
'comment'] =
"%s" % (xid)
477 xdef[
'genc'][
'maxlen'] = maxlen
478 xdef[
'genc'][
'active_cnt'] = active_cnt
485 """ Process derived type XML definition. 488 pathXids - Path (list) of XML ftypedef, msgdef, or fielddef 490 xdef - XML ftypedef, msgdef, or fielddef XML specification. 491 depth - Recursive definition depth. 494 Maximum number of packed bytes required for this encoded definition. 496 ns = self.
mXml[
'meta'][
'ns']
498 fname = xdef[
'ftype']
500 cid = self.
MakeCId(xid, depth==0)
502 base_ftype = xdef[
'base_ftype']
507 bdef = self.
mXml[
'field_types'][bname]
508 maxlen = bdef[
'genc'][
'maxlen']
509 active_cnt = bdef[
'genc'][
'active_cnt']
511 if base_ftype ==
'struct':
512 comment =
"%s structure" % (xid)
513 xdef[
'genc'][
'msgdef'] =
"%s%sMsgDef" % (ns, fname)
514 elif base_ftype ==
'vector':
515 vtype_spec = bdef[
'genc'][
'vtype_spec']
516 const_expr = bdef[
'genc'][
'const_expr']
517 comment =
"%s vector" % (xid)
519 xdef[
'genc'][
'vtype_spec'] = vtype_spec
520 xdef[
'genc'][
'base_vtype'] = bdef[
'vtype']
521 xdef[
'genc'][
'base_vname'] = bname
522 xdef[
'genc'][
'macro_len'] = bdef[
'genc'][
'macro_len']
523 xdef[
'genc'][
'fielddef'] =
"%s%sFieldDef" % (ns, bname)
524 elif base_ftype ==
'string':
528 bdef = self.
mXml[
'field_types'][bname]
529 const_expr = bdef[
'genc'][
'const_expr']
530 comment =
"%s string" % (xid)
532 xdef[
'genc'][
'macro_len'] = bdef[
'genc'][
'macro_len']
537 xdef[
'genc'][
'type_spec'] = type_spec
538 xdef[
'genc'][
'id'] = cid
539 xdef[
'genc'][
'const_expr'] = const_expr
540 xdef[
'genc'][
'comment'] = comment
541 xdef[
'genc'][
'maxlen'] = maxlen
542 xdef[
'genc'][
'active_cnt'] = active_cnt
554 """ Generate C .h and .c source file pair. 557 Raises NetMsgError exception on error. 566 """ Generate h header. 569 Raises NetMsgError exception on error. 575 raise nmBase.NetMsgsError(
"Error: %s" % (err))
589 """ Generate h header. 592 Raises NetMsgError exception on error. 598 raise nmBase.NetMsgsError(
"Error: %s" % (err))
618 """ Generate .h header file prologue. 620 Prologue includes core header file includes plus any prologue specified 624 fp - Opened output file pointer. 626 hdef =
"_" + self.mHBaseName.replace(
".",
"_").upper()
627 prologue = self.
mXml[
'meta'][
'h'][
'prologue']
634 #include "rnr/rnrconfig.h" 635 #include "rnr/netmsgs.h" 639 fp.write(
"%s\n\n" % (prologue))
648 """ Generate .h Message Id enumeration. 651 fp - Opened output file pointer. 653 ns = self.
mXml[
'meta'][
'ns']
654 msgorder = self.
mXml[
'msg_types'][nmBase.NMKeyOrder]
655 section =
'msg_types' 656 if len(msgorder) == 0:
659 fp.write(
"typedef enum\n")
662 nmBase.PrettyPrintCols(fp, 0,
664 40,
'= '+repr(n)+
',',
665 48,
'///< no message\n')
666 for msgid
in msgorder:
667 msgdef = self.
mXml[section][msgid]
669 enum = ns +
"MsgId" + msgid
671 comment =
"%s" % (msgid)
673 comment =
"%s (deprecated)" % (msgid)
674 nmBase.PrettyPrintCols(fp, 0,
676 40,
'= '+repr(n)+
',',
677 48,
"///< %s\n" % (comment))
679 nmBase.PrettyPrintCols(fp, 0,
682 48,
'///< number of message ids\n')
683 fp.write(
"} %s;\n" % (ns+
'MsgId_T'))
689 """ Generate .h header file field types section. 692 fp - Opened output file pointer. 694 section =
'field_types' 695 if len(self.
mXml[section][nmBase.NMKeyOrder]) == 0:
698 for ftid
in self.
mXml[section][nmBase.NMKeyOrder]:
699 ftdef = self.
mXml[section][ftid]
701 "Field Type %s Declarations" % (self.
mXml[
'meta'][
'ns']+ftid))
702 self.
HGenTypedef(fp, ftid, ftdef,
"%s Field Type" % (ftid))
707 """ Generate .h header file message types section. 710 fp - Opened output file pointer. 712 section =
'msg_types' 713 if len(self.
mXml[section][nmBase.NMKeyOrder]) == 0:
716 for msgid
in self.
mXml[section][nmBase.NMKeyOrder]:
717 msgdef = self.
mXml[section][msgid]
719 if msgdef[
'genc'][
'active_cnt'] > 0:
721 "Message %s Declarations" % (self.
mXml[
'meta'][
'ns']+msgid))
722 self.
HGenTypedef(fp, msgid, msgdef,
"Message %s Structure" % (msgid))
727 """ Generate a commented type definition subsection. 730 fp - Opened output file pointer. 731 xid - Unique id in XML database section. 732 xdef - XML ftypedef, msgdef, or fielddef XML database entry. 733 brief - Brief comment string. 735 ns = self.
mXml[
'meta'][
'ns']
736 ftype = xdef[
'ftype']
738 type_spec = xdef[
'genc'][
'type_spec']
739 cid = xdef[
'genc'][
'id']
740 const_expr = xdef[
'genc'][
'const_expr']
749 if ftype ==
'struct':
750 if xdef[
'genc'][
'active_cnt'] == 0:
753 fp.write(
"typedef %s\n{\n" % (type_spec))
755 nmBase.PrettyPrintCols(fp, 0,
757 46,
"///< %s\n" % (xdef[
'genc'].get(
'comment', cid[2:])))
760 elif ftype ==
'vector':
761 vtype_spec = xdef[
'genc'][
'vtype_spec']
776 """ Generate comment structure declaration list (members). 779 fp - Opened output file pointer. 780 fields - XML database field definition 'fields' entry. 781 depth - Current structure depth. 783 ns = self.
mXml[
'meta'][
'ns']
784 for fname
in fields[nmBase.NMKeyOrder]:
786 ftype = fdef[
'ftype']
787 base_ftype = fdef[
'base_ftype']
789 type_spec = fdef[
'genc'][
'type_spec']
790 cid = fdef[
'genc'][
'id']
791 const_expr = fdef[
'genc'][
'const_expr']
802 elif ftype ==
'struct':
803 fp.write(
"%*sstruct\n" % (depth*2,
''))
804 fp.write(
"%*s{\n" % (depth*2,
''))
806 nmBase.PrettyPrintCols(fp, 0,
807 depth*2,
"} %s;" % (cid),
808 46,
"///< %s\n" % (fdef[
'genc'].get(
'comment', cid[2:])))
811 elif ftype ==
'string':
815 elif ftype ==
'vector':
816 vtype_spec = fdef[
'genc'][
'vtype_spec']
824 elif base_ftype ==
'string':
828 elif base_ftype ==
'vector':
838 """ Generation .h cpp #defines macros associated with field or message 842 fp - Opened output file pointer. 843 xid - Unique id in XML database section. 844 xdef - XML ftypedef, msgdef, or fielddef XML database entry. 849 for macro
in [
'macro_len']:
850 if xdef[
'genc'].has_key(macro)
and xdef[
'genc'][macro][
'token_seq']:
851 fp.write(
"/*! %s */\n" % (xdef[
'genc'][macro][
'comment']))
852 fp.write(
"#define %s %s\n\n" % \
853 (xdef[
'genc'][macro][
'name'], xdef[
'genc'][macro][
'token_seq']))
855 if xdef[
'ftype'] ==
'struct':
856 for fname
in xdef[
'fields'][nmBase.NMKeyOrder]:
862 """ Generate .h header public external data. 865 fp - Opened output file pointer. 867 ns = self.
mXml[
'meta'][
'ns']
871 // %s Message Definition Look-Up Table. 872 // (indexed by %sMsgId_T enum) 875 fp.write(
"extern const NMMsgDef_T *%sMsgDefLookupTbl[];\n\n" % (ns))
879 // %s Maximum Message Body Length (bytes) Look-Up Table. 880 // (indexed by %sMsgId_T enum) 883 fp.write(
"extern size_t %sMsgMaxLenLookupTbl[];\n\n" % (ns))
888 """ Generate .h header function prototypes. 891 fp - Opened output file pointer. 893 ns = self.
mXml[
'meta'][
'ns']
894 encoding_pre = self.
mXml[
'genc'][
'encoding_prefix']
895 endian_desc = self.
mXml[
'genc'][
'endian_desc']
896 endian_enum = self.
mXml[
'genc'][
'endian_enum']
900 self.
WriteFuncDef(fp,
'const',
'NMMsgDef_T *',
"%sLookupMsgDef" % (ns),
901 [(
None,
"%sMsgId_T" % (ns),
"eMsgId")])
903 self.
WriteFuncDef(fp,
None,
'size_t',
"%sLookupMsgMaxLen" % (ns),
904 [(
None,
"%sMsgId_T" % (ns),
"eMsgId")])
907 [(
None,
"%sMsgId_T" % (ns),
"eMsgId"),
908 (
None,
"void *",
"pStruct"),
909 (
None,
"byte_t",
"buf[]"),
910 (
None,
"size_t",
"bufSize"),
911 (
None,
"bool_t",
"bTrace")])
913 self.
WriteFuncDef(fp,
None,
'int',
"%sUnpackMsg" % (ns),
914 [(
None,
"%sMsgId_T" % (ns),
"eMsgId"),
915 (
None,
"byte_t",
"buf[]"),
916 (
None,
"size_t",
"uMsgLen"),
917 (
None,
"void *",
"pStruct"),
918 (
None,
"bool_t",
"bTrace")])
920 for msgid
in self.
mXml[
'msg_types'][nmBase.NMKeyOrder]:
921 msgdef = self.
mXml[
'msg_types'][msgid]
922 if self.
IsDeprecated(msgdef)
or msgdef[
'genc'][
'active_cnt'] == 0:
924 self.
WriteFuncDef(fp,
'INLINE_IN_H',
'int',
"%sPack%s" % (ns, msgid),
925 [(
None,
"%s%s_T *" % (ns, msgid),
"pStruct"),
926 (
None,
"byte_t",
"buf[]"),
927 (
None,
"size_t",
"bufSize"),
928 (
None,
"bool_t",
"bTrace")],
930 return %sPackMsg(%sMsgId%s, pStruct, buf, bufSize, bTrace);""" % \
933 \\brief Pack a %s%s %s message in %s byte order 934 into the output buffer. 936 \\param [in] pStruct Pointer to the associated, populated message 938 \\param [out] buf Output message buffer. 939 \\param bufSize Size of output buffer. 940 \\param bTrace Do [not] trace packing. 943 On success, returns the number of bytes packed. 944 On error, returns the appropriate \\h_lt 0 negated NM_ECODE.""" % \
945 (ns, msgid, encoding_pre, endian_desc))
947 self.
WriteFuncDef(fp,
'INLINE_IN_H',
'int',
"%sUnpack%s" % (ns, msgid),
948 [(
None,
"byte_t",
"buf[]"),
949 (
None,
"size_t",
"uMsgLen"),
950 (
None,
"%s%s_T *" % (ns, msgid),
"pStruct"),
951 (
None,
"bool_t",
"bTrace")],
953 return %sUnpackMsg(%sMsgId%s, buf, uMsgLen, pStruct, bTrace);""" % \
956 \\brief Unpack a %s%s %s message in %s byte order 957 from the input buffer. 959 \\param [in] buf Output message buffer. 960 \\param uMsgLen Length of message (bytes) in input buffer. 961 \\param [out] pStruct Pointer to the associated message structure. 962 \\param bTrace Do [not] trace packing. 965 On success, returns the number of bytes unpacked. 966 On error, returns the appropriate \\h_lt 0 negated NM_ECODE.""" % \
967 (ns, msgid, encoding_pre, endian_desc))
972 """ Generate .h header file epilogue. 975 fp - Opened output file pointer. 977 hdef =
"_" + self.mHBaseName.replace(
".",
"_").upper()
978 epilogue = self.
mXml[
'meta'][
'h'][
'epilogue']
984 fp.write(
"\n\n%s" % (epilogue))
988 #endif // %s\n""" % (hdef))
998 """ Generate .c source file prologue. 1000 Prologue includes core header file includes plus any prologue specified 1004 fp - Opened output file pointer. 1006 incpre = self.mIncPrefix.strip()
1007 if len(incpre) > 0
and incpre[-1] != os.path.sep:
1008 incpre += os.path.sep
1009 prologue = self.
mXml[
'meta'][
'c'][
'prologue']
1013 #include "rnr/rnrconfig.h" 1014 #include "rnr/log.h" 1015 #include "rnr/netmsgs.h" 1020 /*! End of Field Definition entry. */ 1021 #define EOFDEF {NULL, 0, NMFTypeNone, 0, } 1026 fp.write(
"%s\n\n" % (prologue))
1031 """ Generate .c field and message definitions from 'field_types' section. 1034 fp - Opened output file pointer. 1036 ns = self.
mXml[
'meta'][
'ns']
1037 for ftid
in self.
mXml[
'field_types'][nmBase.NMKeyOrder]:
1038 ftdef = self.
mXml[
'field_types'][ftid]
1039 ftype = ftdef[
'ftype']
1040 if ftype
in [
'struct',
'vector']:
1048 """ Generate .c field and message definitions from 'msg_types' section. 1051 fp - Opened output file pointer. 1053 ns = self.
mXml[
'meta'][
'ns']
1054 for msgid
in self.
mXml[
'msg_types'][nmBase.NMKeyOrder]:
1055 msgdef = self.
mXml[
'msg_types'][msgid]
1064 """ Recursively generate .c message related data C definition statements. 1067 field ID enum declarations 1068 field definition arrays 1069 message/struct definitions 1072 fp - Opened output file pointer. 1073 pathXids - Path list of XML ftypedef, msgdef, or fielddef 1075 xdef - XML ftypedef, msgdef, or fielddef XML specification. 1077 if xdef[
'ftype'] ==
'struct':
1078 for fname
in xdef[
'fields'][nmBase.NMKeyOrder]:
1079 self.
CGenDefsR(fp, pathXids+[fname], xdef[
'fields'][fname])
1084 elif xdef[
'ftype'] ==
'vector':
1090 """ Generate .c field id enum declaration for the given definition. 1093 fp - Opened output file pointer. 1094 pathXids - Path list of XML identifiers. 1095 xdef - XML ftypedef, msgdef, or fielddef XML specification. 1097 ns = self.
mXml[
'meta'][
'ns']
1098 fields = xdef[
'fields']
1099 nsname = ns +
''.join(pathXids)
1101 fp.write(
"typedef enum\n{\n")
1103 nmBase.PrettyPrintCols(fp, 0,
1104 2,
"%sFIdReserved" % (nsname),
1105 40,
"= %d," % (enum),
1106 48,
"///< reserved field id\n",
1109 for fname
in fields[nmBase.NMKeyOrder]:
1110 fdef = fields[fname]
1111 if fdef[
'ftype'] ==
'pad':
1112 fname =
'_pad' + repr(enum)
1114 comment =
"%s field id" % (fname)
1116 comment =
"%s field id (deprecated)" % (fname)
1117 nmBase.PrettyPrintCols(fp, 0,
1118 2,
"%sFId%s" % (nsname, fname),
1119 40,
"= %d," % (enum),
1120 48,
"///< %s\n" % (comment),
1123 nmBase.PrettyPrintCols(fp, 0,
1124 2,
"%sFIdNumOf" % (nsname),
1125 40,
"= %d" % (enum),
1126 48,
"///< number of fields\n",
1128 fp.write(
"} %sFId_T;\n\n" % (nsname))
1133 """ Generate .c anonomous structure type. 1135 Anonomous structures mirror any inline, non-global 'struct' field 1136 types. External structures are required to calculate member offsets 1140 fp - Opened output file pointer. 1141 pathXids - Path list of XML identifiers. 1142 xdef - XML ftypedef, msgdef, or fielddef XML specification. 1144 ftype = xdef[
'ftype']
1148 elif len(pathXids) <= 1:
1150 elif self.
mXml[
'field_types'].has_key(ftype):
1152 if xdef[
'genc'][
'active_cnt'] == 0:
1155 ns = self.
mXml[
'meta'][
'ns']
1156 xname =
''.join(pathXids)
1158 fields = xdef[
'fields']
1160 anon_type_spec =
'_' + xname +
'_T' 1163 "%s Anonumous Struture Type" % (
' '.join(pathXids)))
1164 fp.write(
"typedef struct\n{\n")
1166 fp.write(
"} %s;\n\n" % (anon_type_spec))
1169 xdef[
'genc'][
'anon_type_spec'] = anon_type_spec
1174 """ Generate .c field definition array for the given definition. 1177 fp - Opened output file pointer. 1178 pathXids - Path list of XML identifiers. 1179 xdef - XML ftypedef, msgdef, or fielddef XML specification. 1181 ns = self.
mXml[
'meta'][
'ns']
1182 fields = xdef[
'fields']
1183 nsname = ns +
''.join(pathXids)
1184 pid = xdef[
'genc'][
'id']
1188 struct_id = xdef[
'genc'].get(
'anon_type_spec', pid)
1191 fp.write(
"static const NMFieldDef_T %sFieldDefs[] =\n{\n" % (nsname))
1192 for fname
in fields[nmBase.NMKeyOrder]:
1193 fdef = fields[fname]
1194 ftype = fdef[
'ftype']
1195 base_ftype = fdef[
'base_ftype']
1196 cid = fdef[
'genc'][
'id']
1203 sFName =
'_pad'+repr(enum)
1204 eFId =
"%sFId%s" % (nsname, sFName)
1205 eFType =
"NMFType%s" % (base_ftype.capitalize())
1206 uOffset =
"(size_t)0" 1209 eFId =
"%sFId%s" % (nsname, fname)
1210 eFType =
"NMFType%s" % (base_ftype.capitalize())
1211 uOffset =
"memberoffset(%s, %s)" % (struct_id, cid)
1215 self.
WriteFDefEntry(fp, sFName, eFId, eFType, uOffset, this, this_init)
1218 nmBase.PrettyPrintCols(fp, 0, 2, eofdef+
'\n')
1224 """ Generate .c vector item field definition array for the given definition. 1227 fp - Opened output file pointer. 1228 pathXids - Path list of XML identifiers. 1229 xdef - XML ftypedef, msgdef, or fielddef XML specification. 1231 ns = self.
mXml[
'meta'][
'ns']
1232 fname = pathXids[-1]
1233 nsname = ns +
''.join(pathXids)
1235 ftype = xdef[
'ftype']
1236 vtype = xdef[
'vtype']
1237 cid = xdef[
'genc'][
'id']
1238 base_vtype = xdef[
'genc'][
'base_vtype']
1239 base_vname = xdef[
'genc'][
'base_vname']
1244 if base_vname ==
'this':
1247 base_vname = xdef[
'genc'][
'base_vname']
1248 base_fdef = self.
mXml[
'field_types'][base_vname]
1250 fielddef =
"%sFieldDef" % (nsname)
1253 eFType =
"NMFType%s" % (base_vtype.capitalize())
1254 uOffset =
"(size_t)0" 1259 fp.write(
"static const NMFieldDef_T %s[] =\n{\n" % (fielddef))
1260 self.
WriteFDefEntry(fp, sFName, eFId, eFType, uOffset, this, this_init)
1261 nmBase.PrettyPrintCols(fp, 0, 2, eofdef+
'\n')
1267 """ Make C field definition this specific initialization for field type. 1270 ftype - XML field type. 1271 fdef - XML field definition. 1274 Returns the pair (this, this_init) where: 1275 this - C union name. 1276 this_int - List of (.member, value) pairs. 1278 nothis_ftype = [
'bool',
'char',
'p32',
'p64']
1285 elif ftype
in nmBase.NMFTypeNumber:
1289 elif ftype
in nothis_ftype:
1293 elif ftype ==
'string':
1297 elif ftype ==
'struct':
1301 elif ftype ==
'vector':
1311 """ Make C field definition this specific initialization for pad 'field'. 1314 ftype - XML field type. 1315 fdef - XML field definition. 1318 Returns the pair (this, this_init) where: 1319 this - C union name. 1320 this_int - List of (.member, value) pairs. 1323 this_init = [(
'm_uCount',
"(byte_t)(%s)" % fdef.get(
'count',
"1"))]
1324 return this, this_init
1329 """ Make C field definition this specific initialization for number field. 1332 ftype - XML field type. 1333 fdef - XML field definition. 1336 Returns the pair (this, this_init) where: 1337 this - C union name. 1338 this_int - List of (.member, value) pairs. 1345 this =
'm_u' + ftype[1:]
1346 casttype = nmBase.NMBuiltInFieldTypes[
'u'+ftype[1:]]['T']
1349 casttype = nmBase.NMBuiltInFieldTypes[ftype][
'T']
1350 if fdef.has_key(
'min'):
1352 bits +=
"%sNMBITS_HAS_MIN" % (bitssep)
1356 this_init += [(
'm_valMin',
"(%s)(%s)" % (casttype, val))]
1358 if fdef.has_key(
'max'):
1360 bits +=
"%sNMBITS_HAS_MAX" % (bitssep)
1364 this_init += [(
'm_valMax',
"(%s)(%s)" % (casttype, val))]
1366 if fdef.has_key(
'const'):
1368 bits +=
"%sNMBITS_HAS_CONST" % (bitssep)
1372 this_init += [(
'm_valConst',
"(%s)(%s)" % (casttype, val))]
1376 this_init = [(
'm_bits',
"(byte_t)(%s)" % bits)] + this_init
1378 return this, this_init
1383 """ Make C field definition this specific initialization for string field. 1386 ftype - XML field type. 1387 fdef - XML field definition. 1390 Returns the pair (this, this_init) where: 1391 this - C union name. 1392 this_int - List of (.member, value) pairs. 1396 casttype = nmBase.NMBuiltInFieldTypes[ftype][
'T']
1398 val = fdef[
'genc'][
'const_expr']
1399 this_init += [(
'm_uMaxCount',
"(size_t)%s" % (val))]
1401 if fdef.has_key(
'const'):
1405 this_init += [(
'm_sConst',
"(%s *)(%s)" % (casttype, val))]
1407 return this, this_init
1412 """ Make C field definition this specific initialization for struct field. 1415 ftype - XML field type. 1416 fdef - XML field definition. 1419 Returns the pair (this, this_init) where: 1420 this - C union name. 1421 this_int - List of (.member, value) pairs. 1424 this_init = [(
'',
"&%s" % (fdef[
'genc'][
'msgdef']))]
1425 return this, this_init
1430 """ Make C field definition this specific initialization for vector field. 1433 ftype - XML field type. 1434 fdef - XML field definition. 1437 Returns the pair (this, this_init) where: 1438 this - C union name. 1439 this_int - List of (.member, value) pairs. 1444 val = fdef[
'genc'][
'const_expr']
1445 this_init += [(
'm_uMaxCount',
"(size_t)%s" % (val))]
1446 this_init += [(
'm_uElemSize',
1447 "sizeof(%s)" % (fdef[
'genc'][
'vtype_spec']))]
1448 this_init += [(
'm_pThisElem', (fdef[
'genc'][
'fielddef']))]
1450 return this, this_init
1455 """ Make C field definition this specific initialization for vector field. 1458 ftype - XML field type. 1459 fdef - XML field definition. 1462 Returns the pair (this, this_init) where: 1463 this - C union name. 1464 this_int - List of (.member, value) pairs. 1466 base_ftype = fdef[
'base_ftype']
1467 if base_ftype
in nmBase.NMFTypeNumber:
1469 elif base_ftype ==
'string':
1471 elif base_ftype ==
'struct':
1473 elif base_ftype ==
'vector':
1481 """ Generate .c source file [sub]message definition from the given 1485 fp - Opened output file pointer. 1486 pathXids - Path list of XML identifiers. 1487 xdef - XML ftypedef, msgdef, or fielddef XML specification. 1489 ns = self.
mXml[
'meta'][
'ns']
1490 xname =
''.join(pathXids)
1498 if len(pathXids) == 1
and self.
mXml[
'msg_types'].has_key(pathXids[0]):
1499 msgid_enum =
"%sMsgId%s" % (ns, xname),
1501 msgid_enum =
"%sMsgIdNone" % (ns),
1503 fp.write(
"static const NMMsgDef_T %sMsgDef =\n{\n" % (nsname))
1504 nmBase.PrettyPrintCols(fp, 0,
1507 24,
"\"%s\"," % (nsname),
1510 24,
"%s," % (msgid_enum),
1513 24,
"(size_t)(%d)," % (xdef[
'genc'][
'active_cnt']),
1516 24,
"%sFieldDefs\n" % (nsname))
1522 """ Generate .c source file look-up tables. 1525 fp - Opened output file pointer. 1527 ns = self.
mXml[
'meta'][
'ns']
1529 "%s Message Definition Look-Up Table. Indexed by %sMsgId_T enum." % \
1531 fp.write(
"const NMMsgDef_T *%sMsgDefLookupTbl[] =\n" % ns)
1533 nmBase.PrettyPrintCols(fp, 0,
1535 40,
"///< [%sMsgIdNone]\n" % (ns))
1536 for msgid
in self.
mXml[
'msg_types'][nmBase.NMKeyOrder]:
1538 nmBase.PrettyPrintCols(fp, 0,
1539 2,
"&%s%sMsgDef," % (ns, msgid),
1540 40,
"///< [%sMsgId%s]\n" % (ns, msgid))
1542 nmBase.PrettyPrintCols(fp, 0,
1544 40,
"///< [%sMsgId%s]\n" % (ns, msgid))
1545 nmBase.PrettyPrintCols(fp, 0,
1547 40,
"///< [%sMsgIdNumOf]\n" % (ns))
1551 "%s Message Maximum Size Look-Up Table. Indexed by %sMsgId_T enum." % \
1553 fp.write(
"size_t %sMsgMaxLenLookupTbl[] =\n" % ns)
1555 nmBase.PrettyPrintCols(fp, 0,
1557 40,
"///< [%sMsgIdNone]\n" % (ns))
1558 for msgid
in self.
mXml[
'msg_types'][nmBase.NMKeyOrder]:
1559 nmBase.PrettyPrintCols(fp, 0,
1560 2,
"(size_t)(%s)," % (self.
mXml[
'msg_types'][msgid][
'genc'][
'maxlen']),
1561 40,
"///< [%sMsgId%s]\n" % (ns, msgid))
1562 nmBase.PrettyPrintCols(fp, 0,
1564 40,
"///< [%sMsgIdNumOf]\n" % (ns))
1570 """ Generate .c source file function definitions. 1573 fp - Opened output file pointer. 1575 ns = self.
mXml[
'meta'][
'ns']
1576 encoding_pre = self.
mXml[
'genc'][
'encoding_prefix']
1577 endian_desc = self.
mXml[
'genc'][
'endian_desc']
1578 endian_enum = self.
mXml[
'genc'][
'endian_enum']
1583 self.
WriteFuncDef(fp,
'const',
'NMMsgDef_T *',
"%sLookupMsgDef" % (ns),
1584 [(
None,
"%sMsgId_T" % (ns),
"eMsgId")],
1586 if( (uint_t)eMsgId >= (uint_t)%sMsgIdNumOf ) 1592 return %sMsgDefLookupTbl[(uint_t)eMsgId]; 1595 \\brief Look up the message definition associated with the message id. 1597 \\param eMsgId Message Id. 1600 On success, returns the pointer to the NMMsgDef_T. 1601 On error, NULL is returned.""")
1604 self.
WriteFuncDef(fp,
None,
'size_t',
"%sLookupMsgMaxLen" % (ns),
1605 [(
None,
"%sMsgId_T" % (ns),
"eMsgId")],
1607 if( (uint_t)eMsgId >= (uint_t)%sMsgIdNumOf ) 1613 return %sMsgMaxLenLookupTbl[(uint_t)eMsgId]; 1616 \\brief Look up the message maximum length associated with the message id. 1618 The maximum length is the total number of packed bytes possible for the 1619 given message. The message may be much shorter. 1621 \\param eMsgId Message Id. 1624 On success, returns the number of bytes. 1625 On error, 0 is returned.""")
1629 [(
None,
"%sMsgId_T" % (ns),
"eMsgId"),
1630 (
None,
"void *",
"pStruct"),
1631 (
None,
"byte_t",
"buf[]"),
1632 (
None,
"size_t",
"bufSize"),
1633 (
None,
"bool_t",
"bTrace")],
1635 const NMMsgDef_T *pMsgDef; 1637 if( (pMsgDef = %sLookupMsgDef(eMsgId)) == NULL ) 1639 LOGERROR("%%s(ecode=%%d): msgid=%%u.", 1640 nmStrError(NM_ECODE_MSGID), NM_ECODE_MSGID, eMsgId); 1641 return -NM_ECODE_MSGID; 1646 return nmPack%sMsgDebug(pMsgDef, pStruct, buf, bufSize, %s); 1650 return nmPack%sMsg(pMsgDef, pStruct, buf, bufSize, %s); 1651 }""" % (ns, encoding_pre, endian_enum, encoding_pre, endian_enum),
1653 \\brief Pack a %s message in %s byte order. 1655 \\param eMsgId Message Id. 1656 \\param [in] pStruct Pointer to the associated, populated message 1658 \\param [out] buf Output message buffer. 1659 \\param bufSize Size of output buffer. 1660 \\param bTrace Do [not] trace packing. 1663 On success, returns the number of bytes packed. 1664 On error, returns the appropriate \< 0 negated NM_ECODE.""" % \
1665 (encoding_pre, endian_desc))
1668 self.
WriteFuncDef(fp,
None,
'int',
"%sUnpackMsg" % (ns),
1669 [(
None,
"%sMsgId_T" % (ns),
"eMsgId"),
1670 (
None,
"byte_t",
"buf[]"),
1671 (
None,
"size_t",
"uMsgLen"),
1672 (
None,
"void *",
"pStruct"),
1673 (
None,
"bool_t",
"bTrace")],
1675 const NMMsgDef_T *pMsgDef; 1677 if( (pMsgDef = %sLookupMsgDef(eMsgId)) == NULL ) 1679 LOGERROR("%%s(ecode=%%d): msgid=%%u.", 1680 nmStrError(NM_ECODE_MSGID), NM_ECODE_MSGID, eMsgId); 1681 return -NM_ECODE_MSGID; 1686 return nmUnpack%sMsgDebug(pMsgDef, buf, uMsgLen, pStruct, %s); 1690 return nmUnpack%sMsg(pMsgDef, buf, uMsgLen, pStruct, %s); 1691 }""" % (ns, encoding_pre, endian_enum, encoding_pre, endian_enum),
1693 \\brief Unpack a %s message in %s byte order. 1695 \\param eMsgId Message Id. 1696 \\param [in] buf Input message buffer. 1697 \\param uMsgLen Length of message (bytes) in input buffer. 1698 \\param [out] pStruct Pointer to the associated message structure. 1699 \\param bTrace Do [not] trace packing. 1702 On success, returns the number of bytes unpacked. 1703 On error, returns the appropriate \< 0 negated NM_ECODE.""" % \
1704 (encoding_pre, endian_desc))
1709 """ Generate .c source file epilogue. 1712 fp - Opened output file pointer. 1714 epilogue = self.
mXml[
'meta'][
'c'][
'epilogue']
1716 fp.write(
"\n\n%s" % (epilogue))
1726 """ Make CPP #define macro name. 1729 names - List of argument subnames. 1732 String "NS_ARG1_..._ARGN" 1734 defname = self.
mXml[
'meta'][
'ns']
1737 return defname.upper()
1742 """ Make C type specifier. 1750 if nmBase.NMBuiltInFieldTypes.has_key(ftype):
1751 type_spec = nmBase.NMBuiltInFieldTypes[ftype][
'T']
1753 type_spec = self.
mXml[
'meta'][
'ns'] + ftype +
'_T' 1759 """ Make C indentifier. 1762 xid - XML [sub]definition id. 1763 isGlobal - Identifier does [not] have global scope. 1769 cid = self.
mXml[
'meta'][
'ns'] + xid +
'_T' 1772 if self.
mHungarian: pre += nmBase.NMBuiltInFieldTypes[ftype][
'pre']
1778 """ Write commented structure declarator. 1782 | type_spec cid [ const_expr ] ; 1785 fp - Opened output file pointer. 1786 indent - Indentation. 1787 type_spec - C type specifier. 1789 const_expr - C array constant expression. None of not an array. 1790 kwargs - Optional keyword arguments. 1791 'comment':string - Overide default comment. 1794 post =
'[' + const_expr +
']' 1797 comment = kwargs.get(
'comment', cid[2:])
1798 nmBase.PrettyPrintCols(fp, 0,
1801 46,
"///< %s\n" % (comment))
1806 """ Write commented structure vector declarator. 1808 struct_vector_decl ::- 1813 vtype_spec m_buf [ const_expr ] ; 1818 fp - Opened output file pointer. 1819 indent - Indentation. 1820 vtype_spec - C vector items type specifier. 1822 const_expr - C array constant expression. None of not an array. 1823 kwargs - Optional keyword arguments. 1824 'comment':string - Overide default comment. 1826 fp.write(
"%*s%s\n" % (indent,
'',
'struct'))
1827 fp.write(
"%*s{\n" % (indent,
''))
1829 comment=
"vector item count")
1830 fp.write(
"%*s%s\n" % (indent+2,
'',
'union'))
1831 fp.write(
"%*s{\n" % (indent+2,
''))
1833 comment=
"force alignment")
1835 comment=
"the item vector")
1836 fp.write(
"%*s} u; ///< aligned vector items\n" % (indent+2,
''))
1837 nmBase.PrettyPrintCols(fp, 0,
1838 indent,
"} %s;" % (cid),
1839 46,
"///< vector\n")
1844 """ Write typedef declaration. 1847 typedef type_spec cid ; 1848 | typedef type_spec cid [ const_expr ] ; 1851 fp - Opened output file pointer. 1852 type_spec - C type specifier. 1854 const_expr - C array constant expression. None of not an array. 1857 post =
'[' + const_expr +
']' 1860 fp.write(
"typedef %s %s%s;\n" % (type_spec, cid, post))
1864 def WriteFuncDef(self, fp, type_qual, type_spec, funcname, funcargs,
1866 """ Write function declaration statement. 1869 extern type_qual type_spec funcname ( arg_list ) ; 1870 | extern type_spec funcname ( arg_list ) ; 1871 | type_qual type_spec funcname ( arg_list ) { stmts } 1872 | type_spec funcname ( arg_list ) { stmts } 1877 | arg_list , arg_decl 1880 type_qual type_spec cid 1884 fp - Opened output file pointer. 1885 type_qual - C function type qualifier(s). 1886 type_spec - C function type specifier(s). 1887 funcname - C function identifier. 1888 funcargs - List of function arguments 3-tuple: 1889 (type_qual(s), type_spec(s), cid) 1890 kwargs - Dictionary of optional arguments. 1894 comments = kwargs.get(
'comments',
'')
1895 stmts = kwargs.get(
'stmts',
'')
1897 s =
"%s %s %s(" % (type_qual, type_spec, funcname)
1899 s =
"%s %s(" % (type_spec, funcname)
1904 for l
in comments.splitlines():
1905 fp.write(
" * %s\n" % l)
1913 for arg3tuple
in funcargs:
1917 s =
"%s %s %s%s" % (arg3tuple[0], arg3tuple[1], arg3tuple[2], sep)
1919 s =
"%s %s%s" % (arg3tuple[1], arg3tuple[2], sep)
1920 nmBase.PrettyPrintCols(fp, cursor, indent, s, force=
True)
1926 for stmt
in stmts.splitlines():
1927 fp.write(
" %s\n" % stmt)
1935 """ Write an NMFieldDef_T entry. 1938 fp - Opened output file pointer. 1939 sFName - m_sFName value. 1940 eFId - m_eFId value. 1941 eFType - m_eFType value. 1942 uOffset - m_uOffset value. 1943 this - m_this.<this> 1944 this_init - List of (member, value) this pairs. 1947 nmBase.PrettyPrintCols(fp, 0,
1950 32,
"\"%s\"," % (sFName),
1956 32,
"%s," % (eFType),
1959 32,
"%s,\n" % (uOffset))
1960 for dotassign
in this_init:
1962 this_mem =
'.' + dotassign[0]
1965 this_val = dotassign[1]
1966 nmBase.PrettyPrintCols(fp, 0,
1967 4,
".m_this.%s%s" % (this, this_mem),
1969 32,
"%s,\n" % this_val)
1975 """ Returns True (False) is field type is (not) simple. 1978 ftype - (Derived) field type. 1986 elif nmBase.NMBuiltInFieldTypes[ftype][
'comp'] ==
'simple':
1994 """ Returns True (False) is definition is (not) deprecated. 1997 xdef - XML ftypedef, msgdef, or fielddef XML specification. 2002 dispo = xdef.get(
'disposition',
'active')
2003 if dispo ==
'deprecated':
2011 """ Returns the base field XML cross-reference name for the given XML 2015 fname - (Derived) field name. 2018 Returns 'this' if fname is a base field, otherwise the XML 2019 cross-referenced field name is returned. 2021 if nmBase.NMBuiltInFieldTypes.has_key(fname):
2023 ftype = self.
mXml[
'field_types'][fname][
'ftype']
2024 while not nmBase.NMBuiltInFieldTypes.has_key(ftype):
2026 ftype = self.
mXml[
'field_types'][fname][
'ftype']
2032 """ Returns the base field type for the given field type. 2035 ftype - (Derived) field type. 2042 while not nmBase.NMBuiltInFieldTypes.has_key(ftype):
2043 if self.
mXml[
'field_types'].has_key(ftype):
2044 ftype = self.
mXml[
'field_types'][ftype][
'ftype']
2046 raise nmBase.NetMsgsError(
"Error: %s is not a defined ftype" % (ftype))
2052 """ Evaluate a summation of terms. 2055 args List of summation terms, with each term one of: 2056 an equation, string, number 2060 5, '(3 * 10)' -> '35' 2061 5, 'MY_MAX', '1*255' -> '300+MY_MAX' 2064 Returns string of the evaluated results. 2072 if type(arg) == str:
2073 arg = arg.replace(
"NMFVAL_LEN_MAX_STRING",
2074 repr(nmBase.NMStringMaxCount))
2075 arg = arg.replace(
"NMFVAL_LEN_MAX_VECTOR",
2076 repr(nmBase.NMVectorMaxCount))
2080 expr = expr +
'+' + arg
2094 def _Simplify(self, expr):
2095 """ Simplify algebraic expression. The simplification is very simple. 2097 The distribution law is not applied. 2100 expr - Algebraic expression in string format. 2103 Simplified algebraic expression in string format. 2105 expr = expr.replace(
' ',
'')
2108 if type(val) == str:
2115 def _EvalTree(self, tree):
2116 """ Evaluate algebraic expression in a tree format. 2121 Only '+' and '*' operators are supported. 2124 tree - Algebraic expression tree 2127 Evaluated number or string. 2129 if type(tree) == list:
2133 if type(lval) == str:
2134 if type(rval) == str:
2135 return '('+lval+op+rval+
')' 2141 elif (rval == 1)
and (op ==
'*'):
2144 return '('+lval+op+repr(rval)+
')' 2145 elif type(rval) == str:
2146 if type(lval) == str:
2147 return '('+lval+op+rval+
')' 2153 elif (lval == 1)
and (op ==
'*'):
2156 return '('+repr(lval)+op+rval+
')' 2162 return '('+repr(lval)+op+repr(rval)+
')' 2171 def _MakeTree(self, expr):
2172 """ Make expression tree. 2178 tree - Algebraic expression tree 2196 def _ParenExprParen(self, expr, start=0):
2197 """ Test if expression is of form '(' expr ')' 2200 expr - Algebraic expression string. 2201 start - Start index in expr. 2206 if expr[start] !=
'(':
2209 if n == len(expr)-1:
2216 def _FindRParen(self, expr, lparen=0):
2217 """ Find corresponding right parentheses. 2220 expr - Algebraic expression string. 2221 lparen - Start index in expression of left parenthesis. 2224 Right parenthesis index in expr. 2228 for c
in expr[lparen+1:]:
2240 def _FindLowOp(self, expr, start=0):
2241 """ Find operator with lowest precedence in expression. 2243 Only '+' and '*' operators are supported. 2246 expr - Algebraic expression string. 2247 start - Start index in search. 2250 Operator index in expression if found. Else None. 2255 while n < len(expr):
2278 """ Prints source file top comment block. 2281 fp - Opened output file pointer. 2282 srcbasename - Base name of source file. 2283 brief - Brief comment. 2285 xmlfilename = self.mXml.GetXMLFileName()
2286 now = time.localtime()
2287 thisdate =
"%d.%02d.%02d" % (now.tm_year, now.tm_mon, now.tm_mday)
2288 thistime =
"%02d:%02d:%02d" % (now.tm_hour, now.tm_min, now.tm_sec)
2290 /////////////////////////////////////////////////////////////////////////////// 2299 * \\warning This file was auto-generated on %s %s from the NetMsgs 2300 * XML specification %s. 2303 * (C) %d. RoadNarrows LLC 2304 * (http://www.roadnarrows.com) 2305 * All Rights Reserved 2307 /////////////////////////////////////////////////////////////////////////////// 2308 """ % (srcbasename, brief, thisdate, thistime, xmlfilename, now.tm_year))
2313 """ Prints major file division comment block. 2316 fp - Opened output file pointer. 2317 comment - Major division comment line. 2321 //----------------------------------------------------------------------------- 2323 //----------------------------------------------------------------------------- 2330 """ Prints minor file division comment block. 2333 fp - Opened output file pointer. 2334 comment - Minor division comment line. 2338 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2340 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2347 """ Print doxygen brief comment block. 2350 fp - Opened output file pointer. 2351 brief - Brief comment. mHBaseName
output .h header file basename
def WriteStructDecl(self, fp, indent, type_spec, cid, const_expr, kwargs)
def CMakeFieldDefThisDerived(self, ftype, fdef)
def CGenFIdEnum(self, fp, pathXids, xdef)
def CMakeFieldDefThisString(self, ftype, fdef)
def Pass0XmlDefStruct(self, pathXids, xdef, depth)
def _EvalTree(self, tree)
def PrettyPrintTopComment(self, fp, srcbasename, brief)
def CGenMsgTypes(self, fp)
def IsDeprecated(self, xdef)
def CGenVectorItemFieldDef(self, fp, pathXids, xdef)
def HGenTypedefMacros(self, fp, xid, xdef)
def HGenTypedef(self, fp, xid, xdef, brief)
def CGenAnonStruct(self, fp, pathXids, xdef)
def Pass0XmlDefString(self, pathXids, xdef, depth)
def WriteFDefEntry(self, fp, sFName, eFId, eFType, uOffset, this, this_init)
def CMakeFieldDefThisStruct(self, ftype, fdef)
def HGenStructDeclList(self, fp, fields, depth)
NetMsgs Base Data Module.
def CGenEpilogue(self, fp)
def HGenFieldTypes(self, fp)
def IsSimple(self, ftype)
def Pass0XmlDefDerived(self, pathXids, xdef, depth)
def MakeTypeSpec(self, ftype)
def BaseXRef(self, fname)
def _Simplify(self, expr)
def WriteVectortDecl(self, fp, indent, vtype_spec, cid, const_expr)
def Pass0XmlDefPad(self, pathXids, xdef, depth)
mCBaseName
output .c header file basename
def _FindRParen(self, expr, lparen=0)
def CGenFieldTypes(self, fp)
def Pass0XmlDef(self, pathXids, xdef, depth)
NetMsgs XML parser module.
def WriteFuncDef(self, fp, type_qual, type_spec, funcname, funcargs, kwargs)
def HGenPrologue(self, fp)
def BaseFType(self, ftype)
def CMakeFieldDefThisNumber(self, ftype, fdef)
def HGenExternData(self, fp)
def CGenFieldDefs(self, fp, pathXids, xdef)
def _FindLowOp(self, expr, start=0)
def CGenLookupTbls(self, fp)
def MakeCId(self, xid, isGlobal)
def CGenPrologue(self, fp)
def PrettyPrintBriefComment(self, fp, brief)
def __init__(self, xml, hfilepath, cfilepath, kwargs)
mHFilePath
output .h header file name
mHungarian
do [not] prepend RN Hungarian notation to message fields
def WriteTypedefStmt(self, fp, type_spec, cid, const_expr)
def MakeCppMacroName(self, names)
def CGenPublicFuncDefs(self, fp)
def HGenEpilogue(self, fp)
def Pass0XmlDefSimple(self, pathXids, xdef, depth)
def PrettyPrintMinorDivComment(self, fp, comment)
def _ParenExprParen(self, expr, start=0)
def PrettyPrintMajorDivComment(self, fp, comment)
def CGenMsgDef(self, fp, pathXids, xdef)
def HGenMsgTypes(self, fp)
def CMakeFieldDefThisVector(self, ftype, fdef)
def CGenDefsR(self, fp, pathXids, xdef)
mCFilePath
output .c header file name
def HGenProtoTypes(self, fp)
def Pass0XmlDefVector(self, pathXids, xdef, depth)
def CMakeFieldDefThisPad(self, ftype, fdef)
def _MakeTree(self, expr)
def CMakeFieldDefThis(self, ftype, fdef)