2015-01-11 21:38:45 +01:00
|
|
|
package ast
|
|
|
|
|
2015-01-11 22:03:37 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2015-01-11 21:38:45 +01:00
|
|
|
// VariableAccess represents a variable access.
|
|
|
|
type VariableAccess struct {
|
|
|
|
Name string
|
2015-01-12 09:28:47 +01:00
|
|
|
Posx Pos
|
2015-01-11 21:38:45 +01:00
|
|
|
}
|
2015-01-11 22:03:37 +01:00
|
|
|
|
2015-01-15 01:36:01 +01:00
|
|
|
func (n *VariableAccess) Accept(v Visitor) Node {
|
|
|
|
return v(n)
|
2015-01-12 00:26:54 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 09:28:47 +01:00
|
|
|
func (n *VariableAccess) Pos() Pos {
|
|
|
|
return n.Posx
|
|
|
|
}
|
|
|
|
|
2015-01-11 22:03:37 +01:00
|
|
|
func (n *VariableAccess) GoString() string {
|
|
|
|
return fmt.Sprintf("*%#v", *n)
|
|
|
|
}
|
2015-01-13 17:50:28 +01:00
|
|
|
|
|
|
|
func (n *VariableAccess) String() string {
|
|
|
|
return fmt.Sprintf("Variable(%s)", n.Name)
|
|
|
|
}
|
2015-01-15 05:13:35 +01:00
|
|
|
|
|
|
|
func (n *VariableAccess) Type(s Scope) (Type, error) {
|
|
|
|
v, ok := s.LookupVar(n.Name)
|
|
|
|
if !ok {
|
|
|
|
return TypeInvalid, fmt.Errorf("unknown variable: %s", n.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return v.Type, nil
|
|
|
|
}
|