@@ -70,7 +70,7 @@ class {name}(Structure):
7070 def __init__(self, cstruct, structure, source=None):
7171 self.structure = structure
7272 self.source = source
73- super({name}, self).__init__(cstruct, structure.name, structure.fields)
73+ super({name}, self).__init__(cstruct, structure.name, structure.fields, structure.commentAttributes )
7474
7575 def _read(self, stream):
7676 r = OrderedDict()
@@ -353,7 +353,7 @@ def _parse_fields_enums(self, s):
353353 nextval = 0
354354 values = {}
355355 fields = re .finditer (
356- r'(?P<commentBlock>\/\*(\*(?!\/)|[^*])*\*\/)?\n [ \t\r\n]*(?P<value>[^\n,]+),' ,
356+ r'(?P<commentBlock>\/\*(\*(?!\/)|[^*])*\*\/)?[ \t\r\n]*(?P<value>[^\n,]+),' ,
357357 s ,
358358 )
359359
@@ -363,8 +363,6 @@ def _parse_fields_enums(self, s):
363363 # Ignore fo now
364364 # commentAttributes = self.parse_comment_block(d['commentBlock'])
365365
366- print (d ["value" ])
367-
368366 field = re .finditer (
369367 r'(?P<key>[a-zA-z][^ ]*)[ ]*=?[ ]*(?P<value>[^ ]+)?' ,
370368 d ["value" ],
@@ -381,7 +379,7 @@ def _parse_fields_enums(self, s):
381379 def _structs (self , data ):
382380 compiler = Compiler (self .cstruct )
383381 r = re .finditer (
384- r'(#(?P<flags>(?:compile))\s+)?((?P<typedef>typedef)\s+)?(?P<type>[^\s]+)\s+(__attribute__\(\([^)]+\)\)\s*)?(?P<name>[^\s]+)?(?P<fields>\s*\{(\s*//[^\n]*|/\*[^*]*\*/|[^}])+\}(?P<defs>\s+[^;\n]+)?)?\s*;' ,
382+ r'(?P<commentBlock>\/\*(\*(?!\/)|[^*])*\*\/)?[ \t\r\n]*( #(?P<flags>(?:compile))\s+)?((?P<typedef>typedef)\s+)?(?P<type>[^\s]+)\s+(__attribute__\(\([^)]+\)\)\s*)?(?P<name>[^\s]+)?(?P<fields>\s*\{(\s*//[^\n]*|/\*[^*]*\*/|[^}])+\}(?P<defs>\s+[^;\n]+)?)?\s*;' ,
385383 data ,
386384 )
387385 for t in r :
@@ -396,7 +394,8 @@ def _structs(self, data):
396394
397395 if d ['type' ] == 'struct' :
398396 data = self ._parse_fields_struct (d ['fields' ][1 :- 1 ].strip ())
399- st = Structure (self .cstruct , name , data )
397+ commentAttributes = self .parse_comment_block (d ['commentBlock' ])
398+ st = Structure (self .cstruct , name , data , commentAttributes )
400399 if d ['flags' ] == 'compile' or self .compiled :
401400 st = compiler .compile (st )
402401 elif d ['typedef' ] == 'typedef' :
@@ -774,11 +773,12 @@ def __repr__(self):
774773class Structure (BaseType ):
775774 """Type class for structures."""
776775
777- def __init__ (self , cstruct , name , fields = None ):
776+ def __init__ (self , cstruct , name , fields = None , commentAttributes = {} ):
778777 self .name = name
779778 self .size = None
780779 self .lookup = OrderedDict ()
781780 self .fields = fields if fields else []
781+ self .commentAttributes = commentAttributes
782782
783783
784784 for f in self .fields :
@@ -932,7 +932,7 @@ def __repr__(self):
932932 def show (self , indent = 0 ):
933933 """Pretty print this structure."""
934934 if indent == 0 :
935- print ("struct {}" .format (self .name ))
935+ print ("{} struct {}" .format (self . commentAttributes , self .name ))
936936
937937 for field in self .fields :
938938 if field .offset is None :
@@ -1382,6 +1382,9 @@ def __getattr__(self, attr):
13821382 def __contains__ (self , attr ):
13831383 return attr in self .values
13841384
1385+ def __repr__ (self ):
1386+ return '<Enum {}>' .format (self .name )
1387+
13851388
13861389class EnumInstance (object ):
13871390 """Implements a value instance of an Enum"""
0 commit comments