def get_params_symtable( params: FuncParameterList, schema: s_schema.Schema, *, inlined_defaults: bool, ) -> Dict[str, qlast.Expr]: anchors: Dict[str, qlast.Expr] = {} defaults_mask = qlast.TypeCast( expr=qlast.Parameter(name='__defaults_mask__', optional=False), type=qlast.TypeName( maintype=qlast.ObjectRef( module='std', name='bytes', ), ), ) for pi, p in enumerate(params.get_in_canonical_order(schema)): p_shortname = p.get_parameter_name(schema) p_is_optional = p.get_typemod(schema) is not ft.TypeModifier.SINGLETON anchors[p_shortname] = qlast.TypeCast( expr=qlast.Parameter( name=p_shortname, optional=p_is_optional, ), type=utils.typeref_to_ast(schema, p.get_type(schema)), ) p_default = p.get_default(schema) if p_default is None: continue if not inlined_defaults: continue anchors[p_shortname] = qlast.IfElse( condition=qlast.BinOp( left=qlast.FunctionCall( func=('std', 'bytes_get_bit'), args=[ defaults_mask, qlast.IntegerConstant(value=str(pi)), ]), op='=', right=qlast.IntegerConstant(value='0'), ), if_expr=anchors[p_shortname], else_expr=qlast._Optional(expr=p_default.qlast), ) return anchors
def visit_Variable(self, node): varname = node.name.value var = self._context.vars[varname] vartype = var.defn.type if isinstance(vartype, gql_ast.NonNullType): # TODO: Add non-null validation to the produced EdgeQL? vartype = vartype.type casttype = qlast.TypeName(maintype=qlast.ObjectRef( name=gt.GQL_TO_EDB_SCALARS_MAP[vartype.name.value])) # potentially this is an array if self.is_list_type(vartype): casttype = qlast.TypeName(maintype=qlast.ObjectRef(name='array'), subtypes=[casttype]) return qlast.TypeCast(type=casttype, expr=qlast.Parameter(name=varname))
def reduce_ARGUMENT(self, *kids): self.val = qlast.Parameter(name=kids[0].val[1:], optional=False)
def reduce_DOLLAR_AnyIdentifier(self, *kids): self.val = qlast.Parameter(name=kids[1].val)
def reduce_DOLLAR_ICONST(self, *kids): self.val = qlast.Parameter(name=str(kids[1].val))
def visit_Parameter(self, node): return qlast.Parameter(name=node.name)