-
Notifications
You must be signed in to change notification settings - Fork 0
/
var.go
157 lines (129 loc) · 2.77 KB
/
var.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package model
import (
_ "fmt"
)
type Var struct {
typeName string
name string
comment string
initValue string
}
func NewVar() *Var {
return &Var{}
}
func (this *Var) GetTypeName() string {
return this.typeName
}
func (this *Var) GetName() string {
return this.name
}
func (this *Var) GetInitValue() string {
return this.initValue
}
func (this *Var) GetComment() string {
return this.comment
}
func (this *Var) SetTypeName(val string) {
this.typeName = val
}
func (this *Var) SetName(val string) {
this.name = val
}
func (this *Var) SetInitValue(val string) {
this.initValue = val
}
func (this *Var) SetComment(val string) {
this.comment = val
}
type StructFieldDefine Var
/*func (this *StructFieldDefine) Accept(visitor CodeVisitor) {
visitor.VisitStructFieldDefine(this)
}*/
type VarList struct {
vars []*Var
}
func NewVarList() *VarList {
return &VarList{}
}
func (this *VarList) AcceptAsFuncReturns(visitor CodeVisitor) {
if len(this.vars) <= 0 {
visitor.VisitFuncNoReturn()
return
}
visitor.VisitFuncReturnFirst(this.vars[0])
for _, v := range this.vars {
visitor.VisitFuncReturnNonFirst(v)
}
}
func (this *VarList) AcceptAsStructField(visitor CodeVisitor) {
if len(this.vars) <= 0 {
return
}
visitor.VisitStructFieldVarListBegin(this)
for _, v := range this.vars {
visitor.VisitStructFieldVar(v)
}
visitor.VisitStructFieldVarListEnd(this)
}
func (this *VarList) AcceptAsFuncParmList(visitor CodeVisitor) {
if len(this.vars) <= 0 {
return
}
visitor.VisitFuncParamVarFirst(this.vars[0])
if len(this.vars) == 1 {
return
}
visitor.VisitFuncParamVarNonFirstBegin()
for i := 1; i < len(this.vars); i++ {
visitor.VisitFuncParamVarNonFirst(this.vars[i])
}
visitor.VisitFuncParamVarNonFirstEnd()
}
func (this *VarList) AcceptAsMacroParmList(visitor CodeVisitor) {
if len(this.vars) <= 0 {
return
}
visitor.VisitMacroParamVarFirst(this.vars[0])
if len(this.vars) == 1 {
return
}
visitor.VisitMacroParamVarNonFirstBegin()
for i := 1; i < len(this.vars); i++ {
visitor.VisitMacroParamVarNonFirst(this.vars[i])
}
visitor.VisitMacroParamVarNonFirstEnd()
}
func (this *VarList) Append(val ...*Var) *VarList {
//fmt.Println("this =", this)
//fmt.Println("this.Vars =", this.Vars)
//fmt.Println("val =", val)
this.vars = append(this.vars, val...)
return this
}
func (this *VarList) GetMaxNameLen() int {
max := 0
for _, v := range this.vars {
if len(v.name) > max {
max = len(v.name)
}
}
return max
}
func (this *VarList) GetMaxTypeNameLen() int {
max := 0
for _, v := range this.vars {
if len(v.typeName) > max {
max = len(v.typeName)
}
}
return max
}
func (this *VarList) GetMaxValueLen() int {
max := 0
for _, v := range this.vars {
if len(v.initValue) > max {
max = len(v.initValue)
}
}
return max
}