Skip to content

Commit b461a6c

Browse files
committed
Introduce a way to passe flags to the config and use it
This will allow to enable/disable stuff in the future. The f1 flag, when set, will add the __va_list_tag declarations to the tree. By default the flag is not set.
1 parent 3db3dde commit b461a6c

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

pygccxml/parser/config.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def __init__(
4343
compiler=None,
4444
xml_generator="gccxml",
4545
keep_xml=False,
46-
compiler_path=None):
46+
compiler_path=None,
47+
flags=None):
4748

4849
object.__init__(self)
4950
self.__working_directory = working_directory
@@ -68,6 +69,10 @@ def __init__(
6869

6970
self.__keep_xml = keep_xml
7071

72+
if flags is None:
73+
flags = []
74+
self.__flags = flags
75+
7176
# If no compiler path was set and we are using castxml, set the path
7277
self.__compiler_path = create_compiler_path(
7378
xml_generator, compiler_path)
@@ -128,6 +133,18 @@ def keep_xml(self, keep_xml):
128133
"""Set if xml files kept after errors."""
129134
self.__keep_xml = keep_xml
130135

136+
@property
137+
def flags(self):
138+
"""Optional flags for pygccxml."""
139+
return self.__flags
140+
141+
@flags.setter
142+
def flags(self, flags):
143+
"""Optional flags for pygccxml."""
144+
if flags is None:
145+
flags = []
146+
self.__flags = flags
147+
131148
@property
132149
def compiler_path(self):
133150
"""Get the path for the compiler."""
@@ -192,7 +209,8 @@ def __init__(
192209
compiler=None,
193210
xml_generator="gccxml",
194211
keep_xml=False,
195-
compiler_path=None):
212+
compiler_path=None,
213+
flags=None):
196214

197215
parser_configuration_t.__init__(
198216
self,
@@ -204,7 +222,8 @@ def __init__(
204222
compiler=compiler,
205223
xml_generator=xml_generator,
206224
keep_xml=keep_xml,
207-
compiler_path=compiler_path)
225+
compiler_path=compiler_path,
226+
flags=flags)
208227

209228
if gccxml_path != '':
210229
self.__gccxml_path = gccxml_path
@@ -400,6 +419,8 @@ def load_xml_generator_configuration(configuration, **defaults):
400419
cfg.xml_generator = value
401420
elif name == 'keep_xml':
402421
cfg.keep_xml = value
422+
elif name == 'flags':
423+
cfg.flags = value
403424
elif name == 'compiler_path':
404425
cfg.compiler_path = value
405426
else:

pygccxml/parser/scanner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def startElement(self, name, attrs):
205205
# With CastXML and clang some __va_list_tag declarations are
206206
# present in the tree: we do not want to have these in the tree.
207207
# This option is set to True by default
208-
remove_va_list_tag = utils.remove__va_list_tag
208+
remove_va_list_tag = "f1" not in self.config.flags
209209

210210
if isinstance(obj, declarations.declaration_t):
211211

pygccxml/utils/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,3 @@
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/test_va_list_tag_removal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_keep_va_list_tag(self):
3131
if "GCCXML" in self.config.xml_generator:
3232
return True
3333

34-
utils.remove__va_list_tag = False
34+
self.config.flags = ["f1"]
3535
src_reader = parser.source_reader_t(self.config)
3636
decls = declarations.make_flatten(src_reader.read_string(self.__code))
3737

@@ -62,7 +62,7 @@ def test_remove_va_list_tag(self):
6262
if "GCCXML" in self.config.xml_generator:
6363
return True
6464

65-
utils.remove__va_list_tag = True
65+
self.config.flags = []
6666
src_reader = parser.source_reader_t(self.config)
6767
decls = declarations.make_flatten(src_reader.read_string(self.__code))
6868

0 commit comments

Comments
 (0)