Skip to content

Commit 8bb7912

Browse files
matthijskooijmanFederico Fissore
authored and
Federico Fissore
committed
Be more conservative about what prototypes to add
Previously, a prototype was added if the generated prototype was contained in the original source code line, to catch cases where ctags did not provide enough information to generate a completely correct prototype. However, this substring matching was still too liberal: if something unsupported was present at the start of the function definition (such as `static` in `static void func()`) the substring matching would still think the prototype was correct, but the compiler would complain. This commit changes this to use prefix matching: Only if the original source line starts with the generated prefix, a prototype is added. Ideally, the full definition is matched, but that requires knowing where it ends, which can be at a curly open, but also a comment start, etc., so better to just leave it at this. This means that inline functions and functions with attributes specified at the start will no longer get a prototype, so the TestPrototypesAdderSketchWithInlineFunction is modified accordingly. Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
1 parent bb83289 commit 8bb7912

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/arduino.cc/builder/ctags_parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func prototypeAndCodeDontMatch(tag map[string]string) bool {
182182
prototype := removeSpacesAndTabs(tag[KIND_PROTOTYPE])
183183
prototype = removeTralingSemicolon(prototype)
184184

185-
return strings.Index(code, prototype) == -1
185+
return strings.Index(code, prototype) != 0
186186
}
187187

188188
func removeTralingSemicolon(s string) string {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) {
574574
}
575575

576576
require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
577-
require.Equal(t, "void setup();\nvoid loop();\nshort unsigned int testInt();\nint8_t testInline();\nuint8_t testAttribute();\n#line 1\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
577+
require.Equal(t, "void setup();\nvoid loop();\nshort unsigned int testInt();\n#line 1\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
578578
}
579579

580580
func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) {

0 commit comments

Comments
 (0)