Skip to content

Commit 68933f7

Browse files
committed
Add comment check in Scanner
Since comment_t no longer is a declaration_t child, add a new check in startElement for a comment object. Add it to a new dictionary just for comments. Remove leftover debugging statement.
1 parent 3b7abcf commit 68933f7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pygccxml/parser/scanner.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def __init__(self, xml_file, decl_factory, config, *args):
152152
self.__calldefs = []
153153
# list of enums I need later
154154
self.__enums = []
155+
# mapping of id -> comment decl
156+
self.__comments = {}
155157
# mapping from id -> type
156158
self.__types = {}
157159
# mapping from id -> file
@@ -200,7 +202,7 @@ def read(self):
200202
xml.sax.parse(self.xml_file, self)
201203

202204
def _handle_comment(self, declaration):
203-
comm_decl = self.__declarations.get(declaration.comment)
205+
comm_decl = self.__comments.get(declaration.comment)
204206
if comm_decl:
205207
# First acquire file_name placeholder
206208
file_decl = comm_decl.location.file_name
@@ -307,6 +309,11 @@ def startElement(self, name, attrs):
307309
self.__read_byte_size(obj, attrs)
308310
self.__read_byte_align(obj, attrs)
309311

312+
elif isinstance(obj, declarations.comment.comment_t):
313+
self.__comments[element_id] = obj
314+
self.__update_membership(attrs)
315+
self.__read_attributes(obj, attrs)
316+
310317
elif utils.is_str(obj):
311318

312319
self.__files[element_id] = os.path.normpath(obj)

unittests/test_comments.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def test(self):
4141
tnamespace = self.global_ns.namespace("comment")
4242

4343
self.assertIn("comment", dir(tnamespace))
44-
print(tnamespace.comment)
4544
if tnamespace.comment.text:
4645
self.assertEqual(["//! Namespace Comment",
4746
"//! Across multiple lines"],

0 commit comments

Comments
 (0)