How to use the pygccxml.declarations.get_global_namespace function in pygccxml

To help you get started, we’ve selected a few pygccxml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gccxml / pygccxml / unittests / type_as_exception_bug_tester.py View on Github external
def setUp(self):
        if not Test.global_ns:
            decls = parser.parse([self.header], self.config)
            Test.global_ns = declarations.get_global_namespace(decls)
            Test.global_ns.init_optimizer()
github gccxml / pygccxml / unittests / test_pattern_parser.py View on Github external
def test_matcher(self):
        """
        Run the matcher on all the templated classes.

        This exercises the whole pipeline even more.

        """

        if self.config.xml_generator == "gccxml":
            return

        decls = parser.parse([self.header], self.config)
        global_ns = declarations.get_global_namespace(decls)
        criteria = declarations.declaration_matcher(name="myClass")
        _ = declarations.matcher.find(criteria, global_ns)
github gccxml / pygccxml / unittests / test_smart_pointer.py View on Github external
def test_smart_pointer(self):
        """
        Test code in the smart_pointer_traits module.

        """

        if self.config.xml_generator == "gccxml":
            return

        decls = parser.parse([self.header], self.config)
        global_ns = declarations.get_global_namespace(decls)

        criteria = declarations.declaration_matcher(name="yes1")
        decls = declarations.matcher.find(criteria, global_ns)
        self.assertTrue(
            declarations.smart_pointer_traits.is_smart_pointer(
                decls[0].decl_type))

        criteria = declarations.declaration_matcher(name="yes2")
        decls = declarations.matcher.find(criteria, global_ns)
        self.assertTrue(
            declarations.auto_ptr_traits.is_smart_pointer(decls[0].decl_type))

        criteria = declarations.declaration_matcher(name="no1")
        decls = declarations.matcher.find(criteria, global_ns)
        self.assertFalse(
            declarations.auto_ptr_traits.is_smart_pointer(decls[0].decl_type))
github gccxml / pygccxml / unittests / non_copyable_classes_tester.py View on Github external
def setUp(self):
        if not self.global_ns:
            decls = parser.parse([self.header], self.config)
            self.global_ns = declarations.get_global_namespace(decls)
            self.global_ns.init_optimizer()
github gccxml / pygccxml / unittests / test_non_copyable_recursive.py View on Github external
def test_infinite_recursion_base_classes(self):
        """
        Test find_noncopyable_vars

        See #71

        find_noncopyable_vars was throwing:
        RuntimeError: maximum recursion depth exceeded while
        calling a Python object
        """
        decls = parser.parse([self.header], self.config)
        global_ns = declarations.get_global_namespace(decls)

        # Description of the problem (before the fix):
        # find_noncopyable_vars (on Child class) looks up the variables,
        # and finds aBasePtr2 (a pointer to the Base2 class).
        # Then it looks recursively at the base classes of Base2, and finds
        # Base1. Then, it looks up the variables from Base, to check if Base1
        # is non copyable. It finds another aBasePtr2 variable, which leads to
        # a new check of Base2; this recurses infinitely.
        test_ns = global_ns.namespace('Test1')
        cls = test_ns.class_('Child')
        declarations.type_traits_classes.find_noncopyable_vars(cls)
        self.assertTrue(declarations.type_traits_classes.is_noncopyable(cls))
github apitrace / apitrace / specs / scripts / cxx2api.py View on Github external
include_paths = includes,
        cflags = ' '.join(cxxflags),
        compiler = compiler,
        #keep_xml = True,
    )

    script_dir = os.path.dirname(__file__)
    headers = [
        os.path.join(script_dir, '..', '..', 'compat', 'winsdk_compat.h'),
        os.path.join(script_dir, 'cxx2api.h'),
    ]
    main_header = args[0]
    headers.append(main_header)

    decls = parser.parse(headers, config, parser.COMPILATION_MODE.ALL_AT_ONCE)
    global_ns = declarations.get_global_namespace(decls)

    def decl_filter(decl):
        location = decl.location
        if location is None:
            return False
        return os.path.basename(location.file_name) in map(os.path.basename, args)

    module, _ = os.path.splitext(main_header)
    visitor = decl2_dumper_t(module)
    visitor.start()
    for decl in global_ns.declarations:
        if not decl_filter(decl):
            continue

        if sys.stdout.isatty():
            print('# ' + str(decl))
