Skip to content

Commit 3282535

Browse files
committed
Avoid checking if a function uses itself as function pointer
Fixes #206 The sample code from the issue provided a smart way to cheat the dumb FP parser. In fact, the & is referred to the return type (correct) but the comparator doesn't know about semantics and simply prepends the ampersand before searching for the match. So the code matches itself, which makes absolutely no sense. Avoiding this occurrence fixes the issue, however the entire code for prototype line insertion should be refactored in a saner way (see #180 and #191 for another problem)
1 parent bc2c38f commit 3282535

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,32 @@ func (p *CTagsParser) findLineWhereToInsertPrototypes() int {
5656
}
5757

5858
func (p *CTagsParser) firstFunctionPointerUsedAsArgument() int {
59-
functionNames := p.collectFunctionNames()
59+
functionTags := p.collectFunctions()
6060
for _, tag := range p.tags {
61-
if functionNameUsedAsFunctionPointerIn(tag, functionNames) {
61+
if functionNameUsedAsFunctionPointerIn(tag, functionTags) {
6262
return tag.Line
6363
}
6464
}
6565
return -1
6666
}
6767

68-
func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionNames []string) bool {
69-
for _, functionName := range functionNames {
70-
if strings.Index(tag.Code, "&"+functionName) != -1 {
68+
func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionTags []*types.CTag) bool {
69+
for _, functionTag := range functionTags {
70+
if tag.Line != functionTag.Line && strings.Index(tag.Code, "&"+functionTag.FunctionName) != -1 {
7171
return true
7272
}
7373
}
7474
return false
7575
}
7676

77-
func (p *CTagsParser) collectFunctionNames() []string {
78-
names := []string{}
77+
func (p *CTagsParser) collectFunctions() []*types.CTag {
78+
functionTags := []*types.CTag{}
7979
for _, tag := range p.tags {
8080
if tag.Kind == KIND_FUNCTION {
81-
names = append(names, tag.FunctionName)
81+
functionTags = append(functionTags, tag)
8282
}
8383
}
84-
return names
84+
return functionTags
8585
}
8686

8787
func (p *CTagsParser) firstFunctionAtLine() int {

0 commit comments

Comments
 (0)