Skip to content

Commit 14e2351

Browse files
committed
Moving check for signatureContainsDefaultArg to prototypes_adder
ctags should list all prototypes, this commit moves the responsibility of prototypes selection to prototypes_adder Signed-off-by: Cristian Maglie <[email protected]>
1 parent 505cc4a commit 14e2351

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

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

-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func (s *CTagsParser) Run(context map[string]interface{}) error {
6767

6868
skipTagsWhere(tags, tagIsUnknown, context)
6969
skipTagsWhere(tags, tagIsUnhandled, context)
70-
skipTagsWhere(tags, signatureContainsDefaultArg, context)
7170
addPrototypes(tags)
7271
removeDefinedProtypes(tags, context)
7372
removeDuplicate(tags)
@@ -149,10 +148,6 @@ func skipTagsWhere(tags []*types.CTag, skipFunc skipFuncType, context map[string
149148
}
150149
}
151150

152-
func signatureContainsDefaultArg(tag *types.CTag) bool {
153-
return strings.Contains(tag.Prototype, "=")
154-
}
155-
156151
func prototypeAndCodeDontMatch(tag *types.CTag) bool {
157152
if tag.SkipMe {
158153
return true

src/arduino.cc/builder/prototypes_adder.go

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func composePrototypeSection(line int, prototypes []*types.Prototype) string {
7878
func joinPrototypes(prototypes []*types.Prototype) string {
7979
prototypesSlice := []string{}
8080
for _, proto := range prototypes {
81+
if signatureContainsaDefaultArg(proto) {
82+
continue
83+
}
8184
prototypesSlice = append(prototypesSlice, "#line "+strconv.Itoa(proto.Line)+" \""+proto.File+"\"")
8285
prototypeParts := []string{}
8386
if proto.Modifiers != "" {
@@ -89,6 +92,10 @@ func joinPrototypes(prototypes []*types.Prototype) string {
8992
return strings.Join(prototypesSlice, "\n")
9093
}
9194

95+
func signatureContainsaDefaultArg(proto *types.Prototype) bool {
96+
return strings.Contains(proto.Prototype, "=")
97+
}
98+
9299
func firstFunctionOutsideOfSource(firstFunctionLine int, sourceRows []string) bool {
93100
return firstFunctionLine > len(sourceRows)-1
94101
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,11 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) {
336336

337337
prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype)
338338

339-
require.Equal(t, 2, len(prototypes))
340-
require.Equal(t, "void setup();", prototypes[0].Prototype)
341-
require.Equal(t, "/tmp/test179252494/preproc/ctags_target.cpp", prototypes[0].File)
342-
require.Equal(t, "void loop();", prototypes[1].Prototype)
339+
require.Equal(t, 3, len(prototypes))
340+
require.Equal(t, "void test(int x = 1);", prototypes[0].Prototype)
341+
require.Equal(t, "void setup();", prototypes[1].Prototype)
342+
require.Equal(t, "/tmp/test179252494/preproc/ctags_target.cpp", prototypes[1].File)
343+
require.Equal(t, "void loop();", prototypes[2].Prototype)
343344

344345
prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int)
345346
require.Equal(t, 2, prototypeLine)

0 commit comments

Comments
 (0)