Skip to content

Commit 3cad689

Browse files
committed
Simplify CTag structure
Signed-off-by: Cristian Maglie <[email protected]>
1 parent db653b2 commit 3cad689

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/arduino.cc/builder/ctags_parser.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func addPrototypes(tags []*types.CTag) {
8787
}
8888

8989
func addPrototype(tag *types.CTag) {
90-
if strings.Index(tag.Returntype, TEMPLATE) == 0 || strings.Index(tag.Code, TEMPLATE) == 0 {
90+
if strings.Index(tag.Prototype, TEMPLATE) == 0 || strings.Index(tag.Code, TEMPLATE) == 0 {
9191
code := tag.Code
9292
if strings.Contains(code, "{") {
9393
code = code[:strings.Index(code, "{")]
@@ -98,8 +98,6 @@ func addPrototype(tag *types.CTag) {
9898
return
9999
}
100100

101-
tag.Prototype = tag.Returntype + " " + tag.FunctionName + tag.Signature + ";"
102-
103101
tag.PrototypeModifiers = ""
104102
if strings.Index(tag.Code, STATIC+" ") != -1 {
105103
tag.PrototypeModifiers = tag.PrototypeModifiers + " " + STATIC
@@ -152,7 +150,7 @@ func skipTagsWhere(tags []*types.CTag, skipFunc skipFuncType, context map[string
152150
}
153151

154152
func signatureContainsDefaultArg(tag *types.CTag) bool {
155-
return strings.Contains(tag.Signature, "=")
153+
return strings.Contains(tag.Prototype, "=")
156154
}
157155

158156
func prototypeAndCodeDontMatch(tag *types.CTag) bool {
@@ -207,6 +205,8 @@ func parseTag(row string) *types.CTag {
207205

208206
parts = parts[2:]
209207

208+
signature := ""
209+
returntype := ""
210210
for _, part := range parts {
211211
if strings.Contains(part, ":") {
212212
colon := strings.Index(part, ":")
@@ -222,9 +222,9 @@ func parseTag(row string) *types.CTag {
222222
case "typeref":
223223
tag.Typeref = value
224224
case "signature":
225-
tag.Signature = value
225+
signature = value
226226
case "returntype":
227-
tag.Returntype = value
227+
returntype = value
228228
case "class":
229229
tag.Class = value
230230
case "struct":
@@ -234,6 +234,7 @@ func parseTag(row string) *types.CTag {
234234
}
235235
}
236236
}
237+
tag.Prototype = returntype + " " + tag.FunctionName + signature + ";"
237238

238239
if strings.Contains(row, "/^") && strings.Contains(row, "$/;") {
239240
tag.Code = row[strings.Index(row, "/^")+2 : strings.Index(row, "$/;")]

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ func TestCTagsParserShouldListTemplates(t *testing.T) {
104104
idx := 0
105105
require.Equal(t, "minimum", ctags[idx].FunctionName)
106106
require.Equal(t, "function", ctags[idx].Kind)
107-
require.Equal(t, "(T a, T b)", ctags[idx].Signature)
107+
require.Equal(t, "template <typename T> T minimum (T a, T b);", ctags[idx].Prototype)
108108
idx++
109109
require.Equal(t, "setup", ctags[idx].FunctionName)
110110
require.Equal(t, "function", ctags[idx].Kind)
111+
require.Equal(t, "void setup();", ctags[idx].Prototype)
111112
idx++
112113
require.Equal(t, "loop", ctags[idx].FunctionName)
113114
require.Equal(t, "function", ctags[idx].Kind)
115+
require.Equal(t, "void loop();", ctags[idx].Prototype)
114116
}
115117

116118
func TestCTagsParserShouldListTemplates2(t *testing.T) {
@@ -136,11 +138,11 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) {
136138
idx++
137139
require.Equal(t, "SRAM_writeAnything", ctags[idx].FunctionName)
138140
require.Equal(t, "function", ctags[idx].Kind)
139-
require.Equal(t, "(int ee, const T& value)", ctags[idx].Signature)
141+
require.Equal(t, "template <class T> int SRAM_writeAnything(int ee, const T& value);", ctags[idx].Prototype)
140142
idx++
141143
require.Equal(t, "SRAM_readAnything", ctags[idx].FunctionName)
142144
require.Equal(t, "function", ctags[idx].Kind)
143-
require.Equal(t, "(int ee, T& value)", ctags[idx].Signature)
145+
require.Equal(t, "template <class T> int SRAM_readAnything(int ee, T& value);", ctags[idx].Prototype)
144146
}
145147

146148
func TestCTagsParserShouldDealWithClasses(t *testing.T) {
@@ -355,7 +357,7 @@ func TestCTagsParserDefaultArguments(t *testing.T) {
355357
idx := 0
356358
require.Equal(t, "test", ctags[idx].FunctionName)
357359
require.Equal(t, "function", ctags[idx].Kind)
358-
require.Equal(t, "(int x = 1)", ctags[idx].Signature)
360+
require.Equal(t, "void test(int x = 1);", ctags[idx].Prototype)
359361
idx++
360362
require.Equal(t, "setup", ctags[idx].FunctionName)
361363
require.Equal(t, "function", ctags[idx].Kind)
@@ -469,10 +471,9 @@ func TestCTagsParserFunctionPointers(t *testing.T) {
469471
idx++
470472
require.Equal(t, "funcArr", ctags[idx].FunctionName)
471473
require.Equal(t, "function", ctags[idx].Kind)
472-
require.Equal(t, "()", ctags[idx].Signature)
474+
require.Equal(t, "int funcArr();", ctags[idx].Prototype)
473475
idx++
474476
require.Equal(t, "funcCombo", ctags[idx].FunctionName)
475477
require.Equal(t, "function", ctags[idx].Kind)
476-
require.Equal(t, "(void (*(&in)[5])(int))", ctags[idx].Signature)
477-
478-
}
478+
require.Equal(t, "void funcCombo(void (*(&in)[5])(int));", ctags[idx].Prototype)
479+
}

src/arduino.cc/builder/types/types.go

-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ type CTag struct {
180180
FunctionName string
181181
Kind string
182182
Line int
183-
Signature string
184-
Returntype string
185183
Code string
186184
Class string
187185
Struct string

0 commit comments

Comments
 (0)