summaryrefslogtreecommitdiff
path: root/vendor/github.com/hashicorp/hil/ast/call.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/hil/ast/call.go')
-rw-r--r--vendor/github.com/hashicorp/hil/ast/call.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hil/ast/call.go b/vendor/github.com/hashicorp/hil/ast/call.go
new file mode 100644
index 00000000..05570110
--- /dev/null
+++ b/vendor/github.com/hashicorp/hil/ast/call.go
@@ -0,0 +1,47 @@
+package ast
+
+import (
+ "fmt"
+ "strings"
+)
+
+// Call represents a function call.
+type Call struct {
+ Func string
+ Args []Node
+ Posx Pos
+}
+
+func (n *Call) Accept(v Visitor) Node {
+ for i, a := range n.Args {
+ n.Args[i] = a.Accept(v)
+ }
+
+ return v(n)
+}
+
+func (n *Call) Pos() Pos {
+ return n.Posx
+}
+
+func (n *Call) String() string {
+ args := make([]string, len(n.Args))
+ for i, arg := range n.Args {
+ args[i] = fmt.Sprintf("%s", arg)
+ }
+
+ return fmt.Sprintf("Call(%s, %s)", n.Func, strings.Join(args, ", "))
+}
+
+func (n *Call) Type(s Scope) (Type, error) {
+ f, ok := s.LookupFunc(n.Func)
+ if !ok {
+ return TypeInvalid, fmt.Errorf("unknown function: %s", n.Func)
+ }
+
+ return f.ReturnType, nil
+}
+
+func (n *Call) GoString() string {
+ return fmt.Sprintf("*%#v", *n)
+}