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

📄 types.py

📁 编译工具
💻 PY
📖 第 1 页 / 共 3 页
字号:
        if d_type.objref() and not type.array():            base = d_type.base(environment)        # Deal with special cases ----------------------------------        if not self.array():            if direction == OUT and not use_out:                if d_type.string() and not old_sig:                    return self.__base_type_OUT(environment)                if d_type.wstring() and not old_sig:                    return self.__base_type_OUT(environment)                if d_type.objref() and not old_sig:                    return self.__base_type_OUT(environment)                if d_type.typecode() and not old_sig:                    return self.__base_type_OUT(environment)                if d_type.any() and not old_sig:                    return self.__base_type_OUT(environment)                            if direction == OUT:                if d_type.string():                    return self.__base_type_OUT(environment)                if d_type.wstring():                    return self.__base_type_OUT(environment)                if d_type.typecode():                    return self.__base_type_OUT(environment)                if d_type.objref():                    return self.__base_type_OUT(environment)                if d_type.any() and (not old_sig or use_out):                    return self.__base_type_OUT(environment)                if d_type.variable() and (not old_sig or use_out):                    return self.__base_type_OUT(environment)            if direction == INOUT:                if d_type.string() and use_out:                    return self.__base_type_INOUT(environment)                if d_type.wstring() and use_out:                    return self.__base_type_INOUT(environment)                if d_type.typecode() and use_out:                    return self.__base_type_INOUT(environment)                if d_type.objref() and use_out:                    return self.__base_type_INOUT(environment)                        if d_type.string() and not type.array():            base = d_type.base(environment)        if d_type.wstring() and not type.array():            base = d_type.base(environment)            # P1-104 mentions two cases: returning an array and a variable        # array out argument. For the latter rely on the _out type        if (type.array() and direction == RET):            base = base + "_slice"                    mapping = self._argmapping(direction)                return self.__apply_mapping(mapping, base)    def member(self, environment = None, decl = None):        """member(types.Type, id.Environment option, idlast.Declarator option):           C++ member type"""        decl_dims = []        if decl != None:            assert isinstance(decl, idlast.Declarator)            decl_dims = decl.sizes()        is_array_declarator = decl_dims != []        if not self.array():            d_type = self.deref()            if d_type.string():                return "CORBA::String_member"            if d_type.wstring():                return "CORBA::WString_member"            if d_type.objref():                return d_type.objRefTemplate("Member", environment)            if d_type.typecode():                return "CORBA::TypeCode_member"            if self.sequence():                return d_type.sequenceTemplate(environment)                    if self.typedef():            # for the type to have dimensions, it must be a typedef            return id.Name(self.__type.scopedName()).unambiguous(environment)        return self.base(environment)    def objRefTemplate(self, suffix, environment = None):        """objRefTemplate(types.Type, suffix string, id.Environment option):           Returns a template objref instance for the current type"""        type = self.deref().__type        name = type.decl().scopedName()        if name == ["CORBA", "Object"]:            return "CORBA::Object_" + suffix        name = id.Name(name)        uname = name.unambiguous(environment)        objref_name = name.prefix("_objref_")        objref_uname = objref_name.unambiguous(environment)        return "_CORBA_ObjRef_" + suffix + \               "< " + objref_uname + ", " + uname + "_Helper> "    def literal(self, value, environment = None):        """literal(types.Type, value any, id.Environment option): string           Returns a C++ representation of a value"""        type = self.deref()        kind = type.__type.kind()        # (unsigned) short ints are themselves        if kind in [ idltype.tk_short, idltype.tk_ushort ]:            return str(value)        # careful with long ints to avoid "L" postfix        if kind in [ idltype.tk_long, idltype.tk_ulong ]:            s = str(value)            if s[-1] == 'L':             s = s[0:-1]            if kind == idltype.tk_ulong: s = s + "U"            return s        if kind in [ idltype.tk_longlong, idltype.tk_ulonglong ]:            s = str(value)            if s[-1] == 'L':                 s = s[:-1]            if kind == idltype.tk_ulonglong: s = s + "U"            return "_CORBA_LONGLONG_CONST(" + s + ")"        if kind in [ idltype.tk_float ]:            return idlutil.reprFloat(value) + "F"        if kind in [ idltype.tk_double ]:            return idlutil.reprFloat(value)        if kind in [ idltype.tk_longdouble ]:            return idlutil.reprFloat(value) + "L"        # chars are single-quoted        if kind in [ idltype.tk_char ]:            return "'" + idlutil.escapifyString(value) + "'"        if kind in [ idltype.tk_wchar ]:            return "L'" + idlutil.escapifyWString([value], "x") + "'"                # booleans are straightforward        if kind in [ idltype.tk_boolean ]:            return str(value)        if kind in [ idltype.tk_enum ]:            # value is an enumerator            enum_name = id.Name(value.scopedName())            #enum_name = id.Name(type.__type.decl().scopedName() + [str(value)])            return enum_name.unambiguous(environment)        if kind in [ idltype.tk_string ]:            return '"' + idlutil.escapifyString(value) + '"'        if kind in [ idltype.tk_wstring ]:            return 'L"' + idlutil.escapifyWString(value, "x") + '"'        if kind in [ idltype.tk_octet ]:            return str(value)        if kind in [ idltype.tk_fixed ]:            return '"' + value + '"'        util.fatalError("Internal error when handling value (" +\                        repr(value) +")" )    def sequenceTemplate(self, environment = None):        """sequenceTemplate(types.Type, id.Environment option): C++ template           Returns a C++ template instance for the current type as a           sequence"""        # returns a template instantiation suitable for the        # sequence type        # (similar in function to o2be_sequence::seq_template_name)        sequence = self.__type        assert isinstance(sequence, idltype.Sequence)                SeqType = Type(sequence.seqType())        d_SeqType = SeqType.deref()        SeqTypeID = SeqType.base(environment)        d_SeqTypeID = d_SeqType.base(environment)        if d_SeqType.typecode():            d_SeqTypeID = "CORBA::TypeCode_member"            SeqTypeID = "CORBA::TypeCode_member"        elif d_SeqType.objref():            d_SeqTypeID = string.replace(d_SeqTypeID,"_ptr","")            SeqTypeID = string.replace(SeqTypeID,"_ptr","")        elif d_SeqType.string():            d_SeqTypeID = "CORBA::String_member"        elif d_SeqType.wstring():            d_SeqTypeID = "CORBA::WString_member"                if SeqType.string():            SeqTypeID = "CORBA::String_member"        if SeqType.wstring():            SeqTypeID = "CORBA::WString_member"        # silly special case (not needed?):        #if d_SeqType.objref() and SeqType.typedef():        #    SeqTypeID = id.Name(SeqType.type().scopedName()).\        #                unambiguous(environment)        seq_dims = SeqType.dims()        is_array = seq_dims != []        dimension = reduce(lambda x,y: x * y, seq_dims, 1)        template = {}        template["bounded"]   = sequence.bound()        template["array"]     = is_array        template["dimension"] = dimension                template["seqTypeID"] = SeqTypeID        template["derefSeqTypeID"] = d_SeqTypeID        # if the seqType is a typedef to a sequence, use the typedef name        # else if a direct sequence<sequence<...., do recursion        if d_SeqType.sequence() and not SeqType.typedef():            element_template = d_SeqType.sequenceTemplate(environment)            template["seqTypeID"] = element_template            template["derefSeqTypeID"] = element_template        if is_array:            if d_SeqType.sequence():                template["derefSeqTypeID"] = d_SeqType.\                                             sequenceTemplate(environment)                if d_SeqType.char():            template["suffix"] = "_Char"        elif d_SeqType.wchar():            template["suffix"] = "_WChar"        elif d_SeqType.boolean():            template["suffix"] = "_Boolean"        elif d_SeqType.octet():            template["suffix"] = "_Octet"            # strings are always special        elif d_SeqType.string() and not is_array:            template["suffix"] = "_String"        elif d_SeqType.wstring() and not is_array:            template["suffix"] = "_WString"        elif d_SeqType.structforward() or d_SeqType.unionforward():            template["forward"] = 1        elif typeSizeAlignMap.has_key(d_SeqType.type().kind()):            template["fixed"] = typeSizeAlignMap[d_SeqType.type().\                                                        kind()]        elif d_SeqType.objref():            scopedName = d_SeqType.type().decl().scopedName()            is_CORBA_Object = scopedName == ["CORBA", "Object"]            scopedName = id.Name(scopedName)                        if not is_CORBA_Object:                # CORBA::Object doesn't have an _objref_xxx                scopedName = scopedName.prefix("_objref_")                       objref_name = scopedName.unambiguous(environment)            if not is_array:                objref_template = d_SeqType.objRefTemplate("Element", environment)            else:                objref_template = d_SeqType.objRefTemplate("Member", environment)            template["objref_name"]     = objref_name            template["objref_template"] = objref_template            template["objref_helper"]   = SeqTypeID + "_Helper"            template["objref"]          = 1        return self.__templateToString(template)    # converts a hash of template properties into a template instance    def __templateToString(self, template):        # ------------------------------------        # work out the template name        if template["bounded"]:            name = "_CORBA_Bounded_Sequence"        else:            name = "_CORBA_Unbounded_Sequence"        if template["array"]:            name = name + "_Array"                if template.has_key("suffix"):            name = name + template["suffix"]        if template.has_key("forward"):            name = name + "_Forward"        elif template.has_key("objref") and not template["array"]:            name = name + "_ObjRef"        if template.has_key("fixed"):            name = name + "_w_FixSizeElement"        # ------------------------------------        # build the argument list        args = []        seqTypeID      = template["seqTypeID"]        derefSeqTypeID = template["derefSeqTypeID"]        dimension      = template["dimension"]        # Note the difference between an ObjRef and an array of ObjRefs        if template["array"]:            args.extend([seqTypeID, seqTypeID + "_slice"])                    if template.has_key("objref"):                args.append(template["objref_template"])            elif not template.has_key("suffix"):                # __Boolean __Octet __String                # these already contain the type info- no need for another                # parameter...                args.append(derefSeqTypeID)                            args.append(str(dimension))                elif template.has_key("objref"):            args.extend([template["objref_name"],                         template["objref_template"],                         template["objref_helper"]])        elif not template.has_key("suffix"):            # see above            args.append(seqTypeID)                if template.has_key("bounded") and \           template["bounded"]:            args.append(str(template["bounded"]))        if template.has_key("fixed"):            (element_size, alignment) = template["fixed"]            args.extend([str(element_size), str(alignment)])        # -----------------------------------        # build the template instance        if args:            name = name + "< " + string.join(args, ", ") + " > "            return name        return name    def _var(self, environment = None):

⌨️ 快捷键说明

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