⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defs.py

📁 编译工具
💻 PY
📖 第 1 页 / 共 5 页
字号:
# Control arrives here#def visitAST(node):    self.__insideInterface  = 0    self.__insideModule     = 0    self.__insideClass      = 0    self.__interfaces       = {}    self.__completedModules = {}    for n in node.declarations():        if ast.shouldGenerateCodeForDecl(n):            n.accept(self)def visitModule(node):    # Ensure we only output the definitions once.    # In particular, when the splice-modules flag is set and this is    # a reopened module, the node will be marked as completed already.    if self.__completedModules.has_key(node):        return    self.__completedModules[node] = 1        ident = node.identifier()    cxx_id = id.mapID(ident)    if not config.state['Fragment']:        stream.out(template.module_begin, name = cxx_id)        stream.inc_indent()    # push self.__insideModule, true    insideModule = self.__insideModule    self.__insideModule = 1    for n in node.definitions():        n.accept(self)    # deal with continuations (only if the splice-modules flag is set)    if config.state['Splice Modules']:        for c in node.continuations():            for n in c.definitions():                n.accept(self)            self.__completedModules[c] = 1    # pop self.__insideModule    self.__insideModule = insideModule        if not config.state['Fragment']:        stream.dec_indent()        stream.out(template.module_end, name = cxx_id)        def visitInterface(node):    # It's legal to have a forward interface declaration after    # the actual interface definition. Make sure we ignore these.    self.__interfaces[node.repoId()] = 1    name = node.identifier()    cxx_name = id.mapID(name)    outer_environment = id.lookup(node)    environment = outer_environment.enter(name)    # push self.__insideInterface, true    # push self.__insideClass, true    insideInterface = self.__insideInterface    self.__insideInterface = 1    insideClass = self.__insideClass    self.__insideClass = 1    # make the necessary forward references, typedefs and define    # the _Helper class    I = iface.Interface(node)    I_Helper = iface.instance("I_Helper")(I)    I_Helper.hh(stream)    # recursively take care of other IDL declared within this    # scope (evaluate function later- lazy eval though 'thunking')    def Other_IDL(node = node):        for n in node.declarations():            n.accept(self)    # Output the this interface's corresponding class    stream.out(template.interface_type,               name = id.mapID(node.identifier()),               Other_IDL = Other_IDL)    _objref_I = iface.instance("_objref_I")(I)    _objref_I.hh(stream)    _pof_I = iface.instance("_pof_I")(I)    _pof_I.hh(stream)    _impl_I = iface.instance("_impl_I")(I)    _impl_I.hh(stream)    # Generate BOA compatible skeletons?    if config.state['BOA Skeletons']:        _sk_I = iface.instance("_sk_I")(I)        _sk_I.hh(stream)    # pop self.__insideInterface    # pop self.__insideClass    self.__insideInterface = insideInterface    self.__insideClass = insideClass    # Typecode and Any    if config.state['Typecode']:        qualifier = const_qualifier(self.__insideModule, self.__insideClass)        stream.out(template.typecode,                   qualifier = qualifier,                   name = cxx_name)            return    def visitForward(node):    # Note it's legal to have multiple forward declarations    # of the same name. So ignore the duplicates.    if self.__interfaces.has_key(node.repoId()):        return    self.__interfaces[node.repoId()] = 1    environment = id.lookup(node)    scope = environment.scope()    cxx_id = id.mapID(node.identifier())    name = id.Name(node.scopedName())    guard = name.guard()    # Potentially forward declare BOA skeleton class    class_sk = ""    if config.state['BOA Skeletons']:        class_sk = "class _sk_" + name.unambiguous(environment) + ";"    # output the definition    stream.out(template.interface_Helper,               guard = guard,               class_sk_name = class_sk,               name = name.unambiguous(environment))def visitConst(node):    environment = id.lookup(node)    scope = environment.scope()    constType = types.Type(node.constType())    d_constType = constType.deref()    if d_constType.string():        type_string = "char *"    elif d_constType.wstring():        type_string = "CORBA::WChar *"    elif d_constType.fixed():        type_string = constType.member()    else:        type_string = d_constType.member()        # should this be .base?    cxx_name = id.mapID(node.identifier())    value = d_constType.literal(node.value(), environment)    representedByInteger = d_constType.representable_by_int()    # depends on whether we are inside a class / in global scope    # etc    # should be rationalised with tyutil.const_qualifier    if self.__insideClass:        if representedByInteger:            stream.out(template.const_inclass_isinteger,                       type = type_string, name = cxx_name, val = value)        else:            stream.out(template.const_inclass_notinteger,                       type = type_string, name = cxx_name)    else:        where = "GLOBAL"        if self.__insideModule:            where = "MODULE"        if representedByInteger:            stream.out(template.const_outsideclass_isinteger,                       where = where,                       type = type_string,                       name = cxx_name,                       val = value)        else:            stream.out(template.const_outsideclass_notinteger,                       where = where,                       type = type_string,                       name = cxx_name)def visitTypedef(node):    environment = id.lookup(node)    scope = environment.scope()        is_global_scope = not (self.__insideModule or self.__insideInterface)        aliasType = types.Type(node.aliasType())    aliasTypeID = aliasType.member(environment)    # is _this_ type a constructed type?    if node.constrType():        node.aliasType().decl().accept(self)        d_type = aliasType.deref()    derefTypeID = d_type.base(environment)    basicReferencedTypeID = aliasType.member(environment)    # each one is handled independently    for d in node.declarators():                # derivedName is the new typedef'd name        # alias_dims is a list of dimensions of the type being aliased        derivedName = id.mapID(d.identifier())                alias_dims = aliasType.dims()        # array_declarator indicates whether this is a simple (non-array)        # declarator or not        array_declarator = d.sizes() != []        # Typecode and Any        if config.state['Typecode']:            qualifier = const_qualifier(self.__insideModule,self.__insideClass)            stream.out(template.typecode,                       qualifier = qualifier,                       name = derivedName)                            # is it a simple alias (ie not an array at this level)?        if not array_declarator:            # not an array declarator but a simple declarator to an array            if aliasType.array():                # simple alias to an array should alias all the                # array handling functions, but we don't need to duplicate                # array looping code since we can just call the functions                # for the base type                stream.out(template.typedef_simple_to_array,                           base = basicReferencedTypeID,                           derived = derivedName,                           qualifier = func_qualifier(),                           inline_qualifier = inline_qualifier())                                       # Non-array of string            elif d_type.string():                stream.out(template.typedef_simple_string,                           name = derivedName)            elif d_type.wstring():                stream.out(template.typedef_simple_wstring,                           name = derivedName)            elif d_type.typecode():                stream.out(template.typedef_simple_typecode,                           name = derivedName)            elif d_type.any():                stream.out(template.typedef_simple_any,                           name = derivedName)            elif d_type.fixed():                stream.out(template.typedef_simple_fixed,                           name = derivedName,                           digits = d_type.type().digits(),                           scale = d_type.type().scale())            # Non-array of basic type            elif isinstance(d_type.type(), idltype.Base):                stream.out(template.typedef_simple_basic,                           base = basicReferencedTypeID,                           derived = derivedName)            # a typedef to a struct or union, or a typedef to a            # typedef to a sequence            elif d_type.struct() or d_type.structforward() or \                 d_type.union() or d_type.unionforward() or \                 (d_type.sequence() and aliasType.typedef()):                                stream.out(template.typedef_simple_constructed,                           base = basicReferencedTypeID,                           name = derivedName)                                # Non-array of objrect reference            elif d_type.objref():                derefTypeID = string.replace(derefTypeID,"_ptr","")                # Note that the base name is fully flattened                is_CORBA_Object = d_type.type().scopedName() ==\                                  ["CORBA", "Object"]                impl_base = ""                objref_base = ""                sk_base = ""                if not is_CORBA_Object:                    scopedName = d_type.type().decl().scopedName()                    name = id.Name(scopedName)                    impl_scopedName = name.prefix("_impl_")                    objref_scopedName = name.prefix("_objref_")                    sk_scopedName = name.prefix("_sk_")                    impl_name = impl_scopedName.unambiguous(environment)                    objref_name = objref_scopedName.unambiguous(environment)                    sk_name = sk_scopedName.unambiguous(environment)                    impl_base =   "typedef " + impl_name   + " _impl_"   +\                                   derivedName + ";"                    objref_base = "typedef " + objref_name + " _objref_" +\                                   derivedName + ";"                    sk_base =     "typedef " + sk_name     + " _sk_"     +\                                   derivedName + ";"                stream.out(template.typedef_simple_objref,                           base = derefTypeID,                           name = derivedName,                           impl_base = impl_base,                           objref_base = objref_base)                if config.state['BOA Skeletons']:                    stream.out(sk_base)                                                               # Non-array of enum            elif d_type.enum():                stream.out(template.typedef_simple_basic,                           base = basicReferencedTypeID,                           derived = derivedName)            # Non-array of sequence            elif d_type.sequence():                seqType = types.Type(d_type.type().seqType())                d_seqType = seqType.deref()                bounded = d_type.type().bound()                                seq_dims = seqType.dims()                templateName = d_type.sequenceTemplate(environment)                                if d_seqType.structforward() or d_seqType.unionforward():                    # Sequence of forward-declared struct or union.                    # We cannot use the normal sequence templates                    # since they have inline methods that require the

⌨️ 快捷键说明

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