Skip to content

Commit 9f371d2

Browse files
author
Federico Fissore
committed
Comparing prototypes with original functions. If they don't match,
prototype is skipped Signed-off-by: Federico Fissore <f.fissore@arduino.cc>
1 parent 0af3f7f commit 9f371d2

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/arduino.cc/builder/ctags_parser.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (s *CTagsParser) Run(context map[string]interface{}) error {
7777
tags = addPrototypes(tags)
7878
tags = removeDefinedProtypes(tags)
7979
tags = removeDuplicate(tags)
80+
tags = skipTagsWhere(tags, prototypeAndCodeDontMatch)
8081

8182
if len(tags) > 0 {
8283
line, err := strconv.Atoi(tags[0][FIELD_LINE])
@@ -172,6 +173,24 @@ func signatureContainsDefaultArg(tag map[string]string) bool {
172173
return strings.Contains(tag[FIELD_SIGNATURE], "=")
173174
}
174175

176+
func prototypeAndCodeDontMatch(tag map[string]string) bool {
177+
if tag[FIELD_SKIP] == "true" {
178+
return true
179+
}
180+
181+
code := removeSpacesAndTabs(tag[FIELD_CODE])
182+
prototype := removeSpacesAndTabs(tag[KIND_PROTOTYPE])
183+
prototype = prototype[0 : len(prototype)-1]
184+
185+
return strings.Index(code, prototype) == -1
186+
}
187+
188+
func removeSpacesAndTabs(s string) string {
189+
s = strings.Replace(s, " ", "", -1)
190+
s = strings.Replace(s, "\t", "", -1)
191+
return s
192+
}
193+
175194
func filterOutTagsWithField(tags []map[string]string, field string) []map[string]string {
176195
var newTags []map[string]string
177196
for _, tag := range tags {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
setup /tmp/test907446433/preproc/ctags_target.cpp /^void setup(){$/;" kind:function line:2 signature:() returntype:void
2+
loop /tmp/test907446433/preproc/ctags_target.cpp /^void loop(){}$/;" kind:function line:5 signature:() returntype:void
3+
func /tmp/test907446433/preproc/ctags_target.cpp /^void (*func())(){$/;" kind:function line:7 signature:() returntype:void
4+
funcArr /tmp/test907446433/preproc/ctags_target.cpp /^int (&funcArr())[5]{$/;" kind:function line:11 signature:() returntype:int
5+
funcCombo /tmp/test907446433/preproc/ctags_target.cpp /^void (*(&funcCombo(void (*(&in)[5])(int)))[5])(int){$/;" kind:function line:15 signature:(void (*(&in)[5])(int)) returntype:void

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,21 @@ func TestCTagsParserNamespace(t *testing.T) {
243243
require.Equal(t, "void setup();", prototypes[0].Prototype)
244244
require.Equal(t, "void loop();", prototypes[1].Prototype)
245245
}
246+
247+
func TestCTagsParserFunctionPointers(t *testing.T) {
248+
context := make(map[string]interface{})
249+
250+
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointers.txt"))
251+
NoError(t, err)
252+
253+
context[constants.CTX_CTAGS_OUTPUT] = string(bytes)
254+
255+
ctagsParser := builder.CTagsParser{PrototypesField: constants.CTX_PROTOTYPES}
256+
ctagsParser.Run(context)
257+
258+
prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype)
259+
260+
require.Equal(t, 2, len(prototypes))
261+
require.Equal(t, "void setup();", prototypes[0].Prototype)
262+
require.Equal(t, "void loop();", prototypes[1].Prototype)
263+
}

0 commit comments

Comments
 (0)