Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Copyright 2014-2016 Insight Software Consortium.
# Copyright 2004-2008 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
import os
import unittest
import parser_test_case
from pygccxml import parser
class Test(parser_test_case.parser_test_case_t):
COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
def __init__(self, *args):
parser_test_case.parser_test_case_t.__init__(self, *args)
self.header = 'complex_types.hpp'
self.declarations = None
def setUp(self):
if not self.declarations:
self.declarations = parser.parse([self.header], self.config)
def test(self):
"""
This test tests presence of complex long double, float within
FUNDAMENTAL_TYPES map
"""
pass
def test(self):
fconfig = parser.file_configuration_t(
data='int i;',
start_with_declarations=None,
content_type=parser.file_configuration_t.CONTENT_TYPE.TEXT)
prj_reader = parser.project_reader_t(self.config)
decls = prj_reader.read_files(
[fconfig],
compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE)
var_i = declarations.find_declaration(
decls, decl_type=declarations.variable_t, name='i')
self.assertTrue(var_i, "Variable i has not been found.")
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()
Test.xml_generator_from_xml_file = \
self.config.xml_generator_from_xml_file
self.global_ns = Test.global_ns
self.xml_generator_from_xml_file = Test.xml_generator_from_xml_file
# Copyright 2014-2016 Insight Software Consortium.
# Copyright 2004-2008 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
import unittest
import parser_test_case
from pygccxml import parser
from pygccxml import declarations
class Test(parser_test_case.parser_test_case_t):
COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
global_ns = None
def __init__(self, *args):
parser_test_case.parser_test_case_t.__init__(self, *args)
self.header = 'has_public_binary_operator_traits.hpp'
self.global_ns = None
def setUp(self):
if not Test.global_ns:
decls = parser.parse([self.header], self.config)
Test.global_ns = declarations.get_global_namespace(decls)
self.global_ns = Test.global_ns
def test_yes(self):
yes_ns = self.global_ns.namespace('yes')
for typedef in yes_ns.typedefs():
def setUp(self):
decls = parser.parse([self.header], self.config)
self.xml_generator_from_xml_file = \
self.config.xml_generator_from_xml_file
self.global_ns = declarations.get_global_namespace(decls)
self.header_files = [os.path.abspath(f) for f in header_files]
self.location_filter = declarations.custom_matcher_t(self.__location_match)
if whitelist_paths is not None:
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():
if whitelist_paths is not None:
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.config_t(include_paths=include_paths, **gccxml_options)
else:
self.gccxml_config = parser.config_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()
define_symbols = defines,
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():
return t.name
elif isinstance(t, declarations.typedef_t):
return t.decl_string[2:] # remove ::
def replace_by_typedef(some_type):
if str(some_type) in typedef:
rep_typedef = typedef[str(some_type)]
if not '<' in rep_typedef: # replace only if not a template
return rep_typedef
return str(some_type)
# main loop
if 'xml_generator_configuration_t' in dir(parser):
config = parser.xml_generator_configuration_t(include_paths=include_paths,
ignore_gccxml_output=False,
keep_xml=True)
else:
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
this_module_dir_path = os.path.abspath(
os.path.dirname(sys.modules[__name__].__file__))
# Find out the c++ parser
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
decls = parser.parse([filename], xml_generator_config)
global_namespace = declarations.get_global_namespace(decls)
ns = global_namespace.namespace("ns")
# We have just one declaration in ns, which is our Test class:
classTest = ns.declarations[0]
print(classTest.name, type(classTest))
# > 'Test', ns::Test::Test() [constructor], False