[openrtm-commit:01316] r2511 - in branches/work_ForDoil/OpenRTM-aist/src/lib/doil/utils/omniidl_be/doil: . ice
openrtm @ openrtm.org
openrtm @ openrtm.org
2014年 2月 17日 (月) 18:20:37 JST
Author: win-ei
Date: 2014-02-17 18:20:37 +0900 (Mon, 17 Feb 2014)
New Revision: 2511
Modified:
branches/work_ForDoil/OpenRTM-aist/src/lib/doil/utils/omniidl_be/doil/dictbuilder.py
branches/work_ForDoil/OpenRTM-aist/src/lib/doil/utils/omniidl_be/doil/ice/__init__.py
Log:
Daily work.
Modified: branches/work_ForDoil/OpenRTM-aist/src/lib/doil/utils/omniidl_be/doil/dictbuilder.py
===================================================================
--- branches/work_ForDoil/OpenRTM-aist/src/lib/doil/utils/omniidl_be/doil/dictbuilder.py 2014-02-17 03:30:45 UTC (rev 2510)
+++ branches/work_ForDoil/OpenRTM-aist/src/lib/doil/utils/omniidl_be/doil/dictbuilder.py 2014-02-17 09:20:37 UTC (rev 2511)
@@ -61,6 +61,7 @@
return self.dict
def __init__(self, tree, config):
+
# configuration parameters from command options
self.config = config
@@ -74,7 +75,7 @@
# idl file name
idl_fname = ast.mainFile()
self.dict['idl_fname'] = idl_fname
-
+
# included idl files
incs = []
idl_incs = ast.includes()
@@ -148,6 +149,17 @@
"CORBA::TypeCode_ptr" : "::std::string"
}
+ self.ice_primitive = {
+ "Ice::Short" : "short int",
+ "Ice::Int" : "int",
+ "Ice::Long" : "long",
+ "Ice::Float" : "float",
+ "Ice::Double" : "double",
+ "Ice::Byte" : "char",
+ "bool" : "bool",
+ "string" : "::std::string",
+ }
+
def createHeaderInfo(self, idl_path):
dict = {}
idl_path_list = idl_path.split('/')
@@ -313,6 +325,7 @@
ldict['scoped_name'] = ldict['iface_ns'] + [local_name]
return dict
+ return dict
def createInterfaceIdent(self, dict, node):
"""
@@ -432,7 +445,6 @@
ldict['switch_type'] = ltype.split('::')[-1]
return
-
def createStructIdent(self, dict, node):
return self.createIdent(dict, node)
@@ -598,6 +610,7 @@
return dict
+
def createTypedef(self, aliasType, decl, env):
"""
typedefé¾ÉÖ·éfBNVi̶¬
@@ -650,6 +663,7 @@
return dict
+
# ------------------------------------------------------------
# Iy[VÉÖ·é«ð쬷é
#
@@ -1024,4 +1038,682 @@
self.dict['tree'].append(dict)
return
+ #For Ice
+ def createDeclForIce(self, decl_type):
+ """
+ é¾îñÌî{fBNVi̶¬
+ decl_type: é¾Ì^Cv, struct, interface, union ÈÇ
+ ice:
+ decl_type: é¾Ì^Cv, struct, interface, union ÈÇ
+ corba_ns: [] l[Xy[XÌXg
+ local:
+ decl_type: é¾Ì^Cv, struct, interface, union ÈÇ
+ local_ns: [] [JC^[tF[XÌl[Xy[X
+ porxy_ns: [] A_v^Ìl[Xy[X
+ servant_ns: [] T[ogÌl[Xy[X
+ """
+ cdict = {'decl_type': decl_type}
+ ldict = {'decl_type': decl_type}
+ cdict['ice_ns'] = self.module
+ ldict['iface_ns'] = self.module + self.config['IfaceNs']
+ ldict['proxy_ns'] = self.module + self.config['ProxyNs']
+ ldict['servant_ns'] = self.module + self.config['ServantNs']
+ return {'decl_type': decl_type, 'ice': cdict, 'local': ldict}
+
+ def getTypeForIce(self, typeobj):
+ """
+ Ice Æ Local Ì^¼ðæ¾·é
+ """
+ ice_type = typeobj.base()
+ # for omniidl4 4.1.1-2
+ if ice_type[:2] == "::":
+ ice_type = ice_type[2:]
+ is_primitive = None
+ # if CORBA to Local mapping is specified explicitly
+ if self.typemap.has_key(ice_type):
+ local_type = self.typemap[ice_type]
+
+ # if CORBA type is primitive, string or Any
+ elif self.ice_primitive.has_key(ice_type):
+ local_type = self.ice_primitive[ice_type]
+ if ice_type[:5] == 'Ice':
+ corba_type = '::' + corba_type
+ tk = self.tk_map[typeobj.kind()]
+ primitive = ["tk_short", "tk_long", "tk_ushort",
+ "tk_ulong", "tk_float", "tk_double",
+ "tk_boolean", "tk_char", "tk_octet"]
+ if primitive.count(tk) > 0:
+ is_primitive = 'YES'
+
+
+ # other case
+ else:
+ ice_scoped_type = ice_type.split('::')
+ ice_ns = ice_scoped_type[:-1]
+ ice_base = ice_scoped_type[-1]
+ local_ns = ice_ns + self.config['IfaceNs']
+ local_scope = string.join(local_ns, '::')
+ if typeobj.objref():
+ ice_base = ice_base[:ice_base.rfind('_ptr')]
+ local_type = local_scope + '::' + \
+ self.config['IfacePrefix'] + \
+ ice_base + \
+ self.config['IfaceSuffix']
+ elif typeobj.sequence():
+ seqType = types.Type(typeobj.type().seqType())
+ # get type of element of sequence
+ (ice_etype, local_etype, eis_primitive) = self.getType(seqType)
+ if seqType.objref():
+ local_etype = local_etype + '*'
+ local_type = "std::vector< " + local_etype + " >"
+
+ else:
+ local_type = local_scope + '::' + ice_base
+ ice_type = '::' + ice_type
+ local_type = '::' + local_type
+ return (ice_type, local_type, is_primitive)
+
+ def createIdentForIce(self, dict, node):
+ """
+ é¾Ì¯ÊqÉÖ·éfBNVi̶¬
+ åÉA¯ÊqÌIDLAC++ALocal¼ð¶¬·é
+ createDeclŶ¬µ½fBNViÆnodeðøÉæé
+
+ corba:
+ idl_name: é¾Ìidlã̯Êq
+ name: C++É}bsO³ê½¯Êq
+ name_fq: C++¯ÊqÌ®SCü¼
+ scoped_name: [] Xg`®Ì®SCü¼
+ local:
+ idl_name: é¾Ìidlã̯Êq
+ name: C++É}bsO³ê½¯Êq
+ name_fq: C++¯ÊqÌ®SCü¼
+ scoped_name: [] Xg`®Ì®SCü¼
+
+ """
+ cdict = dict['ice']
+ ldict = dict['local']
+
+ cdict['idl_name'] = idl_name = node.identifier()
+ cdict['name'] = cxx_name = id.mapID(idl_name)
+ ns = node.scopedName()[:-1]
+ cdict['ice_ns'] = ns
+ ldict['iface_ns'] = ns + self.config['IfaceNs']
+ ldict['proxy_ns'] = ns + self.config['ProxyNs']
+ ldict['servant_ns'] = ns + self.config['ServantNs']
+ cxx_fq_name = id.Name(node.scopedName()).fullyQualify()
+ cdict['name_fq'] = '::' + cxx_fq_name
+ cdict['scoped_name'] = node.scopedName()
+
+ iface_ns = '::' + string.join(ldict['iface_ns'], '::')
+
+ if self.typemap.has_key(cxx_fq_name):
+ local_fq_name = self.typemap[cxx_fq_name]
+ local_name = local_fq_name.split('::')[-1]
+ elif self.ice_primitive.has_key(cxx_fq_name):
+ local_fq_name = self.ice_primitive[cxx_fq_name]
+ local_name = local_fq_name
+ else:
+ local_name = cxx_name
+ local_fq_name = iface_ns + '::' + local_name
+
+ ldict['name'] = local_name
+ ldict['name_fq'] = local_fq_name
+ ldict['scoped_name'] = ldict['iface_ns'] + [local_name]
+
+ def createInterfaceIdentForIce(self, dict, node):
+ """
+ C^[tF[Xé¾Ì¯ÊqÉÖ·éfBNVi̶¬
+ interface/servant/adapter ¼ð쬵fBNViÉÇÁ·é
+
+ corba:
+ name_poa: CORBA POANX¼
+ local:
+ iface_name: Interface̯Êq
+ iface_name_fq: InterfaceÌ®SCü¼
+ iface_scoped_name: InterfaceÌXg`®®SCü¼
+ servant_name: Servant̯Êq
+ servant_name_fq: ServantÌ®SCü¼
+ servant_scoped_name: ServantÌXg`®®SCü¼
+ adapter_name: Adapter̯Êq
+ adapter_name_fq: AdapterÌ®SCü¼
+ adapter_scoped_name: AdapterÌXg`®®SCü¼
+
+ """
+ self.createIdent(dict, node)
+ cdict = dict['ice']
+ ldict = dict['local']
+ cdict['name_poa'] = '::POA_' + cdict['name_fq'].strip(':')
+
+ # set iface_name, servant_name adapter_name
+ name = ldict['name']
+ p = "Prefix"
+ s = "Suffix"
+ n = "Ns"
+ for t in ['Iface', 'Servant', 'Proxy']:
+ key = t.lower() + '_name'
+ local_name = self.config[t + p] + name + self.config[t + s]
+ scoped_name = cdict['ice_ns'] + self.config[t + n] + [local_name]
+ local_fq_name = '::' + string.join(scoped_name, '::')
+ ldict[key] = local_name
+ ldict[key + '_fq'] = local_fq_name
+ ldict[key + '_scoped_name'] = scoped_name
+ return dict
+
+ def createInterfaceFileInfoForIce(self, dict, node):
+ """
+ C^[tF[XÖAt@C¼ÌfBNVi̶¬
+
+ local:
+ iface_h: Interfacewb_t@C¼
+ iface_cpp: InterfaceÀt@C¼
+ iface_h_path: Interfacewb_ÌCN[hpX
+ iface_include_guard: Interfacewb_ÌÌCN[hK[h
+ servant_h: Servantwb_t@C¼
+ servant_cpp: ServantÀt@C¼
+ servant_h_path: Servantwb_ÌCN[hpX
+ servant_include_guard: Servantwb_ÌÌCN[hK[h
+ adapter_h: Adapterwb_t@C¼
+ adapter_cpp: AdapterÀt@C¼
+ adapter_h_path: Adapterwb_ÌCN[hpX
+ adapter_include_guard: Adapterwb_ÌÌCN[hK[h
+
+ """
+ cdict = dict['ice']
+ ldict = dict['local']
+ ldict['include_h'] = self.config["IncludeHeaders"]
+
+ # set [iface|servant|adapter]_[h|cpp|h_path|include_guard]
+
+ for t in ['Iface', 'Servant', 'Proxy']:
+ k = t.lower()
+ ldict[k + '_h'] = ldict[k + '_name'] + ".h"
+ ldict[k + '_cpp'] = ldict[k + '_name'] + ".cpp"
+ if self.config[t + 'Dir'] == '':
+ ldict[k + '_h_path'] = ldict[k + '_h']
+ else:
+ ldict[k + '_h_path'] = \
+ self.config[t + 'Dir'] + '/' + ldict[k + '_h']
+ ns = string.join(map(lambda x: x + '_',
+ ldict[k + '_ns']), '')
+ ns = ns.upper()
+ name = ldict[k + '_name'].upper()
+ ldict[k + '_include_guard'] = ns + name + "_H"
+ return dict
+
+ def createUnionIdentForIce(self, dict, node):
+ """
+ ¤pÌé¾Ì̯ÊqÉÖ·éfBNVi̶¬
+
+ corba:
+ idl_name: é¾Ìidlã̯Êq
+ name: C++É}bsO³ê½¯Êq
+ name_fq: C++¯ÊqÌ®SCü¼
+ scoped_name: [] Xg`®Ì®SCü¼
+ switch_type: switchÌ^
+ switch_fq_type: switchÌ®SCü^
+ deref_switch_type: switchÌñQÆ^
+ local:
+ idl_name: é¾Ìidlã̯Êq
+ name: C++É}bsO³ê½¯Êq
+ name_fq: C++¯ÊqÌ®SCü¼
+ scoped_name: [] Xg`®Ì®SCü¼
+
+ """
+ self.createIdent(dict, node)
+ cdict = dict['ice']
+ ldict = dict['local']
+
+ switchType = types.Type(node.switchType())
+ ast.markDefaultCase(node)
+ hasDefault = ast.defaultCase(node) != None
+
+ (ctype, ltype, is_primitive) = self.getType(switchType)
+ cdict['switch_fq_type'] = ctype
+ cdict['switch_type'] = ctype.split('::')[-1]
+ ldict['switch_fq_type'] = ltype
+ ldict['switch_type'] = ltype.split('::')[-1]
+ return
+
+
+ def createMembersForIce(self, dict, node):
+ corba_name = dict['ice']['name']
+ outer_environment = id.lookup(node)
+ environment = outer_environment.enter(id.mapID(corba_name))
+ scope = environment.scope()
+
+ members = []
+ for member in node.members():
+ #------------------------------------------------------------
+ # member
+ # - type_d: type of a member
+ # - decl_d: decralation list
+ memberType = types.Type(member.memberType())
+
+ memtype = memberType.member(environment)
+ for decl in member.declarators():
+ m = self.createMember(decl, member, environment)
+ if m != None:
+ members.append(m)
+ dict['members'] = members
+ return dict
+
+ def createMemberForIce(self, decl, member, env):
+ dict = self.createDecl('member')
+ cdict = dict['ice']
+ ldict = dict['local']
+
+ memberType = types.Type(member.memberType())
+ memtype = memberType.member(env)
+
+ (ctype, ltype, is_primitive) = self.getType(memberType)
+ cdict['base_type'] = ctype
+ cdict['tk'] = self.tk_map[memberType.kind()]
+ ldict['base_type'] = ltype
+ cdict['member_name'] = id.mapID(decl.identifier())
+ cdict['member_dims'] = decl.sizes()
+ ldict['member_name'] = cdict['member_name']
+ ldict['member_dims'] = cdict['member_dims']
+
+ if memberType.objref():
+ corba_mtype = ctype
+ local_mtype = ltype + '*'
+ else:
+ corba_mtype = ctype
+ local_mtype = ltype
+
+ cdict['member_type'] = corba_mtype
+ ldict['member_type'] = local_mtype
+ return dict
+
+ def createUnionCaseForIce(self, case, node, switchtype, environment):
+ dict = self.createDecl('union_case')
+ cdict = dict['ice']
+ ldict = dict['local']
+
+ caseType = types.Type(case.caseType())
+ d_caseType = caseType.deref()
+ (corba_ctype, local_ctype, is_primitive) = self.getType(caseType)
+ cdict['case_type'] = corba_ctype
+ ldict['case_type'] = local_ctype
+
+ decl = case.declarator()
+ case_member = id.mapID(decl.identifier())
+ cdict['case_member'] = case_member
+ ldict['case_member'] = case_member
+
+ decl_dims = decl.sizes()
+ full_dims = decl_dims + caseType.dims()
+ is_array = full_dims != []
+ if is_array: raise "array union case type is not supported."
+
+ # ------------------------------------------------------------
+ # generate default discriminator
+ def choose(switchType = switchtype,
+ values = ast.allCaseLabelValues(node),
+ environment = environment):
+ switchType = switchType.deref()
+ def min_unused(start, used = values):
+ x = start
+ while x in used:
+ x = x + 1
+ return x
+ kind = switchType.type().kind()
+ if switchType.integer():
+ (low, high) = ast.integer_type_ranges[kind]
+ s = switchType.literal(min_unused(low+1))
+ return s
+ elif kind == idltype.tk_char:
+ all = map(chr, range(0, 255))
+ elif kind == idltype.tk_boolean:
+ all = [0, 1]
+ elif kind == idltype.tk_enum:
+ all = switchType.type().decl().enumerators()
+ else:
+ util.fatalError("Failed to generate a default union " +\
+ "discriminator value")
+ possibles = util.minus(all, values)
+ return switchType.literal(possibles[0], environment)
+ # ------------------------------------------------------------
+
+ labels = case.labels()
+ if labels != []:
+ non_default_labels = filter(lambda x:not x.default(), labels)
+ if non_default_labels == []:
+ # only one label and it's the default
+ label = labels[0]
+ discrimvalue = choose()
+ elif len(non_default_labels) > 1:
+ # oooh, we have a choice. Let's pick the second one.
+ # no-one will be expecting that
+ label = non_default_labels[1]
+ else:
+ # just the one interesting label
+ label = non_default_labels[0]
+
+ if label.default():
+ discrimvalue = choose()
+ else:
+ discrimvalue = switchtype.literal(label.value(),
+ environment)
+ cdict['discriminator'] = discrimvalue
+ ldict['discriminator'] = discrimvalue
+
+ if switchtype.enum():
+ corba_ns = '::' + string.join(cdict['ice_ns'], '::')
+ local_ns = '::' + string.join(ldict['iface_ns'], '::')
+ cdict['discriminator_fq'] = corba_ns + '::' + discrimvalue
+ ldict['discriminator_fq'] = local_ns + '::' + discrimvalue
+ else:
+ cdict['discriminator_fq'] = discrimvalue
+ ldict['discriminator_fq'] = discrimvalue
+ non_default_labels = filter(lambda x:not x.default(), labels)
+ return dict
+
+ def createTypedefForIce(self, aliasType, decl, env):
+ """
+ typedefé¾ÉÖ·éfBNVi̶¬
+
+ corba:
+ derived_type: ±o^¼
+ derived_fq_type: ®SCü±o^¼
+ deref_type: ñQÆ^¼
+ deref_fq_type: ®SCüñQ^¼
+ tk: TypeCode
+ local:
+ derived_type: ±o^¼
+ derived_fq_type: ®SCü±o^¼
+ deref_type: ñQÆ^¼
+ deref_fq_type: ®SCüñQ^¼
+ """
+
+ dict = self.createDecl('typedef')
+ cdict = dict['ice']
+ ldict = dict['local']
+
+ (cdict['base_type'], ldict['base_type'], is_primitive) = self.getType(aliasType)
+ derivedName = id.mapID(decl.identifier())
+ alias_dims = aliasType.dims()
+ cdict['derived_type'] = derivedName
+ ldict['derived_type'] = derivedName
+
+ corba_ns = '::' + string.join(cdict['ice_ns'], '::')
+ local_ns = '::' + string.join(ldict['iface_ns'], '::')
+ cdict['derived_type_fq'] = corba_ns + '::' + derivedName
+ ldict['derived_type_fq'] = local_ns + '::' + derivedName
+ cdict['tk'] = tk = self.tk_map[aliasType.kind()]
+ primitive = ["tk_short", "tk_long", "tk_ushort",
+ "tk_ulong", "tk_float", "tk_double",
+ "tk_boolean", "tk_char", "tk_octet"]
+ if primitive.count(tk) > 0:
+ cdict['is_primitive'] = 'YES'
+
+ if aliasType.sequence():
+ seqType = types.Type(aliasType.type().seqType())
+ # get type of element of sequence
+ (corba_etype, local_etype, is_primitive) = self.getType(seqType)
+ cdict['element_tk'] = self.tk_map[seqType.kind()]
+ if seqType.objref():
+ cdict['element_type_fq'] = corba_etype
+ ldict['element_type_fq'] = local_etype + '*'
+ else:
+ cdict['element_type_fq'] = corba_etype
+ ldict['element_type_fq'] = local_etype
+ return dict
+
+ # ------------------------------------------------------------
+ # Iy[VÌßèlÉÖ·é«ð쬷é
+ #
+ # type_r: remoteßèlÌ^¼
+ # type_l: localßèlÌ^¼
+ # var_r: remoteßèlÌϼ
+ # var_l: localßèlÌϼ
+ # to_doil: to_remoteÏ·Ö
+ # to_local: to_localÏ·Ö
+ #
+ def createReturnForIce(self, operation):
+ """
+ corba:
+ base_type:
+ ret_type:
+ decl_type:
+ tk:
+ local:
+ base_type:
+ ret_type:
+ decl_type:
+ tk:
+ """
+ dict = self.createDecl('return')
+ cdict = dict['ice']
+ ldict = dict['local']
+
+ retType = types.Type(operation.returnType())
+ (corba_type, local_type, is_primitive) = self.getType(retType)
+ cdict['base_type'] = corba_type
+ ldict['base_type'] = local_type
+ if is_primitive != None:
+ cdict['is_primitive'] = is_primitive
+ retn_type = types.Type(operation.returnType()).op(types.RET)
+ retn_type = retn_type.replace('Ice', '::Ice')
+ retn_type = retn_type.replace('RTC', '::RTC')
+ retn_type = retn_type.replace('SDOPackage', '::SDOPackage')
+ retn_type = retn_type.replace('::::', '::')
+ cdict['retn_type'] = retn_type
+
+ if retType.objref(): local_rtype = local_type + '*'
+ else: local_rtype = local_type
+
+ ldict['retn_type'] = local_rtype
+ cdict['tk'] = ldict['tk'] = self.tk_map[retType.kind()]
+
+ if retType.deref().sequence():
+ retType = retType.deref()
+
+ if retType.sequence():
+ seqType = types.Type(retType.type().seqType())
+ # get type of element of sequence
+ (corba_etype, local_etype, is_primitive) = self.getType(seqType)
+ cdict['deref_tk'] = self.tk_map[seqType.kind()]
+ else:
+ derefType = retType.deref()
+ (corba_dtype, local_dtype, is_primitive) = self.getType(derefType)
+ cdict['deref_tk'] = self.tk_map[derefType.kind()]
+ return dict
+ # ------------------------------------------------------------
+ # Iy[VÌøÉÖ·é«ð쬷é
+ #
+ # type_r: remoteÌøÌ^
+ # type_l: localÌøÌ^
+ # var_r: remoteÌϼ
+ # var_l: localÌϼ
+ # to_doil: to_remoteÏ·Ö
+ # to_local: to_localÏ·Ö
+ #
+ def createArgsForIce(self, operation, env):
+ """
+
+ corba:
+ base_type:
+ arg_type:
+ arg_name:
+ var_name:
+ decl_type:
+ direction:
+ tk:
+ local:
+ base_type:
+ arg_type:
+ arg_name:
+ var_name:
+ decl_type:
+ direction:
+ tk:
+
+
+ """
+ args = []
+ direction = ['return']
+ for arg in operation.parameters():
+ # corba args information
+ dict = self.createDecl('arg')
+ cdict = dict['ice']
+ ldict = dict['local']
+
+ paramType = types.Type(arg.paramType())
+ (corba_type, local_type, is_primitive) = self.getType(paramType)
+
+ cdict['base_type'] = corba_type
+ ldict['base_type'] = local_type
+ if is_primitive != None:
+ cdict['is_primitive'] = is_primitive
+
+ arg_name = id.mapID(arg.identifier())
+ cdict['arg_name'] = arg_name
+ ldict['arg_name'] = arg_name
+ cdict['var_name'] = '_' + arg_name
+ ldict['var_name'] = '_' + arg_name
+
+ direction_val = direction[arg.direction()]
+ cdict['direction'] = direction_val
+ ldict['direction'] = direction_val
+
+ cdict['tk'] = ldict['tk'] = self.tk_map[paramType.kind()]
+ arg_type = paramType.op(types.direction(arg), use_out = 0)
+ arg_type = arg_type.replace('Ice', '::Ice')
+ arg_type = arg_type.replace('RTC', '::RTC')
+ arg_type = arg_type.replace('SDOPackage', '::SDOPackage')
+ arg_type = arg_type.replace('::::', '::')
+ cdict['arg_type'] = arg_type
+ out = arg.is_out()
+ self.createArg(dict, paramType, out)
+ args.append(dict)
+ return args
+
+ def createArgForIce(self, dict, typeobj, out):
+ (corba_type, local_type, is_primitive) = self.getType(typeobj)
+ cdict = dict['ice']
+ ldict = dict['local']
+ if is_primitive != None:
+ cdict['is_primitive'] = is_primitive
+
+ paramType = typeobj
+ if paramType.typedef():
+ paramType = paramType.deref()
+ # primitive type
+ if paramType.is_basic_data_types():
+ if out: ldict['arg_type'] = local_type + '&'
+ else: ldict['arg_type'] = local_type
+ ldict['var_type'] = local_type
+ cdict['var_type'] = corba_type
+ # Enum type
+ elif paramType.enum():
+ if out: ldict['arg_type'] = local_type + '&'
+ else: ldict['arg_type'] = local_type
+ ldict['var_type'] = local_type
+ cdict['var_type'] = corba_type
+ # Struct type
+ # Sequence type
+ # Union type
+ elif paramType.struct() or paramType.sequence() or \
+ paramType.union():
+ if out: ldict['arg_type'] = local_type + '&'
+ else: ldict['arg_type'] = 'const '+local_type+'&'
+ ldict['var_type'] = local_type
+ cdict['var_type'] = corba_type + '*'
+ # Object type
+ elif paramType.objref():
+ if out: ldict['arg_type'] = local_type + '*'
+ else: ldict['arg_type'] = 'const '+local_type+'*'
+ ldict['var_type'] = local_type + '*'
+ cdict['var_type'] = corba_type
+ # String type
+ # Any type
+ elif paramType.any() or paramType.string():
+ if out: ldict['arg_type'] = local_type + '&'
+ else: ldict['arg_type'] = 'const ' + local_type + '&'
+ ldict['var_type'] = local_type
+ cdict['var_type'] = corba_type
+ else:
+ raise "UNKNOWN TYPE", (
+ self.tk_map[paramType.kind()],
+ paramType.typedef())
+
+ def visitEnumForIce(self, node):
+ dict = self.createDecl('enum')
+ cdict = dict['ice']
+ ldict = dict['local']
+ self.createEnumIdent(dict, node)
+
+ enumerators = node.enumerators()
+ memberlist = map(lambda x: id.Name(x.scopedName()).simple(),
+ enumerators)
+ cdict['members'] = memberlist
+ ldict['members'] = memberlist
+ self.dict['tree'].append(dict)
+ return
+
+ # interfaces cannot be further nested
+ def visitInterfaceForIce(self, node):
+ self.__allInterfaces.append(node)
+ # listed scope and interface name
+ dict = self.createDecl('interface')
+ self.createInterfaceIdent(dict, node)
+ self.createInterfaceFileInfo(dict, node)
+
+ dict['inherits'] = []
+ for ihnode in ast.allInherits(node):
+ idict = self.createDecl('inherit')
+ self.createInterfaceIdent(idict, ihnode)
+ self.createInterfaceFileInfo(idict, ihnode)
+ dict['inherits'].append(idict)
+
+ env = id.lookup(node)
+
+ allInterfaces = [node]# + ast.allInherits(node)
+ allCallables = util.fold( map(lambda x:x.callables(), allInterfaces),
+ [], lambda x, y: x + y )
+
+ dict['operations'] = []
+ dict['attributes'] = []
+ for c in allCallables:
+ if isinstance(c, idlast.Attribute):
+ attrType = types.Type(c.attrType())
+ d_attrType = attrType.deref()
+ (corba_atype, local_atype, is_primitive) = self.getType(attrType)
+
+ for i in c.identifiers():
+ ident = id.mapID(i)
+ returnType = attrType.op(types.RET)
+ inType = attrType.op(types.IN)
+
+ adict = createDecl('attribute')
+ cdict = adict['ice']
+ ldict = adict['local']
+ cdict['base_type'] = corba_atype;
+ ldict['base_type'] = local_atype
+ cdict['name'] = ident
+ adict['return'] = self.createReturn(c)
+ adict['arg'] = {}
+ self.createArg(adict['arg'], attrType, False)
+
+ dict['attributes'].append(adict)
+ if c.readonly():
+ dict['readonly'] = 'yes'
+ dict['attributes'].append(gdict)
+
+ elif isinstance(c, idlast.Operation):
+ # operations
+ op_dict = self.createOperation(c)
+ op_dict['return'] = self.createReturn(c)
+ op_dict['args'] = self.createArgs(c, env)
+ dict['operations'].append(op_dict)
+ else:
+ util.fatalError("Internal error generating interface member")
+ raise "No code for interface member: " + repr(c)
+
+# self.dict['interfaces'].append(dict)
+ self.dict['tree'].append(dict)
+ return
+
Modified: branches/work_ForDoil/OpenRTM-aist/src/lib/doil/utils/omniidl_be/doil/ice/__init__.py
===================================================================
--- branches/work_ForDoil/OpenRTM-aist/src/lib/doil/utils/omniidl_be/doil/ice/__init__.py 2014-02-17 03:30:45 UTC (rev 2510)
+++ branches/work_ForDoil/OpenRTM-aist/src/lib/doil/utils/omniidl_be/doil/ice/__init__.py 2014-02-17 09:20:37 UTC (rev 2511)
@@ -1,23 +1,147 @@
#!/usr/bin/env python
+# -*- coding: shift_jis -*-
# -*- python -*-
#
-# @file iceadapter/__init__.py
-# @brief doil ice adapter generator for omniidl backend
-# @date $Date$
-# @author Noriaki Ando <n-ando at aist.go.jp>
-#
+# @file omniidl_be/doil/ice/__init__.py
+# @brief ice servant/adapter code generator for doil backend
+# @date $Date$
+# @author Norkai Ando <n-ando at aist.go.jp>
+#
# Copyright (C) 2008
# Task-intelligence Research Group,
# Intelligent Systems Research Institute,
# National Institute of
# Advanced Industrial Science and Technology (AIST), Japan
# All rights reserved.
-#
-# $Id$
-#
+#
+# $Id$
+#
-#from omniidl_be.doil.iceadapter import main
+import os
-def run(tree):
- print "## doil ice adapter generator has not been implemented yet."
- print "## sorry :-p"
+from omniidl_be.doil.ice import template
+import omniidl_be.doil.yat as yat
+
+keys = ['idl_fname', 'idl_includes',
+ 'types_h', 'types_h_path',
+ 'typeconv_h', 'typeconv_h_path',
+ 'include_h']
+
+decl_map = {
+ 'interface': {
+ 'decl': template.object_conv_h, 'impl': template.object_conv_cpp},
+ 'struct': {
+ 'decl': template.struct_conv_h, 'impl': template.struct_conv_cpp},
+ 'union': {
+ 'decl': template.union_conv_h, 'impl': template.union_conv_cpp},
+ 'enum': {
+ 'decl': template.enum_conv_h, 'impl': template.enum_conv_cpp},
+ 'exception': {
+ 'decl': template.exception_conv_h, 'impl': template.exception_conv_cpp},
+ 'typedef': {
+ 'decl': template.typedef_decl_h, 'impl': template.typedef_dec_cpp}
+}
+
+def generate_servant(dict):
+ for d in dict['tree']:
+ if d['ice']['decl_type'] == 'interface':
+ ifdict = {}
+ for key in keys:
+ ifdict[key] = dict[key]
+
+ ifdict.update(d)
+
+ t = yat.Template(template.servant_h)
+ text = t.generate(ifdict)
+ fname = d['local']['servant_h']
+ f = open(fname, "w")
+ f.write(text)
+ f.close()
+
+ t = yat.Template(template.servant_cpp)
+ text = t.generate(ifdict)
+ fname = d['local']['servant_cpp']
+ f = open(fname, "w")
+ f.write(text)
+ f.close()
+
+def generate_adapter(dict):
+ for d in dict['tree']:
+ if d['ice']['decl_type'] == 'interface':
+ ifdict = {}
+ for key in keys:
+ ifdict[key] = dict[key]
+
+ ifdict.update(d)
+
+ t = yat.Template(template.adapter_h)
+ text = t.generate(ifdict)
+ fname = d['local']['adapter_h']
+ f = open(fname, "w")
+ f.write(text)
+ f.close()
+
+ t = yat.Template(template.adapter_cpp)
+ text = t.generate(ifdict)
+ fname = d['local']['adapter_cpp']
+ f = open(fname, "w")
+ f.write(text)
+ f.close()
+
+def generate_proxy(dict):
+ for d in dict['tree']:
+ if d['ice']['decl_type'] == 'interface':
+ ifdict = {}
+ for key in keys:
+ ifdict[key] = dict[key]
+
+ ifdict.update(d)
+
+ t = yat.Template(template.proxy_h)
+ text = t.generate(ifdict)
+ fname = d['local']['proxy_h']
+ f = open(fname, "w")
+ f.write(text)
+ f.close()
+
+ t = yat.Template(template.proxy_cpp)
+ text = t.generate(ifdict)
+ fname = d['local']['proxy_cpp']
+ f = open(fname, "w")
+ f.write(text)
+ f.close()
+
+def generate_types(dict):
+ decl = []
+ impl = []
+ for d in dict['tree']:
+ decl_type = d['decl_type']
+
+ if not decl_map.has_key(decl_type): continue
+
+ decl_temp = yat.Template(decl_map[decl_type]['decl'])
+ decl_text = decl_temp.generate(d)
+ decl.append(decl_text)
+
+ impl_temp = yat.Template(decl_map[decl_type]['impl'])
+ impl_text = impl_temp.generate(d)
+ impl.append(impl_text)
+
+
+ dict['declarations'] = decl
+ dict['implementations'] = impl
+
+ typeconv_h = dict['typeconv_h']
+ typeconv_cpp = dict['typeconv_cpp']
+
+ t = yat.Template(template.typeconv_h)
+ f = open(typeconv_h, "w")
+ text = t.generate(dict)
+ f.write(text)
+ f.close()
+
+ t = yat.Template(template.typeconv_cpp)
+ f = open(typeconv_cpp, "w")
+ text = t.generate(dict)
+ f.write(text)
+ f.close()
More information about the openrtm-commit
mailing list