-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdebug.go
More file actions
86 lines (82 loc) · 2.2 KB
/
Copy pathdebug.go
File metadata and controls
86 lines (82 loc) · 2.2 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
)
func printNodes(funcs []*Function) {
for i, f := range funcs {
fmt.Println("")
fmt.Println("[Function]", i, f.name)
for i, s := range f.stmts {
fmt.Println("")
fmt.Println("[Statements]", i)
printNode(s, 0)
}
fmt.Println("========================")
}
}
func printNode(node interface{}, dep int) {
if node == nil {
fmt.Printf("dep: %d, nil\n", dep)
return
}
switch n := node.(type) {
// Expressions.
case *StringLit:
fmt.Printf("dep: %d, node: %#v, \n type: %#v \n", dep, n, n.ty)
case *IntLit:
fmt.Printf("dep: %d, node: %#v, \n type: %#v \n", dep, n, n.ty)
case *Addr:
fmt.Printf("dep: %d, node: %#v, \n type: %#v \n", dep, n, n.ty)
printNode(n.child, dep+1)
case *Deref:
fmt.Printf("dep: %d, node: %#v, \n type: %#v \n", dep, n, n.ty)
printNode(n.child, dep+1)
case *Binary:
fmt.Printf("dep: %d, node: %#v, \n type: %#v \n", dep, n, n.ty)
printNode(n.lhs, dep+1)
printNode(n.rhs, dep+1)
case *Var:
fmt.Printf("dep: %d, node: %#v, \n type: %#v \n", dep, n, n.ty)
case *ArrayRef:
fmt.Printf("dep: %d, node: %#v, \n type: %#v \n", dep, n, n.ty)
printNode(n.lhs, dep+1)
printNode(n.rhs, dep+1)
case *FuncCall:
fmt.Printf("dep: %d, node: %#v, \n type: %#v \n", dep, n, n.ty)
for _, arg := range n.args {
printNode(arg, dep+1)
}
// Statements.
case *Empty:
fmt.Printf("dep: %d, node: %#v\n", dep, n)
case *ExprStmt:
fmt.Printf("dep: %d, node: %#v\n", dep, n)
printNode(n.child, dep+1)
case *Return:
fmt.Printf("dep: %d, node: %#v\n", dep, n)
printNode(n.child, dep+1)
case *Block:
fmt.Printf("dep: %d, node: %#v\n", dep, n)
for _, c := range n.children {
printNode(c, dep+1)
}
case *Assign:
fmt.Printf("dep: %d, node: %#v\n", dep, n)
for i := range n.lvals {
printNode(n.lvals[i], dep+1)
printNode(n.rvals[i], dep+1)
}
case *If:
fmt.Printf("dep: %d, node: %#v\n", dep, n)
printNode(n.init, dep+1)
printNode(n.cond, dep+1)
printNode(n.then, dep+1)
printNode(n.els, dep+1)
case *For:
fmt.Printf("dep: %d, node: %#v\n", dep, n)
printNode(n.init, dep+1)
printNode(n.cond, dep+1)
printNode(n.post, dep+1)
printNode(n.then, dep+1)
}
}