-
Notifications
You must be signed in to change notification settings - Fork 9
/
parse_block_stmt.go
72 lines (68 loc) · 2.47 KB
/
parse_block_stmt.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
70
71
72
package main
import (
"go/ast"
"log"
)
func ParseDeclStmt(declStmt *ast.DeclStmt, objectTypeMap *ObjectTypeMap) []string {
var ret []string
if genDecl, ok := declStmt.Decl.(*ast.GenDecl); ok {
ret = append(ret, ParseGenDecl(genDecl, objectTypeMap)...)
} else {
log.Fatal("not implemented decl otherwise gendecl")
}
return ret
}
func ParseStmt(stmt *ast.Stmt, objectTypeMap *ObjectTypeMap) []string {
var ret []string
switch (*stmt).(type) {
case *ast.BadStmt:
log.Fatal("bad statement")
case *ast.DeclStmt:
ret = append(ret, ParseDeclStmt((*stmt).(*ast.DeclStmt), objectTypeMap)...)
case *ast.EmptyStmt:
// do nothing
case *ast.LabeledStmt:
ret = append(ret, ParseLabeledStmt((*stmt).(*ast.LabeledStmt), objectTypeMap)...)
case *ast.ExprStmt:
ret = append(ret, ParseExprStmt((*stmt).(*ast.ExprStmt))...)
case *ast.SendStmt:
case *ast.IncDecStmt:
ret = append(ret, ParseIncDecStmt((*stmt).(*ast.IncDecStmt))...)
case *ast.AssignStmt:
ret = append(ret, ParseAssignStmt((*stmt).(*ast.AssignStmt), objectTypeMap)...)
case *ast.GoStmt:
case *ast.DeferStmt:
ret = append(ret, ParseDeferStmt((*stmt).(*ast.DeferStmt), objectTypeMap)...)
case *ast.ReturnStmt:
ret = append(ret, ParseReturnStmt((*stmt).(*ast.ReturnStmt))...)
case *ast.BranchStmt:
ret = append(ret, ParseBranchStmt((*stmt).(*ast.BranchStmt))...)
case *ast.BlockStmt:
ret = append(ret, ParseBlockStmt((*stmt).(*ast.BlockStmt), objectTypeMap)...)
case *ast.IfStmt:
ret = append(ret, ParseIfStmt((*stmt).(*ast.IfStmt), objectTypeMap)...)
case *ast.CaseClause:
ret = append(ret, ParseCaseClause((*stmt).(*ast.CaseClause), objectTypeMap)...)
case *ast.SwitchStmt:
ret = append(ret, ParseSwitchStmt((*stmt).(*ast.SwitchStmt), objectTypeMap)...)
case *ast.TypeSwitchStmt:
ret = append(ret, ParseTypeSwitchStmt((*stmt).(*ast.TypeSwitchStmt), objectTypeMap)...)
case *ast.CommClause:
case *ast.SelectStmt:
ret = append(ret, ParseSelectStmt((*stmt).(*ast.SelectStmt), objectTypeMap)...)
case *ast.ForStmt:
ret = append(ret, ParseForStmt((*stmt).(*ast.ForStmt), objectTypeMap)...)
case *ast.RangeStmt:
ret = append(ret, ParseRangeStmt((*stmt).(*ast.RangeStmt), objectTypeMap)...)
}
return ret
}
func ParseBlockStmt(blockStmt *ast.BlockStmt, objectTypeMap *ObjectTypeMap) [] string {
var ret []string
//ret = append(ret, "{")
for _, stmt := range blockStmt.List {
ret = append(ret, ParseStmt(&stmt, objectTypeMap)...)
}
//ret = append(ret, "}")
return ret
}