Skip to content

Commit bfe2e9c

Browse files
author
Federico Fissore
committed
Collecting prototype modifiers in Modifiers struct key
Signed-off-by: Federico Fissore <[email protected]>
1 parent 70099c8 commit bfe2e9c

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/arduino.cc/builder/ctags_parser.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const FIELD_NAMESPACE = "namespace"
4949
const FIELD_SKIP = "skipMe"
5050

5151
const KIND_PROTOTYPE = "prototype"
52+
const KIND_PROTOTYPE_MODIFIERS = "prototype_modifiers"
5253

5354
const TEMPLATE = "template"
5455
const STATIC = "static"
@@ -98,7 +99,7 @@ func toPrototypes(tags []map[string]string) []*types.Prototype {
9899
prototypes := []*types.Prototype{}
99100
for _, tag := range tags {
100101
if tag[FIELD_SKIP] != "true" {
101-
ctag := types.Prototype{FunctionName: tag[FIELD_FUNCTION_NAME], Prototype: tag[KIND_PROTOTYPE], Fields: tag}
102+
ctag := types.Prototype{FunctionName: tag[FIELD_FUNCTION_NAME], Prototype: tag[KIND_PROTOTYPE], Modifiers: tag[KIND_PROTOTYPE_MODIFIERS], Fields: tag}
102103
prototypes = append(prototypes, &ctag)
103104
}
104105
}
@@ -126,9 +127,11 @@ func addPrototype(tag map[string]string) {
126127

127128
tag[KIND_PROTOTYPE] = tag[FIELD_RETURNTYPE] + " " + tag[FIELD_FUNCTION_NAME] + tag[FIELD_SIGNATURE] + ";"
128129

130+
tag[KIND_PROTOTYPE_MODIFIERS] = ""
129131
if strings.Index(tag[FIELD_CODE], STATIC+" ") != -1 {
130-
tag[KIND_PROTOTYPE] = STATIC + " " + tag[KIND_PROTOTYPE]
132+
tag[KIND_PROTOTYPE_MODIFIERS] = tag[KIND_PROTOTYPE_MODIFIERS] + " " + STATIC
131133
}
134+
tag[KIND_PROTOTYPE_MODIFIERS] = strings.TrimSpace(tag[KIND_PROTOTYPE_MODIFIERS])
132135
}
133136

134137
func removeDefinedProtypes(tags []map[string]string) []map[string]string {

src/arduino.cc/builder/prototypes_adder.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,24 @@ func composePrototypeSection(line int, prototypes []*types.Prototype) string {
7575
}
7676

7777
str := joinPrototypes(prototypes)
78-
str += "#line "
78+
str += "\n#line "
7979
str += strconv.Itoa(line)
8080
str += "\n"
8181

8282
return str
8383
}
8484

8585
func joinPrototypes(prototypes []*types.Prototype) string {
86-
join := ""
86+
prototypesSlice := []string{}
8787
for _, proto := range prototypes {
88-
join = join + proto.Prototype + "\n"
88+
prototypeParts := []string{}
89+
if proto.Modifiers != "" {
90+
prototypeParts = append(prototypeParts, proto.Modifiers)
91+
}
92+
prototypeParts = append(prototypeParts, proto.Prototype)
93+
prototypesSlice = append(prototypesSlice, strings.Join(prototypeParts, " "))
8994
}
90-
return join
95+
return strings.Join(prototypesSlice, "\n")
9196
}
9297

9398
func composeIncludeArduinoSection() string {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,5 +260,6 @@ func TestCTagsParserStatic(t *testing.T) {
260260
require.Equal(t, 3, len(prototypes))
261261
require.Equal(t, "void setup();", prototypes[0].Prototype)
262262
require.Equal(t, "void loop();", prototypes[1].Prototype)
263-
require.Equal(t, "static void doStuff();", prototypes[2].Prototype)
263+
require.Equal(t, "void doStuff();", prototypes[2].Prototype)
264+
require.Equal(t, "static", prototypes[2].Modifiers)
264265
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ type Command interface {
154154
type Prototype struct {
155155
FunctionName string
156156
Prototype string
157+
Modifiers string
157158
Fields map[string]string
158159
}
159160

0 commit comments

Comments
 (0)