diff --git a/docs/faq.rst b/docs/faq.rst index 3acccbe5..e7597f66 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -98,6 +98,9 @@ Currently this adds the support for elaborated type specifiers. \_\_va_list_tag and other hidden declarations (f1) -------------------------------------------------- +!!! This flag has been removed from pygccxml > 2.6 +We will now always remove these declarations + When parsing with CastXML, the XML tree can contain declarations named ``__va_list_tag``. If the compiler is llvm 3.9, ``__NSConstantString_tag`` and ``__NSConstantString`` declarations may also be present. diff --git a/src/pygccxml/parser/scanner.py b/src/pygccxml/parser/scanner.py index d11814d9..160c308a 100644 --- a/src/pygccxml/parser/scanner.py +++ b/src/pygccxml/parser/scanner.py @@ -197,6 +197,15 @@ def __init__(self, xml_file, decl_factory, config, *args): "__vr_offs", ] + # With CastXML and clang some __va_list_tag declarations are + # present in the tree + # With llvm 3.9 there is a __NSConstantString(_tag) in the tree + self.__declarations_to_skip = [ + "__va_list_tag", + "__NSConstantString_tag", + "__NSConstantString" + ] + self.__xml_generator_from_xml_file = None @property @@ -297,21 +306,10 @@ def startElement(self, name, attrs): self.__read_access(attrs) element_id = attrs.get(XML_AN_ID) - # With CastXML and clang some __va_list_tag declarations are - # present in the tree: we do not want to have these in the tree. - # With llvm 3.9 there is a __NSConstantString(_tag) in the tree - # We hide these declarations by default - rm1 = "f1" not in self.config.flags - names = [ - "__va_list_tag", - "__NSConstantString_tag", - "__NSConstantString"] - if isinstance(obj, declarations.declaration_t): - if rm1 and str(obj.name) in names: + if obj.name in self.__declarations_to_skip: return - self.__update_membership(attrs) self.__declarations[element_id] = obj if not isinstance(obj, declarations.namespace_t): diff --git a/tests/test_va_list_tag_removal.py b/tests/test_va_list_tag_removal.py deleted file mode 100644 index 2a675665..00000000 --- a/tests/test_va_list_tag_removal.py +++ /dev/null @@ -1,116 +0,0 @@ -# Copyright 2014-2017 Insight Software Consortium. -# Copyright 2004-2009 Roman Yakovenko. -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt - -import os -import platform - -from . import autoconfig - -from pygccxml import parser -from pygccxml import declarations - - -""" -Test the remove__va_list_tag option - -With CastXML and clang some __va_list_tag declarations are present in the -tree. This options allows to remove them when parsing the xml file. - -""" - - -__code = os.linesep.join(['struct a{};']) -known_typedefs = ["__int128_t", "__uint128_t", "__builtin_va_list"] -known_typedefs_llvm39 = known_typedefs + ["__builtin_ms_va_list"] -known_classes = ["a"] -known_classes_llvm39 = known_classes + ["__NSConstantString_tag"] - - -def test_keep_va_list_tag(): - - if platform.system() == 'Windows': - return True - - config = autoconfig.cxx_parsers_cfg.config.clone() - - config.flags = ["f1"] - src_reader = parser.source_reader_t(config) - decls = declarations.make_flatten(src_reader.read_string(__code)) - - classes = [ - i for i in decls if isinstance(i, declarations.class_t)] - - typedefs = [ - i for i in decls if isinstance(i, declarations.typedef_t)] - - variables = [ - i for i in decls if isinstance(i, declarations.variable_t)] - - assert "a" in [class_.name for class_ in classes] - if len(classes) == 2: - for c in known_classes: - assert c in [cl.name for cl in classes] - elif len(classes) == 3: - for c in known_classes_llvm39: - # This is for llvm 3.9 - assert c in [cl.name for cl in classes] - - if len(typedefs) == 5: - # This is for llvm 3.9. The class __va_list_tag struct is still - # there but the typedef is gone - for t in known_typedefs_llvm39: - assert t in [ty.name for ty in typedefs] - assert "__NSConstantString_tag" in [class_.name for class_ in classes] - assert "__NSConstantString" in [ty.name for ty in typedefs] - else: - for t in known_typedefs: - assert t in [ty.name for ty in typedefs] - - # 4 variables in __va_list_tag, and 4 more in __NSConstantString_tag - # for llvm 3.9 - assert len(variables) == 4 or len(variables) == 8 - - -def test_remove_va_list_tag(): - - if platform.system() == 'Windows': - return True - - config = autoconfig.cxx_parsers_cfg.config.clone() - - config.flags = [] - src_reader = parser.source_reader_t(config) - decls = declarations.make_flatten(src_reader.read_string(__code)) - - classes = [ - i for i in decls if isinstance(i, declarations.class_t)] - - typedefs = [ - i for i in decls if isinstance(i, declarations.typedef_t)] - - variables = [ - i for i in decls if isinstance(i, declarations.variable_t)] - - tag = "__va_list_tag" - - assert tag not in [class_.name for class_ in classes] - assert "a" in [class_.name for class_ in classes] - assert len(classes) == 1 - - assert tag not in [ty.name for ty in typedefs] - if len(typedefs) == 4: - # This is for llvm 3.9 - for t in known_typedefs_llvm39: - assert t in [ty.name for ty in typedefs] - assert "__NSConstantString_tag" not in \ - [class_.name for class_ in classes] - assert "__NSConstantString" not in \ - [ty.name for ty in typedefs] - else: - for t in known_typedefs: - assert t in [ty.name for ty in typedefs] - - assert tag not in [var.decl_string.split("::")[1] for var in variables] - assert len(variables) == 0