def global_namespace(): #configure GCC-XML parser config = parser.config_t( gccxml_path= "c:/Progra~1/GCC_XML/bin/gccxml.exe",\ include_paths= ["e:/starteam/docplatform/nextrelease/code/common"] ) #parsing source file decls = parser.parse( ['interf.h'], config ) return declarations.get_global_namespace( decls )
def test(self): src_reader = parser.source_reader_t(self.config) global_ns = declarations.get_global_namespace( src_reader.read_string(code)) global_ns.decl('A<int>') f = global_ns.free_fun('f') self.failUnless(f.demangled == 'void f<int>(A<int> const&)')
def setUp(self): if not tester_t.global_ns: decls = parser.parse([self.header], self.config) tester_t.global_ns = declarations.get_global_namespace(decls) tester_t.global_ns.init_optimizer() process = subprocess.Popen( args='scons msvc_compiler=%s' % autoconfig.cxx_parsers_cfg.gccxml.compiler, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self.binary_parsers_dir) process.stdin.close() while process.poll() is None: line = process.stdout.readline() print(line.rstrip()) for line in process.stdout.readlines(): print(line.rstrip()) if process.returncode: raise RuntimeError( ("unable to compile binary parser module. " + "See output for the errors."))
def test(self): """ The purpose of this test was to check if changes to GCCXML would lead to changes in the outputted xml file (Meaning the bug was fixed). GCCXML wrongly outputted partial template specialization. CastXML does not have this bug. In this case we check if the template specialization can not be found; which is the expected/wanted behaviour. https://github.com/CastXML/CastXML/issues/20 """ src_reader = parser.source_reader_t(self.config) global_ns = declarations.get_global_namespace( src_reader.read_string(code)) if 'GCCXML' in utils.xml_generator: a = global_ns.class_('A<const char [N]>') a.mem_fun('size') elif 'CastXML' in utils.xml_generator: self.assertRaises( global_ns.declaration_not_found_t, lambda: global_ns.class_('A<const char [N]>'))
def test(self): code = """ namespace A{ struct B{ int c; }; template <class T> struct C: public T{ int d; }; template <class T> struct D{ int dD; }; typedef C<B> easy; typedef D<easy> Deasy; inline void instantiate(){ sizeof(easy); } } """ global_ns = parser.parse_string( code, autoconfig.cxx_parsers_cfg.gccxml) global_ns = declarations.get_global_namespace( global_ns ) easy = global_ns.typedef( 'easy' ) c_a = declarations.class_traits.get_declaration( easy ) #this works very well deasy = global_ns.typedef( 'Deasy' ) d_a = declarations.class_traits.get_declaration( deasy ) self.failUnless( isinstance( d_a, declarations.class_types ) )
def test_attributes_thiscall(self): """ Test attributes with the "f2" flag """ if self.config.compiler != "msvc": return self.config.flags = ["f2"] decls = parser.parse([self.header], self.config) Test.global_ns = declarations.get_global_namespace(decls) Test.global_ns.init_optimizer() numeric = self.global_ns.class_('numeric_t') do_nothing = numeric.member_function('do_nothing') arg = do_nothing.arguments[0] generator = self.config.xml_generator_from_xml_file if generator.is_castxml1 or ( generator.is_castxml and float(generator.xml_output_version) >= 1.137): self.assertTrue("annotate(sealed)" == numeric.attributes) self.assertTrue("annotate(out)" == arg.attributes) self.assertTrue( "__thiscall__ annotate(no throw)" == do_nothing.attributes) self.assertTrue( numeric.member_operators(name="=")[0].attributes == "__thiscall__")
def test_attributes(self): decls = parser.parse([self.header], self.config) Test.global_ns = declarations.get_global_namespace(decls) Test.global_ns.init_optimizer() numeric = self.global_ns.class_('numeric_t') do_nothing = numeric.member_function('do_nothing') arg = do_nothing.arguments[0] generator = self.config.xml_generator_from_xml_file if generator.is_castxml1 or \ (generator.is_castxml and float(generator.xml_output_version) >= 1.137): # This works since: # https://github.com/CastXML/CastXML/issues/25 # https://github.com/CastXML/CastXML/pull/26 # https://github.com/CastXML/CastXML/pull/27 # The version bump to 1.137 came way later but this is the # only way to make sure the test is running correctly self.assertTrue("annotate(sealed)" == numeric.attributes) self.assertTrue("annotate(no throw)" == do_nothing.attributes) self.assertTrue("annotate(out)" == arg.attributes) self.assertTrue( numeric.member_operators(name="=")[0].attributes is None) else: self.assertTrue("gccxml(no throw)" == do_nothing.attributes) self.assertTrue("gccxml(out)" == arg.attributes)
def test(self): db = pypp_utils.exposed_decls_db_t() config = parser.config_t( gccxml_path=autoconfig.gccxml.executable ) reader = parser.project_reader_t( config, None, decl_wrappers.dwfactory_t() ) decls = reader.read_files( [parser.create_text_fc(self.CODE)] ) global_ns = declarations.get_global_namespace( decls ) ns = global_ns.namespace( 'ns' ) ns_skip = global_ns.namespace( 'ns_skip' ) global_ns.exclude() ns.include() db.register_decls( global_ns, [] ) for x in ns.decls(recursive=True): self.failUnless( db.is_exposed( x ) == True ) for x in ns_skip.decls(recursive=True): self.failUnless( db.is_exposed( x ) == False ) db.save( os.path.join( autoconfig.build_dir, 'exposed.db.pypp' ) ) db2 = pypp_utils.exposed_decls_db_t() db2.load( os.path.join( autoconfig.build_dir, 'exposed.db.pypp' ) ) for x in ns.decls(recursive=True): self.failUnless( db.is_exposed( x ) == True ) ns_skip = global_ns.namespace( 'ns_skip' ) for x in ns_skip.decls(recursive=True): self.failUnless( db.is_exposed( x ) == False )
def test_map_gcc5(self): """ The code in test_map_gcc5.hpp was breaking pygccxml. Test that case (gcc5 + castxml + c++11). See issue #45 and #55 """ if self.config.xml_generator == "gccxml": return decls = parser.parse([self.header], self.config) global_ns = declarations.get_global_namespace(decls) # This calldef is defined with gcc > 4.9 (maybe earlier, not tested) # and -std=c++11. Calling create_decl_string is failing with gcc. # With clang the calldef does not exist so the matcher # will just return an empty list, letting the test pass. # See the test_argument_without_name.py for an equivalent test, # which is not depending on the presence of the _M_clone_node # method in the stl_tree.h file. criteria = declarations.calldef_matcher(name="_M_clone_node") free_funcs = declarations.matcher.find(criteria, global_ns) for free_funcs in free_funcs: free_funcs.create_decl_string(with_defaults=False)
def parse_files(path, files): # Find the location of the xml generator (castxml or gccxml) #generator_path, generator_name = utils.find_xml_generator() #print("GENER " + generator_path) # Configure the xml generator args = { 'include_paths':[path], 'keep_xml': True } if(xml_generator != None): args['xml_generator'] =xml_generator if(xml_generator_path != None): args['xml_generator_path'] =xml_generator_path xml_generator_config = parser.xml_generator_configuration_t(**args) # not sure this actually does anything when compilation_mode is set to "ALL_AT_ONCE" def cache_file(filename): return parser.file_configuration_t( data=filename, content_type=parser.CONTENT_TYPE.CACHED_SOURCE_FILE, cached_source_file=filename.replace(path, "tmp/xml")+".xml") cached_files = [cache_file(f) for f in files] project_reader = parser.project_reader_t(xml_generator_config) decls = project_reader.read_files( cached_files, compilation_mode=parser.COMPILATION_MODE.ALL_AT_ONCE) return declarations.get_global_namespace(decls)
def test_function_pointer(self): """ Test working with pointers and function pointers. """ decls = parser.parse([self.header], self.config) global_ns = declarations.get_global_namespace(decls) # Test on a function pointer criteria = declarations.variable_matcher(name="func1") variables = declarations.matcher.find(criteria, global_ns) self.assertTrue(variables[0].name == "func1") self.assertTrue( isinstance(variables[0].decl_type, declarations.pointer_t)) self.assertTrue( str(variables[0].decl_type) == "void (*)( int,double )") self.assertTrue( declarations.is_calldef_pointer(variables[0].decl_type)) self.assertTrue( isinstance(declarations.remove_pointer(variables[0].decl_type), declarations.free_function_type_t)) # Get the function (free_function_type_t) and test the return and # argument types function = variables[0].decl_type.base self.assertTrue(isinstance(function.return_type, declarations.void_t)) self.assertTrue( isinstance(function.arguments_types[0], declarations.int_t)) self.assertTrue( isinstance(function.arguments_types[1], declarations.double_t)) # Test on a normal pointer criteria = declarations.variable_matcher(name="myPointer") variables = declarations.matcher.find(criteria, global_ns) self.assertTrue(variables[0].name == "myPointer") self.assertTrue( isinstance(variables[0].decl_type, declarations.pointer_t)) self.assertFalse( declarations.is_calldef_pointer(variables[0].decl_type)) self.assertTrue( isinstance(declarations.remove_pointer(variables[0].decl_type), declarations.volatile_t)) # Test on function pointer in struct (x8) for d in global_ns.declarations: if d.name == "x8": self.assertTrue( isinstance(d.decl_type, declarations.pointer_t)) self.assertTrue(declarations.is_calldef_pointer(d.decl_type)) self.assertTrue( isinstance( declarations.remove_pointer(d.decl_type), declarations.member_function_type_t)) self.assertTrue( str(declarations.remove_pointer(d.decl_type)) == "void ( ::some_struct_t::* )( )")
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() Test.xml_generator_from_xml_file = \ self.config.xml_generator_from_xml_file self.xml_generator_from_xml_file = Test.xml_generator_from_xml_file
def test2(self): code = 'int* aaaa[2][3][4][5];' src_reader = parser.source_reader_t(self.config) global_ns = declarations.get_global_namespace( src_reader.read_string(code)) aaaa_type = global_ns.var('aaaa').type self.failUnless( 'int *[2][3][4][5]' == aaaa_type.decl_string, aaaa_type.decl_string)
def test4(self): code = 'struct xyz{}; xyz aaaa[2][3];' src_reader = parser.source_reader_t(self.config) global_ns = declarations.get_global_namespace( src_reader.read_string(code)) aaaa_type = global_ns.variable('aaaa').type self.assertTrue( '::xyz[2][3]' == aaaa_type.decl_string, aaaa_type.decl_string)
def test3(self): code = 'int aaaa[2];' src_reader = parser.source_reader_t(self.config) global_ns = declarations.get_global_namespace( src_reader.read_string(code)) aaaa_type = global_ns.variable('aaaa').type self.assertTrue( 'int[2]' == aaaa_type.decl_string, aaaa_type.decl_string)
def test_on_big_file(file_name, count): file_name = os.path.join(autoconfig.data_directory, file_name) for i in range(count): reader = parser.project_reader_t( parser.xml_generator_configuration_t( xml_generator_path=autoconfig.generator_path)) decls = reader.read_files([parser.create_gccxml_fc(file_name)]) global_ns = declarations.get_global_namespace(decls) global_ns.init_optimizer()
def setUp(self): if not gccxml_declarations_t.global_ns: decls = parser.parse( self.test_files, self.config, self.COMPILATION_MODE) gccxml_declarations_t.global_ns = \ declarations.get_global_namespace(decls) if not self.global_ns: self.global_ns = gccxml_declarations_t.global_ns
def global_namespace(options): config = setup_pygccxml(options) gcccache = options["gccxml-cache"] if not gcccache: gcccache = "gcccache" cache = parser.directory_cache.directory_cache_t(dir=gcccache, md5_sigs=False) # normalize input files so that cache can match them # mixed slashes does not play well with the cache in_files = [os.path.abspath(p) for p in options["infiles"]] decls = parser.parse(in_files, config, cache=cache) return declarations.get_global_namespace(decls)
def test(self): decls = parser.parse_string(code, self.config) global_ns = declarations.get_global_namespace(decls) # TODO: demangled attribute does not existe for castxml # and will not be added. Remove this test once gccxml # support is dropped. if self.config.xml_generator_from_xml_file.is_gccxml: global_ns.decl('A<int>') f = global_ns.free_function('f') self.assertTrue(f.demangled == 'void f<int>(A<int> const&)')
def setUp(self): reader = parser.source_reader_t( self.config ) decls = None if 32 == self.architecture: decls = reader.read_file( self.header ) else: original_get_architecture = utils.get_architecture utils.get_architecture = lambda: 64 decls = reader.read_xml_file( os.path.join( autoconfig.data_directory, 'demangled_tester_64bit.xml' ) ) utils.get_architecture = original_get_architecture self.global_ns = declarations.get_global_namespace( decls )
def test(self): src_reader = parser.source_reader_t(self.config) global_ns = declarations.get_global_namespace( src_reader.read_string(code)) # TODO: demangled attribute does not existe for castxml # and will not be added. Remove this test once gccxml # support is dropped. if 'GCCXML' in utils.xml_generator: global_ns.decl('A<int>') f = global_ns.free_fun('f') self.assertTrue(f.demangled == 'void f<int>(A<int> const&)')
def show_declarations( self, file_configuration, compiler_config ): try: reader = parser.project_reader_t( config=compiler_config ) decls = reader.read_files( [file_configuration] ) global_ns = declarations.get_global_namespace( decls ) tmp = [] declarations.print_declarations( decls, verbose=False, writer=lambda x: tmp.append( x.rstrip() ) ) return os.linesep.join( tmp ), '' except Exception, error: user_msg = [ 'Error occured during code generation process!' ] user_msg.append( 'Error:' ) user_msg.append( str( error ) ) return '', '\n'.join( user_msg )
def test_map_gcc5(self): """ The code in test_map_gcc5.hpp was breaking pygccxml. Test that case (gcc5 + castxml + c++11). See issue #45 """ if self.config.xml_generator == "gccxml": return decls = parser.parse([self.header], self.config) self.global_ns = declarations.get_global_namespace(decls)
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)
def parseHeader(decls, hFile): global freeFnList global clsList global ns ns = declarations.get_global_namespace( decls ) ns.ALLOW_EMPTY_MDECL_WRAPPER = True # non-member functions freeFnList = [] for func in ns.free_funs(header_file = hFile): if func.name.startswith("__builtin"): continue # filter builtin functions freeFnList.append(func) return freeFnList
def test_is_elaborated_type(self): """ Test for the is_elaborated function """ if self.config.castxml_epic_version != 1: return decls = parser.parse([self.header], self.config) global_ns = declarations.get_global_namespace(decls) if self.config.xml_generator_from_xml_file.is_castxml1: for specifier in ["class", "struct", "enum", "union"]: self._test_impl_yes(global_ns, specifier) self._test_impl_no(global_ns, specifier) self._test_arg_impl(global_ns, specifier)
def main(): config = parser.config_t(include_paths=["../../include"], compiler="gcc") headers = ["brw_types.h", "brw_structs.h"] decls = parser.parse(headers, config, parser.COMPILATION_MODE.ALL_AT_ONCE) global_ns = declarations.get_global_namespace(decls) names = [] for class_ in global_ns.classes(decl_filter): names.append(class_.name) names.sort() dump_interfaces(decls, global_ns, names) dump_implementations(decls, global_ns, names)
def test6(self): code = 'char volatile arr[4] = {};' src_reader = parser.source_reader_t(self.config) global_ns = declarations.get_global_namespace( src_reader.read_string(code)) arr_type = global_ns.variable('arr').decl_type if self.config.xml_generator == "gccxml": self.assertTrue( 'char [4] volatile' == arr_type.decl_string, arr_type.decl_string) else: self.assertTrue( 'char volatile [4]' == arr_type.decl_string, arr_type.decl_string) self.assertTrue( declarations.is_array(arr_type)) self.assertTrue( declarations.is_volatile(arr_type))
def main(): print copyright.strip() print print '/**' print ' * @file' print ' * Dump SVGA commands.' print ' *' print ' * Generated automatically from svga3d_reg.h by svga_dump.py.' print ' */' print print '#include "svga_types.h"' print '#include "svga_shader_dump.h"' print '#include "svga3d_reg.h"' print print '#include "util/u_debug.h"' print '#include "svga_dump.h"' print config = parser.config_t( include_paths = ['../../../include', '../include'], compiler = 'gcc', ) headers = [ 'svga_types.h', 'svga3d_reg.h', ] decls = parser.parse(headers, config, parser.COMPILATION_MODE.ALL_AT_ONCE) global_ns = declarations.get_global_namespace(decls) names = set() for id, header, body, footer in cmds: names.add(header) for struct, count in body: names.add(struct) if footer is not None: names.add(footer) for class_ in global_ns.classes(lambda decl: decl.name in names): dump_struct(decls, class_) dump_cmds()
def test_infinite_recursion_sstream(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) # Real life example of the bug. This leads to a similar error, # but the situation is more complex as there are multiple # classes that are related the one to the others # (basic_istream, basic_ios, ios_base, ...) test_ns = global_ns.namespace('Test2') cls = test_ns.class_('FileStreamDataStream') declarations.type_traits_classes.find_noncopyable_vars(cls) self.assertFalse(declarations.type_traits_classes.is_noncopyable(cls))
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)
def setUp(self): if not self.global_ns: xml_file = os.path.join( autoconfig.data_directory, 'ogre.1.7.xml' ) reader = parser.source_reader_t( autoconfig.cxx_parsers_cfg.gccxml ) self.global_ns = declarations.get_global_namespace( reader.read_xml_file(xml_file) ) self.global_ns.init_optimizer()
def __init__(self, *args): parser_test_case.parser_test_case_t.__init__(self, *args) self.header = "find_noncopyable_vars.hpp" decls = parser.parse([self.header], self.config) self.global_ns = declarations.get_global_namespace(decls)
def generate_xml(env): heads = [] flags = '' add_sources(heads, 'include/core', 'hpp') add_sources(heads, 'include/gen', 'hpp') gen_path = '/usr/bin/castxml' if sys.platform == 'win32': gen_path = "C:\\castxml\\bin\\castxml.exe" generator_path = gen_path generator_name = "castxml" for st in env['CCFLAGS']: flags += ' ' + st # Configure the xml generator xml_generator_config = parser.xml_generator_configuration_t( xml_generator_path=generator_path, xml_generator=generator_name, compiler=env['CXX'], compiler_path=env['CC'], include_paths=env['CPPPATH'], keep_xml=True, flags=flags, castxml_epic_version=1) # To test just do [heads[index]] # Parse the cpp files and output docs for t in heads: decls = parser.parse([t], xml_generator_config) global_ns = declarations.get_global_namespace(decls) ns = global_ns.namespace('godot') classes = to_dict(ns.classes(allow_empty=True), t) print(classes.values()) for clAss in classes.values(): print(clAss.name) # Parse classes if clAss.name != "" and clAss.class_type == 'class' or ( not clAss.name.startswith('_') and clAss.class_type == 'struct') or clAss.class_type == 'union': print(clAss.class_type) root = ET.Element('class', name=clAss.name, path=t) methods = ET.SubElement(root, 'methods') members = ET.SubElement(root, 'members') constants = ET.SubElement(root, 'constants') if len(clAss.bases) != 0: root.set('inherits', clAss.bases[0].related_class.name) # Parse functions for member in clAss.member_functions(allow_empty=True): if member.access_type == 'public' and member.name != "": method = ET.SubElement(methods, 'method', name=member.name) typ = str(member.return_type).replace( '::', '').replace('godot', '').replace('const', '') returnType = ET.SubElement(method, 'return', type=typ) indx = 0 for args in member.arguments: if str(args.decl_type) in member.decl_string: typeText = str(args.decl_type).replace( '::', '').replace('godot', '').replace('const', '') argument = ET.SubElement(method, 'argument', index=str(indx), name=args.name, type=typeText) # indx += 1 if member.has_const: method.set('qualifiers', "const") # Parse constructors for member in clAss.constructors(allow_empty=True): if member.access_type == 'public' and member.name != "": method = ET.SubElement(methods, 'method', name=member.name) typ = str(member.return_type).replace( '::', '').replace('godot', '').replace('const', '') if typ != 'None': returnType = ET.SubElement(method, 'return', type=typ) indx = 0 for args in member.arguments: if str(args.decl_type) in member.decl_string: typeText = str(args.decl_type).replace( '::', '').replace('godot', '').replace('const', '') argument = ET.SubElement(method, 'argument', index=str(indx), name=args.name, type=typeText) # indx += 1 if member.has_const: method.set('qualifiers', "const") # Parse variables for var in clAss.variables(allow_empty=True): if var.name == "": continue if var.access_type == 'public': typeText = str(var.decl_type).replace('::', '').replace( 'godot', '') if '[' in typeText: typeText = 'Array<' + typeText.partition('[')[0] + '>' variable = ET.SubElement(members, 'member', name=var.name, type=typeText) # Parse enumerations for enum in clAss.enumerations(allow_empty=True): for val in enum.values: constant = ET.SubElement(constants, 'constant', name=val[0], value=str(val[1]), enum=enum.name) indent(root) ET.ElementTree(root).write('../libraries/' + 'Godot/' + clAss.name + '.xml')