diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hil/ast/arithmetic.go')
-rw-r--r-- | vendor/github.com/hashicorp/hil/ast/arithmetic.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hil/ast/arithmetic.go b/vendor/github.com/hashicorp/hil/ast/arithmetic.go new file mode 100644 index 0000000..94dc24f --- /dev/null +++ b/vendor/github.com/hashicorp/hil/ast/arithmetic.go | |||
@@ -0,0 +1,43 @@ | |||
1 | package ast | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "fmt" | ||
6 | ) | ||
7 | |||
8 | // Arithmetic represents a node where the result is arithmetic of | ||
9 | // two or more operands in the order given. | ||
10 | type Arithmetic struct { | ||
11 | Op ArithmeticOp | ||
12 | Exprs []Node | ||
13 | Posx Pos | ||
14 | } | ||
15 | |||
16 | func (n *Arithmetic) Accept(v Visitor) Node { | ||
17 | for i, expr := range n.Exprs { | ||
18 | n.Exprs[i] = expr.Accept(v) | ||
19 | } | ||
20 | |||
21 | return v(n) | ||
22 | } | ||
23 | |||
24 | func (n *Arithmetic) Pos() Pos { | ||
25 | return n.Posx | ||
26 | } | ||
27 | |||
28 | func (n *Arithmetic) GoString() string { | ||
29 | return fmt.Sprintf("*%#v", *n) | ||
30 | } | ||
31 | |||
32 | func (n *Arithmetic) String() string { | ||
33 | var b bytes.Buffer | ||
34 | for _, expr := range n.Exprs { | ||
35 | b.WriteString(fmt.Sprintf("%s", expr)) | ||
36 | } | ||
37 | |||
38 | return b.String() | ||
39 | } | ||
40 | |||
41 | func (n *Arithmetic) Type(Scope) (Type, error) { | ||
42 | return TypeInt, nil | ||
43 | } | ||