Skip to content

Commit 539cb7d

Browse files
author
Federico Fissore
committed
Preserving 'static' keyword when generating function prototypes. Fixes #47
Signed-off-by: Federico Fissore <[email protected]>
1 parent 0af3f7f commit 539cb7d

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

Diff for: src/arduino.cc/builder/ctags_parser.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const FIELD_SKIP = "skipMe"
5151
const KIND_PROTOTYPE = "prototype"
5252

5353
const TEMPLATE = "template"
54+
const STATIC = "static"
5455

5556
var FIELDS = map[string]bool{"kind": true, "line": true, "typeref": true, "signature": true, "returntype": true, "class": true, "struct": true, "namespace": true}
5657
var KNOWN_TAG_KINDS = map[string]bool{"prototype": true, "function": true}
@@ -120,8 +121,13 @@ func addPrototype(tag map[string]string) {
120121
code = code[:strings.LastIndex(code, ")")+1]
121122
}
122123
tag[KIND_PROTOTYPE] = code + ";"
123-
} else {
124-
tag[KIND_PROTOTYPE] = tag[FIELD_RETURNTYPE] + " " + tag[FIELD_FUNCTION_NAME] + tag[FIELD_SIGNATURE] + ";"
124+
return
125+
}
126+
127+
tag[KIND_PROTOTYPE] = tag[FIELD_RETURNTYPE] + " " + tag[FIELD_FUNCTION_NAME] + tag[FIELD_SIGNATURE] + ";"
128+
129+
if strings.Index(tag[FIELD_CODE], STATIC+" ") != -1 {
130+
tag[KIND_PROTOTYPE] = STATIC + " " + tag[KIND_PROTOTYPE]
125131
}
126132
}
127133

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
setup /tmp/test542833488/preproc/ctags_target.cpp /^void setup(){}$/;" kind:function line:2 signature:() returntype:void
2+
loop /tmp/test542833488/preproc/ctags_target.cpp /^void loop(){}$/;" kind:function line:3 signature:() returntype:void
3+
doStuff /tmp/test542833488/preproc/ctags_target.cpp /^static void doStuff() {}$/;" kind:function line:4 signature:() returntype:void

Diff for: src/arduino.cc/builder/test/ctags_parser_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,22 @@ 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 TestCTagsParserStatic(t *testing.T) {
248+
context := make(map[string]interface{})
249+
250+
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStatic.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, 3, len(prototypes))
261+
require.Equal(t, "void setup();", prototypes[0].Prototype)
262+
require.Equal(t, "void loop();", prototypes[1].Prototype)
263+
require.Equal(t, "static void doStuff();", prototypes[2].Prototype)
264+
}

Diff for: src/arduino.cc/builder/test/prototypes_adder_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) {
574574
}
575575

576576
require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
577-
require.Equal(t, "void setup();\nvoid loop();\nshort unsigned int testInt();\nint8_t testInline();\nuint8_t testAttribute();\n#line 1\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
577+
require.Equal(t, "void setup();\nvoid loop();\nshort unsigned int testInt();\nstatic int8_t testInline();\nuint8_t testAttribute();\n#line 1\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
578578
}
579579

580580
func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) {

0 commit comments

Comments
 (0)