Exemple #1
0
    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 )

        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,
            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)
Exemple #4
0
    def __parse_declarations(self, files, xml_generator_config,
                             compilation_mode, cache, indexing_suite_version):
        if None is xml_generator_config:
            xml_generator_config = parser.xml_generator_configuration_t()
        if None is compilation_mode:
            compilation_mode = parser.COMPILATION_MODE.FILE_BY_FILE
        start_time = timer()
        self.logger.debug('parsing files - started')
        reader = parser.project_reader_t(xml_generator_config, cache,
                                         decl_wrappers.dwfactory_t())
        decls = reader.read_files(files, compilation_mode)

        self.logger.debug('parsing files - done( %f seconds )' %
                          (timer() - 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(allow_empty=True):
                cls.indexing_suite_version = indexing_suite_version
            for cls in global_ns.decls(
                    decl_type=decls_package.class_declaration_t,
                    allow_empty=True):
                cls.indexing_suite_version = indexing_suite_version

        start_time = timer()
        self.__apply_decls_defaults(decls)
        self.logger.debug(
            'settings declarations defaults - done( %f seconds )' %
            (timer() - start_time))
        return global_ns
Exemple #5
0
    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 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
Exemple #7
0
    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