]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | package ast |
2 | ||
3 | import ( | |
4 | "fmt" | |
5 | ) | |
6 | ||
7 | // VariableAccess represents a variable access. | |
8 | type VariableAccess struct { | |
9 | Name string | |
10 | Posx Pos | |
11 | } | |
12 | ||
13 | func (n *VariableAccess) Accept(v Visitor) Node { | |
14 | return v(n) | |
15 | } | |
16 | ||
17 | func (n *VariableAccess) Pos() Pos { | |
18 | return n.Posx | |
19 | } | |
20 | ||
21 | func (n *VariableAccess) GoString() string { | |
22 | return fmt.Sprintf("*%#v", *n) | |
23 | } | |
24 | ||
25 | func (n *VariableAccess) String() string { | |
26 | return fmt.Sprintf("Variable(%s)", n.Name) | |
27 | } | |
28 | ||
29 | func (n *VariableAccess) Type(s Scope) (Type, error) { | |
30 | v, ok := s.LookupVar(n.Name) | |
31 | if !ok { | |
32 | return TypeInvalid, fmt.Errorf("unknown variable: %s", n.Name) | |
33 | } | |
34 | ||
35 | return v.Type, nil | |
36 | } |