def gen_xml(params, q_result, q_error): ''' Generate XML code @param params: List of parameters [gccxml,incPath,macros] @param q_result: python queue to put result in @param q_error: python queue to put error in @return None (isn't evaluated) ''' try: config = parser.config_t( gccxml_path=params[0] , include_paths=params[1] , define_symbols=params[2]) header_file = params[3] config.include_paths.append( os.path.split( header_file )[0] ) config.working_directory = os.path.split( header_file )[0] reader = parser.source_reader_t( config=config ) xml_file = reader.create_xml_file( header_file ) xml_file_obj = file( xml_file ) q_result.put( xml_file_obj.read() ) xml_file_obj.close() os.remove( xml_file ) #self._statistics.set_parse_time( parsed_time ) #self._statistics.set_code_generation_time( 0 ) except Exception, error: q_result.put(str( error )) q_error.put(str( error ))
def parseIncludeFile(f, define = [], includes = [], ps = 4): global ptr_size ptr_size = ps gccxmlexe = os.getenv("GCCXML", "gccxml") config = parser.config_t(gccxml_path = gccxmlexe, define_symbols = define, include_paths = includes) functions = {} if isinstance(f, list): global_ns = parser.parse(f, config) else: global_ns = parser.parse([f], config) all_decls = declarations.make_flatten(global_ns) all_functions = filter(lambda decl: isinstance(decl, declarations.free_function_t), \ all_decls) for f in all_functions: if not f.name.startswith("__"): # if f.name == "ReadFileEx": functions[f.name] = parseFunction(f) return functions
def create_module(): parser_config = parser.config_t( ) fx_xml = os.path.join( settings.xml_files, 'fx.xml' ) mb = module_builder.module_builder_t( [ parser.create_cached_source_fc( 'fx.h', fx_xml ) ] , gccxml_path=settings.gccxml_path , include_paths=[settings.boost_path, settings.tnfox_include_path] , define_symbols=settings.defined_symbols_gccxml ) mb.run_query_optimizer() print 'filtering declarations' filter_decls( mb ) print 'filtering declarations - done' print 'set call policies' set_call_policies( mb ) print 'set call policies - done' print 'customize declarations' customize_decls( mb ) print 'customize declarations - done' print 'creating module' mb.build_code_creator(settings.module_name ) print 'creating module - done' print 'customizing module' customize_module( mb ) print 'customizing module - done' return mb
def setup_pygccxml(options): """options dictionary keys: - infiles .. list of c++ files to process - includes .. list of c++ include directories """ # logger log_level = logging.NOTSET # logging.NOTSET|DEBUG utils.loggers.gccxml.setLevel(log_level) utils.loggers.root.setLevel(log_level) utils.loggers.root.addHandler(logging.StreamHandler()) # trailing backslash quotes the following " includes = [inc.rstrip("\\") for inc in options["includes"]] gccxml_path = options["gccxml-path"] if not gccxml_path: gccxml_path = os.getenv("JAG_GCCXML_PATH") if None == gccxml_path: gccxml_path = "GCCXML not found" gccxml_compiler = None if options["gccxml-compiler"]: gccxml_compiler = options["gccxml-compiler"] # configure GCC-XML parser config = parser.config_t( gccxml_path=gccxml_path, compiler=gccxml_compiler, include_paths=includes, undefine_symbols=["__MINGW32__"], define_symbols=[], ) return config
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 setup_pygccxml(options): """options dictionary keys: - infiles .. list of c++ files to process - includes .. list of c++ include directories """ #logger log_level = logging.NOTSET # logging.NOTSET|DEBUG utils.loggers.gccxml.setLevel(log_level) utils.loggers.root.setLevel(log_level) utils.loggers.root.addHandler(logging.StreamHandler()) #trailing backslash quotes the following " includes = [inc.rstrip('\\') for inc in options['includes']] gccxml_path = options['gccxml-path'] if not gccxml_path: gccxml_path = os.getenv("JAG_GCCXML_PATH") if None == gccxml_path: gccxml_path = "GCCXML not found" gccxml_compiler = None if options['gccxml-compiler']: gccxml_compiler = options['gccxml-compiler'] #configure GCC-XML parser config = parser.config_t( gccxml_path= gccxml_path,\ compiler = gccxml_compiler, \ include_paths= includes,\ undefine_symbols=['__MINGW32__'], define_symbols=[]) return config
def main(): #set up argument parser cmd_parser = argparse.ArgumentParser() cmd_parser.add_argument('--lib2geom_dir', action='store') cmd_parser.add_argument('--file_name', action='store') cmd_parser.add_argument('--class_name', action='store') cmd_args = cmd_parser.parse_args() #set up pygccxml includes = [ cmd_args.lib2geom_dir, os.path.join(cmd_args.lib2geom_dir, 'src'), "/usr/include/boost" ] config = parser.config_t(compiler='gcc', include_paths=includes, cflags="") file_to_parse = [ os.path.join(cmd_args.lib2geom_dir, "src", "2geom", cmd_args.file_name) ] decls = parser.parse(file_to_parse, config) global_namespace = declarations.get_global_namespace(decls) wrapper = CythonWrapper(global_namespace) wrapper.wrap_class(cmd_args.class_name, cmd_args.file_name)
def __parse_declarations( self, files, gccxml_config, compilation_mode, cache, indexing_suite_version ): if None is gccxml_config: gccxml_config = parser.config_t() if None is compilation_mode: compilation_mode = parser.COMPILATION_MODE.FILE_BY_FILE start_time = time.clock() self.logger.debug( 'parsing files - started' ) reader = parser.project_reader_t( gccxml_config, cache, decl_wrappers.dwfactory_t() ) decls = reader.read_files( files, compilation_mode ) self.logger.debug( 'parsing files - done( %f seconds )' % ( time.clock() - start_time ) ) self.logger.debug( 'settings declarations defaults - started' ) global_ns = decls_package.matcher.get_single( decls_package.namespace_matcher_t( name='::' ) , decls ) if indexing_suite_version != 1: for cls in global_ns.classes(): cls.indexing_suite_version = indexing_suite_version try: for cls in global_ns.decls(decl_type=decls_package.class_declaration_t): cls.indexing_suite_version = indexing_suite_version except RuntimeError: pass start_time = time.clock() self.__apply_decls_defaults(decls) self.logger.debug( 'settings declarations defaults - done( %f seconds )' % ( time.clock() - start_time ) ) return global_ns
def test(self): db = pypp_utils.exposed_decls_db_t() config = parser.config_t( gccxml_path=autoconfig.gccxml.executable, compiler=pygccxml.utils.native_compiler.get_gccxml_compiler()) 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(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 process_get_result(args): global known_models file_name = args[0] cpp_flags = args[1] previous_flags = args[2] parser_cpp_flags = " -D\'__deprecated__(s)=__deprecated__\' -D_GNU_SOURCE -P -O3" + \ " -I/usr/lib/gcc/x86_64-linux-gnu/4.7 -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include" + \ " -I/usr/include/x86_64-linux-gnu " + " ".join(cpp_flags) config = parser.config_t( cflags=parser_cpp_flags ) try: decls = parser.parse( [file_name], config ) except parser.source_reader.gccxml_runtime_error_t as e: return (False, file_name, previous_flags, cpp_flags) target_model = args[3] found = "" decls = declarations.get_global_namespace(decls).declarations models = parse_decls(decls) for m in models: m_info = m.get_model_info() m_str = str(m) known_models[m_info] = m_str if m_info == target_model: found = m_str return (True, file_name, found)
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 parseIncludeFile(f, define=[], includes=[], ps=4): global ptr_size ptr_size = ps gccxmlexe = os.getenv("GCCXML", "gccxml") config = parser.config_t(gccxml_path=gccxmlexe, define_symbols=define, include_paths=includes) functions = {} if isinstance(f, list): global_ns = parser.parse(f, config) else: global_ns = parser.parse([f], config) all_decls = declarations.make_flatten(global_ns) all_functions = filter(lambda decl: isinstance(decl, declarations.free_function_t), \ all_decls) for f in all_functions: if not f.name.startswith("__"): # if f.name == "ReadFileEx": functions[f.name] = parseFunction(f) return functions
def __parse_declarations( self, files, gccxml_config, compilation_mode=None, cache=None ): if None is gccxml_config: gccxml_config = parser.config_t() if None is compilation_mode: compilation_mode = parser.COMPILATION_MODE.FILE_BY_FILE start_time = time.clock() self.logger.debug( 'parsing files - started' ) reader = parser.project_reader_t( gccxml_config, cache, decl_wrappers.dwfactory_t() ) decls = reader.read_files( files, compilation_mode ) self.logger.debug( 'parsing files - done( %f seconds )' % ( time.clock() - start_time ) ) return decls_package.matcher.get_single( decls_package.namespace_matcher_t( name='::' ) , decls )
def _create_xml_file(self): # On windows I have some problems to compile boost.date_time # library, so I use xml files generated on linux config = parser.config_t( gccxml_path=date_time_settings.gccxml.executable, include_paths=[date_time_settings.boost.include], define_symbols=date_time_settings.defined_symbols, undefine_symbols=date_time_settings.undefined_symbols, ) reader = parser.source_reader_t(config) destination = os.path.join(date_time_settings.date_time_pypp_include, "date_time.pypp.xml") if sys.platform == "linux2": reader.create_xml_file(self.__file, destination) return destination
def _create_xml_file(self): #On windows I have some problems to compile boost.date_time #library, so I use xml files generated on linux config = parser.config_t( gccxml_path=date_time_settings.gccxml.executable, include_paths=[date_time_settings.boost.include], define_symbols=date_time_settings.defined_symbols, undefine_symbols=date_time_settings.undefined_symbols) reader = parser.source_reader_t(config) destination = os.path.join(date_time_settings.date_time_pypp_include, 'date_time.pypp.xml') if sys.platform == 'linux2': reader.create_xml_file(self.__file, destination) return destination
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 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 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 main(): #set up argument parser cmd_parser = argparse.ArgumentParser() cmd_parser.add_argument('--lib2geom_dir', action = 'store') cmd_parser.add_argument('--file_name', action = 'store') cmd_parser.add_argument('--class_name', action = 'store') cmd_args = cmd_parser.parse_args() #set up pygccxml includes = [cmd_args.lib2geom_dir, os.path.join(cmd_args.lib2geom_dir, 'src'), "/usr/include/boost"] config = parser.config_t(compiler='gcc', include_paths=includes, cflags="") file_to_parse = [os.path.join(cmd_args.lib2geom_dir, "src", "2geom", cmd_args.file_name)] decls = parser.parse( file_to_parse, config ) global_namespace = declarations.get_global_namespace( decls ) wrapper = CythonWrapper(global_namespace) wrapper.wrap_class(cmd_args.class_name, cmd_args.file_name)
def test(self): config = parser.config_t( gccxml_path=autoconfig.gccxml.executable ) code = [] code.append('struct a{};') code.append('struct b{};') code.append('struct c{};') code.append('struct d : public a{};') code.append('struct e : public a, public b{};') code.append('struct f{};') code.append('struct g : public d, public f{};') code.append('struct h : public f{};') code.append('struct i : public h, public g{};') code.append('struct j{};') code.append('struct k{};') global_ns = parser.parse_string( os.linesep.join( code ), config ) decls = global_ns[0].declarations dorder = module_creator.findout_desired_order( decls ) self.failUnless( len( code ) == len( dorder ), 'all classes should stay within the list' ) for i in range( 1, len(dorder) ): bases = set( self._findout_base_classes( dorder[i] ) ) exported = set( dorder[:i]) self.failUnless( bases.issubset( exported ) , 'for derived class %s not all base classes have been exported' % dorder[i].name )
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)
# print('Found {:} in {:}'.format(header_file, path)) for ee in sorted(kernel_prio, key=lambda k: k[1]): if ee[0] in path: 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():
import os import sys #find out the file location within the sources tree this_module_dir_path = os.path.abspath ( os.path.dirname( sys.modules[__name__].__file__) ) #find out gccxml location gccxml_09_path = os.path.join( this_module_dir_path, '..', '..', '..', 'gccxml_bin', 'v09', sys.platform, 'bin' ) #add pygccxml package to Python path sys.path.append( os.path.join( this_module_dir_path, '..', '..' ) ) from pygccxml import parser from pygccxml import declarations #configure GCC-XML parser config = parser.config_t( gccxml_path=gccxml_09_path ) #parsing source file decls = parser.parse( ['example.hpp'], config ) global_ns = declarations.get_global_namespace( decls ) #get object that describes unittests namespace unittests = global_ns.namespace( 'unittests' ) print '"unittests" declarations: ' declarations.print_declarations( unittests ) #print all base and derived class names for class_ in unittests.classes(): print 'class "%s" hierarchy information:' % class_.name
# print('Found {:} in {:}'.format(header_file, path)) for ee in sorted(kernel_prio, key=lambda k: k[1]): if ee[0] in path: 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
def parse(self): """Parse the header files and setup the known declarations. Currently this method can only be called once. This method can be called anytime after initialization and all Template() calls have been made. @returns: Returns the root of the declaration tree @rtype: L{IDecl<declwrapper.IDecl>} @postcondition: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored. """ if self.mHeaderFiles==[]: raise ValueError, "No header files specified" if self.mVerbose: print "Parsing headers: ", self.mHeaderFiles # Record the time when parsing started... self.mStartTime = time.time() # Create and initialize the config object parser_cfg = parser.config_t(self.mGccXmlPath, self.mWorkingDir, self.mIncludePaths, define_symbols=self.mDefines, undefine_symbols=self.mUndefines, start_with_declarations=None) full_header_list = self.mHeaderFiles[:] # Handle template instantiation as needed temp_file, temp_filename = (None,None) template_instantiation_text = self.buildTemplateFileContents() if None != template_instantiation_text: temp_filename = pygccxml.utils.create_temp_file_name(suffix=".h") temp_file = file(temp_filename, 'w') temp_file.write(template_instantiation_text) temp_file.close() if self.mVerbose: print " creating template instantiation file: ", temp_filename full_header_list.append(temp_filename) # Create the cache object... if self.mCacheDir!=None: if self.mVerbose: print "Using directory cache in '%s'"%self.mCacheDir cache = parser.directory_cache_t(self.mCacheDir) elif self.mCacheFile!=None: if self.mVerbose: print "Using file cache '%s'"%self.mCacheFile cache = parser.file_cache_t(self.mCacheFile) else: if self.mVerbose: print "No cache in use" cache = None # Create the parser object... the_parser = parser.project_reader_t(config=parser_cfg, cache=cache, decl_factory=decl_wrappers.dwfactory_t()) # ...and parse the headers parsed_decls = the_parser.read_files(full_header_list, parser.project_reader.COMPILATION_MODE.FILE_BY_FILE) assert len(parsed_decls) == 1 # assume that we get root of full tree self.mDeclRoot = parsed_decls[0] # Parse the files and add to decl root # - then traverse tree setting everything to ignore self.mDeclRootWrapper = DeclWrapper(self.mDeclRoot) # Set the module builder instance (this is done here and not in the # constructor so that Allen's DeclWrapper object still work as well) self.mDeclRootWrapper.modulebuilder = self self.mDeclRootWrapper.ignore() # Cleanup if temp_filename: pygccxml.utils.remove_file_no_raise( temp_filename ) typedef_decls = declarations.make_flatten(parsed_decls) typedef_decls = decls = filter( lambda x: (isinstance( x, declarations.typedef_t ) and not x.name.startswith('__') and x.location.file_name != "<internal>") , typedef_decls ) self.mTypeDefMap = {} for d in typedef_decls: type_def_name = d.name full_name = declarations.full_name(d) if full_name.startswith("::"): # Remove the base namespace full_name = full_name[2:] real_type_name = d.type.decl_string if real_type_name.startswith("::"): # Remove base namespace real_type_name = real_type_name[2:] self.mTypeDefMap[full_name] = real_type_name self.mParseEndTime = time.time() if self.mVerbose: print "Completed parsing in %s."%self._time2str(self.mParseEndTime-self.mStartTime) return self.mDeclRootWrapper
def parse(self): """Parse the header files and setup the known declarations. Currently this method can only be called once. This method can be called anytime after initialization and all Template() calls have been made. :rtype: Returns the root of the declaration tree @rtype: L{IDecl<declwrapper.IDecl>} @postcondition: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored. """ if self.mHeaderFiles == []: raise ValueError, "No header files specified" if self.mVerbose: print "Parsing headers: ", self.mHeaderFiles # Record the time when parsing started... self.mStartTime = time.time() # Create and initialize the config object parser_cfg = parser.config_t(self.mGccXmlPath, self.mWorkingDir, self.mIncludePaths, define_symbols=self.mDefines, undefine_symbols=self.mUndefines, start_with_declarations=None) full_header_list = self.mHeaderFiles[:] # Handle template instantiation as needed temp_file, temp_filename = (None, None) template_instantiation_text = self.buildTemplateFileContents() if None != template_instantiation_text: temp_filename = pygccxml.utils.create_temp_file_name(suffix=".h") temp_file = file(temp_filename, 'w') temp_file.write(template_instantiation_text) temp_file.close() if self.mVerbose: print " creating template instantiation file: ", temp_filename full_header_list.append(temp_filename) # Create the cache object... if self.mCacheDir != None: if self.mVerbose: print "Using directory cache in '%s'" % self.mCacheDir cache = parser.directory_cache_t(self.mCacheDir) elif self.mCacheFile != None: if self.mVerbose: print "Using file cache '%s'" % self.mCacheFile cache = parser.file_cache_t(self.mCacheFile) else: if self.mVerbose: print "No cache in use" cache = None # Create the parser object... the_parser = parser.project_reader_t( config=parser_cfg, cache=cache, decl_factory=decl_wrappers.dwfactory_t()) # ...and parse the headers parsed_decls = the_parser.read_files( full_header_list, parser.project_reader.COMPILATION_MODE.FILE_BY_FILE) assert len(parsed_decls) == 1 # assume that we get root of full tree self.mDeclRoot = parsed_decls[0] # Parse the files and add to decl root # - then traverse tree setting everything to ignore self.mDeclRootWrapper = DeclWrapper(self.mDeclRoot) # Set the module builder instance (this is done here and not in the # constructor so that Allen's DeclWrapper object still work as well) self.mDeclRootWrapper.modulebuilder = self self.mDeclRootWrapper.ignore() # Cleanup if temp_filename: pygccxml.utils.remove_file_no_raise(temp_filename) typedef_decls = declarations.make_flatten(parsed_decls) typedef_decls = decls = filter( lambda x: (isinstance(x, declarations.typedef_t) and not x.name.startswith( '__') and x.location.file_name != "<internal>"), typedef_decls) self.mTypeDefMap = {} for d in typedef_decls: type_def_name = d.name full_name = declarations.full_name(d) if full_name.startswith("::"): # Remove the base namespace full_name = full_name[2:] real_type_name = d.type.decl_string if real_type_name.startswith("::"): # Remove base namespace real_type_name = real_type_name[2:] self.mTypeDefMap[full_name] = real_type_name self.mParseEndTime = time.time() if self.mVerbose: print "Completed parsing in %s." % self._time2str( self.mParseEndTime - self.mStartTime) return self.mDeclRootWrapper
global pathLen, this_module_dir_path this_module_dir_path = os.path.abspath( os.path.dirname(sys.modules[__name__].__file__)) pathLen = len(this_module_dir_path) #find out gccxml location #gccxml_09_path = os.path.join( this_module_dir_path, '..', '..', '..', 'gccxml_bin', 'v09', sys.platform, 'bin' ) gccxml_09_path = os.path.join('gccxml') #add pygccxml package to Python path #sys.path.append( os.path.join( this_module_dir_path, '..', '..' ) ) print this_module_dir_path from pygccxml import parser from pygccxml import declarations #configure GCC-XML parser config = parser.config_t(gccxml_path=gccxml_09_path, compiler='gcc') #parsing source file decls = parser.parse(['HaskellBulletAPI.h'], config) global_ns = declarations.get_global_namespace(decls) #from bulletCfg import * #{#fun [pure] [unsafe] cid [as (hsid | ^)] [ctxt =>] { parm1 , ... , parmn } -> parm #{#class [hsid1 =>] hsid2 hsid3#} # class example #{#pointer *GtkWidget newtype#} #{#class GtkObjectClass => GtkWidgetClass GtkWidget#} # Overview:
# Distributed under the Boost Software License, Version 1.0. (See # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) import autoconfig import os from pygccxml import parser from pyplusplus import module_builder #Configurating GCC-XML parser #Basically you should copy here your makefile configuration parser_configuration = parser.config_t( #path to GCC-XML binary gccxml_path=r"c:/tools/gccxml/bin/gccxml.exe", working_directory=r"D:\pygccxml_sources\source\pyplusplus\unittests\data", include_paths=['D:/pygccxml_sources/source/pyplusplus/gui'], define_symbols=[], compiler=pygccxml.utils.native_compiler.get_gccxml_compiler()) #Creating an instance of class that will help you to expose your declarations mb = module_builder.module_builder_t([ r"D:\pygccxml_sources\source\pyplusplus\unittests\data\call_policies_to_be_exported.hpp" ], parser_configuration) #Well, don't you want to see what is going on? mb.print_declarations() #Creating code creator. After this step you should not modify/customize declarations. mb.build_code_creator(module_name='pyplusplus')
def __init__( self , files , gccxml_path='' , working_directory='.' , include_paths=None , define_symbols=None , undefine_symbols=None , start_with_declarations=None , compilation_mode=None , cache=None , optimize_queries=True , ignore_gccxml_output=False , indexing_suite_version=1 , cflags="" , encoding='ascii' , compiler=None , gccxml_config=None): """ :param files: list of files, declarations from them you want to export :type files: list of strings or :class:`parser.file_configuration_t` instances :param gccxml_path: path to gccxml binary. If you don't pass this argument, pygccxml parser will try to locate it using you environment PATH variable :type gccxml_path: str :param include_paths: additional header files location. You don't have to specify system and standard directories. :type include_paths: list of strings :param define_symbols: list of symbols to be defined for preprocessor. :param define_symbols: list of strings :param undefine_symbols: list of symbols to be undefined for preprocessor. :param undefine_symbols: list of strings :param cflags: Raw string to be added to gccxml command line. :param gccxml_config: instance of pygccxml.parser.config_t class, holds gccxml( compiler ) configuration. You can use this argument instead of passing the compiler configuration separately. """ module_builder.module_builder_t.__init__( self, global_ns=None, encoding=encoding ) if not gccxml_config: gccxml_config = parser.config_t( gccxml_path=gccxml_path , working_directory=working_directory , include_paths=include_paths , define_symbols=define_symbols , undefine_symbols=undefine_symbols , start_with_declarations=start_with_declarations , ignore_gccxml_output=ignore_gccxml_output , cflags=cflags , compiler=compiler) #may be in future I will add those directories to user_defined_directories to self.__code_creator. self.__parsed_files = map( pygccxml_utils.normalize_path , parser.project_reader_t.get_os_file_names( files ) ) tmp = map( lambda file_: os.path.split( file_ )[0], self.__parsed_files ) self.__parsed_dirs = filter( None, tmp ) self.global_ns = self.__parse_declarations( files , gccxml_config , compilation_mode , cache , indexing_suite_version) self.global_ns.decls(recursive=True, allow_empty=True)._code_generator = decl_wrappers.CODE_GENERATOR_TYPES.CTYPES self.__code_creator = None if optimize_queries: self.run_query_optimizer() self.__declarations_code_head = [] self.__declarations_code_tail = [] self.__registrations_code_head = [] self.__registrations_code_tail = []
# Copyright 2004-2008 Roman Yakovenko. # Distributed under the Boost Software License, Version 1.0. (See # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) import os import sys from pygccxml import parser from pygccxml import declarations #configure GCC-XML parser config = parser.config_t(include_paths=[ "E:\\Work\\0429\\PSDash\\Source", "E:\\Work\\0429\\PSDash\\include" ]) #parsing source file decls = parser.parse(['test.cpp'], config) global_ns = declarations.get_global_namespace(decls) #get object that describes unittests namespace dash = global_ns.namespace('TEST') for free_fun in dash.free_functions(): print free_fun print dir(free_fun)
from pygccxml import parser, declarations import pymisc # useful functions + debugging import pyscope import pyresolvable import pydeps import sys global prjDir prjDir = sys.path[0] prjDir = prjDir.rstrip('/') # if it's just '/' prjDir += '/' # test files tests = [ \ ['tests/dbgprint.h', None, {}], \ ['tests/3proxy/proxy.h', parser.config_t(define_symbols = ['NOODBC']), {'header':'tests/3proxy/proxy.h'}] ] # modify some tests fields for test in tests: if test[2].has_key('header'): test[2]['header'] = prjDir + test[2]['header'] # when pygccxml does not find anything of particular type declarations.ALLOW_EMPTY_MDECL_WRAPPER = True def main(): runTest(0)
def mb_override__init__( self , files , gccxml_path='' , working_directory='.' , include_paths=None , define_symbols=None , undefine_symbols=None , start_with_declarations=None , compilation_mode=None , cache=None , optimize_queries=True , ignore_gccxml_output=False , indexing_suite_version=1 , cflags="" , dependent_headers=[]): """ See standard method. dependent_headers: A list of header files (full paths) that this module depends upon and should be made part of the cache signature. """ object.__init__( self ) self.logger = _logging_.loggers.module_builder gccxml_config = parser.config_t( gccxml_path=gccxml_path , working_directory=working_directory , include_paths=include_paths , define_symbols=define_symbols , undefine_symbols=undefine_symbols , start_with_declarations=start_with_declarations , ignore_gccxml_output=ignore_gccxml_output , cflags=cflags) #may be in future I will add those directories to user_defined_directories #to self.__code_creator. self._module_builder_t__working_dir = os.path.abspath( working_directory ) self._module_builder_t__parsed_files = map( decls_package.filtering.normalize_path , parser.project_reader_t.get_os_file_names( files ) ) tmp = map( lambda file_: os.path.split( file_ )[0], self._module_builder_t__parsed_files ) self._module_builder_t__parsed_dirs = filter( None, tmp ) self._module_builder_t__global_ns = None # Have to do it here because the parser changes the config :( config_sig = configuration_signature(gccxml_config) # If we have a cache filename # - Compute signature and check it against file # - If matches, load it if cache and os.path.exists(cache): mb_cache = ModuleBuilderCache(cache) self._module_builder_t__global_ns = \ mb_cache.getCachedTree(self._module_builder_t__parsed_files, config_sig) self._module_builder_t__code_creator = None # If didn't load global_ns from cache # - Parse and optimize it # - Then save to cache if requested if not self._module_builder_t__global_ns: self.logger.info("Parsing declarations.") self._module_builder_t__global_ns = self._module_builder_t__parse_declarations( files , gccxml_config , compilation_mode , None , indexing_suite_version) self._module_builder_t__code_creator = None if optimize_queries: self.logger.info("Running optimizer.") self.run_query_optimizer() if cache: mb_cache = ModuleBuilderCache(cache) mb_cache.dumpCachedTree(self._module_builder_t__parsed_files, config_sig, self._module_builder_t__global_ns) self._module_builder_t__declarations_code_head = [] self._module_builder_t__declarations_code_tail = [] self._module_builder_t__registrations_code_head = [] self._module_builder_t__registrations_code_tail = []
# Distributed under the Boost Software License, Version 1.0. (See # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) import autoconfig import os from pygccxml import parser from pyplusplus import module_builder #Configurating GCC-XML parser #Basically you should copy here your makefile configuration parser_configuration = parser.config_t( #path to GCC-XML binary gccxml_path=r"c:/tools/gccxml/bin/gccxml.exe" , working_directory=r"D:\pygccxml_sources\source\pyplusplus\unittests\data" , include_paths=['D:/pygccxml_sources/source/pyplusplus/gui'] , define_symbols=[] , compiler=pygccxml.utils.native_compiler.get_gccxml_compiler() ) #Creating an instance of class that will help you to expose your declarations mb = module_builder.module_builder_t( [r"D:\pygccxml_sources\source\pyplusplus\unittests\data\call_policies_to_be_exported.hpp"], parser_configuration ) #Well, don't you want to see what is going on? mb.print_declarations() #Creating code creator. After this step you should not modify/customize declarations. mb.build_code_creator( module_name='pyplusplus' ) #Writing code to file. mb.write_module( './bindings.cpp' )
# Copyright 2004 Roman Yakovenko. # Distributed under the Boost Software License, Version 1.0. (See # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) import sys sys.path.append('../..') #adding pygccxml to the path from pygccxml import parser from pygccxml import declarations #configure GCC-XML parser config = parser.config_t( gccxml_path='/home/roman/gccxml-build/bin/gccxml' ) #parsing source file decls = parser.parse( ['example.hpp'], config ) global_ns = declarations.get_global_namespace( decls ) #printing all declarations found in file and its includes declarations.print_declarations( global_ns ) #print all base and derived class names for class_ in global_ns.classes(): print class_.name print '\tbases: ', `[base.related_class.name for base in class_.bases]` print '\tderived: ', `[derive.related_class.name for derive in class_.derived]`
def parser_configuration(self): return parser.config_t( gccxml_path=self._gccxml_location.get() , include_paths=list(self._include_paths.get( 0, Tkinter.END ) ) , define_symbols=list(self._defines.get( 0, Tkinter.END ) ) )
def __init__( self , files , gccxml_path='' , working_directory='.' , include_paths=None , define_symbols=None , undefine_symbols=None , start_with_declarations=None , compilation_mode=None , cache=None , optimize_queries=True , ignore_gccxml_output=False , indexing_suite_version=1 , cflags="" , encoding='ascii' , compiler=None): """ @param files: list of files, declarations from them you want to export @type files: list of strings or L{file_configuration_t} instances @param gccxml_path: path to gccxml binary. If you don't pass this argument, pygccxml parser will try to locate it using you environment PATH variable @type gccxml_path: str @param include_paths: additional header files location. You don't have to specify system and standard directories. @type include_paths: list of strings @param define_symbols: list of symbols to be defined for preprocessor. @param define_symbols: list of strings @param undefine_symbols: list of symbols to be undefined for preprocessor. @param undefine_symbols: list of strings @param cflags: Raw string to be added to gccxml command line. """ object.__init__( self ) self.logger = _logging_.loggers.module_builder self.__encoding = encoding gccxml_config = parser.config_t( gccxml_path=gccxml_path , working_directory=working_directory , include_paths=include_paths , define_symbols=define_symbols , undefine_symbols=undefine_symbols , start_with_declarations=start_with_declarations , ignore_gccxml_output=ignore_gccxml_output , cflags=cflags , compiler=compiler) #may be in future I will add those directories to user_defined_directories #to self.__code_creator. self.__working_dir = os.path.abspath( working_directory ) self.__parsed_files = map( decls_package.filtering.normalize_path , parser.project_reader_t.get_os_file_names( files ) ) tmp = map( lambda file_: os.path.split( file_ )[0], self.__parsed_files ) self.__parsed_dirs = filter( None, tmp ) self.__global_ns = self.__parse_declarations( files , gccxml_config , compilation_mode , cache , indexing_suite_version) self.__code_creator = None if optimize_queries: self.run_query_optimizer() self.__declarations_code_head = [] self.__declarations_code_tail = [] self.__registrations_code_head = [] self.__registrations_code_tail = []
#find out the file location within the sources tree global pathLen,this_module_dir_path this_module_dir_path = os.path.abspath ( os.path.dirname( sys.modules[__name__].__file__) ) pathLen = len(this_module_dir_path) #find out gccxml location #gccxml_09_path = os.path.join( this_module_dir_path, '..', '..', '..', 'gccxml_bin', 'v09', sys.platform, 'bin' ) gccxml_09_path = os.path.join( 'gccxml' ) #add pygccxml package to Python path #sys.path.append( os.path.join( this_module_dir_path, '..', '..' ) ) print this_module_dir_path from pygccxml import parser from pygccxml import declarations #configure GCC-XML parser config = parser.config_t( gccxml_path=gccxml_09_path, compiler='gcc' ) #parsing source file decls = parser.parse( ['HaskellBulletAPI.h'], config ) global_ns = declarations.get_global_namespace( decls ) #from bulletCfg import * #{#fun [pure] [unsafe] cid [as (hsid | ^)] [ctxt =>] { parm1 , ... , parmn } -> parm #{#class [hsid1 =>] hsid2 hsid3#} # class example #{#pointer *GtkWidget newtype#} #{#class GtkObjectClass => GtkWidgetClass GtkWidget#} # Overview:
def parser_configuration(self): return parser.config_t( gccxml_path=self._gccxml_location.get(), include_paths=list(self._include_paths.get(0, Tkinter.END)), define_symbols=list(self._defines.get(0, Tkinter.END)))
import os import sys #find out the file location within the sources tree this_module_dir_path = os.path.abspath ( os.path.dirname( sys.modules[__name__].__file__) ) #find out gccxml location gccxml_09_path = os.path.join( this_module_dir_path, '..', '..', '..', 'gccxml_bin', 'v09', sys.platform, 'bin' ) #add pygccxml package to Python path sys.path.append( os.path.join( this_module_dir_path, '..', '..' ) ) from pygccxml import parser from pygccxml import declarations #configure GCC-XML parser config = parser.config_t( gccxml_path=gccxml_09_path, compiler='msvc71' ) #parsing source file decls = parser.parse( ['example.hpp'], config ) global_ns = declarations.get_global_namespace( decls ) #get object that describes unittests namespace unittests = global_ns.namespace( 'unittests' ) print '"unittests" declarations: \n' declarations.print_declarations( unittests ) #print all base and derived class names for class_ in unittests.classes(): print 'class "%s" hierarchy information:' % class_.name