blob: be48f89d46fca326857511ae65d1625362d30335 (
plain)
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
|
package ast
import (
"fmt"
)
type Conditional struct {
CondExpr Node
TrueExpr Node
FalseExpr Node
Posx Pos
}
// Accept passes the given visitor to the child nodes in this order:
// CondExpr, TrueExpr, FalseExpr. It then finally passes itself to the visitor.
func (n *Conditional) Accept(v Visitor) Node {
n.CondExpr = n.CondExpr.Accept(v)
n.TrueExpr = n.TrueExpr.Accept(v)
n.FalseExpr = n.FalseExpr.Accept(v)
return v(n)
}
func (n *Conditional) Pos() Pos {
return n.Posx
}
func (n *Conditional) Type(Scope) (Type, error) {
// This is not actually a useful value; the type checker ignores
// this function when analyzing conditionals, just as with Arithmetic.
return TypeInt, nil
}
func (n *Conditional) GoString() string {
return fmt.Sprintf("*%#v", *n)
}
|