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

Method semMapCall

compiler/semantic/expr.go:889–920  ·  view source on GitHub ↗
(call *ast.CallExpr, args []sem.Expr, argTypes []super.Type)

Source from the content-addressed store, hash-verified

887}
888
889func (t *translator) semMapCall(call *ast.CallExpr, args []sem.Expr, argTypes []super.Type) (sem.Expr, super.Type) {
890 if len(args) != 2 {
891 t.error(call, errors.New("map requires two arguments"))
892 return badExpr, t.checker.unknown
893 }
894 ref, ok := args[1].(*sem.FuncRef)
895 if !ok {
896 t.error(call, errors.New("second argument to map must be a function"))
897 return badExpr, t.checker.unknown
898 }
899 elemType, ok := t.checker.hasArray(argTypes[0])
900 if !ok {
901 t.error(call, errors.New("map expression must be an array"))
902 return badExpr, t.checker.unknown
903 }
904 mapArgs := []sem.Expr{sem.NewThis(call.Args[1], nil)}
905 mapTypes := []super.Type{elemType}
906 t.checker.pushErrs()
907 e, typ := t.resolver.resolveCall(call.Args[1], ref.ID, mapArgs, mapTypes)
908 errs := t.checker.popErrs()
909 for _, err := range errs {
910 t.error(err.loc, fmt.Errorf("in functon called from map: %w", err.err))
911 }
912 if callExpr, ok := e.(*sem.CallExpr); ok {
913 return &sem.MapCallExpr{
914 Node: call,
915 Expr: args[0],
916 Lambda: callExpr,
917 }, t.sctx.LookupTypeArray(typ)
918 }
919 return e, t.sctx.LookupTypeArray(typ)
920}
921
922func (t *translator) semExtractExpr(e, partExpr, argExpr ast.Expr, inType super.Type) (sem.Expr, super.Type) {
923 var partstr string

Callers 1

semCallByNameMethod · 0.95

Calls 8

NewThisFunction · 0.92
NewMethod · 0.80
hasArrayMethod · 0.80
pushErrsMethod · 0.80
resolveCallMethod · 0.80
popErrsMethod · 0.80
LookupTypeArrayMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected