Example #1
0
    def createArgs(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 = ['in', 'out', 'inout','return']
        for arg in operation.parameters():
            # corba args information
            dict = self.createDecl('arg')
            cdict = dict['corba']
            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('CORBA', '::CORBA')
            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
Example #2
0
    def addOps(self,node,ops):
	
	for i in node.inherits():
            self.addOps(i,ops)

        for d in node.contents():
            if isinstance(d, idlast.Operation):
                new_op = CC.Operation(d.identifier(),baseTypes[d.returnType().kind()])
                # Get the c++ mappping of the return type
                cxxRT = types.Type(d.returnType())
                new_op.cxxReturnType = cxxRT.base()
#                if new_op.returnType == 'string':
#                    print foo2.base()
                #print new_op.name + "::" + d.identifier() + "()"
                #tmpstr = node.identifier() + "::" + d.identifier() + "("
                #tmpstr2 = "  " + node.identifier() + "::" + d.identifier() + "("
                if hasattr(d,'parameters'):
                    for p in d.parameters():
                        new_param = CC.Param(p.identifier())
                        t =  p.paramType()
                        # Get the c++ mapping of the type
                        cxxT = types.Type(t)
                        new_param.cxxType = cxxT.op(types.direction(p))
						
                        if hasattr(t,'scopedName'):
                            #print ' '*8 + str(t.scopedName()),
                            new_param.dataType = idlutil.ccolonName(t.scopedName())
                        else:
                            if isinstance(t,idltype.Type):
                                #print ' '*8 + baseTypes[t.kind()],
                                new_param.dataType = baseTypes[t.kind()]

                        if p.is_in() and p.is_out():
                            new_param.direction = 'inout'
                        elif p.is_out():
                            new_param.direction = 'out'
                        else:
                            new_param.direction = 'in'
                        new_op.params.append(new_param)
                        #tmpstr += new_param.direction + " " + new_param.dataType + ","
                        #tmpstr2 += new_param.direction + " " + new_param.cxxType + ","
                ops.append(new_op)
Example #3
0
    def _from_Callable(self, use_out):
        # Grab the IDL environment
        ifc = self.callable().interface()
        environment = ifc.environment().enter("_objref_" + ifc.name().simple())

        # 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 mangle 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()
Example #4
0
    def _from_Callable(self, use_out):
        # Grab the IDL environment
        ifc = self.callable().interface()
        environment = ifc.environment().enter("_objref_" + ifc.name().simple())

        # 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 mangle 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()
Example #5
0
    def buildCallables(interface, where, continuation, defined_so_far = {}):
        interface = ast.remove_ast_typedefs(interface)
        
        callables = interface.callables()
        operations = filter(lambda x:isinstance(x, idlast.Operation),
                            callables)
        for operation in operations:
            returnType = types.Type(operation.returnType())
            identifier = operation.identifier()
            if (defined_so_far.has_key(identifier)):
                # don't repeat it
                continue
            defined_so_far[identifier] = 1
            
            parameters = operation.parameters()
            has_return_value = not returnType.void()
            # FIXME: return types are fully scoped but argument types
            # arent?
            returnType_name = returnType.op(types.RET)

            operation_name = id.mapID(identifier)
            
            signature = []
            call = []

            for parameter in parameters:
                paramType = types.Type(parameter.paramType())
                # Need to call the _impl operation not the _objref operation
                param_type_name = paramType.op(types.direction(parameter),
                                               use_out = 0)
                param_id = id.mapID(parameter.identifier())
                signature.append(param_type_name + " " + param_id)
                call.append(param_id)

            # deal with call contextx
            if operation.contexts() != []:
                signature.append("::CORBA::Context_ptr _ctxt")
                call.append("_ctxt")

            if has_return_value:
                return_str = "return "
            else:
                return_str = ""
                
            where.out("""\
@return_type_name@ @operation_name@(@signature@) { @return_str@pd_obj->@operation_name@(@call@); }""", return_type_name = returnType_name,
                      operation_name = operation_name,
                      return_str = return_str,
                      signature = ", ".join(signature),
                      call = ", ".join(call))
                    
        attributes = filter(lambda x:isinstance(x, idlast.Attribute),
                            callables)
        for attribute in attributes:
            identifiers = attribute.identifiers()
            attrType = types.Type(attribute.attrType())

            attrType_name_RET = attrType.op(types.RET)
            attrType_name_IN = attrType.op(types.IN)
            
            for identifier in identifiers:
                if defined_so_far.has_key(identifier):
                    # don't repeat it
                    continue
                defined_so_far[identifier] = 1
                
                ident = id.mapID(identifier)
                where.out("""\
@attr_type_ret_name@ @attribute_name@() { return pd_obj->@attribute_name@(); }""", attr_type_ret_name = attrType_name_RET,
                          attribute_name = ident)

                if not attribute.readonly():
                    where.out("""\
void @attribute_name@(@attr_type_in_name@ _value) { pd_obj->@attribute_name@(_value); }""", attribute_name = ident,
                              attr_type_in_name = attrType_name_IN)                    
        # do the recursive bit
        for i in interface.inherits():
            i = i.fullDecl()
            continuation(i, where, continuation, defined_so_far)

        # done
        return
    def addOps(self, node, ops, attrs):

        # add inherited operations
        for i in node.inherits():
            self.addOps(i, ops, attrs)

        for d in node.contents():
            if isinstance(d, idlast.Operation):
                # create the Operation object
                #new_op = base.Operation(d.identifier(),baseTypes[d.returnType().kind()])
                kind = d.returnType().kind()
                if (kind == idltype.tk_alias):  # resolve the 'alias'
                    kind = d.returnType().decl().alias().aliasType().kind()
                new_op = Operation(d.identifier(), baseTypes[kind])

                # Get the c++ mapping of the return type
                cxxRT = types.Type(d.returnType())
                #if not new_op.cxxReturnType == 'void':
                new_op.cxxReturnType = (cxxRT.base(), cxxRT.variable())

                #print new_op.name + "::" + d.identifier() + "()"
                #tmpstr = node.identifier() + "::" + d.identifier() + "("
                #tmpstr2 = "  " + node.identifier() + "::" + d.identifier() + "("

                # find and process the parameters of the operation
                if hasattr(d, 'parameters'):
                    for p in d.parameters():
                        #new_param = base.Param(p.identifier())
                        new_param = Param(p.identifier())
                        t = p.paramType()
                        # Get the c++ mapping of the type
                        cxxT = types.Type(t)
                        new_param.cxxType = cxxT.op(types.direction(p))

                        if hasattr(t, 'scopedName'):
                            new_param.dataType = idlutil.ccolonName(
                                t.scopedName())
                        else:
                            if isinstance(t, idltype.Type):
                                new_param.dataType = baseTypes[t.kind()]

                        if p.is_in() and p.is_out():
                            new_param.direction = 'inout'
                        elif p.is_out():
                            new_param.direction = 'out'
                        else:
                            new_param.direction = 'in'
                        new_op.params.append(new_param)

                if hasattr(d, 'raises'):
                    for r in d.raises():
                        #print r.identifier()
                        new_raises = Raises(r.identifier())
                        new_op.raises.append(new_raises)

                ops.append(new_op)
            if isinstance(d, idlast.Attribute):
                # create the Attribute object
                decl = d.declarators()[0]
                kind = d.attrType().kind()
                if (kind == idltype.tk_alias):  # resolve the 'alias'
                    kind = d.attrType().decl().alias().aliasType().kind()
                if hasattr(d.attrType(), 'scopedName'):
                    dataType = idlutil.ccolonName(d.attrType().scopedName())
                else:
                    dataType = baseTypes[kind]
                new_attr = Attribute(decl.identifier(), d.readonly(), dataType,
                                     baseTypes[kind])

                # Get the c++ mapping of the return type
                cxxRT = types.Type(d.attrType())
                new_attr.cxxReturnType = (cxxRT.base(), cxxRT.variable())
                new_attr.cxxType = cxxRT.op(0)

                attrs.append(new_attr)
Example #7
0
    def buildCallables(interface, where, continuation, defined_so_far={}):
        interface = ast.remove_ast_typedefs(interface)

        callables = interface.callables()
        operations = filter(lambda x: isinstance(x, idlast.Operation),
                            callables)
        for operation in operations:
            returnType = types.Type(operation.returnType())
            identifier = operation.identifier()
            if (defined_so_far.has_key(identifier)):
                # don't repeat it
                continue
            defined_so_far[identifier] = 1

            parameters = operation.parameters()
            has_return_value = not returnType.void()
            # FIXME: return types are fully scoped but argument types
            # arent?
            returnType_name = returnType.op(types.RET)

            operation_name = id.mapID(identifier)

            signature = []
            call = []

            for parameter in parameters:
                paramType = types.Type(parameter.paramType())
                # Need to call the _impl operation not the _objref operation
                param_type_name = paramType.op(types.direction(parameter),
                                               use_out=0)
                param_id = id.mapID(parameter.identifier())
                signature.append(param_type_name + " " + param_id)
                call.append(param_id)

            # deal with call contextx
            if operation.contexts() != []:
                signature.append("::CORBA::Context_ptr _ctxt")
                call.append("_ctxt")

            if has_return_value:
                return_str = "return "
            else:
                return_str = ""

            where.out("""\
@return_type_name@ @operation_name@(@signature@) { @return_str@pd_obj->@operation_name@(@call@); }""",
                      return_type_name=returnType_name,
                      operation_name=operation_name,
                      return_str=return_str,
                      signature=", ".join(signature),
                      call=", ".join(call))

        attributes = filter(lambda x: isinstance(x, idlast.Attribute),
                            callables)
        for attribute in attributes:
            identifiers = attribute.identifiers()
            attrType = types.Type(attribute.attrType())

            attrType_name_RET = attrType.op(types.RET)
            attrType_name_IN = attrType.op(types.IN)

            for identifier in identifiers:
                if defined_so_far.has_key(identifier):
                    # don't repeat it
                    continue
                defined_so_far[identifier] = 1

                ident = id.mapID(identifier)
                where.out("""\
@attr_type_ret_name@ @attribute_name@() { return pd_obj->@attribute_name@(); }""",
                          attr_type_ret_name=attrType_name_RET,
                          attribute_name=ident)

                if not attribute.readonly():
                    where.out("""\
void @attribute_name@(@attr_type_in_name@ _value) { pd_obj->@attribute_name@(_value); }""",
                              attribute_name=ident,
                              attr_type_in_name=attrType_name_IN)
        # do the recursive bit
        for i in interface.inherits():
            i = i.fullDecl()
            continuation(i, where, continuation, defined_so_far)

        # done
        return
    def addOps(self,node,ops,attrs):

        # add inherited operations
        for i in node.inherits():
            self.addOps(i,ops,attrs)

        for d in node.contents():
            if isinstance(d, idlast.Operation):
                # create the Operation object
                #new_op = base.Operation(d.identifier(),baseTypes[d.returnType().kind()])
                kind = d.returnType().kind()
                if (kind==idltype.tk_alias): # resolve the 'alias'
                    kind = d.returnType().decl().alias().aliasType().kind()
                new_op = Operation(d.identifier(),baseTypes[kind])

                # Get the c++ mapping of the return type
                cxxRT = types.Type(d.returnType())
                new_op.cxxReturnType = cxxRT.base()

                #print new_op.name + "::" + d.identifier() + "()"
                #tmpstr = node.identifier() + "::" + d.identifier() + "("
                #tmpstr2 = "  " + node.identifier() + "::" + d.identifier() + "("

                # find and process the parameters of the operation
                if hasattr(d,'parameters'):
                    for p in d.parameters():
                        #new_param = base.Param(p.identifier())
                        new_param = Param(p.identifier())
                        t =  p.paramType()
                        # Get the c++ mapping of the type
                        cxxT = types.Type(t)
                        new_param.cxxType = cxxT.op(types.direction(p))

                        if hasattr(t,'scopedName'):
                            new_param.dataType = idlutil.ccolonName(t.scopedName())
                        else:
                            if isinstance(t,idltype.Type):
                                new_param.dataType = baseTypes[t.kind()]

                        if p.is_in() and p.is_out():
                            new_param.direction = 'inout'
                        elif p.is_out():
                            new_param.direction = 'out'
                        else:
                            new_param.direction = 'in'
                        new_op.params.append(new_param)

                if hasattr(d, 'raises'):
                    for r in d.raises():
                        #print r.identifier()
                        new_raises = Raises(r.identifier())
                        new_op.raises.append(new_raises)

                ops.append(new_op)
            if isinstance(d, idlast.Attribute):
                # create the Attribute object
                decl = d.declarators()[0]
                kind = d.attrType().kind()
                if (kind==idltype.tk_alias): # resolve the 'alias'
                    kind = d.attrType().decl().alias().aliasType().kind()
                if hasattr(d.attrType(),'scopedName'):
                    dataType = idlutil.ccolonName(d.attrType().scopedName())
                else:
                    dataType = baseTypes[kind]
                new_attr = Attribute(decl.identifier(),d.readonly(),dataType,baseTypes[kind])

                # Get the c++ mapping of the return type
                cxxRT = types.Type(d.attrType())
                new_attr.cxxReturnType = cxxRT.base()
                new_attr.cxxType = cxxRT.op(0)

                attrs.append(new_attr)
Example #9
0
    def visitInterface(self, node):
        scopedName = id.Name(node.scopedName())
        openns, closens = namespaces(scopedName, self.environment)
        
        impl_name = scopedName.simple(cxx=1)
        impl_tpl_name = impl_tplname (scopedName)
        cxx_fqname = scopedName.fullyQualify()
        hpp_class = self.toCppNamespace (scopedName).fullyQualify(cxx=1)

        fqname = scopedName.fullyQualify(cxx = 0)

        is_base_class = not bool(node.inherits())
        ptr_t = self.toCppNamespace (scopedName.suffix("Ptr_t")).fullyQualify(cxx=1)
        if is_base_class:
            key = hpp_servant_name (scopedName)
            impl_base_name = "ServantBase"
            if key in self.storages:
                st = self.storages[key]
                # declare storage
                self.interface_declarations.out(st.decl)
                storage = st.sc.simple() + "< "+ptr_t+" >"
            else:
                storage = ptr_t
        else:
            baseScopedName = id.Name (node.inherits()[0].scopedName())
            key = hpp_servant_name (baseScopedName)
            impl_base_name = hpp_servant_name (baseScopedName.suffix('Servant'))
            if key in self.storages:
                st = self.storages[key]
                storage = st.sc.simple() + "< "+ptr_t+" >"
                self.storages[fqname] = st
            else:
                storage = ptr_t
        
        # build methods corresponding to attributes, operations etc.
        # attributes[] and operations[] will contain lists of function
        # signatures eg
        #   [ char *echoString(const char *mesg) ]
        attributes = []
        operations = []

        allCallables = node.callables()

        # declarations contains a list of in-class decl signatures
        # implementations contains a list of out of line impl signatures
        # (typically differ by classname::)
        declarations = output.StringStream()
        implementations = output.StringStream()
        
        for c in allCallables:
            comments = c.comments()
            hpp_opname = None
            comments_impl = []
            for comment in comments:
                if comment.text().startswith("// ") or comment.text().startswith("///"):
                    # Skip this comment
                    pass
                elif comment.text().startswith("//*"):
                    if not comments_impl:
                        comments_impl.append (" // generated from {}:{}\n".format(node.file(), node.line()))
                    comments_impl.append (comment.text()[3:])
                elif comment.text().startswith("//->"):
                    if hpp_opname is not None: raise makeError("Function was already renamed", comment.file(), comment.line())
                    hpp_opname = comment.text()[4:].strip()

            if isinstance(c, idlast.Attribute):
                attrType = types.Type(c.attrType())
                d_attrType = attrType.deref()

                for i in c.identifiers():
                    attribname = id.mapID(i)
                    returnType = attrType.op(types.RET)
                    inType = attrType.op(types.IN)
                    attributes.append(returnType + " " + attribname + "()")
                    # need a set method if not a readonly attribute
                    if not c.readonly():
                        declarations.out (template.operation_decl_code,
                                return_type = "void",
                                opname = attribname,
                                arg_defs = inType + " _" + attribname)

                        tmpVar, in_conv, out_conv = self.argConversion ("_" + attribname, attrType, True, False, c)
                        implementations.out (template.operation_impl_code,
                                return_type = "void",
                                impl_tpl_name = impl_tpl_name,
                                opname = attribname,
                                hpp_opname = hpp_opname if hpp_opname else attribname,
                                arg_defs = inType + " _" + attribname,
                                in_conversions = in_conv if in_conv else "",
                                out_conversions = out_conv if out_conv else "",
                                store_return = "",
                                do_return = "",
                                arg_calls = tmpVar)

                    declarations.out (template.operation_decl_code,
                            return_type = returnType,
                            opname = attribname,
                            arg_defs = "")

                    store_return, do_return = self.retConversion (attrType)
                    implementations.out (template.operation_impl_code,
                            return_type = returnType,
                            impl_tpl_name = impl_tpl_name,
                            opname = attribname,
                            hpp_opname = hpp_opname if hpp_opname else attribname,
                            arg_defs = "",
                            in_conversions = "",
                            out_conversions = "",
                            store_return = store_return,
                            do_return = do_return,
                            arg_calls = "")
            elif isinstance(c, idlast.Operation):
                params = []
                paramNames = []
                in_conversions = []
                out_conversions = []
                for p in c.parameters():
                    paramType = types.Type(p.paramType())
                    cxx_type = paramType.op(types.direction(p), use_out = 0)
                    
                    argname = id.mapID(p.identifier())
                    if not comments_impl:
                        tmpVar, in_conv, out_conv = self.argConversion (argname, paramType, p.is_in(), p.is_out(), p)
                        if in_conv:
                            in_conversions.append(in_conv)
                        if out_conv:
                            out_conversions.append(out_conv)
                    else:
                        tmpVar = argname

                    params.append(cxx_type + " " + argname)
                    paramNames.append(tmpVar)


                # deal with possible "context"
                if c.contexts() != []:
                    params.append("CORBA::Context_ptr _ctxt")

                store_return, do_return = self.retConversion (types.Type(c.returnType()))
                return_type = types.Type(c.returnType()).op(types.RET)

                opname = id.mapID(c.identifier())
                arguments = ", ".join(params)
                argumentsCall = ", ".join(paramNames)
                args = opname + "(" + arguments + ")"

                declarations.out (template.operation_decl_code,
                        return_type = return_type,
                        opname = opname,
                        arg_defs = arguments)

                if comments_impl:
                    implementations.out (template.provided_operation_impl_code,
                            return_type = return_type,
                            impl_tpl_name = impl_tpl_name,
                            opname = opname,
                            implementation = "".join(comments_impl),
                            arg_defs = arguments,)
                elif opname in template.predefined_operations_impl_code:
                    #assert not c.parameters(), "Interface operation str should not have arguments"
                    implementations.out (template.predefined_operations_impl_code[opname],
                            return_type = return_type,
                            impl_tpl_name = impl_tpl_name,
                            opname = opname,
                            conversions = "\n  ".join(in_conversions),
                            arg_defs = arguments,
                            store_return = store_return,
                            do_return = do_return,
                            arg_calls = argumentsCall)
                else:
                    implementations.out (template.operation_impl_code,
                            return_type = return_type,
                            impl_tpl_name = impl_tpl_name,
                            opname = opname,
                            hpp_opname = hpp_opname if hpp_opname is not None else opname,
                            in_conversions = "\n  ".join(in_conversions),
                            out_conversions = "\n  ".join(out_conversions),
                            arg_defs = arguments,
                            store_return = store_return,
                            do_return = do_return,
                            arg_calls = argumentsCall)

            else:
                util.fatalError("Internal error generating interface member")
                raise AssertionError("No code for interface member: "+repr(c))

        openns, closens = namespaces(scopedName, self.environment)

        # Output the _i class definition definition
        self.interface_declarations.out(
                template.base_interface_def if is_base_class else template.inherited_interface_def,
                fq_name = fqname,
                impl_tpl_name = impl_tpl_name,
                impl_base_name = impl_base_name,
                operations = str(declarations),
                impl_name = impl_name,
                fq_POA_name = "POA_" + cxx_fqname,

                hpp_class = hpp_class,
                storage = storage,
                open_namespaces = openns,
                close_namespaces = closens,
                )

        self.interface_implementations.out(
                template.base_interface_code if is_base_class else template.inherited_interface_code,
                fqname = fqname,
                impl_name = impl_name,
                impl_tpl_name = impl_tpl_name,
                impl_base_name = impl_base_name,
                hpp_class = hpp_class,
                operations = str(implementations),
                open_namespaces = openns,
                close_namespaces = closens,
                )
Example #10
0
    def visitInterface(self, node):
        self.__allInterfaces.append(node)
    
        scopedName = id.Name(node.scopedName())
        
        cxx_fqname = scopedName.fullyQualify()
        impl_flat_name = impl_fullname(scopedName)

        fqname = scopedName.fullyQualify(cxx = 0)

        
        # build methods corresponding to attributes, operations etc.
        # attributes[] and operations[] will contain lists of function
        # signatures eg
        #   [ char *echoString(const char *mesg) ]
        attributes = []

        # we need to consider all callables, including inherited ones
        # since this implementation class is not inheriting from anywhere
        # other than the IDL skeleton
        allInterfaces = [node] + ast.allInherits(node)

        allCallables = []
        for intf in allInterfaces:
            allCallables.extend(intf.callables())

        # declarations[] contains a list of in-class decl signatures
        # implementations[] contains a list of out of line impl signatures
        # (typically differ by classname::)
        declarations = []
        implementations = []
        
        for c in allCallables:
            if isinstance(c, idlast.Attribute):
                attrType = types.Type(c.attrType())

                for i in c.identifiers():
                    attribname = id.mapID(i)
                    returnType = attrType.op(types.RET)
                    inType = attrType.op(types.IN)
                    attributes.append(returnType + " " + attribname + "()")

                    # need a set method if not a readonly attribute
                    if not c.readonly():
                        args = attribname + "(" + inType + ")"
                        declarations.append("void " + args)
                        implementations.append("void " + impl_flat_name +\
                                               "::" + args)
                    declarations.append(returnType + " " + attribname + "()")
                    implementations.append(returnType + " " + impl_flat_name+\
                                           "::" + attribname + "()")

            elif isinstance(c, idlast.Operation):
                params = []
                for p in c.parameters():
                    paramType = types.Type(p.paramType())
                    cxx_type = paramType.op(types.direction(p), use_out = 0)
                    
                    argname = id.mapID(p.identifier())
                    params.append(cxx_type + " " + argname)

                # deal with possible "context"
                if c.contexts() != []:
                    params.append("CORBA::Context_ptr _ctxt")

                return_type = types.Type(c.returnType()).op(types.RET)

                opname = id.mapID(c.identifier())
                arguments = ", ".join(params)
                args = opname + "(" + arguments + ")"
                declarations.append(return_type + " " + args + ";")
                implementations.append(return_type + " " + impl_flat_name +
                                       "::" + args)
            else:
                util.fatalError("Internal error generating interface member")

        # the class definition has no actual code...
        defs = "\n".join(declarations)

        # Output the _i class definition definition
        self.stream.out(template.interface_def,
                        impl_fqname = impl_flat_name,
                        impl_name = impl_flat_name,
                        fq_name = fqname,
                        fq_POA_name = "POA_" + cxx_fqname,
                        operations = defs)

        # Output the implementations of the class methods
        impls = "".join([ """\
%s
{
  // insert code here and remove the warning
  #warning "Code missing in function <%s>"
}

""" % (impl,impl) for impl in implementations ])
               
        self.stream.out(template.interface_code,
                        fqname = fqname,
                        impl_name = impl_flat_name,
                        impl_fqname = impl_flat_name,
                        operations = impls)
Example #11
0
	def visitInterface(self, node):
		self.__allInterfaces.append(node)
	
		scopedName = id.Name(node.scopedName())
		
		cxx_fqname = scopedName.fullyQualify()
		impl_flat_name = impl_fullname(scopedName)

		fqname = scopedName.fullyQualify(cxx = 0)

		
		# build methods corresponding to attributes, operations etc.
		# attributes[] and operations[] will contain lists of function
		# signatures eg
		#   [ char *echoString(const char *mesg) ]
		attributes = []
		operations = []
		virtual_operations = []

		# we need to consider all callables, including inherited ones
		# since this implementation class is not inheriting from anywhere
		# other than the IDL skeleton
		allInterfaces = [node] + ast.allInherits(node)
		allCallables = util.fold( map(lambda x:x.callables(), allInterfaces),
								  [], lambda x, y: x + y )


		# declarations[] contains a list of in-class decl signatures
		# implementations[] contains a list of out of line impl signatures
		# (typically differ by classname::)
		declarations = []
		implementations = []
		
		for c in allCallables:

			if isinstance(c, idlast.Attribute) :
				attrType = types.Type(c.attrType())
				d_attrType = attrType.deref()

				for i in c.identifiers():
					attribname = id.mapID(i)
					returnType = attrType.op(types.RET)
					inType = attrType.op(types.IN)
					attributes.append(returnType + " " + attribname + "()")
					# need a set method if not a readonly attribute
					if not c.readonly():
						args = attribname + "(" + inType + ")"
						declarations.append("void " + args)
						implementations.append("void " + impl_flat_name +\
											   "::" + args)
					if not attribname in self.ignore_operations:
						declarations.append(returnType + " " + attribname + "()")
						implementations.append(returnType + " " + impl_flat_name+\
										   "::" + attribname + "()")
			elif isinstance(c, idlast.Operation):
				params = []
				for p in c.parameters():
					paramType = types.Type(p.paramType())
					cxx_type = paramType.op(types.direction(p), use_out = 0)
					
					argname = id.mapID(p.identifier())
					params.append(cxx_type + " " + argname)

				# deal with possible "context"
				if c.contexts() != []:
					params.append("CORBA::Context_ptr _ctxt")

				return_type = types.Type(c.returnType()).op(types.RET)

				opname = id.mapID(c.identifier())
				if not opname in self.ignore_operations:
					arguments = string.join(params, ", ")
					args = opname + "(" + arguments + ")"
					declarations.append(return_type + " " + args)
					implementations.append(return_type + " " + \
										   impl_flat_name + \
										   "::" + args)
			else:
				util.fatalError("Internal error generating interface member")
				raise "No code for interface member: " + repr(c)

		# the class definition has no actual code...
		defs = string.join(map(lambda x:x + ";\n", declarations), "")

		# Output the class definition of the implementation
		self.stream_h.out(interface_def,
						  impl_fqname = impl_flat_name,
						  impl_name = impl_flat_name,
						  fq_name = fqname,
						  fq_POA_name = "POA_" + cxx_fqname,
						  operations = defs)

		# Output the class methods implementations
		impls = string.join(map(lambda x: x + """\

{
  // Please insert your code here and remove the following warning pragma
#ifndef WIN32
  #warning "Code missing in function <""" + x + """>"
#endif
}

""",
								implementations), "")
		
		self.stream_cpp.out(interface_code,
							fqname = fqname,
							impl_name = impl_flat_name,
							impl_fqname = impl_flat_name,
							operations = impls)
Example #12
0
    def visitInterface(self, node):
        self.__allInterfaces.append(node)

        scopedName = id.Name(node.scopedName())

        cxx_fqname = scopedName.fullyQualify()
        impl_flat_name = impl_fullname(scopedName)

        fqname = scopedName.fullyQualify(cxx=0)

        # build methods corresponding to attributes, operations etc.
        # attributes[] and operations[] will contain lists of function
        # signatures eg
        #   [ char *echoString(const char *mesg) ]
        attributes = []

        # we need to consider all callables, including inherited ones
        # since this implementation class is not inheriting from anywhere
        # other than the IDL skeleton
        allInterfaces = [node] + ast.allInherits(node)

        allCallables = []
        for intf in allInterfaces:
            allCallables.extend(intf.callables())

        # declarations[] contains a list of in-class decl signatures
        # implementations[] contains a list of out of line impl signatures
        # (typically differ by classname::)
        declarations = []
        implementations = []

        for c in allCallables:
            if isinstance(c, idlast.Attribute):
                attrType = types.Type(c.attrType())

                for i in c.identifiers():
                    attribname = id.mapID(i)
                    returnType = attrType.op(types.RET)
                    inType = attrType.op(types.IN)
                    attributes.append(returnType + " " + attribname + "()")

                    # need a set method if not a readonly attribute
                    if not c.readonly():
                        args = attribname + "(" + inType + ")"
                        declarations.append("void " + args)
                        implementations.append("void " + impl_flat_name +\
                                               "::" + args)
                    declarations.append(returnType + " " + attribname + "()")
                    implementations.append(returnType + " " + impl_flat_name+\
                                           "::" + attribname + "()")

            elif isinstance(c, idlast.Operation):
                params = []
                for p in c.parameters():
                    paramType = types.Type(p.paramType())
                    cxx_type = paramType.op(types.direction(p), use_out=0)

                    argname = id.mapID(p.identifier())
                    params.append(cxx_type + " " + argname)

                # deal with possible "context"
                if c.contexts() != []:
                    params.append("CORBA::Context_ptr _ctxt")

                return_type = types.Type(c.returnType()).op(types.RET)

                opname = id.mapID(c.identifier())
                arguments = ", ".join(params)
                args = opname + "(" + arguments + ")"
                declarations.append(return_type + " " + args + ";")
                implementations.append(return_type + " " + impl_flat_name +
                                       "::" + args)
            else:
                util.fatalError("Internal error generating interface member")

        # the class definition has no actual code...
        defs = "\n".join(declarations)

        # Output the _i class definition definition
        self.stream.out(template.interface_def,
                        impl_fqname=impl_flat_name,
                        impl_name=impl_flat_name,
                        fq_name=fqname,
                        fq_POA_name="POA_" + cxx_fqname,
                        operations=defs)

        # Output the implementations of the class methods
        impls = "".join([
            """\
%s
{
  // insert code here and remove the warning
  #warning "Code missing in function <%s>"
}

""" % (impl, impl) for impl in implementations
        ])

        self.stream.out(template.interface_code,
                        fqname=fqname,
                        impl_name=impl_flat_name,
                        impl_fqname=impl_flat_name,
                        operations=impls)
    def visitInterface(self, node):
        scopedName = id.Name(node.scopedName())
        openns, closens = namespaces(scopedName, self.environment)
        
        impl_name = scopedName.simple(cxx=1)
        impl_tpl_name = impl_tplname (scopedName)
        cxx_fqname = scopedName.fullyQualify()
        hpp_class = self.toCppNamespace (scopedName).fullyQualify(cxx=1)

        fqname = scopedName.fullyQualify(cxx = 0)

        is_base_class = not bool(node.inherits())
        ptr_t = self.toCppNamespace (scopedName.suffix("Ptr_t")).fullyQualify(cxx=1)
        if is_base_class:
            key = hpp_servant_name (scopedName)
            impl_base_name = "ServantBase"
            if key in self.storages:
                st = self.storages[key]
                # declare storage
                self.interface_declarations.out(st.decl)
                storage = st.sc.simple() + "< "+ptr_t+" >"
            else:
                storage = ptr_t
        else:
            baseScopedName = id.Name (node.inherits()[0].scopedName())
            key = hpp_servant_name (baseScopedName)
            impl_base_name = hpp_servant_name (baseScopedName.suffix('Servant'))
            if key in self.storages:
                st = self.storages[key]
                storage = st.sc.simple() + "< "+ptr_t+" >"
                self.storages[fqname] = st
            else:
                storage = ptr_t
        
        # build methods corresponding to attributes, operations etc.
        # attributes[] and operations[] will contain lists of function
        # signatures eg
        #   [ char *echoString(const char *mesg) ]
        attributes = []
        operations = []

        allCallables = node.callables()

        # declarations contains a list of in-class decl signatures
        # implementations contains a list of out of line impl signatures
        # (typically differ by classname::)
        declarations = output.StringStream()
        implementations = output.StringStream()
        
        for c in allCallables:
            comments = c.comments()
            hpp_opname = None
            comments_impl = []
            for comment in comments:
                if comment.text().startswith("// ") or comment.text().startswith("///"):
                    # Skip this comment
                    pass
                elif comment.text().startswith("//*"):
                    if not comments_impl:
                        comments_impl.append (" // generated from {}:{}\n".format(node.file(), node.line()))
                    comments_impl.append (comment.text()[3:])
                elif comment.text().startswith("//->"):
                    if hpp_opname is not None: raise makeError("Function was already renamed", comment.file(), comment.line())
                    hpp_opname = comment.text()[4:].strip()

            if isinstance(c, idlast.Attribute):
                attrType = types.Type(c.attrType())
                d_attrType = attrType.deref()

                for i in c.identifiers():
                    attribname = id.mapID(i)
                    returnType = attrType.op(types.RET)
                    inType = attrType.op(types.IN)
                    attributes.append(returnType + " " + attribname + "()")
                    # need a set method if not a readonly attribute
                    if not c.readonly():
                        declarations.out (template.operation_decl_code,
                                return_type = "void",
                                opname = attribname,
                                arg_defs = inType + " _" + attribname)

                        tmpVar, conv = self.argConversion ("_" + attribname, attrType, True, False, c)
                        implementations.out (template.operation_impl_code,
                                return_type = "void",
                                impl_tpl_name = impl_tpl_name,
                                opname = attribname,
                                hpp_opname = hpp_opname if hpp_opname else attribname,
                                arg_defs = inType + " _" + attribname,
                                conversions = conv if conv else "",
                                store_return = "",
                                do_return = "",
                                arg_calls = tmpVar)

                    declarations.out (template.operation_decl_code,
                            return_type = returnType,
                            opname = attribname,
                            arg_defs = "")

                    store_return, do_return = self.retConversion (attrType)
                    implementations.out (template.operation_impl_code,
                            return_type = returnType,
                            impl_tpl_name = impl_tpl_name,
                            opname = attribname,
                            hpp_opname = hpp_opname if hpp_opname else attribname,
                            arg_defs = "",
                            conversions = "",
                            store_return = store_return,
                            do_return = do_return,
                            arg_calls = "")
            elif isinstance(c, idlast.Operation):
                params = []
                paramNames = []
                conversions = []
                for p in c.parameters():
                    paramType = types.Type(p.paramType())
                    cxx_type = paramType.op(types.direction(p), use_out = 0)
                    
                    argname = id.mapID(p.identifier())
                    if not comments_impl:
                        tmpVar, conv = self.argConversion (argname, paramType, p.is_in(), p.is_out(), p)
                        if conv:
                            conversions.append(conv)
                    else:
                        tmpVar = argname

                    params.append(cxx_type + " " + argname)
                    paramNames.append(tmpVar)


                # deal with possible "context"
                if c.contexts() != []:
                    params.append("CORBA::Context_ptr _ctxt")

                store_return, do_return = self.retConversion (types.Type(c.returnType()))
                return_type = types.Type(c.returnType()).op(types.RET)

                opname = id.mapID(c.identifier())
                arguments = ", ".join(params)
                argumentsCall = ", ".join(paramNames)
                args = opname + "(" + arguments + ")"

                declarations.out (template.operation_decl_code,
                        return_type = return_type,
                        opname = opname,
                        arg_defs = arguments)

                if comments_impl:
                    implementations.out (template.provided_operation_impl_code,
                            return_type = return_type,
                            impl_tpl_name = impl_tpl_name,
                            opname = opname,
                            implementation = "".join(comments_impl),
                            arg_defs = arguments,)
                elif opname in template.predefined_operations_impl_code:
                    #assert not c.parameters(), "Interface operation str should not have arguments"
                    implementations.out (template.predefined_operations_impl_code[opname],
                            return_type = return_type,
                            impl_tpl_name = impl_tpl_name,
                            opname = opname,
                            conversions = "\n  ".join(conversions),
                            arg_defs = arguments,
                            store_return = store_return,
                            do_return = do_return,
                            arg_calls = argumentsCall)
                else:
                    implementations.out (template.operation_impl_code,
                            return_type = return_type,
                            impl_tpl_name = impl_tpl_name,
                            opname = opname,
                            hpp_opname = hpp_opname if hpp_opname is not None else opname,
                            conversions = "\n  ".join(conversions),
                            arg_defs = arguments,
                            store_return = store_return,
                            do_return = do_return,
                            arg_calls = argumentsCall)

            else:
                util.fatalError("Internal error generating interface member")
                raise AssertionError("No code for interface member: "+repr(c))

        openns, closens = namespaces(scopedName, self.environment)

        # Output the _i class definition definition
        self.interface_declarations.out(
                template.base_interface_def if is_base_class else template.inherited_interface_def,
                fq_name = fqname,
                impl_tpl_name = impl_tpl_name,
                impl_base_name = impl_base_name,
                operations = str(declarations),
                impl_name = impl_name,
                fq_POA_name = "POA_" + cxx_fqname,

                hpp_class = hpp_class,
                storage = storage,
                open_namespaces = openns,
                close_namespaces = closens,
                )

        self.interface_implementations.out(
                template.base_interface_code if is_base_class else template.inherited_interface_code,
                fqname = fqname,
                impl_name = impl_name,
                impl_tpl_name = impl_tpl_name,
                impl_base_name = impl_base_name,
                hpp_class = hpp_class,
                operations = str(implementations),
                open_namespaces = openns,
                close_namespaces = closens,
                )
Example #14
0
	def visitInterface(self, node):
		self.__allInterfaces.append(node)
	
		scopedName = id.Name(node.scopedName())
		
		cxx_fqname = scopedName.fullyQualify()
		impl_flat_name = impl_fullname(scopedName)

		fqname = scopedName.fullyQualify(cxx = 0)

		
		# build methods corresponding to attributes, operations etc.
		# attributes[] and operations[] will contain lists of function
		# signatures eg
		#   [ char *echoString(const char *mesg) ]
		attributes = []
		operations = []
		virtual_operations = []

		# we need to consider all callables, including inherited ones
		# since this implementation class is not inheriting from anywhere
		# other than the IDL skeleton
		allInterfaces = [node] + ast.allInherits(node)
		allCallables = util.fold( map(lambda x:x.callables(), allInterfaces),
								  [], lambda x, y: x + y )


		# declarations[] contains a list of in-class decl signatures
		# implementations[] contains a list of out of line impl signatures
		# (typically differ by classname::)
		declarations = []
		implementations = []
		
		for c in allCallables:

			if isinstance(c, idlast.Attribute) :
				attrType = types.Type(c.attrType())
				d_attrType = attrType.deref()

				for i in c.identifiers():
					attribname = id.mapID(i)
					returnType = attrType.op(types.RET)
					inType = attrType.op(types.IN)
					attributes.append(returnType + " " + attribname + "()")
					# need a set method if not a readonly attribute
					if not c.readonly():
						args = attribname + "(" + inType + ")"
						declarations.append("void " + args)
						implementations.append("void " + impl_flat_name +\
											   "::" + args)
					if not attribname in self.ignore_operations:
						declarations.append(returnType + " " + attribname + "()")
						implementations.append(returnType + " " + impl_flat_name+\
										   "::" + attribname + "()")
			elif isinstance(c, idlast.Operation):
				params = []
				for p in c.parameters():
					paramType = types.Type(p.paramType())
					cxx_type = paramType.op(types.direction(p), use_out = 0)
					
					argname = id.mapID(p.identifier())
					params.append(cxx_type + " " + argname)

				# deal with possible "context"
				if c.contexts() != []:
					params.append("CORBA::Context_ptr _ctxt")

				return_type = types.Type(c.returnType()).op(types.RET)

				opname = id.mapID(c.identifier())
				if not opname in self.ignore_operations:
					arguments = string.join(params, ", ")
					args = opname + "(" + arguments + ")"
					declarations.append(return_type + " " + args)
					implementations.append(return_type + " " + \
										   impl_flat_name + \
										   "::" + args)
			else:
				util.fatalError("Internal error generating interface member")
				raise "No code for interface member: " + repr(c)

		# the class definition has no actual code...
		defs = string.join(map(lambda x:x + ";\n", declarations), "")

		# Output the class definition of the implementation
		self.stream_h.out(interface_def,
						  impl_fqname = impl_flat_name,
						  impl_name = impl_flat_name,
						  fq_name = fqname,
						  fq_POA_name = "POA_" + cxx_fqname,
						  operations = defs)

		# Output the class methods implementations
		impls = string.join(map(lambda x: x + """\

{
  // Please insert your code here and remove the following warning pragma
#ifndef WIN32
  #warning "Code missing in function <""" + x + """>"
#endif
}

""",
								implementations), "")
		
		self.stream_cpp.out(interface_code,
							fqname = fqname,
							impl_name = impl_flat_name,
							impl_fqname = impl_flat_name,
							operations = impls)