Skip to content

Commit fe14f45

Browse files
author
Federico Fissore
committed
Removed CTagsField from CTagsParser: hard coded ctx key to
CTX_CTAGS_OF_PREPROC_SOURCE Signed-off-by: Federico Fissore <[email protected]>
1 parent b074e0e commit fe14f45

File tree

5 files changed

+69
-47
lines changed

5 files changed

+69
-47
lines changed

Diff for: src/arduino.cc/builder/container_add_prototypes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (s *ContainerAddPrototypes) Run(context map[string]interface{}) error {
4343
&ReadFileAndStoreInContext{TargetField: constants.CTX_GCC_MINUS_E_SOURCE},
4444
&CTagsTargetFileSaver{SourceField: constants.CTX_GCC_MINUS_E_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
4545
&CTagsRunner{},
46-
&CTagsParser{CTagsField: constants.CTX_CTAGS_OF_PREPROC_SOURCE},
46+
&CTagsParser{},
4747
&CollectCTagsFromSketchFiles{},
4848
&CTagsToPrototypes{},
4949
&PrototypesAdder{},

Diff for: src/arduino.cc/builder/ctags_parser.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ var FIELDS = map[string]bool{"kind": true, "line": true, "typeref": true, "signa
5959
var KNOWN_TAG_KINDS = map[string]bool{"prototype": true, "function": true}
6060
var FIELDS_MARKING_UNHANDLED_TAGS = []string{FIELD_CLASS, FIELD_STRUCT, FIELD_NAMESPACE}
6161

62-
type CTagsParser struct {
63-
CTagsField string
64-
}
62+
type CTagsParser struct{}
6563

6664
func (s *CTagsParser) Run(context map[string]interface{}) error {
6765
rows := strings.Split(context[constants.CTX_CTAGS_OUTPUT].(string), "\n")
@@ -81,7 +79,7 @@ func (s *CTagsParser) Run(context map[string]interface{}) error {
8179
removeDuplicate(tags)
8280
skipTagsWhere(tags, prototypeAndCodeDontMatch)
8381

84-
context[s.CTagsField] = tags
82+
context[constants.CTX_CTAGS_OF_PREPROC_SOURCE] = tags
8583

8684
return nil
8785
}

Diff for: src/arduino.cc/builder/test/ctags_parser_test.go

+28-28
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func TestCTagsParserShouldListPrototypes(t *testing.T) {
4646

4747
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
4848

49-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
49+
ctagsParser := builder.CTagsParser{}
5050
ctagsParser.Run(context)
5151

52-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
52+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
5353

5454
require.Equal(t, 8, len(ctags))
5555
idx := 0
@@ -94,10 +94,10 @@ func TestCTagsParserShouldListTemplates(t *testing.T) {
9494

9595
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
9696

97-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
97+
ctagsParser := builder.CTagsParser{}
9898
ctagsParser.Run(context)
9999

100-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
100+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
101101

102102
require.Equal(t, 3, len(ctags))
103103
idx := 0
@@ -120,10 +120,10 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) {
120120

121121
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
122122

123-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
123+
ctagsParser := builder.CTagsParser{}
124124
ctagsParser.Run(context)
125125

126-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
126+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
127127

128128
require.Equal(t, 4, len(ctags))
129129
idx := 0
@@ -150,10 +150,10 @@ func TestCTagsParserShouldDealWithClasses(t *testing.T) {
150150

151151
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
152152

153-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
153+
ctagsParser := builder.CTagsParser{}
154154
ctagsParser.Run(context)
155155

156-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
156+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
157157

158158
require.Equal(t, 2, len(ctags))
159159
idx := 0
@@ -172,10 +172,10 @@ func TestCTagsParserShouldDealWithStructs(t *testing.T) {
172172

173173
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
174174

175-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
175+
ctagsParser := builder.CTagsParser{}
176176
ctagsParser.Run(context)
177177

178-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
178+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
179179

180180
require.Equal(t, 5, len(ctags))
181181
idx := 0
@@ -204,10 +204,10 @@ func TestCTagsParserShouldDealWithMacros(t *testing.T) {
204204

205205
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
206206

207-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
207+
ctagsParser := builder.CTagsParser{}
208208
ctagsParser.Run(context)
209209

210-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
210+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
211211

212212
require.Equal(t, 8, len(ctags))
213213
idx := 0
@@ -244,10 +244,10 @@ func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) {
244244

245245
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
246246

247-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
247+
ctagsParser := builder.CTagsParser{}
248248
ctagsParser.Run(context)
249249

250-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
250+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
251251

252252
require.Equal(t, 3, len(ctags))
253253
idx := 0
@@ -269,10 +269,10 @@ func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) {
269269

270270
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
271271

272-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
272+
ctagsParser := builder.CTagsParser{}
273273
ctagsParser.Run(context)
274274

275-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
275+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
276276

277277
require.Equal(t, 5, len(ctags))
278278
idx := 0
@@ -303,10 +303,10 @@ func TestCTagsParserStructWithFunctions(t *testing.T) {
303303

304304
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
305305

306-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
306+
ctagsParser := builder.CTagsParser{}
307307
ctagsParser.Run(context)
308308

309-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
309+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
310310

311311
require.Equal(t, 8, len(ctags))
312312
idx := 0
@@ -345,10 +345,10 @@ func TestCTagsParserDefaultArguments(t *testing.T) {
345345

346346
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
347347

348-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
348+
ctagsParser := builder.CTagsParser{}
349349
ctagsParser.Run(context)
350350

351-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
351+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
352352

353353
require.Equal(t, 3, len(ctags))
354354
idx := 0
@@ -371,10 +371,10 @@ func TestCTagsParserNamespace(t *testing.T) {
371371

372372
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
373373

374-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
374+
ctagsParser := builder.CTagsParser{}
375375
ctagsParser.Run(context)
376376

377-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
377+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
378378

379379
require.Equal(t, 3, len(ctags))
380380
idx := 0
@@ -397,10 +397,10 @@ func TestCTagsParserStatic(t *testing.T) {
397397

398398
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
399399

400-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
400+
ctagsParser := builder.CTagsParser{}
401401
ctagsParser.Run(context)
402402

403-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
403+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
404404

405405
require.Equal(t, 3, len(ctags))
406406
idx := 0
@@ -422,10 +422,10 @@ func TestCTagsParserFunctionPointer(t *testing.T) {
422422

423423
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
424424

425-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
425+
ctagsParser := builder.CTagsParser{}
426426
ctagsParser.Run(context)
427427

428-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
428+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
429429

430430
require.Equal(t, 4, len(ctags))
431431
idx := 0
@@ -450,10 +450,10 @@ func TestCTagsParserFunctionPointers(t *testing.T) {
450450

451451
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
452452

453-
ctagsParser := builder.CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE}
453+
ctagsParser := builder.CTagsParser{}
454454
ctagsParser.Run(context)
455455

456-
ctags := context[constants.CTX_CTAGS_OF_SOURCE].([]map[string]string)
456+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
457457

458458
require.Equal(t, 5, len(ctags))
459459
idx := 0

Diff for: src/arduino.cc/builder/test/ctags_to_prototypes_test.go

+28-14
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) {
4848
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
4949

5050
commands := []types.Command{
51-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
51+
&builder.CTagsParser{},
52+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
5253
&builder.CTagsToPrototypes{},
5354
}
5455

@@ -80,7 +81,8 @@ func TestCTagsToPrototypesShouldListTemplates(t *testing.T) {
8081
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
8182

8283
commands := []types.Command{
83-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
84+
&builder.CTagsParser{},
85+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
8486
&builder.CTagsToPrototypes{},
8587
}
8688

@@ -110,7 +112,8 @@ func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) {
110112
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
111113

112114
commands := []types.Command{
113-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
115+
&builder.CTagsParser{},
116+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
114117
&builder.CTagsToPrototypes{},
115118
}
116119

@@ -141,7 +144,8 @@ func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) {
141144
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
142145

143146
commands := []types.Command{
144-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
147+
&builder.CTagsParser{},
148+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
145149
&builder.CTagsToPrototypes{},
146150
}
147151

@@ -167,7 +171,8 @@ func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) {
167171
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
168172

169173
commands := []types.Command{
170-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
174+
&builder.CTagsParser{},
175+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
171176
&builder.CTagsToPrototypes{},
172177
}
173178

@@ -197,7 +202,8 @@ func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) {
197202
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
198203

199204
commands := []types.Command{
200-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
205+
&builder.CTagsParser{},
206+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
201207
&builder.CTagsToPrototypes{},
202208
}
203209

@@ -229,7 +235,8 @@ func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T
229235
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
230236

231237
commands := []types.Command{
232-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
238+
&builder.CTagsParser{},
239+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
233240
&builder.CTagsToPrototypes{},
234241
}
235242

@@ -257,7 +264,8 @@ func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) {
257264
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
258265

259266
commands := []types.Command{
260-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
267+
&builder.CTagsParser{},
268+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
261269
&builder.CTagsToPrototypes{},
262270
}
263271

@@ -286,7 +294,8 @@ func TestCTagsToPrototypesStructWithFunctions(t *testing.T) {
286294
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
287295

288296
commands := []types.Command{
289-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
297+
&builder.CTagsParser{},
298+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
290299
&builder.CTagsToPrototypes{},
291300
}
292301

@@ -315,7 +324,8 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) {
315324
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
316325

317326
commands := []types.Command{
318-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
327+
&builder.CTagsParser{},
328+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
319329
&builder.CTagsToPrototypes{},
320330
}
321331

@@ -344,7 +354,8 @@ func TestCTagsToPrototypesNamespace(t *testing.T) {
344354
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
345355

346356
commands := []types.Command{
347-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
357+
&builder.CTagsParser{},
358+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
348359
&builder.CTagsToPrototypes{},
349360
}
350361

@@ -373,7 +384,8 @@ func TestCTagsToPrototypesStatic(t *testing.T) {
373384
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
374385

375386
commands := []types.Command{
376-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
387+
&builder.CTagsParser{},
388+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
377389
&builder.CTagsToPrototypes{},
378390
}
379391

@@ -404,7 +416,8 @@ func TestCTagsToPrototypesFunctionPointer(t *testing.T) {
404416
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
405417

406418
commands := []types.Command{
407-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
419+
&builder.CTagsParser{},
420+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
408421
&builder.CTagsToPrototypes{},
409422
}
410423

@@ -434,7 +447,8 @@ func TestCTagsToPrototypesFunctionPointers(t *testing.T) {
434447
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
435448

436449
commands := []types.Command{
437-
&builder.CTagsParser{CTagsField: constants.CTX_COLLECTED_CTAGS},
450+
&builder.CTagsParser{},
451+
&CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS},
438452
&builder.CTagsToPrototypes{},
439453
}
440454

Diff for: src/arduino.cc/builder/test/helper.go

+10
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,13 @@ func (s ByLibraryName) Swap(i, j int) {
9595
func (s ByLibraryName) Less(i, j int) bool {
9696
return s[i].Name < s[j].Name
9797
}
98+
99+
type CopyContextKeys struct {
100+
From string
101+
To string
102+
}
103+
104+
func (s *CopyContextKeys) Run(context map[string]interface{}) error {
105+
context[s.To] = context[s.From]
106+
return nil
107+
}

0 commit comments

Comments
 (0)