1616XML_AN_ACCESS = "access"
1717XML_AN_ALIGN = "align"
1818XML_AN_ARTIFICIAL = "artificial"
19+ XML_AN_ATTACHED = "attached"
1920XML_AN_ATTRIBUTES = "attributes"
2021XML_AN_BASE_TYPE = "basetype"
2122XML_AN_BASES = "bases"
2223XML_AN_BITS = "bits"
24+ XML_AN_COMMENT = "comment"
2325XML_AN_CONST = "const"
2426XML_AN_CONTEXT = "context"
2527XML_AN_CVS_REVISION = "cvs_revision"
2628XML_AN_CASTXML_FORMAT = "format"
2729XML_AN_DEFAULT = "default"
30+ XML_AN_END_LINE = "end_line"
2831XML_AN_EXPLICIT = "explicit"
2932XML_AN_EXTERN = "extern"
3033XML_AN_FILE = "file"
3336XML_AN_INIT = "init"
3437XML_AN_INLINE = "inline"
3538XML_AN_LINE = "line"
39+ XML_AN_BEGIN_LINE = "begin_line"
3640XML_AN_MANGLED = "mangled"
3741XML_AN_MAX = "max"
3842XML_AN_MEMBERS = "members"
5256XML_NN_ARRAY_TYPE = "ArrayType"
5357XML_NN_CASTING_OPERATOR = "Converter"
5458XML_NN_CLASS = "Class"
59+ XML_NN_COMMENT = "Comment"
5560XML_NN_CONSTRUCTOR = "Constructor"
5661XML_NN_CV_QUALIFIED_TYPE = "CvQualifiedType"
5762XML_NN_DESTRUCTOR = "Destructor"
@@ -110,6 +115,7 @@ def __init__(self, xml_file, decl_factory, config, *args):
110115 XML_NN_UNION : self .__read_union ,
111116 XML_NN_FIELD : self .__read_field ,
112117 XML_NN_CASTING_OPERATOR : self .__read_casting_operator ,
118+ XML_NN_COMMENT : self .__read_comment ,
113119 XML_NN_CONSTRUCTOR : self .__read_constructor ,
114120 XML_NN_DESTRUCTOR : self .__read_destructor ,
115121 XML_NN_FUNCTION : self .__read_function ,
@@ -125,6 +131,7 @@ def __init__(self, xml_file, decl_factory, config, *args):
125131 XML_NN_DESTRUCTOR ,
126132 XML_NN_ENUMERATION ,
127133 XML_NN_FILE ,
134+ XML_NN_COMMENT ,
128135 XML_NN_FUNCTION ,
129136 XML_NN_FREE_OPERATOR ,
130137 XML_NN_MEMBER_OPERATOR ,
@@ -186,6 +193,19 @@ def xml_generator_from_xml_file(self):
186193 def read (self ):
187194 xml .sax .parse (self .xml_file , self )
188195
196+ def _handle_comment (self , declaration ):
197+ comm_decl = self .__declarations .get (declaration .comment )
198+ if comm_decl :
199+ with open (self .__files .get (comm_decl .location .file_name , "r" )) as file :
200+ line_list = file .readlines ()
201+ comment_text = []
202+ for indx in range (comm_decl .start_line - 1 ,comm_decl .end_line ):
203+ comm_line = line_list [indx ]
204+ comm_line = comm_line .strip ("\n " )
205+ comment_text .append (comm_line )
206+ comm_decl .text = comment_text
207+ return comm_decl
208+
189209 def endDocument (self ):
190210 # updating membership
191211 members_mapping = {}
@@ -195,6 +215,8 @@ def endDocument(self):
195215 continue
196216 members_mapping [id (decl )] = members
197217 self .__members = members_mapping
218+ for gccxml_id , decl in self .__declarations .items ():
219+ decl .comment = self ._handle_comment (decl )
198220
199221 def declarations (self ):
200222 return self .__declarations
@@ -287,9 +309,13 @@ def __read_location(decl, attrs, to_skip):
287309 if "name" in attrs and attrs ["name" ] in to_skip :
288310 decl .location = declarations .location_t ('' , - 1 )
289311 else :
312+ if XML_AN_BEGIN_LINE in attrs :
313+ line_number = attrs [XML_AN_BEGIN_LINE ]
314+ else :
315+ line_number = attrs [XML_AN_LINE ]
290316 decl .location = declarations .location_t (
291317 file_name = attrs [XML_AN_FILE ],
292- line = int (attrs [ XML_AN_LINE ] ))
318+ line = int (line_number ))
293319
294320 def __update_membership (self , attrs ):
295321 parent = attrs .get (XML_AN_CONTEXT )
@@ -501,6 +527,8 @@ def __read_calldef(self, calldef, attrs, is_declaration):
501527 else :
502528 calldef .does_throw = True
503529 calldef .exceptions = throw_stmt .split ()
530+ if attrs .get (XML_AN_COMMENT ):
531+ calldef .comment = attrs .get (XML_AN_COMMENT )
504532
505533 def __read_member_function (self , calldef , attrs , is_declaration ):
506534 self .__read_calldef (calldef , attrs , is_declaration )
@@ -551,6 +579,8 @@ def __read_variable(self, attrs):
551579 XML_AN_INIT ),
552580 bits = bits )
553581 self .__read_byte_offset (decl , attrs )
582+ if attrs .get (XML_AN_COMMENT ):
583+ decl .comment = attrs .get (XML_AN_COMMENT )
554584 return decl
555585
556586 __read_field = __read_variable # just a synonym
@@ -568,6 +598,8 @@ def __read_class_impl(self, class_type, attrs):
568598 decl .is_abstract = bool (attrs .get (XML_AN_ABSTRACT , False ))
569599 self .__read_byte_size (decl , attrs )
570600 self .__read_byte_align (decl , attrs )
601+ if attrs .get (XML_AN_COMMENT ):
602+ decl .comment = attrs .get (XML_AN_COMMENT )
571603 return decl
572604
573605 def __read_class (self , attrs ):
@@ -584,6 +616,13 @@ def __read_casting_operator(self, attrs):
584616 self .__read_member_function (operator , attrs , True )
585617 return operator
586618
619+ def __read_comment (self , attrs ):
620+ comment = self .__decl_factory .create_comment ()
621+ comment ._start_line = int (attrs .get (XML_AN_BEGIN_LINE ))
622+ comment ._end_line = int (attrs .get (XML_AN_END_LINE ))
623+ self .__read_location (comment , attrs , self .__name_attrs_to_skip )
624+ return comment
625+
587626 def __read_constructor (self , attrs ):
588627 constructor = self .__decl_factory .create_constructor ()
589628 self .__read_member_function (constructor , attrs , True )
0 commit comments