@@ -37,37 +37,37 @@ func (a StructMemberSorter) Len() int { return len(a) }
37
37
func (a StructMemberSorter ) Swap (i , j int ) { a [i ], a [j ] = a [j ], a [i ] }
38
38
func (a StructMemberSorter ) Less (i , j int ) bool { return a [i ].Tag < a [j ].Tag }
39
39
40
- // StructInfo record struct information.
41
- type StructInfo struct {
40
+ // Struct record struct information.
41
+ type Struct struct {
42
42
Name string
43
43
OriginName string //original name
44
44
Mb []StructMember
45
45
DependModule map [string ]bool
46
46
DependModuleWithJce map [string ]string
47
47
}
48
48
49
- // ArgInfo record argument information.
50
- type ArgInfo struct {
49
+ // Arg record argument information.
50
+ type Arg struct {
51
51
Name string
52
52
OriginName string //original name
53
53
IsOut bool
54
54
Type * VarType
55
55
}
56
56
57
- // FunInfo record function information.
58
- type FunInfo struct {
57
+ // Func record function information.
58
+ type Func struct {
59
59
Name string // after the uppercase converted name
60
60
OriginName string // original name
61
61
HasRet bool
62
62
RetType * VarType
63
- Args []ArgInfo
63
+ Args []Arg
64
64
}
65
65
66
- // InterfaceInfo record interface information.
67
- type InterfaceInfo struct {
66
+ // Interface record interface information.
67
+ type Interface struct {
68
68
Name string
69
69
OriginName string // original name
70
- Fun [] FunInfo
70
+ Funcs [] Func
71
71
DependModule map [string ]bool
72
72
DependModuleWithJce map [string ]string
73
73
}
@@ -80,104 +80,112 @@ type EnumMember struct {
80
80
Name string //type 1
81
81
}
82
82
83
- // EnumInfo record EnumMember information include name.
84
- type EnumInfo struct {
83
+ // Enum record EnumMember information include name.
84
+ type Enum struct {
85
85
Module string
86
86
Name string
87
87
OriginName string // original name
88
88
Mb []EnumMember
89
89
}
90
90
91
- // ConstInfo record const information.
92
- type ConstInfo struct {
91
+ // Const record const information.
92
+ type Const struct {
93
93
Type * VarType
94
94
Name string
95
95
OriginName string // original name
96
96
Value string
97
97
}
98
98
99
- // HashKeyInfo record hash key information.
100
- type HashKeyInfo struct {
99
+ // HashKey record hash key information.
100
+ type HashKey struct {
101
101
Name string
102
102
Member []string
103
103
}
104
104
105
- type ModuleInfo struct {
105
+ type TarsFile struct {
106
106
Source string
107
107
// proto file name(not include .tars)
108
- ProtoName string
108
+ ProtoName string
109
+ Module Module
110
+
111
+ Include []string
112
+ // have parsed include file
113
+ IncTarsFile []* TarsFile
114
+ }
115
+
116
+ type Module struct {
109
117
Name string
110
118
OriginName string
111
- Include []string
112
119
113
- Struct []StructInfo
114
- HashKey []HashKeyInfo
115
- Enum []EnumInfo
116
- Const []ConstInfo
117
- Interface []InterfaceInfo
118
-
119
- // have parsed include file
120
- IncModule []* ModuleInfo
120
+ Struct []Struct
121
+ HashKey []HashKey
122
+ Enum []Enum
123
+ Const []Const
124
+ Interface []Interface
121
125
}
122
126
123
127
// Rename module
124
- func (p * ModuleInfo ) Rename (moduleUpper bool ) {
125
- p .OriginName = p .Name
128
+ func (m * Module ) Rename (moduleUpper bool ) {
129
+ m .OriginName = m .Name
126
130
if moduleUpper {
127
- p .Name = utils .UpperFirstLetter (p .Name )
131
+ m .Name = utils .UpperFirstLetter (m .Name )
128
132
}
129
133
}
130
134
135
+ func (tf * TarsFile ) Rename (moduleUpper bool ) {
136
+ tf .Module .Rename (moduleUpper )
137
+ }
138
+
131
139
// FindTNameType Looking for the true type of user-defined identifier
132
- func (p * ModuleInfo ) FindTNameType (tname string ) (token.Type , string , string ) {
133
- for _ , v := range p .Struct {
134
- if p . Name + "::" + v .Name == tname {
135
- return token .Struct , p . Name , p .ProtoName
140
+ func (tf * TarsFile ) FindTNameType (tName string ) (token.Type , string , string ) {
141
+ for _ , v := range tf . Module .Struct {
142
+ if tf . Module . Name + "::" + v .Name == tName {
143
+ return token .Struct , tf . Module . Name , tf .ProtoName
136
144
}
137
145
}
138
146
139
- for _ , v := range p .Enum {
140
- if p . Name + "::" + v .Name == tname {
141
- return token .Enum , p . Name , p .ProtoName
147
+ for _ , v := range tf . Module .Enum {
148
+ if tf . Module . Name + "::" + v .Name == tName {
149
+ return token .Enum , tf . Module . Name , tf .ProtoName
142
150
}
143
151
}
144
152
145
- for _ , pInc := range p . IncModule {
146
- ret , mod , protoName := pInc .FindTNameType (tname )
153
+ for _ , tarsFile := range tf . IncTarsFile {
154
+ ret , mod , protoName := tarsFile .FindTNameType (tName )
147
155
if ret != token .Name {
148
156
return ret , mod , protoName
149
157
}
150
158
}
151
159
// not find
152
- return token .Name , p . Name , p .ProtoName
160
+ return token .Name , tf . Module . Name , tf .ProtoName
153
161
}
154
162
155
- func (p * ModuleInfo ) FindEnumName (ename string , moduleCycle bool ) (* EnumMember , * EnumInfo , error ) {
163
+ func (tf * TarsFile ) FindEnumName (ename string , moduleCycle bool ) (* EnumMember , * Enum , error ) {
156
164
if strings .Contains (ename , "::" ) {
157
165
vec := strings .Split (ename , "::" )
158
166
if len (vec ) >= 2 {
159
167
ename = vec [1 ]
160
168
}
161
169
}
162
170
var cmb * EnumMember
163
- var cenum * EnumInfo
164
- for ek , enum := range p .Enum {
171
+ var cenum * Enum
172
+ for ek , enum := range tf . Module .Enum {
165
173
for mk , mb := range enum .Mb {
166
174
if mb .Key != ename {
167
175
continue
168
176
}
169
177
if cmb == nil {
170
178
cmb = & enum .Mb [mk ]
171
- cenum = & p .Enum [ek ]
179
+ cenum = & tf . Module .Enum [ek ]
172
180
} else {
173
181
return nil , nil , errors .New (ename + " name conflict [" + cenum .Name + "::" + cmb .Key + " or " + enum .Name + "::" + mb .Key )
174
182
}
175
183
}
176
184
}
177
185
var err error
178
- for _ , pInc := range p . IncModule {
186
+ for _ , tarsFile := range tf . IncTarsFile {
179
187
if cmb == nil {
180
- cmb , cenum , err = pInc .FindEnumName (ename , moduleCycle )
188
+ cmb , cenum , err = tarsFile .FindEnumName (ename , moduleCycle )
181
189
if err != nil {
182
190
return cmb , cenum , err
183
191
}
@@ -187,17 +195,16 @@ func (p *ModuleInfo) FindEnumName(ename string, moduleCycle bool) (*EnumMember,
187
195
}
188
196
if cenum != nil && cenum .Module == "" {
189
197
if moduleCycle {
190
- cenum .Module = p .ProtoName + "_" + p .Name
198
+ cenum .Module = tf .ProtoName + "_" + tf . Module .Name
191
199
} else {
192
- cenum .Module = p .Name
200
+ cenum .Module = tf . Module .Name
193
201
}
194
202
}
195
203
return cmb , cenum , nil
196
204
}
197
205
198
- // Rename struct
199
- // struct Name { 1 require Mb type}
200
- func (st * StructInfo ) Rename () {
206
+ // Rename Struct Name { 1 require Mb type}
207
+ func (st * Struct ) Rename () {
201
208
st .OriginName = st .Name
202
209
st .Name = utils .UpperFirstLetter (st .Name )
203
210
for i := range st .Mb {
@@ -206,38 +213,39 @@ func (st *StructInfo) Rename() {
206
213
}
207
214
}
208
215
209
- // Rename interface
210
- // interface Name { Fun }
211
- func (itf * InterfaceInfo ) Rename () {
216
+ // Rename Interface Name { Funcs }
217
+ func (itf * Interface ) Rename () {
212
218
itf .OriginName = itf .Name
213
219
itf .Name = utils .UpperFirstLetter (itf .Name )
214
- for i := range itf .Fun {
215
- itf .Fun [i ].Rename ()
220
+ for i := range itf .Funcs {
221
+ itf .Funcs [i ].Rename ()
216
222
}
217
223
}
218
224
219
- func (en * EnumInfo ) Rename () {
225
+ // Rename Enum Name { Mb }
226
+ func (en * Enum ) Rename () {
220
227
en .OriginName = en .Name
221
228
en .Name = utils .UpperFirstLetter (en .Name )
222
229
for i := range en .Mb {
223
230
en .Mb [i ].Key = utils .UpperFirstLetter (en .Mb [i ].Key )
224
231
}
225
232
}
226
233
227
- func (cst * ConstInfo ) Rename () {
234
+ // Rename Const Name
235
+ func (cst * Const ) Rename () {
228
236
cst .OriginName = cst .Name
229
237
cst .Name = utils .UpperFirstLetter (cst .Name )
230
238
}
231
239
232
- // Rename func
233
- // type Fun (arg ArgType), in case keyword and name conflicts,argname need to capitalize.
234
- // Fun (type int32)
235
- func (fun * FunInfo ) Rename () {
240
+ // Rename Func Name { Args }
241
+ // type Funcs (arg ArgType), in case keyword and name conflicts, arg name need to capitalize.
242
+ // Funcs (type int32)
243
+ func (fun * Func ) Rename () {
236
244
fun .OriginName = fun .Name
237
245
fun .Name = utils .UpperFirstLetter (fun .Name )
238
246
for i := range fun .Args {
239
247
fun .Args [i ].OriginName = fun .Args [i ].Name
240
- // func args donot upper firs
241
- //fun.Args[i].Name = utils.UpperFirstLetter(fun.Args[i].Name)
248
+ // func args do not upper firs
249
+ // fun.Args[i].Name = utils.UpperFirstLetter(fun.Args[i].Name)
242
250
}
243
251
}
0 commit comments