-
Notifications
You must be signed in to change notification settings - Fork 10
/
indexexp.go
52 lines (45 loc) · 1.23 KB
/
indexexp.go
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
48
49
50
51
52
package ast
// An IndexExp is an expression node representing indexing, i.e. "Coll[Index]".
type IndexExp struct {
Location
Coll ExpNode
Idx ExpNode
}
var _ Var = IndexExp{}
// NewIndexExp returns an IndexExp instance for the given collection and index.
func NewIndexExp(coll ExpNode, idx ExpNode) IndexExp {
return IndexExp{
Location: MergeLocations(coll, idx), // TODO: use the "]" for locaion end
Coll: coll,
Idx: idx,
}
}
// ProcessExp uses the given ExpProcessor to process the receiver.
func (e IndexExp) ProcessExp(p ExpProcessor) {
p.ProcessIndexExp(e)
}
// ProcessVar uses the given VarProcessor to process the receiver.
func (e IndexExp) ProcessVar(p VarProcessor) {
p.ProcessIndexExpVar(e)
}
// FunctionName returns the function name associated with this expression (i.e.
// if it is part of a function definition statement), or an empty string if
// there is no sensible name.
func (e IndexExp) FunctionName() string {
if s, ok := e.Idx.(String); ok {
return string(s.Val)
}
return ""
}
// HWrite prints a tree representation of the node.
func (e IndexExp) HWrite(w HWriter) {
w.Writef("idx")
w.Indent()
w.Next()
w.Writef("coll: ")
e.Coll.HWrite(w)
w.Next()
w.Writef("at: ")
e.Idx.HWrite(w)
w.Dedent()
}