Exemplo n.º 1
0
 def __parse_file_by_file(self, files):
     namespaces = []
     config = self.__config.clone()
     self.logger.debug( "Reading project files: file by file" )
     for prj_file in files:
         reader = None
         header = None
         content_type = None
         if isinstance( prj_file, file_configuration_t ):
             del config.start_with_declarations[:]
             config.start_with_declarations.extend( prj_file.start_with_declarations )
             header = prj_file.data
             content_type = prj_file.content_type
         else:
             config = self.__config
             header = prj_file
             content_type = file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE
         reader = source_reader.source_reader_t( config
                                                 , self.__dcache
                                                 , self.__decl_factory )
         decls = None
         if content_type == file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE:
             self.logger.info( 'Parsing source file "%s" ... ' % header )
             decls = reader.read_file( header )
         elif content_type == file_configuration_t.CONTENT_TYPE.GCCXML_GENERATED_FILE:
             self.logger.info( 'Parsing xml file "%s" ... ' % header )
             decls = reader.read_xml_file( header )
         elif content_type == file_configuration_t.CONTENT_TYPE.CACHED_SOURCE_FILE:
             #TODO: raise error when header file does not exist
             if not os.path.exists( prj_file.cached_source_file ):
                 dir_ = os.path.split( prj_file.cached_source_file )[0]
                 if dir_ and not os.path.exists( dir_ ):
                     os.makedirs( dir_ )
                 self.logger.info( 'Creating xml file "%s" from source file "%s" ... '
                                   % ( prj_file.cached_source_file, header ) )
                 reader.create_xml_file( header, prj_file.cached_source_file )
             self.logger.info( 'Parsing xml file "%s" ... ' % prj_file.cached_source_file )
             decls = reader.read_xml_file( prj_file.cached_source_file )
         else:
             decls = reader.read_string( header )
         namespaces.append( decls )
     self.logger.debug( "Flushing cache... " )
     start_time = time.clock()
     self.__dcache.flush()
     self.logger.debug( "Cache has been flushed in %.1f secs" % ( time.clock() - start_time ) )
     answer = []
     self.logger.debug( "Joining namespaces ..." )
     for file_nss in namespaces:
         answer = self._join_top_namespaces( answer, file_nss )
     self.logger.debug( "Joining declarations ..." )
     for ns in answer:
         if isinstance( ns, pygccxml.declarations.namespace_t ):
             self._join_declarations( ns )
     leaved_classes = self._join_class_hierarchy( answer )
     types = self.__declarated_types(answer)
     self.logger.debug( "Relinking declared types ..." )
     self._relink_declarated_types( leaved_classes, types )
     source_reader.bind_aliases( pygccxml.declarations.make_flatten( answer ) )
     return answer
Exemplo n.º 2
0
 def __parse_file_by_file(self, files):
     namespaces = []
     config = self.__config.clone()
     self.logger.debug( "Reading project files: file by file" )
     for prj_file in files:
         reader = None
         header = None
         content_type = None
         if isinstance( prj_file, file_configuration_t ):
             del config.start_with_declarations[:]
             config.start_with_declarations.extend( prj_file.start_with_declarations )
             header = prj_file.data
             content_type = prj_file.content_type
         else:
             config = self.__config
             header = prj_file
             content_type = file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE
         reader = source_reader.source_reader_t( config
                                                 , self.__dcache
                                                 , self.__decl_factory )
         decls = None
         if content_type == file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE:
             self.logger.info( 'Parsing source file "%s" ... ' % header )
             decls = reader.read_file( header )
         elif content_type == file_configuration_t.CONTENT_TYPE.GCCXML_GENERATED_FILE:
             self.logger.info( 'Parsing xml file "%s" ... ' % header )
             decls = reader.read_xml_file( header )
         elif content_type == file_configuration_t.CONTENT_TYPE.CACHED_SOURCE_FILE:
             #TODO: raise error when header file does not exist
             if not os.path.exists( prj_file.cached_source_file ):
                 dir_ = os.path.split( prj_file.cached_source_file )[0]
                 if dir_ and not os.path.exists( dir_ ):
                     os.makedirs( dir_ )
                 self.logger.info( 'Creating xml file "%s" from source file "%s" ... '
                                   % ( prj_file.cached_source_file, header ) )
                 reader.create_xml_file( header, prj_file.cached_source_file )
             self.logger.info( 'Parsing xml file "%s" ... ' % prj_file.cached_source_file )
             decls = reader.read_xml_file( prj_file.cached_source_file )
         else:
             decls = reader.read_string( header )
         namespaces.append( decls )
     self.logger.debug( "Flushing cache... " )
     start_time = time.clock()
     self.__dcache.flush()
     self.logger.debug( "Cache has been flushed in %.1f secs" % ( time.clock() - start_time ) )
     answer = []
     self.logger.debug( "Joining namespaces ..." )
     for file_nss in namespaces:
         answer = self._join_top_namespaces( answer, file_nss )
     self.logger.debug( "Joining declarations ..." )
     for ns in answer:
         if isinstance( ns, pygccxml.declarations.namespace_t ):
             self._join_declarations( ns )
     leaved_classes = self._join_class_hierarchy( answer )
     types = self.__declarated_types(answer)
     self.logger.debug( "Relinking declared types ..." )
     self._relink_declarated_types( leaved_classes, types )
     source_reader.bind_aliases( pygccxml.declarations.make_flatten( answer ) )
     return answer
