MCPcopy Create free account
hub / github.com/brimdata/super / mustResolveCall

Method mustResolveCall

compiler/semantic/resolver.go:74–117  ·  view source on GitHub ↗
(n ast.Node, id string, args []sem.Expr, argTypes []super.Type)

Source from the content-addressed store, hash-verified

72}
73
74func (r *resolver) mustResolveCall(n ast.Node, id string, args []sem.Expr, argTypes []super.Type) (sem.Expr, super.Type) {
75 d, ok := r.decls[id]
76 if !ok {
77 panic(id)
78 }
79 // Translate the decl ID to a func by converting any
80 // function refs passed as args to a key into the variants table removing
81 // correponding args.
82 var params []string
83 var exprs []sem.Expr
84 declParams := d.lambda.Params
85 if len(declParams) != len(args) {
86 r.t.error(n, fmt.Errorf("%q: expected %d params but called with %d", d.name, len(declParams), len(args)))
87 return badExpr, r.t.checker.unknown
88 }
89 var lambdas []lambda
90 var fields []super.Field
91 for k, arg := range args {
92 if f, ok := arg.(*sem.FuncRef); ok {
93 lambdas = append(lambdas, lambda{param: declParams[k].Name, pos: k, id: f.ID})
94 continue
95 }
96 params = append(params, declParams[k].Name)
97 exprs = append(exprs, arg)
98 fields = append(fields, super.NewField(declParams[k].Name, argTypes[k]))
99 }
100 argType := r.t.sctx.MustLookupTypeRecord(fields)
101 if len(declParams) == len(params) {
102 // No need to specialize this call since no function args are being passed.
103 tag, typ := r.lookupFixed(id, argType)
104 return &sem.CallExpr{
105 Node: n,
106 Tag: tag,
107 Args: args,
108 }, typ
109 }
110 // Enter the new function scope and set up the bindings for the
111 // values we retrieved above while evaluating args in the outer scope.
112 return &sem.CallExpr{
113 Node: n,
114 Tag: r.getVariant(id, params, lambdas, argType).tag,
115 Args: exprs,
116 }, r.t.checker.unknown
117}
118
119func (r *resolver) resolveVariant(d *funcDecl, variant *funcDef, inType super.Type) {
120 save := r.t.scope

Callers 3

resolveCallMethod · 0.95
semCallLambdaMethod · 0.80
semCallByNameMethod · 0.80

Calls 5

lookupFixedMethod · 0.95
getVariantMethod · 0.95
NewFieldFunction · 0.92
MustLookupTypeRecordMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected