📄 iface.py
字号:
# -*- python -*-# Package : omniidl# iface.py Created on: 2000/8/10# Author : David Scott (djs)## Copyright (C) 2000 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:# # Code associated with IDL interfaces# $Id: iface.py,v 1.1.4.14 2004/10/17 21:47:40 dgrisby Exp $# $Log: iface.py,v $# Revision 1.1.4.14 2004/10/17 21:47:40 dgrisby# Fully qualify scopes in _ptrToObjRef and _ptrToInterface.## Revision 1.1.4.13 2003/07/25 16:03:06 dgrisby# Initialise base classes in correct order.## Revision 1.1.4.12 2003/03/03 15:02:30 dgrisby# -Wbvirtual_objref option went astray. Thanks Malge Nishant.## Revision 1.1.4.11 2002/08/16 15:56:27 dgrisby# Bug in generated code with evil IDL that uses the same parameter# names as type names.## Revision 1.1.4.10 2001/11/08 16:33:51 dpg1# Local servant POA shortcut policy.## Revision 1.1.4.9 2001/11/07 15:45:53 dpg1# Faster _ptrToInterface/_ptrToObjRef in common cases.## Revision 1.1.4.8 2001/08/15 10:26:10 dpg1# New object table behaviour, correct POA semantics.## Revision 1.1.4.7 2001/07/25 13:40:52 dpg1# Suppress compiler warning about unused variable in _dispatch() for# empty interfaces.## Revision 1.1.4.6 2001/07/25 11:42:15 dpg1# Generate correct code for operation parameters whose names clash with# C++ keywords.## Revision 1.1.4.5 2001/06/08 17:12:13 dpg1# Merge all the bug fixes from omni3_develop.## Revision 1.1.4.4 2001/01/25 13:09:11 sll# Fixed up cxx backend to stop it from dying when a relative# path name is given to the -p option of omniidl.## Revision 1.1.4.3 2000/11/07 18:27:51 sll# Pass environment to out_objrefcall.## Revision 1.1.4.2 2000/11/03 19:30:21 sll# Rationalise code generation. Consolidate all code that use call descriptors# into the CallDescriptor class.## Revision 1.1.4.1 2000/10/12 15:37:47 sll# Updated from omni3_1_develop.## Revision 1.1.2.2 2000/09/14 16:03:02 djs# Remodularised C++ descriptor name generator# Bug in listing all inherited interfaces if one is a forward# repoID munging function now handles #pragma ID in bootstrap.idl# Naming environments generating code now copes with new IDL AST types# Modified type utility functions# Minor tidying## Revision 1.1.2.1 2000/08/21 11:34:34 djs# Lots of omniidl/C++ backend changes## o Keep related code in one place# o Expose internals at a finer granularity than before (useful for# overriding one aspect (eg _objref class for AMI))import stringfrom omniidl import idlast, idltypefrom omniidl_be.cxx import types, id, call, ast, cxx, output, config, descriptor# from omniidl_be.cxx import header# from omniidl_be.cxx import skel# XXX it seems that the above import fails when this file is import by# cxx.header.defs AND a relative patch -p argument is given to omniidl# Use the following import works.import omniidl_be.cxx.skelimport omniidl_be.cxx.header# Interface is a wrapper around an IDL interface# .callables(): get a list of Callable objects representing the operations# and attributes# .inherits(): get a list of all directly inherited interfaces# .allInherits(): get all inherited interfaces (using a breadth first search)# .name(): return the IDL fully scoped name (as an id.Name)# .environment(): returns the IDL environment where this interface was# declaredclass Interface: """Wrapper around an IDL interface""" def __init__(self, node): self._node = node self._environment = id.lookup(node) self._node_name = id.Name(node.scopedName()) def callables(self): """Return a list of Callable objects representing the combined operations and attributes for this interface""" if hasattr(self, "_callables"): return self._callables # build a list of all the Callable objects # The old backend processed all operations first # (FIXME: duplicate for the sake of easy checking) self._callables = [] for c in self._node.callables(): if isinstance(c, idlast.Operation): self._callables.append(call.operation(self, c)) for c in self._node.callables(): if isinstance(c, idlast.Attribute): self._callables = self._callables + call.read_attributes(self, c) if c.readonly(): continue self._callables = self._callables + call.write_attributes(self, c) return self._callables def inherits(self): return map(lambda x:Interface(x), self._node.inherits()) def allInherits(self): return map(lambda x:Interface(x), ast.allInherits(self._node)) def name(self): return self._node_name def environment(self): return self._environment _classes = {}_proxy_call_descriptors = {}def instance(name): if _classes.has_key(name): return _classes[name] instance = eval(name) _classes[name] = instance return instancedef register_class(name, cl): _classes[name] = cl# Class associated with an IDL interface.# .interface(): return the associated Interface object# .methods(): return a list of Method objects# .environment(): return the IDL environment associated with the interfaceclass Class(cxx.Class): def __init__(self, interface): assert isinstance(interface, Interface) cxx.Class.__init__(self, interface.name()) self._interface = interface self._environment = interface.environment() self._methods = [] self._callables = {} def interface(self): return self._interface def methods(self): return self._methods def environment(self): return self._environmentclass _objref_Method(cxx.Method): def __init__(self, callable, parent_class): assert isinstance(callable, call.Callable) assert isinstance(parent_class, cxx.Class) self._callable = callable self._parent_class = parent_class self.from_Callable() def callable(self): return self._callable def from_Callable(self): self._from_Callable(use_out = 1) def _from_Callable(self, use_out): # Grab the IDL environment environment = self.callable().interface().environment() # Kept as a type object because in .cc part the _return_ type # must be fully qualified. self._return_type = types.Type(self.callable().returnType()) # Parameters are always relative, both in .hh and .cc (param_types, param_names) = ([], []) for p in self.callable().parameters(): pType = types.Type(p.paramType()) direction = types.direction(p) param_types.append(pType.op(direction, environment, use_out = use_out)) # Special ugly case. If the IDL says something like (in foo::bar # bar), the parameter name may be the same as the relative type # name. We mangly the parameter name if this happens. typeBase = pType.base(environment) ident = id.mapID(p.identifier()) if typeBase == ident: ident = "_" + ident param_names.append(ident) # an operation has optional context if self.callable().contexts() != []: param_types.append("CORBA::Context_ptr") param_names.append("_ctxt") self._arg_types = param_types self._arg_names = param_names self._name = self.callable().method_name()class _impl_Method(_objref_Method): def __init__(self, callable, parent_class): _objref_Method.__init__(self, callable, parent_class) def from_Callable(self): self._from_Callable(use_out = 0)class I_Helper(Class): def __init__(self, I): Class.__init__(self, I) self._name = self._name.suffix("_Helper") def hh(self, stream): class_sk_name = "" if config.state['BOA Skeletons']: class_sk_name = "class " + \ self.interface().name().prefix("_sk_").simple() + ";" stream.out(omniidl_be.cxx.header.template.interface_Helper, class_sk_name = class_sk_name, name = self.interface().name().simple(), guard = self.interface().name().guard()) def cc(self, stream): stream.out(omniidl_be.cxx.skel.template.interface_Helper, name = self.interface().name().fullyQualify())class _objref_I(Class): def __init__(self, I): Class.__init__(self, I) self._name = self._name.prefix("_objref_") for callable in self.interface().callables(): method = _objref_Method(callable, self) self._methods.append(method) self._callables[method] = callable def hh(self, stream): # build the inheritance list objref_inherits = [] for i in self.interface().inherits(): objref_inherited_name = i.name().prefix("_objref_") uname = objref_inherited_name.unambiguous(self._environment) objref_inherits.append("public virtual " + uname) # if already inheriting, the base class will be present # (transitivity of the inherits-from relation) if self.interface().inherits() == []: objref_inherits = [ "public virtual CORBA::Object, " + \ "public virtual omniObjRef" ] methods = [] for method in self.methods(): if config.state['Virtual Objref Methods']: methods.append(method.hh(virtual = 1, pure = 0)) else: methods.append(method.hh()) if config.state['Shortcut']: shortcut = output.StringStream() shortcut.out(omniidl_be.cxx.header.template.interface_shortcut, name = self.interface().name().simple()) shortcut = str(shortcut) init_shortcut = ": _shortcut(0)" else:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -