MCPcopy
hub / github.com/google/mangle / typeOfFn

Function typeOfFn

analysis/validation.go:1561–1601  ·  view source on GitHub ↗
(x ast.ApplyFn, varRanges map[ast.Variable]ast.BaseTerm, nameTrie symbols.NameTrie)

Source from the content-addressed store, hash-verified

1559}
1560
1561func typeOfFn(x ast.ApplyFn, varRanges map[ast.Variable]ast.BaseTerm, nameTrie symbols.NameTrie) ast.BaseTerm {
1562 switch x.Function.Symbol {
1563 case symbols.Max.Symbol:
1564 fallthrough
1565 case symbols.Min.Symbol:
1566 fallthrough
1567 case symbols.Count.Symbol:
1568 fallthrough
1569 case symbols.Div.Symbol:
1570 fallthrough
1571 case symbols.FloatDiv.Symbol:
1572 fallthrough
1573 case symbols.Sum.Symbol:
1574 fallthrough
1575 case symbols.Plus.Symbol:
1576 fallthrough
1577 case symbols.Minus.Symbol:
1578 fallthrough
1579 case symbols.Mult.Symbol:
1580 return ast.NumberBound
1581 case symbols.Collect.Symbol:
1582 fallthrough
1583 case symbols.CollectDistinct.Symbol:
1584 if len(x.Args) == 1 {
1585 if v, ok := x.Args[0].(ast.Variable); ok {
1586 return ast.ApplyFn{symbols.ListType, []ast.BaseTerm{varRanges[v]}}
1587 }
1588 }
1589 elemTpe := boundOfArg(x.Args[0], varRanges, nameTrie)
1590 return ast.ApplyFn{symbols.ListType, []ast.BaseTerm{elemTpe}}
1591 }
1592 fnTpe, ok := builtin.GetBuiltinFunctionType(x.Function)
1593 if !ok {
1594 return ast.AnyBound // TODO: return error
1595 }
1596 res, err := checkFunApply(x, fnTpe, varRanges, nameTrie)
1597 if err != nil {
1598 return ast.AnyBound
1599 }
1600 return res
1601}

Callers 1

Calls 3

GetBuiltinFunctionTypeFunction · 0.92
boundOfArgFunction · 0.85
checkFunApplyFunction · 0.85

Tested by

no test coverage detected