NetMsgs.NetMsgsGenC
index
/prj/rnr-sdk/netmsgs/nmPython/modules/NetMsgs/NetMsgsGenC.py

NetMsgs Generate C files module.
 
A pair of C .h header and .c source files are generated from a  RoadNarrows
NetMsg XML specification.

 
Modules
       
NetMsgs.NetMsgsXmlParser
NetMsgs.NetMsgsBase
os
sys
time

 
Classes
       
NetMsgsGenC

 
class NetMsgsGenC
    RoadNarrows Net Messages C Source Generator Class.
 
The NetMsgsGenC class reads the post-parsed database of a NetMsgsXmlParser
class instance and generates a C .h and .c file pair. The C files expects
the libnetmsgs C library.
 
  Methods defined here:
AugmentXmlDB(self)
Augument the XML database of parsed XML values with C generated
parameters.
BaseFType(self, ftype)
Returns the base field type for the given field type.
 
 Parameters:
   ftype   - (Derived) field type.
 
Return:
   Base field type.
BaseXRef(self, fname)
Returns the base field XML cross-reference name for the given XML
 name.
 
 Parameters:
   fname   - (Derived) field name.
 
Return:
   Returns 'this' if fname is a base field, otherwise the XML
   cross-referenced field name is returned.
CGenAnonStruct(self, fp, pathXids, xdef)
Generate .c anonomous structure type.
 
Anonomous structures mirror any inline, non-global 'struct' field
types. External structures are required to calculate member offsets
correctlhy.
 
Parameters:
  fp        - Opened output file pointer.
  pathXids  - Path list of XML identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
CGenDefsR(self, fp, pathXids, xdef)
Recursively generate .c message related data C definition statements.
 
Data generated:
  field ID enum declarations
  field definition arrays
  message/struct definitions
 
Parameters:
  fp        - Opened output file pointer.
  pathXids  - Path list of XML ftypedef, msgdef, or fielddef
              identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
CGenEpilogue(self, fp)
Generate .c source file epilogue.
 
Parameters:
  fp    - Opened output file pointer.
CGenFIdEnum(self, fp, pathXids, xdef)
Generate .c field id enum declaration for the given definition.
 
Parameters:
  fp        - Opened output file pointer.
  pathXids  - Path list of XML identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
CGenFieldDefs(self, fp, pathXids, xdef)
Generate .c field definition array for the given definition.
 
Parameters:
  fp        - Opened output file pointer.
  pathXids  - Path list of XML identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
CGenFieldTypes(self, fp)
Generate .c field and message definitions from 'field_types' section.
 
Parameters:
  fp    - Opened output file pointer.
CGenLookupTbls(self, fp)
Generate .c source file look-up tables.
 
Parameters:
  fp    - Opened output file pointer.
CGenMsgDef(self, fp, pathXids, xdef)
Generate .c source file [sub]message definition from the given
definition.
 
Parameters:
  fp        - Opened output file pointer.
  pathXids  - Path list of XML identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
CGenMsgTypes(self, fp)
Generate .c field and message definitions from 'msg_types' section.
 
Parameters:
  fp    - Opened output file pointer.
CGenPrologue(self, fp)
Generate .c source file prologue.
 
Prologue includes core header file includes plus any prologue specified
in the XML file.
 
Parameters:
  fp    - Opened output file pointer.
CGenPublicFuncDefs(self, fp)
Generate .c source file function definitions.
 
Parameters:
  fp    - Opened output file pointer.
CGenVectorItemFieldDef(self, fp, pathXids, xdef)
Generate .c vector item field definition array for the given definition.
 
Parameters:
  fp        - Opened output file pointer.
  pathXids  - Path list of XML identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
CMakeFieldDefThis(self, ftype, fdef)
Make C field definition this specific initialization for field type.
 
Parameters:
  ftype   - XML field type.
  fdef    - XML field definition.
 
Return
  Returns the pair (this, this_init) where:
    this      - C union name.
    this_int  - List of (.member, value) pairs.
CMakeFieldDefThisDerived(self, ftype, fdef)
Make C field definition this specific initialization for vector field.
 
Parameters:
  ftype   - XML field type.
  fdef    - XML field definition.
 
Return
  Returns the pair (this, this_init) where:
    this      - C union name.
    this_int  - List of (.member, value) pairs.
CMakeFieldDefThisNumber(self, ftype, fdef)
Make C field definition this specific initialization for number field.
 
Parameters:
  ftype   - XML field type.
  fdef    - XML field definition.
 
Return
  Returns the pair (this, this_init) where:
    this      - C union name.
    this_int  - List of (.member, value) pairs.
CMakeFieldDefThisPad(self, ftype, fdef)
Make C field definition this specific initialization for pad 'field'.
 
Parameters:
  ftype   - XML field type.
  fdef    - XML field definition.
 
Return
  Returns the pair (this, this_init) where:
    this      - C union name.
    this_int  - List of (.member, value) pairs.
CMakeFieldDefThisString(self, ftype, fdef)
Make C field definition this specific initialization for string field.
 
Parameters:
  ftype   - XML field type.
  fdef    - XML field definition.
 
Return
  Returns the pair (this, this_init) where:
    this      - C union name.
    this_int  - List of (.member, value) pairs.
CMakeFieldDefThisStruct(self, ftype, fdef)
Make C field definition this specific initialization for struct field.
 
Parameters:
  ftype   - XML field type.
  fdef    - XML field definition.
 
Return
  Returns the pair (this, this_init) where:
    this      - C union name.
    this_int  - List of (.member, value) pairs.
CMakeFieldDefThisVector(self, ftype, fdef)
Make C field definition this specific initialization for vector field.
 
Parameters:
  ftype   - XML field type.
  fdef    - XML field definition.
 
Return
  Returns the pair (this, this_init) where:
    this      - C union name.
    this_int  - List of (.member, value) pairs.
EvalNum(self, *args)
Evaluate a summation of terms.
 
Paramters:
  args      List of summation terms, with each term one of:
              an equation, string, number
 
Examples:
  5                     -> '5'
  5, '(3 * 10)'         -> '35'
  5, 'MY_MAX', '1*255'  -> '300+MY_MAX'
 
Return:
  Returns string of the evaluated results.
GenCSource(self)
Generate h header.
 
Exceptions:
  Raises NetMsgError exception on error.
GenHSource(self)
Generate h header.
 
Exceptions:
  Raises NetMsgError exception on error.
GenSource(self)
Generate C .h and .c source file pair.
 
Exceptions:
  Raises NetMsgError exception on error.
HGenEpilogue(self, fp)
Generate .h header file epilogue.
 
Parameters:
  fp    - Opened output file pointer.
HGenExternData(self, fp)
Generate .h header public external data.
 
Parameters:
  fp    - Opened output file pointer.
HGenFieldTypes(self, fp)
Generate .h header file field types section.
 
Parameters:
  fp    - Opened output file pointer.
HGenMsgIds(self, fp)
Generate .h Message Id enumeration.
 
Parameters:
  fp    - Opened output file pointer.
HGenMsgTypes(self, fp)
Generate .h header file message types section.
 
Parameters:
  fp    - Opened output file pointer.
HGenPrologue(self, fp)
Generate .h header file prologue.
 
Prologue includes core header file includes plus any prologue specified
in the XML file.
 
Parameters:
  fp    - Opened output file pointer.
HGenProtoTypes(self, fp)
Generate .h header function prototypes.
 
Parameters:
  fp    - Opened output file pointer.
HGenStructDeclList(self, fp, fields, depth)
Generate comment structure declaration list (members).
 
Parameters:
  fp      - Opened output file pointer.
  fields  - XML database field definition 'fields' entry.
  depth   - Current structure depth.
HGenTypedef(self, fp, xid, xdef, brief)
Generate a commented type definition subsection.
 
