Skip to content

Commit 1f5f716

Browse files
committed
Add option to remove the __va_list_tag declaration from the tree when parsing with CastXML
This option is on by default. The __va_list_tag declarations are internal declarations, which are probably not needed. They are for example polluting the declarations tree when running pyplusplus. The removal can still be re-enabled by setting the utils.remove__va_list_tag option to False. This fixes also the filter test, which has now the correct initial number of declarations (the same as for gccxml). It also removes the hack in the hierarchy_travelling test.
1 parent 9fd9dcf commit 1f5f716

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

pygccxml/parser/scanner.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,17 @@ def startElement(self, name, attrs):
201201
self.__inst = obj
202202
self.__read_access(attrs)
203203
element_id = attrs.get(XML_AN_ID, None)
204+
205+
# With CastXML and clang some __va_list_tag declarations are
206+
# present in the tree: we do not want to have these in the tree.
207+
# This option is set to True by default
208+
remove_va_list_tag = utils.remove__va_list_tag
209+
204210
if isinstance(obj, declarations.declaration_t):
211+
212+
if remove_va_list_tag and "__va_list_tag" in str(obj.name):
213+
return
214+
205215
# XML generator. Kept for retrocompatibily
206216
obj.compiler = utils.xml_generator
207217

@@ -217,11 +227,18 @@ def startElement(self, name, attrs):
217227
self.__read_attributes(obj, attrs)
218228

219229
elif isinstance(obj, declarations.type_t):
230+
220231
self.__types[element_id] = obj
221232
self.__read_byte_size(obj, attrs)
222233
self.__read_byte_align(obj, attrs)
234+
223235
elif utils.is_str(obj):
236+
237+
if remove_va_list_tag and "__va_list_tag" in obj:
238+
return
239+
224240
self.__files[element_id] = obj
241+
225242
else:
226243
self.logger.warning(
227244
'Unknown object type has been found.' +

pygccxml/utils/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020

2121
# Version of xml generator which was used.
2222
xml_generator = None
23+
24+
# With CastXML and clang some __va_list_tag declarations are present in the
25+
# tree. This options allows to remove them when parsing the xml file.
26+
remove__va_list_tag = True

unittests/filters_tester.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,8 @@ def test_access_type(self):
3939
criteria = declarations.access_type_matcher_t(
4040
declarations.ACCESS_TYPES.PUBLIC)
4141
public_members = declarations.matcher.find(criteria, self.global_ns)
42-
if "CastXML" in utils.xml_generator:
43-
public_members = [d for d in public_members if not d.is_artificial]
44-
self.assertTrue(21 == len(public_members))
45-
if "0.9" in utils.xml_generator:
46-
public_members = [d for d in public_members if not d.is_artificial]
47-
self.assertTrue(17 == len(public_members))
48-
else:
49-
self.assertTrue(21 == len(public_members))
42+
public_members = [d for d in public_members if not d.is_artificial]
43+
self.assertTrue(17 == len(public_members))
5044

5145
def test_or_matcher(self):
5246
criteria1 = declarations.regex_matcher_t(

unittests/hierarchy_traveling.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from pygccxml import parser
1111
from pygccxml import declarations
12-
from pygccxml import utils
1312

1413

1514
class tester_t(parser_test_case.parser_test_case_t):
@@ -53,11 +52,6 @@ def test_recursive_bases(self):
5352
classes = [
5453
inst for inst in decls if isinstance(inst, declarations.class_t)]
5554
for class_ in classes:
56-
if "CastXML" in utils.xml_generator and \
57-
class_.name == "__va_list_tag":
58-
# With CastXML; there is a __va_list_tag which is generated by
59-
# clang. Do not run the tests for it.
60-
continue
6155
self.assertTrue(class_.name in self.__recursive_bases)
6256
all_bases = class_.recursive_bases
6357
control_bases = self.__recursive_bases[class_.name]
@@ -73,11 +67,6 @@ def test_recursive_derived(self):
7367
inst,
7468
declarations.class_t)]
7569
for class_ in classes:
76-
if "CastXML" in utils.xml_generator and \
77-
class_.name == "__va_list_tag":
78-
# With CastXML; there is a __va_list_tag which is generated by
79-
# clang. Do not run the tests for it.
80-
continue
8170
self.assertTrue(class_.name in self.__recursive_derived)
8271
all_derived = class_.recursive_derived
8372
control_derived = self.__recursive_derived[class_.name]

0 commit comments

Comments
 (0)