NewFunction creates a new function declaration with a set of function options to configure overloads and function definitions (implementations). Functions are checked for name collisions and singleton redefinition.
(name string, opts ...FunctionOpt)
| 34 | // |
| 35 | // Functions are checked for name collisions and singleton redefinition. |
| 36 | func NewFunction(name string, opts ...FunctionOpt) (*FunctionDecl, error) { |
| 37 | fn := &FunctionDecl{ |
| 38 | name: name, |
| 39 | overloads: map[string]*OverloadDecl{}, |
| 40 | overloadOrdinals: []string{}, |
| 41 | } |
| 42 | var err error |
| 43 | for _, opt := range opts { |
| 44 | fn, err = opt(fn) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | } |
| 49 | if len(fn.overloads) == 0 { |
| 50 | return nil, fmt.Errorf("function %s must have at least one overload", name) |
| 51 | } |
| 52 | return fn, nil |
| 53 | } |
| 54 | |
| 55 | // FunctionDecl defines a function name, overload set, and optionally a singleton definition for all |
| 56 | // overload instances. |
no outgoing calls