Skip to content

Commit d5ae87c

Browse files
committed
Refactored a bunch of ctags related context variables
Signed-off-by: Cristian Maglie <[email protected]>
1 parent 9a1f215 commit d5ae87c

14 files changed

+136
-165
lines changed

src/arduino.cc/builder/collect_ctags_from_sketch_files.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}, ctx *t
4242
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
4343
sketchFileNames := collectSketchFileNamesFrom(sketch)
4444

45-
allCtags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
45+
allCtags := ctx.CTagsOfPreprocessedSource
4646
ctagsOfSketch := []*types.CTag{}
4747
for _, ctag := range allCtags {
4848
if utils.SliceContains(sketchFileNames, strings.Replace(ctag.Filename, "\\\\", "\\", -1)) {
4949
ctagsOfSketch = append(ctagsOfSketch, ctag)
5050
}
5151
}
5252

53-
context[constants.CTX_COLLECTED_CTAGS] = ctagsOfSketch
53+
ctx.CTagsCollected = ctagsOfSketch
5454

5555
return nil
5656
}

src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@
2929

3030
package builder
3131

32-
import (
33-
"arduino.cc/builder/constants"
34-
"arduino.cc/builder/types"
35-
)
32+
import "arduino.cc/builder/types"
3633

3734
type ComparePrototypesFromSourceAndPreprocSource struct{}
3835

39-
func (s *ComparePrototypesFromSourceAndPreprocSource) Run(context map[string]interface{}) error {
40-
ctagsOfSource := context[constants.CTX_CTAGS_OF_SOURCE].([]*types.CTag)
41-
ctagsOfPreprocSource := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
36+
func (s *ComparePrototypesFromSourceAndPreprocSource) Run(context map[string]interface{}, ctx *types.Context) error {
37+
ctagsOfSource := ctx.CTagsOfSource
38+
ctagsOfPreprocSource := ctx.CTagsOfPreprocessedSource
4239

4340
actualCTags := []*types.CTag{}
4441
for _, ctagOfPreprocSource := range ctagsOfPreprocSource {
@@ -47,7 +44,7 @@ func (s *ComparePrototypesFromSourceAndPreprocSource) Run(context map[string]int
4744
}
4845
}
4946

50-
context[constants.CTX_COLLECTED_CTAGS] = actualCTags
47+
ctx.CTagsCollected = actualCTags
5148

5249
return nil
5350
}

src/arduino.cc/builder/constants/constants.go

-8
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,8 @@ const CTX_BUILD_OPTIONS_JSON = "buildOptionsJson"
8282
const CTX_BUILD_OPTIONS_PREVIOUS_JSON = "buildOptionsPreviousJson"
8383
const CTX_BUILD_PATH = "buildPath"
8484
const CTX_BUILD_PROPERTIES = "buildProperties"
85-
const CTX_COLLECTED_CTAGS = "collectedCTags"
8685
const CTX_COLLECTED_SOURCE_FILES_QUEUE = "collectedSourceFilesQueue"
8786
const CTX_CORE_BUILD_PATH = "coreBuildPath"
88-
const CTX_CTAGS_OF_PREPROC_SOURCE = "ctagsOfPreprocSource"
89-
const CTX_CTAGS_OF_SOURCE = "ctagsOfSource"
90-
const CTX_CTAGS_OUTPUT = "ctagsOutput"
91-
const CTX_CTAGS_TEMP_FILE_PATH = "ctagsTempFilePath"
9287
const CTX_FILE_PATH_TO_READ = "filePathToRead"
9388
const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue"
9489
const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource"
@@ -102,14 +97,11 @@ const CTX_INCLUDES_JUST_FOUND = "includesJustFound"
10297
const CTX_LIBRARIES_BUILD_PATH = "librariesBuildPath"
10398
const CTX_LIBRARY_RESOLUTION_RESULTS = "libraryResolutionResults"
10499
const CTX_LINE_OFFSET = "lineOffset"
105-
const CTX_LINE_WHERE_TO_INSERT_PROTOTYPES = "lineWhereToInsertPrototypes"
106100
const CTX_OBJECT_FILES_CORE = "objectFilesCore"
107101
const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries"
108102
const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch"
109103
const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite"
110104
const CTX_PREPROC_PATH = "preprocPath"
111-
const CTX_PROTOTYPE_SECTION = "prototypeSection"
112-
const CTX_PROTOTYPES = "prototypes"
113105
const CTX_SKETCH_BUILD_PATH = "sketchBuildPath"
114106
const CTX_SKETCH = "sketch"
115107
const CTX_SOURCE = "source"

src/arduino.cc/builder/ctags/ctags_parser.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var KNOWN_TAG_KINDS = map[string]bool{
5757
type CTagsParser struct{}
5858

5959
func (s *CTagsParser) Run(context map[string]interface{}, ctx *types.Context) error {
60-
rows := strings.Split(context[constants.CTX_CTAGS_OUTPUT].(string), "\n")
60+
rows := strings.Split(ctx.CTagsOutput, "\n")
6161

6262
rows = removeEmpty(rows)
6363

@@ -73,7 +73,7 @@ func (s *CTagsParser) Run(context map[string]interface{}, ctx *types.Context) er
7373
removeDuplicate(tags)
7474
skipTagsWhere(tags, prototypeAndCodeDontMatch, ctx)
7575

76-
context[constants.CTX_CTAGS_OF_PREPROC_SOURCE] = tags
76+
ctx.CTagsOfPreprocessedSource = tags
7777

7878
return nil
7979
}

src/arduino.cc/builder/ctags/ctags_runner.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type CTagsRunner struct{}
4242

4343
func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) error {
4444
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
45-
ctagsTargetFilePath := context[constants.CTX_CTAGS_TEMP_FILE_PATH].(string)
45+
ctagsTargetFilePath := ctx.CTagsTargetFile
4646
logger := ctx.GetLogger()
4747

4848
properties := buildProperties.Clone()
@@ -70,7 +70,7 @@ func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) er
7070
return i18n.WrapError(err)
7171
}
7272

