Esempio n. 1
0
 def VisitFunctionDefInstantiation(self, o, **kwargs):
     new = ast.FunctionDefInstantiation(function_def=o.function_def,
                                        parameters=o.parameters.copy())
     return copy_std(
         o,
         new,
     )
Esempio n. 2
0
    def VisitFunctionDefInstantiation(self, o, **kwargs):

        # Clone the defintion:
        newDef = self.visit(o.function_def)

        params = {}
        for (pName,pObj) in o.parameters.iteritems():
            p = ast.FunctionDefParameterInstantiation(rhs_ast=self.visit(pObj.rhs_ast), symbol=pObj.symbol )
            p.set_function_def_parameter(newDef.parameters[pName]  )
            params[pName] = p
            self.func_param_map[pObj] = p

        return ast.FunctionDefInstantiation(parameters=params, function_def=newDef)
Esempio n. 3
0
    def create_function_call(self, funcname, parameters):

        # BuiltInFunctions have __XX__
        # Load it if not already exisitng:
        if funcname[0:2] == '__' and not funcname in self.builddata.funcdefs:
            self.builddata.funcdefs[funcname] = StdFuncs.get_builtin_function(
                funcname, backend=self.library_manager.backend)

        # Allow fully qulaified names that are not explicity imported
        if '.' in funcname and not funcname in self.builddata.funcdefs:
            mod = '.'.join(funcname.split('.')[:-1])
            self.do_import(mod, tokens=[
                (funcname.split('.')[-1], funcname),
            ])

        assert funcname in self.builddata.funcdefs, ('Function not defined:' +
                                                     funcname)
        func_def = self.builddata.funcdefs[funcname]

        # Single Parameter functions do not need to be
        # identified by name:
        if len(parameters) == 1:
            kFuncDef = list(func_def.parameters.keys())[0]
            kFuncCall = list(parameters.keys())[0]

            # Not called by name, remap to name:
            assert kFuncDef is not None
            if kFuncCall is None:
                parameters[kFuncDef] = parameters[kFuncCall]
                parameters[kFuncDef].symbol = parameters[kFuncDef].symbol
                del parameters[None]
            else:
                assert kFuncDef == kFuncCall

        # Check the parameters tally:
        assert len(parameters) == len(func_def.parameters)
        for p in parameters:
            assert p in func_def.parameters, "Can't find %s in %s" % (
                p, func_def.parameters)
            # Connect the call parameter to the definition:
            parameters[p].symbol = p
            parameters[p].set_function_def_parameter(func_def.parameters[p])

        # Create the functions
        return ast.FunctionDefInstantiation(parameters=parameters,
                                            function_def=func_def)
Esempio n. 4
0
    def VisitFunctionDefInstantiation(self, o):

        if o.function_def.is_builtin():

            params_new = {}
            # Clone the parameter objects:
            for param_name, func_call_param in o.parameters.items():
                pnew = ast.FunctionDefParameterInstantiation(
                    rhs_ast=self.visit(func_call_param.rhs_ast),
                    symbol=func_call_param.symbol,
                    function_def_parameter=func_call_param.
                    _function_def_parameter)
                params_new[param_name] = pnew

            return ast.FunctionDefInstantiation(function_def=o.function_def,
                                                parameters=params_new)

        print 'Function call:', repr(o)
        assert False, 'We shoudl not get here! we are doing depth first search'