headerexporter.py

来自「Boost provides free peer-reviewed portab」· Python 代码 · 共 82 行

PY
82
字号
# Copyright Bruno da Silva de Oliveira 2003. Use, modification and # distribution is subject to 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)from Exporter import Exporterfrom ClassExporter import ClassExporterfrom FunctionExporter import FunctionExporterfrom EnumExporter import EnumExporterfrom VarExporter import VarExporterfrom infos import *from declarations import *import os.pathimport exportersimport MultipleCodeUnit#==============================================================================# HeaderExporter#==============================================================================class HeaderExporter(Exporter):    'Exports all declarations found in the given header'    def __init__(self, info, parser_tail=None):        Exporter.__init__(self, info, parser_tail)    def WriteInclude(self, codeunit):        pass    def IsInternalName(self, name):        '''Returns true if the given name looks like a internal compiler        structure'''        return name.startswith('_')            def Export(self, codeunit, exported_names):        header = os.path.normpath(self.parser_header)        for decl in self.declarations:            # check if this declaration is in the header            location = os.path.abspath(decl.location[0])            if location == header and not self.IsInternalName(decl.name):                # ok, check the type of the declaration and export it accordingly                self.HandleDeclaration(decl, codeunit, exported_names)                def HandleDeclaration(self, decl, codeunit, exported_names):        '''Dispatch the declaration to the appropriate method, that must create        a suitable info object for a Exporter, create a Exporter, set its        declarations and append it to the list of exporters.        '''         dispatch_table = {            Class : ClassExporter,            Enumeration : EnumExporter,            Function : FunctionExporter,            Variable : VarExporter,        }                exporter_class = dispatch_table.get(type(decl))        if exporter_class is not None:            self.HandleExporter(decl, exporter_class, codeunit, exported_names)                def HandleExporter(self, decl, exporter_type, codeunit, exported_names):        # only export complete declarations        if not decl.incomplete:            info = self.info[decl.name]            info.name = decl.FullName()            info.include = self.info.include            exporter = exporter_type(info)            exporter.SetDeclarations(self.declarations)            exporter.SetParsedHeader(self.parser_header)            if isinstance(codeunit, MultipleCodeUnit.MultipleCodeUnit):                codeunit.SetCurrent(self.interface_file, exporter.Name())            else:                codeunit.SetCurrent(exporter.Name())            exporter.GenerateCode(codeunit, exported_names)    def Name(self):        return self.info.include

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?