73-
context[constants.CTX_CTAGS_OUTPUT] = string(sourceBytes)
73+
ctx.CTagsOutput = string(sourceBytes)
7474

7575
return nil
7676
}

src/arduino.cc/builder/ctags/ctags_to_prototypes.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,21 @@
3030
package ctags
3131

3232
import (
33-
"arduino.cc/builder/constants"
3433
"arduino.cc/builder/types"
3534
"strings"
3635
)
3736

3837
type CTagsToPrototypes struct{}
3938

4039
func (s *CTagsToPrototypes) Run(context map[string]interface{}, ctx *types.Context) error {
41-
tags := context[constants.CTX_COLLECTED_CTAGS].([]*types.CTag)
40+
tags := ctx.CTagsCollected
4241

4342
lineWhereToInsertPrototypes := findLineWhereToInsertPrototypes(tags)
4443
if lineWhereToInsertPrototypes != -1 {
45-
context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES] = lineWhereToInsertPrototypes
44+
ctx.PrototypesLineWhereToInsert = lineWhereToInsertPrototypes
4645
}
4746

48-
prototypes := toPrototypes(tags)
49-
context[constants.CTX_PROTOTYPES] = prototypes
50-
47+
ctx.Prototypes = toPrototypes(tags)
5148
return nil
5249
}
5350

src/arduino.cc/builder/ctags_target_file_saver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (s *CTagsTargetFileSaver) Run(context map[string]interface{}, ctx *types.Co
5757
return i18n.WrapError(err)
5858
}
5959

60-
context[constants.CTX_CTAGS_TEMP_FILE_PATH] = ctagsTargetFilePath
60+
ctx.CTagsTargetFile = ctagsTargetFilePath
6161

6262
return nil
6363
}

src/arduino.cc/builder/prototypes_adder.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ package builder
3232
import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/types"
35-
"arduino.cc/builder/utils"
3635
"fmt"
3736
"strconv"
3837
"strings"
@@ -49,19 +48,15 @@ func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context
4948

5049
sourceRows := strings.Split(source, "\n")
5150

52-
if !utils.MapHas(context, constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES) {
53-
return nil
54-
}
55-
56-
firstFunctionLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int)
51+
firstFunctionLine := ctx.PrototypesLineWhereToInsert
5752
if isFirstFunctionOutsideOfSource(firstFunctionLine, sourceRows) {
5853
return nil
5954
}
6055