Exemplo n.º 3
0
    def read_string(self, content):
        """Parse a string containing C/C++ source code.

        @param content: C/C++ source code.
        @type content: str
        @returns: Declarations
        """
        reader = source_reader.source_reader_t( self.__config, None, self.__decl_factory )
        return reader.read_string( content )
Exemplo n.º 4
0
    def read_string(self, content):
        """Parse a string containing C/C++ source code.

        :param content: C/C++ source code.
        :type content: str
        :rtype: Declarations
        """
        reader = source_reader.source_reader_t( self.__config, None, self.__decl_factory )
        return reader.read_string( content )
Exemplo n.º 5
0
    def read_xml( self, file_configuration ):
        """parses C++ code, defined on the file_configurations and returns GCCXML
        generated file content"""

        xml_file_path = None
        delete_xml_file = True
        fc = file_configuration
        reader = source_reader.source_reader_t( self.__config, None, self.__decl_factory )
        try:
            if fc.content_type == fc.CONTENT_TYPE.STANDARD_SOURCE_FILE:
                self.logger.info( 'Parsing source file "%s" ... ' % fc.data )
                xml_file_path = reader.create_xml_file( fc.data )
            elif fc.content_type == file_configuration_t.CONTENT_TYPE.GCCXML_GENERATED_FILE:
                self.logger.info( 'Parsing xml file "%s" ... ' % fc.data )
                xml_file_path = fc.data
                delete_xml_file = False
            elif fc.content_type == fc.CONTENT_TYPE.CACHED_SOURCE_FILE:
                #TODO: raise error when header file does not exist
                if not os.path.exists( fc.cached_source_file ):
                    dir_ = os.path.split( fc.cached_source_file )[0]
                    if dir_ and not os.path.exists( dir_ ):
                        os.makedirs( dir_ )
                    self.logger.info( 'Creating xml file "%s" from source file "%s" ... '
                                      % ( fc.cached_source_file, fc.data ) )
                    xml_file_path = reader.create_xml_file( fc.data, fc.cached_source_file )
                else:
                    xml_file_path = fc.cached_source_file
            else:
                xml_file_path = reader.create_xml_file_from_string( fc.data )
            xml_file = file( xml_file_path, 'r' )
            xml = xml_file.read()
            xml_file.close()
            utils.remove_file_no_raise( xml_file_path )
            return xml
        finally:
            if xml_file_path and delete_xml_file:
                utils.remove_file_no_raise( xml_file_path )
Exemplo n.º 6
0
def parse_xml_file( content, config=None ):
    parser = source_reader_t( config )
    return parser.read_xml_file( content )
Exemplo n.º 7
0
def parse_xml_file(content, config=None):
    parser = source_reader_t(config)
    return parser.read_xml_file(content)