github siconos / siconos / IO / tools / builder.py View on Github external
prio += ee[1]
                                return prio
                    elif len(files) >1:
                        print(files)
                print('Error while finding {:}, found no match'.format(header_file))
            else:
                return prio
    print('Error proccessing header {:}'.format(header))



# main loop
config = parser.config_t(include_paths=include_paths, ignore_gccxml_output=True)

decls = parser.parse(all_headers, config,  compilation_mode=COMPILATION_MODE.ALL_AT_ONCE)
global_ns = declarations.get_global_namespace(decls)

# classes in siconos_namespace
class_names = dict()

# class name of classes with a least a base (for the boost archive
# registration)
with_base = []

# a typedef table to replace templated class by their typedefs in
# macros call
typedef = dict()
for t in global_ns.typedefs():
    typedef[str(t._type)] = name(t)

with open(generated_file, 'a') as dest_file:
github gccxml / pygccxml / docs / examples / parsing-string / example.py View on Github external
xml_generator_config = parser.xml_generator_configuration_t(
    xml_generator_path=generator_path,
    xml_generator=generator_name)

# Write a string containing some c++ code
code = """
    class MyClass {
        int a;
    };
"""

# Parse the code
decls = parser.parse_string(code, xml_generator_config)

# Get access to the global namespace
global_ns = declarations.get_global_namespace(decls)
github Gabrielcarvfer / NS3 / 3rd-party / pybindgen / pybindgen / gccxmlparser.py View on Github external
assert isinstance(whitelist_paths, list)
            self.whitelist_paths = [os.path.abspath(p) for p in whitelist_paths]

        if gccxml_options is None:
            gccxml_options = {}

        if include_paths is not None:
            assert isinstance(include_paths, list)
            warnings.warn("Parameter include_paths is deprecated, use gccxml_options instead", DeprecationWarning,
                          stacklevel=2)
            self.gccxml_config = parser.gccxml_configuration_t(include_paths=include_paths, **gccxml_options)
        else:
            self.gccxml_config = parser.gccxml_configuration_t(**gccxml_options)

        self.declarations = parser.parse(header_files, self.gccxml_config)
        self.global_ns = declarations.get_global_namespace(self.declarations)
        if self.module_namespace_name == '::':
            self.module_namespace = self.global_ns
        else:
            self.module_namespace = self.global_ns.namespace(self.module_namespace_name)

        self.module = Module(self.module_name, cpp_namespace=self.module_namespace.decl_string)

        for inc in includes:
            self.module.add_include(inc)

        for pygen_sink in self._get_all_pygen_sinks():
            pygen_sink.writeln("from pybindgen import Module, FileCodeSink, param, retval, cppclass, typehandlers")
            pygen_sink.writeln()

        pygen_sink = self._get_main_pygen_sink()
        if pygen_sink:
github gccxml / pygccxml / docs / examples / equality / example.py View on Github external
# Find the location of the xml generator (castxml or gccxml)
generator_path, generator_name = utils.find_xml_generator()

# Configure the xml generator
xml_generator_config = parser.xml_generator_configuration_t(
    xml_generator_path=generator_path,
    xml_generator=generator_name)

# The c++ file we want to parse
filename = "example.hpp"
filename = this_module_dir_path + "/" + filename

# Parse the c++ file
decls = parser.parse([filename], xml_generator_config)

global_namespace = declarations.get_global_namespace(decls)

ns_namespace = global_namespace.namespace("ns")

# Search for the function called func1
criteria = declarations.calldef_matcher(name="func1")
func1a = declarations.matcher.get_single(criteria, ns_namespace)

# Search for the function called func2
criteria = declarations.calldef_matcher(name="func2")
func2a = declarations.matcher.get_single(criteria, ns_namespace)

# You can also write a loop on the declaration tree
func1b = None
for decl in ns_namespace.declarations:
    if decl.name == "func1":
        func1b = decl