File: call.go

package info (click to toggle)
golang-github-hashicorp-hil 0.0~git20160711.1e86c6b-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 352 kB
  • sloc: yacc: 161; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 761 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)
}