Skip to content

Commit 12ad32f

Browse files
authored
Merge pull request #294 from facchinm/fix_wrong_function_prototype_match
Fix wrong function prototype match
2 parents e517cae + 491a067 commit 12ad32f

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

Diff for: ctags/ctags_to_prototypes.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionTags []*types.
7272
if tag.Line != functionTag.Line && strings.Index(tag.Code, "&"+functionTag.FunctionName) != -1 {
7373
return true
7474
}
75-
if tag.Line != functionTag.Line && strings.Index(tag.Code, functionTag.FunctionName) != -1 &&
76-
(functionTag.Signature == "(void)" || functionTag.Signature == "()") {
75+
if tag.Line != functionTag.Line && strings.Index(strings.TrimSpace(tag.Code), "("+functionTag.FunctionName+")") != -1 {
7776
return true
7877
}
7978
}

Diff for: test/prototypes_adder_test.go

+47-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
package test
3232

3333
import (
34-
"github.com/arduino/arduino-builder"
35-
"github.com/arduino/arduino-builder/types"
36-
"github.com/arduino/arduino-builder/utils"
37-
"github.com/stretchr/testify/require"
3834
"os"
3935
"path/filepath"
4036
"strings"
4137
"testing"
38+
39+
"github.com/arduino/arduino-builder"
40+
"github.com/arduino/arduino-builder/types"
41+
"github.com/arduino/arduino-builder/utils"
42+
"github.com/stretchr/testify/require"
4243
)
4344

4445
func TestPrototypesAdderBridgeExample(t *testing.T) {
@@ -906,3 +907,45 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) {
906907
}
907908
// only requires no error as result
908909
}
910+
911+
func TestPrototypesAdderSketchWithSubstringFunctionMember(t *testing.T) {
912+
DownloadCoresAndToolsAndLibraries(t)
913+
914+
sketchLocation := filepath.Join("sketch_with_class_and_method_substring", "sketch_with_class_and_method_substring.ino")
915+
quotedSketchLocation := utils.QuoteCppString(Abs(t, sketchLocation))
916+
917+
ctx := &types.Context{
918+
HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"},
919+
ToolsFolders: []string{"downloaded_tools"},
920+
BuiltInLibrariesFolders: []string{"downloaded_libraries"},
921+
OtherLibrariesFolders: []string{"libraries"},
922+
SketchLocation: sketchLocation,
923+
FQBN: "arduino:avr:uno",
924+
ArduinoAPIVersion: "10600",
925+
Verbose: true,
926+
}
927+
928+
buildPath := SetupBuildPath(t, ctx)
929+
defer os.RemoveAll(buildPath)
930+
931+
commands := []types.Command{
932+
933+
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
934+
935+
&builder.ContainerMergeCopySketchFiles{},
936+
937+
&builder.ContainerFindIncludes{},
938+
939+
&builder.PrintUsedLibrariesIfVerbose{},
940+
&builder.WarnAboutArchIncompatibleLibraries{},
941+
942+
&builder.ContainerAddPrototypes{},
943+
}
944+
945+
for _, command := range commands {
946+
err := command.Run(ctx)
947+
NoError(t, err)
948+
}
949+
950+
require.Contains(t, ctx.Source, "class Foo {\nint blooper(int x) { return x+1; }\n};\n\nFoo foo;\n\n#line 7 "+quotedSketchLocation+"\nvoid setup();")
951+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Foo {
2+
int blooper(int x) { return x+1; }
3+
};
4+
5+
Foo foo;
6+
7+
void setup() {
8+
foo.setup();
9+
}
10+
11+
void loop() {
12+
foo.loop();
13+
}

0 commit comments

Comments
 (0)