def reduce_NodeName_LPAREN_OptFuncArgList_RPAREN(self, *kids): module = kids[0].val.module func_name = kids[0].val.name name = func_name if not module else (module, func_name) last_named_seen = None args = [] kwargs = {} for argname, argname_ctx, arg in kids[2].val: if argname is not None: if argname in kwargs: raise EdgeQLSyntaxError( f"duplicate named argument `{argname}`", context=argname_ctx) last_named_seen = argname kwargs[argname] = arg else: if last_named_seen is not None: raise EdgeQLSyntaxError( f"positional argument after named " f"argument `{last_named_seen}`", context=arg.context) args.append(arg) self.val = qlast.FunctionCall(func=name, args=args, kwargs=kwargs)
def visit_FunctionCall(self, node): args = node.args args = [qlast.FuncArg(arg=arg) for arg in self.visit(args)] result = qlast.FunctionCall( func=(node.func_shortname.module, node.func_shortname.name), args=args, ) return result
def visit_FunctionCall(self, node): # FIXME: this is a temporary solution to bridge the gap to EdgeQL if node.agg_set_modifier == qlast.AggDISTINCT: args = qlast.UnaryOp(op=qlast.DISTINCT, operand=node.args[0]) else: args = node.args # FIXME: hack to reconstruct args for a trivial aggregate function args = [qlast.FuncArg(arg=arg) for arg in self.visit(args)] if node.agg_filter or node.agg_sort: args[0].sort = node.agg_sort args[0].filter = (self.visit(node.agg_filter) if node.agg_filter is not None else None) result = qlast.FunctionCall( func=(node.func.shortname.module, node.func.shortname.name), args=args, ) return result
def reduce_NodeName_LPAREN_OptFuncArgList_RPAREN(self, *kids): module = kids[0].val.module func_name = kids[0].val.name name = func_name if not module else (module, func_name) self.val = qlast.FunctionCall(func=name, args=kids[2].val)
def compile_func_to_ir(func, schema, *, anchors=None, security_context=None, modaliases=None, implicit_id_in_shapes=False): """Compile an EdgeQL function into EdgeDB IR.""" if debug.flags.edgeql_compile: debug.header('EdgeQL Function') debug.print(func.get_code(schema)) trees = ql_parser.parse_block(func.get_code(schema) + ';') if len(trees) != 1: raise errors.InvalidFunctionDefinitionError( 'functions can only contain one statement') tree = trees[0] if modaliases: ql_parser.append_module_aliases(tree, modaliases) if anchors is None: anchors = {} anchors['__defaults_mask__'] = irast.Parameter( name='__defaults_mask__', stype=schema.get('std::bytes')) func_params = func.get_params(schema) pg_params = s_func.PgParams.from_params(schema, func_params) for pi, p in enumerate(pg_params.params): p_shortname = p.get_shortname(schema) anchors[p_shortname] = irast.Parameter(name=p_shortname, stype=p.get_type(schema)) if p.get_default(schema) is None: continue tree.aliases.append( qlast.AliasedExpr( alias=p_shortname, expr=qlast. IfElse(condition=qlast.BinOp(left=qlast.FunctionCall( func=('std', 'bytes_get_bit'), args=[ qlast.FuncArg(arg=qlast.Path( steps=[qlast.ObjectRef( name='__defaults_mask__')])), qlast.FuncArg(arg=qlast.IntegerConstant(value=str(pi))) ]), right=qlast.IntegerConstant( value='0'), op='='), if_expr=qlast.Path( steps=[qlast.ObjectRef(name=p_shortname)]), else_expr=qlast._Optional( expr=p.get_ql_default(schema))))) ir = compile_ast_to_ir(tree, schema, anchors=anchors, func=func, security_context=security_context, modaliases=modaliases, implicit_id_in_shapes=implicit_id_in_shapes) return ir