Skip to content

Commit 08606b3

Browse files
committed
Move prototypeAndCodeDontMatch to ctags_has_issues
1 parent 991949b commit 08606b3

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,47 @@ func sliceContainsInt(s []int, e int) bool {
5858
return false
5959
}
6060

61+
func (p *CTagsParser) prototypeAndCodeDontMatch(tag *types.CTag) bool {
62+
if tag.SkipMe {
63+
return true
64+
}
65+
66+
code := removeSpacesAndTabs(tag.Code)
67+
68+
// original code is multi-line, which tags doesn't have - could we find this code in the
69+
// original source file, for purposes of checking here?
70+
if strings.Index(code, ")") == -1 {
71+
file, err := os.Open(tag.Filename)
72+
if err == nil {
73+
defer file.Close()
74+
75+
scanner := bufio.NewScanner(file)
76+
line := 1
77+
78+
// skip lines until we get to the start of this tag
79+
for scanner.Scan() && line < tag.Line {
80+
line++
81+
}
82+
83+
// read up to 10 lines in search of a closing paren
84+
newcode := scanner.Text()
85+
for scanner.Scan() && line < (tag.Line+10) && strings.Index(newcode, ")") == -1 {
86+
newcode += scanner.Text()
87+
}
88+
89+
// don't bother replacing the code text if we haven't found a closing paren
90+
if strings.Index(newcode, ")") != -1 {
91+
code = removeSpacesAndTabs(newcode)
92+
}
93+
}
94+
}
95+
96+
prototype := removeSpacesAndTabs(tag.Prototype)
97+
prototype = removeTralingSemicolon(prototype)
98+
99+
return strings.Index(code, prototype) == -1
100+
}
101+
61102
/* This function scans the source files searching for "extern C" context
62103
* It save the line numbers in a map filename -> {lines...}
63104
*/

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

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
package ctags
3131

3232
import (
33-
"bufio"
34-
"os"
3533
"strconv"
3634
"strings"
3735

@@ -69,7 +67,7 @@ func (p *CTagsParser) Parse(ctagsOutput string) []*types.CTag {
6967
p.addPrototypes()
7068
p.removeDefinedProtypes()
7169
p.skipDuplicates()
72-
p.skipTagsWhere(prototypeAndCodeDontMatch)
70+
p.skipTagsWhere(p.prototypeAndCodeDontMatch)
7371

7472
return p.tags
7573
}
@@ -148,47 +146,6 @@ func (p *CTagsParser) skipTagsWhere(skipFunc skipFuncType) {
148146
}
149147
}
150148

151-
func prototypeAndCodeDontMatch(tag *types.CTag) bool {
152-
if tag.SkipMe {
153-
return true
154-
}
155-
156-
code := removeSpacesAndTabs(tag.Code)
157-
158-
// original code is multi-line, which tags doesn't have - could we find this code in the
159-
// original source file, for purposes of checking here?
160-
if strings.Index(code, ")") == -1 {
161-
file, err := os.Open(tag.Filename)
162-
if err == nil {
163-
defer file.Close()
164-
165-
scanner := bufio.NewScanner(file)
166-
line := 1
167-
168-
// skip lines until we get to the start of this tag
169-
for scanner.Scan() && line < tag.Line {
170-
line++
171-
}
172-
173-
// read up to 10 lines in search of a closing paren
174-
newcode := scanner.Text()
175-
for scanner.Scan() && line < (tag.Line+10) && strings.Index(newcode, ")") == -1 {
176-
newcode += scanner.Text()
177-
}
178-
179-
// don't bother replacing the code text if we haven't found a closing paren
180-
if strings.Index(newcode, ")") != -1 {
181-
code = removeSpacesAndTabs(newcode)
182-
}
183-
}
184-
}
185-
186-
prototype := removeSpacesAndTabs(tag.Prototype)
187-
prototype = removeTralingSemicolon(prototype)
188-
189-
return strings.Index(code, prototype) == -1
190-
}
191-
192149
func removeTralingSemicolon(s string) string {
193150
return s[0 : len(s)-1]
194151
}

0 commit comments

Comments
 (0)