📄 types.py
字号:
"""Returns a representation of the type which is responsible for its own destruction. Assigning a heap allocated thing to this type should allow the user to forget about deallocation.""" d_T = self.deref() if self.array() or d_T.struct() or d_T.union() or \ d_T.exception() or d_T.sequence() or \ d_T.objref(): name = id.Name(self.type().decl().scopedName()).suffix("_var") return name.unambiguous(environment) if d_T.typecode(): return "CORBA::TypeCode_var" if d_T.any(): return "CORBA::Any_var" if d_T.string(): return "CORBA::String_var" if d_T.wstring(): return "CORBA::WString_var" if d_T.enum(): name = id.Name(self.type().decl().scopedName()) return name.unambiguous(environment) if self.is_basic_data_types(): return basic_map[d_T.kind()] if d_T.void(): raise "No such thing as a void _var type" raise "Unknown _var type, kind = " + str(d_T.kind()) def out(self, ident): if self.is_basic_data_types(): return ident return ident + ".out()" def free(self, thing, environment = None): """Ensures that any heap allocated storage associated with this type has been deallocated.""" if self.array(): name = id.Name(self.type().decl().scopedName()).suffix("_free") return name.unambiguous(environment) + "(" + thing + ");" d_T = self.deref() if d_T.objref() or d_T.typecode(): return "CORBA::release(" + thing + ");" if d_T.string(): return "CORBA::string_free(" + thing + ");" if d_T.wstring(): return "CORBA::wstring_free(" + thing + ");" if d_T.struct() or d_T.union() or d_T.exception() or \ d_T.sequence() or d_T.any(): if d_T.variable(): return "delete " + thing + ";" return "" # stored by value if d_T.enum() or d_T.void() or (self.is_basic_data_types()): return "" raise "Don't know how to free type, kind = " + str(d_T.kind()) def copy(self, src, dest, environment = None): """Copies an entity from src to dest""" if self.array(): name = id.Name(self.type().decl().scopedName()).suffix("_dup") return dest + " = " + name.unambiguous(environment) + "("+src+");" d_T = self.deref() if d_T.typecode(): return dest + " = CORBA::TypeCode::_duplicate(" + src + ");" if d_T.objref(): # Use the internal omniORB duplicate function in case the # normal one isn't available name = id.Name(self.type().decl().scopedName()).suffix("_Helper") return name.unambiguous(environment) + "::duplicate" +\ "(" + src + ");\n" + dest + " = " + src + ";" if d_T.string(): return dest + " = CORBA::string_dup(" + src + ");" if d_T.wstring(): return dest + " = CORBA::wstring_dup(" + src + ");" if d_T.any(): return dest + " = new CORBA::Any(" + src + ");" if d_T.struct() or d_T.union() or d_T.exception() or d_T.sequence(): name = id.Name(self.type().decl().scopedName()).\ unambiguous(environment) if d_T.variable(): return dest + " = new " + name + "(" + src + ");" return dest + " = " + src + ";" if d_T.enum() or self.is_basic_data_types(): return dest + " = " + src + ";" raise "Don't know how to free type, kind = " + str(d_T.kind()) def representable_by_int(self): """representable_by_int(types.Type): boolean Returns true if the type is representable by an integer""" return self.integer() or self.char() or self.boolean() or self.octet() def is_basic_data_types(self): d_T = self.deref() return d_T.kind() in basic_map.keys() def integer(self): type = self.__type return type.kind() in [ idltype.tk_short, idltype.tk_long, idltype.tk_longlong, idltype.tk_ushort, idltype.tk_ulong, idltype.tk_ulonglong ] def char(self): type = self.__type return type.kind() == idltype.tk_char def wchar(self): type = self.__type return type.kind() == idltype.tk_wchar def floating(self): type = self.__type return type.kind() in [ idltype.tk_float, idltype.tk_double ] def float(self): type = self.__type return type.kind() == idltype.tk_float def double(self): type = self.__type return type.kind() == idltype.tk_double def boolean(self): type = self.__type return type.kind() == idltype.tk_boolean def enum(self): type = self.__type return type.kind() == idltype.tk_enum def octet(self): type = self.__type return type.kind() == idltype.tk_octet def string(self): type = self.__type return type.kind() == idltype.tk_string def wstring(self): type = self.__type return type.kind() == idltype.tk_wstring def objref(self): type = self.__type return type.kind() == idltype.tk_objref def sequence(self): type = self.__type return type.kind() == idltype.tk_sequence def typecode(self): type = self.__type return type.kind() == idltype.tk_TypeCode def typedef(self): type = self.__type return type.kind() == idltype.tk_alias def struct(self): type = self.__type return type.kind() == idltype.tk_struct def structforward(self): type = self.__type return type.kind() == idltype.ot_structforward def union(self): type = self.__type return type.kind() == idltype.tk_union def unionforward(self): type = self.__type return type.kind() == idltype.ot_unionforward def exception(self): type = self.__type return type.kind() == idltype.tk_except def void(self): type = self.__type return type.kind() == idltype.tk_void def any(self): type = self.__type return type.kind() == idltype.tk_any def fixed(self): type = self.__type return type.kind() == idltype.tk_fixeddef variableDecl(decl): """types.variableDecl(idlast.Decl): boolean Returns true if the declaration represents a variable type""" # interfaces are mapped to objects, which are always # variable types. same goes for exceptions. if isinstance(decl, idlast.Interface) or \ isinstance(decl, idlast.Forward) or \ isinstance(decl, idlast.Exception): return 1 elif isinstance(decl, idlast.Const) or \ isinstance(decl, idlast.Enum): return 0 # a typedef is only a type alias- as such it has no storage # at all. However it eventually points to something that would. elif isinstance(decl, idlast.Typedef): return Type(decl.aliasType()).variable() # a structure is variable if any one of its constituents # is also variable elif isinstance(decl, idlast.Struct): for m in decl.members(): if Type(m.memberType()).variable(): return 1 return 0 # a union is variable if any one if its constituents # is also variable elif isinstance(decl, idlast.Union): for c in decl.cases(): if Type(c.caseType()).variable(): return 1 return 0 # a declarator is variable if it is an alias to a variable # type elif isinstance(decl, idlast.Declarator) and \ decl.alias() != None: return Type(decl.alias().aliasType()).variable() util.fatalError("Unknown AST node, scopedName = " +repr(decl.scopedName()))def direction(param): if param.is_in() and param.is_out(): return INOUT elif param.is_in(): return IN elif param.is_out(): return OUT # Top 12 things likely to be overheard from a Klingon Programmer: # ... # # 7) "Klingon function calls do not have 'parameters' - they # have 'arguments' - and they ALWAYS WIN THEM." # ... util.fatalError("Illegal parameter direction")################################################################## Tables of useful data ripped from the CORBA spec# already_Variable maps typecode kinds onto true/ false# # An entry in this table indicates we already know is a type is# variable or not, without having to look at its declaration.# (note that eg structs and unions are only variable if one of# their members are)# CORBA2.3 P1-21 1.9 Mapping for Structured Typesalready_Variable = { idltype.tk_null: 0, idltype.tk_void: 0, idltype.tk_short: 0, idltype.tk_long: 0, idltype.tk_ushort: 0, idltype.tk_ulong: 0, idltype.tk_float: 0, idltype.tk_double: 0, idltype.tk_boolean: 0, idltype.tk_char: 0, idltype.tk_octet: 0, idltype.tk_any: 1, idltype.tk_objref: 1, idltype.tk_string: 1, idltype.tk_sequence: 1, idltype.tk_except: 1, idltype.tk_longlong: 0, idltype.tk_ulonglong: 0, idltype.tk_longdouble: 0, idltype.tk_wchar: 0, idltype.tk_wstring: 1, idltype.tk_fixed: 0, idltype.tk_value: 1, idltype.tk_value_box: 1, idltype.tk_abstract_interface: 1, idltype.tk_any: 1, idltype.tk_TypeCode: 1 }# CORBA2.3 P1-15 1.5 Mapping for Basic Data Typesbasic_map = { idltype.tk_short: "CORBA::Short", idltype.tk_long: "CORBA::Long", idltype.tk_longlong: "CORBA::LongLong", idltype.tk_ushort: "CORBA::UShort", idltype.tk_ulong: "CORBA::ULong", idltype.tk_ulonglong: "CORBA::ULongLong", idltype.tk_float: "CORBA::Float", idltype.tk_double: "CORBA::Double", idltype.tk_longdouble: "CORBA::LongDouble", idltype.tk_char: "CORBA::Char", idltype.tk_wchar: "CORBA::WChar", idltype.tk_boolean: "CORBA::Boolean", idltype.tk_octet: "CORBA::Octet" }basic_map_out = { }for key,value in basic_map.items(): basic_map_out[key] = value + "_out"# Info on size and alignment of basic typestypeSizeAlignMap = { idltype.tk_char: (1, 1), idltype.tk_boolean: (1, 1), idltype.tk_wchar: (2, 2), idltype.tk_short: (2, 2), idltype.tk_ushort: (2, 2), idltype.tk_long: (4, 4), idltype.tk_ulong: (4, 4), idltype.tk_float: (4, 4), idltype.tk_enum: (4, 4), idltype.tk_double: (8, 8), idltype.tk_octet: (1, 1), idltype.tk_longlong: (8, 8), idltype.tk_ulonglong: (8, 8) }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -