-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathastloop.go
69 lines (54 loc) · 1.14 KB
/
astloop.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package template
import "io"
type astLoop struct {
expr1, expr2, expr3, body iAstNode
}
func (n *astLoop) GetImports() []string {
res := []string{}
if n.expr1 != nil {
res = append(res, n.expr1.GetImports()...)
}
if n.expr2 != nil {
res = append(res, n.expr2.GetImports()...)
}
if n.expr3 != nil {
res = append(res, n.expr3.GetImports()...)
}
if n.body != nil {
res = append(res, n.body.GetImports()...)
}
return res
}
func (n *astLoop) GetStrings() []string {
res := []string{}
if n.expr1 != nil {
res = append(res, n.expr1.GetStrings()...)
}
if n.expr2 != nil {
res = append(res, n.expr2.GetStrings()...)
}
if n.expr3 != nil {
res = append(res, n.expr3.GetStrings()...)
}
if n.body != nil {
res = append(res, n.body.GetStrings()...)
}
return res
}
func (n *astLoop) WriteGo(w io.Writer, opts *GenGoOpts) {
io.WriteString(w, "for ")
if n.expr1 != nil {
n.expr1.WriteGo(w, opts)
}
io.WriteString(w, ";")
if n.expr2 != nil {
n.expr2.WriteGo(w, opts)
}
io.WriteString(w, ";")
if n.expr3 != nil {
n.expr3.WriteGo(w, opts)
}
io.WriteString(w, "{\n")
n.body.WriteGo(w, opts)
io.WriteString(w, "}\n")
}