6156
insertionLine := firstFunctionLine + context[constants.CTX_LINE_OFFSET].(int) - 1
6257
firstFunctionChar := len(strings.Join(sourceRows[:insertionLine], "\n")) + 1
63-
prototypeSection := composePrototypeSection(firstFunctionLine, context[constants.CTX_PROTOTYPES].([]*types.Prototype))
64-
context[constants.CTX_PROTOTYPE_SECTION] = prototypeSection
58+
prototypeSection := composePrototypeSection(firstFunctionLine, ctx.Prototypes)
59+
ctx.PrototypesSection = prototypeSection
6560
source = source[:firstFunctionChar] + prototypeSection + source[firstFunctionChar:]
6661

6762
if debugOutput {

src/arduino.cc/builder/test/ctags_parser_test.go

+28-29
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
package test
3131

3232
import (
33-
"arduino.cc/builder/constants"
3433
"arduino.cc/builder/ctags"
3534
"arduino.cc/builder/types"
3635
"github.com/stretchr/testify/require"
@@ -46,12 +45,12 @@ func TestCTagsParserShouldListPrototypes(t *testing.T) {
4645
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListPrototypes.txt"))
4746
NoError(t, err)
4847

49-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
48+
ctx.CTagsOutput = string(bytes)
5049

5150
ctagsParser := ctags.CTagsParser{}
5251
ctagsParser.Run(context, ctx)
5352

54-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
53+
tags := ctx.CTagsOfPreprocessedSource
5554

5655
require.Equal(t, 8, len(tags))
5756
idx := 0
@@ -95,12 +94,12 @@ func TestCTagsParserShouldListTemplates(t *testing.T) {
9594
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates.txt"))
9695
NoError(t, err)
9796

98-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
97+
ctx.CTagsOutput = string(bytes)
9998

10099
ctagsParser := ctags.CTagsParser{}
101100
ctagsParser.Run(context, ctx)
102101

103-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
102+
tags := ctx.CTagsOfPreprocessedSource
104103

105104
require.Equal(t, 3, len(tags))
106105
idx := 0
@@ -124,12 +123,12 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) {
124123
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates2.txt"))
125124
NoError(t, err)
126125

127-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
126+
ctx.CTagsOutput = string(bytes)
128127

129128
ctagsParser := ctags.CTagsParser{}
130129
ctagsParser.Run(context, ctx)
131130

132-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
131+
tags := ctx.CTagsOfPreprocessedSource
133132

134133
require.Equal(t, 4, len(tags))
135134
idx := 0
@@ -155,12 +154,12 @@ func TestCTagsParserShouldDealWithClasses(t *testing.T) {
155154
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithClasses.txt"))
156155
NoError(t, err)
157156

158-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
157+
ctx.CTagsOutput = string(bytes)
159158

160159
ctagsParser := ctags.CTagsParser{}
161160
ctagsParser.Run(context, ctx)
162161

163-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
162+
tags := ctx.CTagsOfPreprocessedSource
164163

165164
require.Equal(t, 2, len(tags))
166165
idx := 0
@@ -178,12 +177,12 @@ func TestCTagsParserShouldDealWithStructs(t *testing.T) {
178177
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithStructs.txt"))
179178
NoError(t, err)
180179

181-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
180+
ctx.CTagsOutput = string(bytes)
182181

183182
ctagsParser := ctags.CTagsParser{}
184183
ctagsParser.Run(context, ctx)
185184

186-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
185+
tags := ctx.CTagsOfPreprocessedSource
187186

188187
require.Equal(t, 5, len(tags))
189188
idx := 0
@@ -211,12 +210,12 @@ func TestCTagsParserShouldDealWithMacros(t *testing.T) {
211210
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithMacros.txt"))
212211
NoError(t, err)
213212

214-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
213+
ctx.CTagsOutput = string(bytes)
215214

216215
ctagsParser := ctags.CTagsParser{}
217216
ctagsParser.Run(context, ctx)
218217

219-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
218+
tags := ctx.CTagsOfPreprocessedSource
220219

221220
require.Equal(t, 8, len(tags))
222221
idx := 0
@@ -252,12 +251,12 @@ func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) {
252251
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt"))
253252
NoError(t, err)
254253

255-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
254+
ctx.CTagsOutput = string(bytes)
256255

257256
ctagsParser := ctags.CTagsParser{}
258257
ctagsParser.Run(context, ctx)
259258

260-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
259+
tags := ctx.CTagsOfPreprocessedSource
261260

262261
require.Equal(t, 3, len(tags))
263262
idx := 0
@@ -278,12 +277,12 @@ func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) {
278277
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserClassMembersAreFilteredOut.txt"))
279278
NoError(t, err)
280279

281-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
280+
ctx.CTagsOutput = string(bytes)
282281

283282
ctagsParser := ctags.CTagsParser{}
284283
ctagsParser.Run(context, ctx)
285284

286-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
285+
tags := ctx.CTagsOfPreprocessedSource
287286

288287
require.Equal(t, 5, len(tags))
289288
idx := 0
@@ -313,12 +312,12 @@ func TestCTagsParserStructWithFunctions(t *testing.T) {
313312
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStructWithFunctions.txt"))
314313
NoError(t, err)
315314

316-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
315+
ctx.CTagsOutput = string(bytes)
317316

318317
ctagsParser := ctags.CTagsParser{}
319318
ctagsParser.Run(context, ctx)
320319

321-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
320+
tags := ctx.CTagsOfPreprocessedSource
322321

323322
require.Equal(t, 8, len(tags))
324323
idx := 0
@@ -356,12 +355,12 @@ func TestCTagsParserDefaultArguments(t *testing.T) {
356355
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserDefaultArguments.txt"))
357356
NoError(t, err)
358357

359-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
358+
ctx.CTagsOutput = string(bytes)
360359

361360
ctagsParser := ctags.CTagsParser{}
362361
ctagsParser.Run(context, ctx)
363362

364-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
363+
tags := ctx.CTagsOfPreprocessedSource
365364

366365
require.Equal(t, 3, len(tags))
367366
idx := 0
@@ -383,12 +382,12 @@ func TestCTagsParserNamespace(t *testing.T) {
383382
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserNamespace.txt"))
384383
NoError(t, err)
385384

386-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
385+
ctx.CTagsOutput = string(bytes)
387386

388387
ctagsParser := ctags.CTagsParser{}
389388
ctagsParser.Run(context, ctx)
390389

391-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
390+
tags := ctx.CTagsOfPreprocessedSource
392391

393392
require.Equal(t, 3, len(tags))
394393
idx := 0
@@ -410,12 +409,12 @@ func TestCTagsParserStatic(t *testing.T) {
410409
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStatic.txt"))
411410
NoError(t, err)
412411

413-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
412+
ctx.CTagsOutput = string(bytes)
414413

415414
ctagsParser := ctags.CTagsParser{}
416415
ctagsParser.Run(context, ctx)
417416

418-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
417+
tags := ctx.CTagsOfPreprocessedSource
419418

420419
require.Equal(t, 3, len(tags))
421420
idx := 0
@@ -436,12 +435,12 @@ func TestCTagsParserFunctionPointer(t *testing.T) {
436435
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointer.txt"))
437436
NoError(t, err)
438437

439-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
438+
ctx.CTagsOutput = string(bytes)
440439

441440
ctagsParser := ctags.CTagsParser{}
442441
ctagsParser.Run(context, ctx)
443442

444-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
443+
tags := ctx.CTagsOfPreprocessedSource
445444

446445
require.Equal(t, 4, len(tags))
447446
idx := 0
@@ -465,12 +464,12 @@ func TestCTagsParserFunctionPointers(t *testing.T) {
465464
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointers.txt"))
466465
NoError(t, err)
467466

468-
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
467+
ctx.CTagsOutput = string(bytes)
469468

470469
ctagsParser := ctags.CTagsParser{}
471470
ctagsParser.Run(context, ctx)
472471

473-
tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
472+
tags := ctx.CTagsOfPreprocessedSource
474473

475474
require.Equal(t, 5, len(tags))
476475
idx := 0

0 commit comments

Comments
 (0)