Parameters:
  fp      - Opened output file pointer.
  xid     - Unique id in XML database section.
  xdef    - XML ftypedef, msgdef, or fielddef XML database entry.
  brief   - Brief comment string.
HGenTypedefMacros(self, fp, xid, xdef)
Generation .h cpp #defines macros associated with field or message
typedefs.
 
Parameters:
  fp      - Opened output file pointer.
  xid     - Unique id in XML database section.
  xdef    - XML ftypedef, msgdef, or fielddef XML database entry.
IsDeprecated(self, xdef)
Returns True (False) is definition is (not) deprecated.
 
Parameters:
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
 
Return:
  True or False.
IsSimple(self, ftype)
Returns True (False) is field type is (not) simple.
 
Parameters:
  ftype   - (Derived) field type.
 
Return:
  True or False.
MakeCId(self, xid, isGlobal)
Make C indentifier.
 
Parameters:
  xid   - XML [sub]definition id.
  isGlobal  - Identifier does [not] have global scope.
 
Returns:
  C identifier.
MakeCppMacroName(self, *names)
Make CPP #define macro name.
 
Parameters:
  names   - List of argument subnames.
 
Returns:
  String "NS_ARG1_..._ARGN"
MakeTypeSpec(self, ftype)
Make C type specifier.
 
Parameters:
  ftype   - Field type.
 
Returns:
  Type specifier.
Pass0(self)
Make initial pass through the XML database and augument with
specific C information.
 
No generated C code is written to file output.
Pass0XmlDef(self, pathXids, xdef, depth)
Process the given XmL definition and add C specific data.
 
No generated C code is written to file output.
 
Parameters:
  pathXids  - Path (list) of XML ftypedef, msgdef, or fielddef
              identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
  depth     - Recursive definition depth.
 
Return:
  Maximum number of packed bytes required for this encoded definition.
Pass0XmlDefDerived(self, pathXids, xdef, depth)
Process derived type XML definition.
 
Parameters:
  pathXids  - Path (list) of XML ftypedef, msgdef, or fielddef
              identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
  depth     - Recursive definition depth.
 
Return:
  Maximum number of packed bytes required for this encoded definition.
Pass0XmlDefPad(self, pathXids, xdef, depth)
Process pad XML definition.
 
Parameters:
  pathXids  - Path (list) of XML ftypedef, msgdef, or fielddef
              identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
  depth     - Recursive definition depth.
 
Return:
  Maximum number of packed bytes required for this encoded definition.
Pass0XmlDefSimple(self, pathXids, xdef, depth)
Process simple XML definition.
 
Parameters:
  pathXids  - Path (list) of XML ftypedef, msgdef, or fielddef
              identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
  depth     - Recursive definition depth.
 
Return:
  Maximum number of packed bytes required for this encoded definition.
Pass0XmlDefString(self, pathXids, xdef, depth)
Process string XML definition.
 
Parameters:
  pathXids  - Path (list) of XML ftypedef, msgdef, or fielddef
              identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
  depth     - Recursive definition depth.
 
Return:
  Maximum number of packed bytes required for this encoded definition.
Pass0XmlDefStruct(self, pathXids, xdef, depth)
Process struct XML definition.
 
Parameters:
  pathXids  - Path (list) of XML ftypedef, msgdef, or fielddef
              identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
  depth     - Recursive definition depth.
 
Return:
  Maximum number of packed bytes required for this encoded definition.
Pass0XmlDefVector(self, pathXids, xdef, depth)
Process vector XML definition.
 
Parameters:
  pathXids  - Path (list) of XML ftypedef, msgdef, or fielddef
              identifiers.
  xdef      - XML ftypedef, msgdef, or fielddef XML specification.
  depth     - Recursive definition depth.
 
Return:
  Maximum number of packed bytes required for this encoded definition.
PrettyPrintBriefComment(self, fp, brief)
Print doxygen brief comment block.
 
Parameters:
  fp      - Opened output file pointer.
  brief   - Brief comment.
