def test_project_reader(self): reader = parser.project_reader_t(self.config) decls = reader.read_files( [parser.file_configuration_t(self.header, self.config.start_with_declarations)], parser.COMPILATION_MODE.FILE_BY_FILE) self.__check_result(decls) decls = reader.read_files( [parser.file_configuration_t(self.header, self.config.start_with_declarations)], parser.COMPILATION_MODE.ALL_AT_ONCE) self.__check_result(decls)
def test_project_reader_all_at_once(self): reader = parser.project_reader_t(self.config) decls = reader.read_files([ parser.file_configuration_t(self.header, self.config.start_with_declarations) ], parser.COMPILATION_MODE.ALL_AT_ONCE) self.__check_result(decls)
def test_project_reader_file_by_file(self): reader = parser.project_reader_t(self.config) decls = reader.read_files([ parser.file_configuration_t(self.header, self.config.start_with_declarations) ], parser.COMPILATION_MODE.FILE_BY_FILE) self.__check_result(decls)
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, type=declarations.variable_t, name="i") self.failUnless(var_i, "Variable i has not been found.")
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 test(self): fconfig = parser.file_configuration_t( data=self.__fname , content_type=parser.CONTENT_TYPE.CACHED_SOURCE_FILE ) try: prj_reader = parser.project_reader_t( self.config ) prj_decls = prj_reader.read_files( [fconfig] , compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE ) self.failUnless( os.path.exists( fconfig.cached_source_file ) ) mtime1 = os.stat(fconfig.cached_source_file)[stat.ST_MTIME] prj_decls = prj_reader.read_files( [fconfig] , compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE ) mtime2 = os.stat(fconfig.cached_source_file)[stat.ST_MTIME] self.failUnless( mtime1 == mtime2 ) finally: utils.remove_file_no_raise( fconfig.cached_source_file )
def test(self): fconfig = parser.file_configuration_t( data=self.__fname, content_type=parser.CONTENT_TYPE.CACHED_SOURCE_FILE) try: prj_reader = parser.project_reader_t(self.config) prj_reader.read_files( [fconfig], compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) self.assertTrue(os.path.exists(fconfig.cached_source_file)) mtime1 = os.stat(fconfig.cached_source_file)[stat.ST_MTIME] prj_reader.read_files( [fconfig], compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) mtime2 = os.stat(fconfig.cached_source_file)[stat.ST_MTIME] self.assertTrue(mtime1 == mtime2) finally: utils.remove_file_no_raise(fconfig.cached_source_file, self.config)
def test(self): src_reader = parser.source_reader_t( self.config ) src_decls = src_reader.read_file( self.__fname ) xmlfile = src_reader.create_xml_file( self.__fname ) try: fconfig = parser.file_configuration_t( data=xmlfile , start_with_declarations=None , content_type=parser.file_configuration_t.CONTENT_TYPE.GCCXML_GENERATED_FILE ) prj_reader = parser.project_reader_t( self.config ) prj_decls = prj_reader.read_files( [fconfig] , compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE ) self.failUnless( src_decls == prj_decls , "There is a difference between declarations in file %s." % self.__fname ) finally: utils.remove_file_no_raise( xmlfile )
def test(self): src_reader = parser.source_reader_t( self.config ) src_decls = src_reader.read_file( self.__fname ) xmlfile = src_reader.create_xml_file( self.__fname ) print xmlfile try: fconfig = parser.file_configuration_t( data=xmlfile , start_with_declarations=None , content_type=parser.file_configuration_t.CONTENT_TYPE.GCCXML_GENERATED_FILE ) prj_reader = parser.project_reader_t( self.config ) prj_decls = prj_reader.read_files( [fconfig] , compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE ) declarations.dump_declarations( src_decls , os.path.join( autoconfig.build_directory, 'xmlfile_reader.src.txt' ) ) declarations.dump_declarations( prj_decls , os.path.join( autoconfig.build_directory, 'xmlfile_reader.prj.txt' ) ) if src_decls != prj_decls: self.fail( "There is a difference between declarations in file %s." % self.__fname ) finally: pass #utils.remove_file_no_raise( xmlfile )
import os import sys import warnings warnings.simplefilter("error", Warning) # 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 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 file_config = parser.file_configuration_t( data=filename, content_type=parser.CONTENT_TYPE.CACHED_SOURCE_FILE) project_reader = parser.project_reader_t(xml_generator_config) decls = project_reader.read_files( [file_config], compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) global_namespace = declarations.get_global_namespace(decls) value = global_namespace.namespace("ns") print("My name is: " + value.name)
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")
warnings.simplefilter("error", Warning) # 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 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 file_config = parser.file_configuration_t( data=filename, content_type=parser.CONTENT_TYPE.CACHED_SOURCE_FILE) project_reader = parser.project_reader_t(xml_generator_config) decls = project_reader.read_files( [file_config], compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) global_namespace = declarations.get_global_namespace(decls) value = global_namespace.namespace("ns") print("My name is: " + value.name)