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

📄 types.py

📁 编译工具
💻 PY
📖 第 1 页 / 共 3 页
字号:
# -*- python -*-#                           Package   : omniidl# types.py                  Created on: 2000/4/10#			    Author    : David Scott (djs)##    Copyright (C) 1999 AT&T Laboratories Cambridge##  This file is part of omniidl.##  omniidl is free software; you can redistribute it and/or modify it#  under the terms of the GNU General Public License as published by#  the Free Software Foundation; either version 2 of the License, or#  (at your option) any later version.##  This program is distributed in the hope that it will be useful,#  but WITHOUT ANY WARRANTY; without even the implied warranty of#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU#  General Public License for more details.##  You should have received a copy of the GNU General Public License#  along with this program; if not, write to the Free Software#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA#  02111-1307, USA.## Description:#   #   Type utility functions designed for the C++ backendimport stringfrom omniidl import idltype, idlast, idlutilfrom omniidl_be.cxx import util, config, id# direction constantsIN     = 0OUT    = 1INOUT  = 2RET    = 3# we don't support these yetunsupported_typecodes =[idltype.tk_Principal,                        idltype.tk_value,                        idltype.tk_value_box, idltype.tk_native,                        idltype.tk_abstract_interface,                        idltype.tk_local_interface]class Type:    """Wrapper around an IDL type providing useful extra functionality"""    def __init__(self, type):        assert isinstance(type, idltype.Type)        self.__type = type    def type(self):        """type(types.Type): idltype.Type           returns the wrapped type"""        return self.__type    def kind(self):        """type(types.Type): idltype.kind           returns the kind of the wrapped type"""        return self.__type.kind()    def deref(self, keep_dims = 0):        """deref(types.Type, keep_dims boolean option) -> types.Type           Return the type with outer aliases removed.           (if keep_dims is true then it will not remove aliases with           array dimensions)"""        type = self        while (type.typedef()):            decl = type.__type.decl()            if keep_dims and decl.sizes() != []:                return type            type = Type(decl.alias().aliasType())        return type    def variable(self):        """variable(types.Type): boolean           Returns whether the type has a variable length representation           under the C++ mapping"""        type = self.__type        if already_Variable.has_key(type.kind()):            return already_Variable[type.kind()]        if isinstance(type, idltype.Declared):            decl = type.decl()            return variableDecl(decl)        util.fatalError("Error while computing the variable-ness of a type")    def dims(self):        """dims(types.Type): int list           Returns the full dimensions of the type"""        type = self.__type        if isinstance(type, idltype.Declared):            decl = type.decl()            if type.kind() == idltype.tk_alias:                sizes = []                if decl.sizes() != None:                    sizes = decl.sizes()                if decl.alias() != None:                    sizes = sizes + Type(decl.alias().aliasType()).dims()                return sizes            if isinstance(type.decl(), idlast.Typedef):                return Type(type.decl().aliasType()).dims()            return []        return []    def array(self):        """array(types.Type): boolean           Returns true if this type has array dimensions"""        return self.dims() != []    def __apply_mapping(self, (const, ref, ptr), thing):        # __apply_mapping(types.Type, (const bool, ref bool, ptr bool), string)        #  : string        # Make an instance of "thing" which is optionally const, a reference        # and a pointer types        text = thing        if const: text = "const " + text        if ptr:   text = text + "*"        if ref:   text = text + "&"        return text            def _argmapping(self, direction):        # _argmapping(types.Type, int direction): const * reference * pointer        #   Returns info on operation argument mapping for a type for        #   a particular direction.        # CORBA2.3 P1-204 Table 1-3 Basic argument and result mapping        array = self.array()        variable = self.variable()        if array and not variable:            # array of fixed size elements            return ( (1, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 1) )[direction]        if array and variable:            # array of variable size elements            return ( (1, 0, 0), (0, 1, 1), (0, 0, 0), (0, 0, 1) )[direction]        type = self.deref().__type        kind = type.kind()        if kind in [ idltype.tk_short, idltype.tk_long, idltype.tk_longlong,                     idltype.tk_ushort, idltype.tk_ulong, idltype.tk_ulonglong,                     idltype.tk_float, idltype.tk_double, idltype.tk_enum,                     idltype.tk_longdouble, idltype.tk_boolean,                     idltype.tk_char, idltype.tk_wchar, idltype.tk_octet ]:            # from short to enum the entries are the same            return ( (0, 0, 0), (0, 1, 0), (0, 1, 0), (0, 0, 0) )[direction]        if kind in [ idltype.tk_objref, idltype.tk_TypeCode ]:            # objref_ptr objref_ptr& objref_ptr& objref_ptr            return ( (0, 0, 0), (0, 1, 0), (0, 1, 0), (0, 0, 0) )[direction]        if (kind == idltype.tk_struct or kind == idltype.tk_union) and \           not variable:            # fixed struct or union            return ( (1, 1, 0), (0, 1, 0), (0, 1, 0), (0, 0, 0) )[direction]        if (kind == idltype.tk_struct or kind == idltype.tk_union) and \           variable:            # variable struct or union            return ( (1, 1, 0), (0, 1, 1), (0, 1, 0), (0, 0, 1) )[direction]        if kind == idltype.tk_string or kind == idltype.tk_wstring:            return ( (1, 0, 0), (0, 1, 0), (0, 1, 0), (0, 0, 0) )[direction]        if kind == idltype.tk_sequence or kind == idltype.tk_any:            return ( (1, 1, 0), (0, 1, 1), (0, 1, 0), (0, 0, 1) )[direction]        if kind == idltype.tk_fixed:            return ( (1, 1, 0), (0, 1, 0), (0, 1, 0), (0, 0, 0) )[direction]        if kind == idltype.tk_value or kind == idltype.tk_value_box:            return ( (0, 0, 1), (0, 1, 1), (0, 1, 1), (0, 0, 1) )[direction]        if kind == idltype.tk_void:            return (0, 0, 0)        if kind in unsupported_typecodes:            util.unsupportedIDL()        util.fatalError("Unknown type encountered (kind = " + str(kind) + ")")        return    def op_is_pointer(self, direction):        if not self.array() and \           (self.deref().string() or self.deref().wstring()):            return 0        return self._argmapping(direction)[2]    def __var_argmapping(self, direction):        # __var_argmapping(types.Type, direction): const * reference * pointer        #  Returns info on argument mapping for a type in a _var        #  context                # CORBA2.3 P1-204 Table 1-4 T_var argument and result mapping        kind = self.__type.kind()        if kind in [ idltype.tk_objref, idltype.tk_struct, idltype.tk_union,                     idltype.tk_string, idltype.tk_wstring,                     idltype.tk_sequence, idltype.tk_any,                     idltype.tk_value, idltype.tk_value_box ] or \                     self.array():            return ( (1, 1, 0), (0, 1, 0), (0, 1, 0), (0, 0, 0) )[direction]        util.fatalError("T_var argmapping requested for type with no such " +\                        "concept")        return    def base(self, environment = None):        """base(types.Type, id.Environment option): C++ type string           Returns a basic C++ mapped version of the type"""        kind = self.kind()        d_type = self.deref(1)        d_kind = d_type.kind()        # CORBA2.3 P1-15 1.5 Mapping for Basic Data Types        if basic_map.has_key(kind):            return basic_map[kind]        if self.string() or d_type.string():            return "char*"        if self.wstring() or d_type.wstring():            return "CORBA::WChar*"        if self.typecode():            return "CORBA::TypeCode_ptr"        if self.any():            return "CORBA::Any"        if self.void():            return "void"        if self.fixed():            return "CORBA::Fixed"        if self.sequence():            return self.sequenceTemplate(environment)        name = id.Name(self.type().scopedName()).unambiguous(environment)        if d_type.objref() or d_type.typecode():            return name + "_ptr"        else:            return name    def __base_type_OUT(self, environment = None):        # ___base_type_OUT(types.Type, id.Environment option): special C++        #  OUT type        type = self.__type        d_type = self.deref()        d_kind = type.kind()        if basic_map_out.has_key(d_kind):            return basic_map_out[d_kind]        if d_type.string():            return "CORBA::String_out"        if d_type.wstring():            return "CORBA::WString_out"        if d_type.typecode():            return "CORBA::TypeCode_OUT_arg"        if d_type.any():            return "CORBA::Any_OUT_arg"        if d_type.sequence():            return Type(d_type.type().seqType()).__base_type_OUT(environment)        name = id.Name(type.scopedName())        uname = name.unambiguous(environment)        if d_type.objref():            name = id.Name(d_type.type().scopedName())            objref_name = name.prefix("_objref_")            uname = name.unambiguous(environment)                        if d_type.__type.scopedName() == ["CORBA", "Object"]:                return "CORBA::Object_OUT_arg"            return "_CORBA_ObjRef_OUT_arg< " + objref_name.fullyQualify() + \                   ", " + name.unambiguous(environment) + "_Helper >"        return uname + "_out"    def __base_type_INOUT(self, environment = None):        # __base_type_INOUT(types.Type): special C++ INOUT type string                d_type = self.deref()        kind = d_type.kind()        if d_type.string():            return "CORBA::String_INOUT_arg"        if d_type.wstring():            return "CORBA::WString_INOUT_arg"        if d_type.typecode():            return "CORBA::TypeCode_INOUT_arg"        if d_type.any():            return "CORBA::Any_INOUT_arg"        name = id.Name(self.type().scopedName())        uname = name.unambiguous(environment)                if d_type.objref():            name = id.Name(d_type.type().scopedName())            objref_name = name.prefix("_objref_")            uname = name.unambiguous(environment)            if d_type.type().scopedName() == ["CORBA", "Object"]:                return "CORBA::Object_INOUT_arg"            return "_CORBA_ObjRef_INOUT_arg< " + objref_name.fullyQualify() + \                   ", " + name.unambiguous(environment) + "_Helper >"        return uname + "_INOUT_arg"    def op(self, direction, environment = None, use_out = 1):        """op(types.Type, int direction, id.Environment option, use_out bool)           : C++ type argument mapping"""        type = Type(self.__type)        d_type = type.deref()        base = self.base(environment)        old_sig = config.state['Old Signatures']        # this is very superfluous:        if not self.array():            if d_type.any() and self.typedef() and not old_sig:                if direction == OUT:                    return d_type.__base_type_OUT(environment)            if d_type.typecode() and not old_sig:                if direction == OUT:                    return d_type.__base_type_OUT(environment)                elif direction == INOUT and use_out:                    return d_type.__base_type_INOUT(environment)                else:                    base = d_type.base(environment)        # Use the ObjRef template for non-arrays of objrefs rather than use        # the (equivalent?) _out type?        if not d_type.objref() or type.array():            # if its an out type and a typedef (to a variable type),            # use the predefined _out type            if type.typedef() and type.variable() and direction == OUT:                if (not d_type.string() or not d_type.wstring() or \                    (d_type.string() and type.array()) or \                    (d_type.wstring() and type.array())):                    base = id.Name(type.__type.scopedName()).unambiguous(environment)                    base = base + "_out"                    return base        # superfluous deref for a typedef to an objref

⌨️ 快捷键说明

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