PrettyPrintMajorDivComment(self, fp, comment)
Prints major file division comment block.
 
Parameters:
  fp          - Opened output file pointer.
  comment     - Major division comment line.
PrettyPrintMinorDivComment(self, fp, comment)
Prints minor file division comment block.
 
Parameters:
  fp          - Opened output file pointer.
  comment     - Minor division comment line.
PrettyPrintTopComment(self, fp, srcbasename, brief)
Prints source file top comment block.
 
Parameters:
  fp          - Opened output file pointer.
  srcbasename - Base name of source file.
  brief       - Brief comment.
WriteFDefEntry(self, fp, sFName, eFId, eFType, uOffset, this, this_init)
Write an NMFieldDef_T entry.
 
Parameters:
  fp          - Opened output file pointer.
  sFName      - m_sFName value.
  eFId        - m_eFId value.
  eFType      - m_eFType value.
  uOffset     - m_uOffset value.
  this        - m_this.<this>
  this_init   - List of (member, value) this pairs.
WriteFuncDef(self, fp, type_qual, type_spec, funcname, funcargs, **kwargs)
Write function declaration statement.
 
func_def ::-
    extern type_qual type_spec funcname ( arg_list ) ;
  | extern type_spec funcname ( arg_list ) ;
  | type_qual type_spec funcname ( arg_list ) { stmts }
  | type_spec funcname ( arg_list ) { stmts }
 
arg_list ::-
    empty
  ! arg_decl
  | arg_list , arg_decl
 
arg_decl ::-
    type_qual type_spec cid 
    type_spec cid
 
Parameters:
  fp          - Opened output file pointer.
  type_qual   - C function type qualifier(s).
  type_spec   - C function type specifier(s).
  funcname    - C function identifier.
  funcargs    - List of function arguments 3-tuple:
                  (type_qual(s), type_spec(s), cid)
  kwargs      - Dictionary of optional arguments.
                  'comments': string
                  'stmts': string
WriteStructDecl(self, fp, indent, type_spec, cid, const_expr, **kwargs)
Write commented structure declarator.
 
struct_decl ::-
    type_spec cid ;
  | type_spec cid [ const_expr ] ;
 
Parameters:
  fp          - Opened output file pointer.
  indent      - Indentation.
  type_spec   - C type specifier.
  cid         - C identifier.
  const_expr  - C array constant expression. None of not an array.
  kwargs      - Optional keyword arguments.
                  'comment':string  - Overide default comment.
WriteTypedefStmt(self, fp, type_spec, cid, const_expr)
Write typedef declaration.
 
typedef_spec ::-
    typedef type_spec cid ;
  | typedef type_spec cid [ const_expr ] ;
 
Parameters:
  fp          - Opened output file pointer.
  type_spec   - C type specifier.
  cid         - C identifier.
  const_expr  - C array constant expression. None of not an array.
WriteVectortDecl(self, fp, indent, vtype_spec, cid, const_expr)
Write commented structure vector declarator.
 
struct_vector_decl ::-
    struct {
      size_t m_count ;
      union { 
        void * m_pAlign ;
        vtype_spec  m_buf [ const_expr ] ;
      } u ;
    } cid ;
 
Parameters:
  fp          - Opened output file pointer.
  indent      - Indentation.
  vtype_spec  - C vector items type specifier.
  cid         - C identifier.
  const_expr  - C array constant expression. None of not an array.
  kwargs      - Optional keyword arguments.
                  'comment':string  - Overide default comment.
__init__(self, xml, hfilepath, cfilepath, **kwargs)
Initialize NetMsgsGenC instance.
 
Parameters:
  xml         - NetMsgsXMLParser class instance.
  hfilepath   - Generated output h file.
  cfilepath   - Generated output c file.
  kwargs      - Optional keyword arguments.
                  debug     - Set debugging level: 0 == off, 1, 2, 3.
                  incprefix - Generated .h include prefix in .c file.