Skip to content

Fix prototype callback generation if direct reference is used #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/arduino.cc/builder/ctags/ctags_parser.go
Original file line number Diff line number Diff line change
@@ -236,7 +236,6 @@ func parseTag(row string) *types.CTag {

parts = parts[2:]

signature := ""
returntype := ""
for _, part := range parts {
if strings.Contains(part, ":") {
@@ -253,7 +252,7 @@ func parseTag(row string) *types.CTag {
case "typeref":
tag.Typeref = value
case "signature":
signature = value
tag.Signature = value
case "returntype":
returntype = value
case "class":
@@ -265,7 +264,7 @@ func parseTag(row string) *types.CTag {
}
}
}
tag.Prototype = returntype + " " + tag.FunctionName + signature + ";"
tag.Prototype = returntype + " " + tag.FunctionName + tag.Signature + ";"

if strings.Contains(row, "/^") && strings.Contains(row, "$/;") {
tag.Code = row[strings.Index(row, "/^")+2 : strings.Index(row, "$/;")]
3 changes: 3 additions & 0 deletions src/arduino.cc/builder/ctags/ctags_to_prototypes.go
Original file line number Diff line number Diff line change
@@ -70,6 +70,9 @@ func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionNames []string
if strings.Index(tag.Code, "&"+functionName) != -1 {
return true
}
if strings.Index(tag.Code, functionName) != -1 {
return true
}
}
return false
}
27 changes: 27 additions & 0 deletions src/arduino.cc/builder/ctags/ctags_to_prototypes_test.go
Original file line number Diff line number Diff line change
@@ -209,6 +209,33 @@ func TestCTagsToPrototypesFunctionPointers(t *testing.T) {
require.Equal(t, 2, line)
}

func TestCTagsToPrototypesFunctionPointersNoIndirect(t *testing.T) {
ctx := &types.Context{}

bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointersNoIndirect.txt"))
NoError(t, err)

ctx.CTagsOutput = string(bytes)

commands := []types.Command{
&ctags.CTagsParser{},
&ctags.CTagsToPrototypes{},
}

for _, command := range commands {
err := command.Run(ctx)
NoError(t, err)
}

prototypes := ctx.Prototypes
require.Equal(t, 5, len(prototypes))
require.Equal(t, "void setup();", prototypes[0].Prototype)
require.Equal(t, "/tmp/test547238273/preproc/bug_callback.ino", prototypes[0].File)
require.Equal(t, "void loop();", prototypes[1].Prototype)

require.Equal(t, 10, ctx.PrototypesLineWhereToInsert)
}

func TestCTagsRunnerSketchWithClassFunction(t *testing.T) {
prototypes, _ := producePrototypes(t, "TestCTagsRunnerSketchWithClassFunction.txt")

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BUG /tmp/test547238273/preproc/bug_callback.ino /^ public: BUG(void (*fn)(void)) {}$/;" kind:function line:6 class:BUG signature:(void (*fn)(void))
b /tmp/test547238273/preproc/bug_callback.ino /^BUG b(makeItBreak); \/\/this will break$/;" kind:prototype line:10 signature:(makeItBreak)returntype:BUG
setup /tmp/test547238273/preproc/bug_callback.ino /^void setup() {$/;" kind:function line:12 signature:() returntype:void
loop /tmp/test547238273/preproc/bug_callback.ino /^void loop() {}$/;" kind:function line:16 signature:() returntype:void
makeItBreak /tmp/test547238273/preproc/bug_callback.ino /^void makeItBreak() {}$/;" kind:function line:18 signature:() returntype:void
caller /tmp/test547238273/preproc/bug_callback.ino /^void caller(int (*cc)(int ),int a) {$/;" kind:function line:20 signature:(int (*cc)(int ),int a) returntype:void
blub /tmp/test547238273/preproc/bug_callback.ino /^int blub(int a) {$/;" kind:function line:24 signature:(int a) returntype:int
1 change: 1 addition & 0 deletions src/arduino.cc/builder/types/types.go
Original file line number Diff line number Diff line change
@@ -252,6 +252,7 @@ type CTag struct {
Filename string
Typeref string
SkipMe bool
Signature string

Prototype string
Function string