Skip to content

Commit 0379be0

Browse files
author
Federico Fissore
committed
Making CTagsParser aware of functions in struct, and filtering them out.
Also moving all ctags test outputs in separate files, for easier maintenance Fixes #5 Signed-off-by: Federico Fissore <[email protected]>
1 parent 08890f7 commit 0379be0

11 files changed

+105
-42
lines changed

src/arduino.cc/builder/ctags_parser.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ const FIELD_RETURNTYPE = "returntype"
4343
const FIELD_CODE = "code"
4444
const FIELD_FUNCTION_NAME = "functionName"
4545
const FIELD_CLASS = "class"
46+
const FIELD_STRUCT = "struct"
4647

4748
const KIND_PROTOTYPE = "prototype"
4849

4950
const TEMPLATE = "template"
5051

51-
var FIELDS = map[string]bool{"kind": true, "line": true, "typeref": true, "signature": true, "returntype": true, "class": true}
52+
var FIELDS = map[string]bool{"kind": true, "line": true, "typeref": true, "signature": true, "returntype": true, "class": true, "struct": true}
5253
var KNOWN_TAG_KINDS = map[string]bool{"prototype": true, "function": true}
5354

5455
type CTagsParser struct {
@@ -66,7 +67,8 @@ func (s *CTagsParser) Run(context map[string]interface{}) error {
6667
}
6768

6869
tags = filterOutUnknownTags(tags)
69-
tags = filterOutTagsWithClass(tags)
70+
tags = filterOutTagsWithField(tags, FIELD_CLASS)
71+
tags = filterOutTagsWithField(tags, FIELD_STRUCT)
7072
tags = addPrototypes(tags)
7173
tags = removeDefinedProtypes(tags)
7274
tags = removeDuplicate(tags)
@@ -140,10 +142,10 @@ func removeDuplicate(tags []map[string]string) []map[string]string {
140142
return newTags
141143
}
142144

143-
func filterOutTagsWithClass(tags []map[string]string) []map[string]string {
145+
func filterOutTagsWithField(tags []map[string]string, field string) []map[string]string {
144146
var newTags []map[string]string
145147
for _, tag := range tags {
146-
if tag[FIELD_CLASS] == constants.EMPTY_STRING {
148+
if tag[field] == constants.EMPTY_STRING {
147149
newTags = append(newTags, tag)
148150
}
149151
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set_values /tmp/test834438754/preproc/ctags_target.cpp /^ void set_values (int,int);$/;" kind:prototype line:5 class:Rectangle signature:(int,int) returntype:void
2+
area /tmp/test834438754/preproc/ctags_target.cpp /^ int area() {return width*height;}$/;" kind:function line:6 class:Rectangle signature:() returntype:int
3+
set_values /tmp/test834438754/preproc/ctags_target.cpp /^void Rectangle::set_values (int x, int y) {$/;" kind:function line:9 class:Rectangle signature:(int x, int y) returntype:void
4+
setup /tmp/test834438754/preproc/ctags_target.cpp /^void setup() {$/;" kind:function line:14 signature:() returntype:void
5+
loop /tmp/test834438754/preproc/ctags_target.cpp /^void loop() {$/;" kind:function line:18 signature:() returntype:void
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
getBytes /tmp/test260613593/preproc/ctags_target.cpp /^ void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;$/;" kind:prototype line:4330 signature:(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const returntype:void
2+
getBytes /tmp/test260613593/preproc/ctags_target.cpp /^boolean getBytes( byte addr, int amount ) // updates the byte array "received" with the given amount of bytes, read from the given address$/;" kind:function line:5031 signature:( byte addr, int amount ) returntype:boolean
3+
getBytes /tmp/test260613593/preproc/ctags_target.cpp /^boolean getBytes( byte addr, int amount ) // updates the byte array "received" with the given amount of bytes, read from the given address$/;" kind:function line:214 signature:( byte addr, int amount ) returntype:boolean
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SleepCycle /tmp/sketch9043227824785312266.cpp /^ SleepCycle( const char* name );$/;" kind:prototype line:4 signature:( const char* name )
2+
SleepCycle /tmp/sketch9043227824785312266.cpp /^ SleepCycle::SleepCycle( const char* name )$/;" kind:function line:8 signature:( const char* name )
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DEBUG /tmp/sketch5976699731718729500.cpp 1;" kind:macro line:1
2+
DISABLED /tmp/sketch5976699731718729500.cpp 2;" kind:macro line:2
3+
hello /tmp/sketch5976699731718729500.cpp /^String hello = "world!";$/;" kind:variable line:16
4+
setup /tmp/sketch5976699731718729500.cpp /^void setup() {$/;" kind:function line:18 signature:() returntype:void
5+
loop /tmp/sketch5976699731718729500.cpp /^void loop() {$/;" kind:function line:23 signature:() returntype:void
6+
debug /tmp/sketch5976699731718729500.cpp /^void debug() {$/;" kind:function line:35 signature:() returntype:void
7+
disabledIsDefined /tmp/sketch5976699731718729500.cpp /^void disabledIsDefined() {$/;" kind:function line:46 signature:() returntype:void
8+
useMyType /tmp/sketch5976699731718729500.cpp /^int useMyType(MyType type) {$/;" kind:function line:50 signature:(MyType type) returntype:int
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
A_NEW_TYPE /tmp/sketch8930345717354294915.cpp /^struct A_NEW_TYPE {$/;" kind:struct line:3
2+
foo /tmp/sketch8930345717354294915.cpp /^} foo;$/;" kind:variable line:7 typeref:struct:A_NEW_TYPE
3+
setup /tmp/sketch8930345717354294915.cpp /^void setup() {$/;" kind:function line:9 signature:() returntype:void
4+
loop /tmp/sketch8930345717354294915.cpp /^void loop() {$/;" kind:function line:13 signature:() returntype:void
5+
dostuff /tmp/sketch8930345717354294915.cpp /^void dostuff (A_NEW_TYPE * bar)$/;" kind:function line:17 signature:(A_NEW_TYPE * bar) returntype:void
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
server /tmp/sketch7210316334309249705.cpp /^YunServer server;$/;" kind:variable line:31
2+
setup /tmp/sketch7210316334309249705.cpp /^void setup() {$/;" kind:function line:33 signature:() returntype:void
3+
loop /tmp/sketch7210316334309249705.cpp /^void loop() {$/;" kind:function line:46 signature:() returntype:void
4+
process /tmp/sketch7210316334309249705.cpp /^void process(YunClient client);$/;" kind:prototype line:61 signature:(YunClient client) returntype:void
5+
process /tmp/sketch7210316334309249705.cpp /^void process(YunClient client) {$/;" kind:function line:62 signature:(YunClient client) returntype:void
6+
digitalCommand /tmp/sketch7210316334309249705.cpp /^void digitalCommand(YunClient client) {$/;" kind:function line:82 signature:(YunClient client) returntype:void
7+
analogCommand /tmp/sketch7210316334309249705.cpp /^void analogCommand(YunClient client) {$/;" kind:function line:110 signature:(YunClient client) returntype:void
8+
modeCommand /tmp/sketch7210316334309249705.cpp /^void modeCommand(YunClient client) {$/;" kind:function line:151 signature:(YunClient client) returntype:void
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minimum /tmp/sketch8398023134925534708.cpp /^template <typename T> T minimum (T a, T b) $/;" kind:function line:2 signature:(T a, T b) returntype:templateT
2+
setup /tmp/sketch8398023134925534708.cpp /^void setup () $/;" kind:function line:9 signature:() returntype:void
3+
loop /tmp/sketch8398023134925534708.cpp /^void loop () { }$/;" kind:function line:13 signature:() returntype:void
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
setup /tmp/sketch463160524247569568.cpp /^void setup() {$/;" kind:function line:1 signature:() returntype:void
2+
loop /tmp/sketch463160524247569568.cpp /^void loop() {$/;" kind:function line:6 signature:() returntype:void
3+
SRAM_writeAnything /tmp/sketch463160524247569568.cpp /^template <class T> int SRAM_writeAnything(int ee, const T& value)$/;" kind:function line:11 signature:(int ee, const T& value) returntype:template int
4+
SRAM_readAnything /tmp/sketch463160524247569568.cpp /^template <class T> int SRAM_readAnything(int ee, T& value)$/;" kind:function line:21 signature:(int ee, T& value) returntype:template int
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sensorData /tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp /^struct sensorData {$/;" kind:struct line:2
2+
sensorData /tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp /^ sensorData(int iStatus, float iTemp, float iMinTemp) : status(iStatus), temp(iTemp), minTemp(iMinTemp) {}$/;" kind:function line:3 struct:sensorData signature:(int iStatus, float iTemp, float iMinTemp)
3+
sensorData /tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp /^ sensorData() : status(-1), temp(1023.0), minTemp(1023.0) {}$/;" kind:function line:4 struct:sensorData signature:()
4+
sensors /tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp /^sensorData sensors[2];$/;" kind:variable line:10
5+
sensor1 /tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp /^sensorData sensor1; \/\/(-1,1023.0,1023.0);$/;" kind:variable line:12
6+
sensor2 /tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp /^sensorData sensor2; \/\/(-1,1023.0,1023.0);$/;" kind:variable line:13
7+
setup /tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp /^void setup() {$/;" kind:function line:16 signature:() returntype:void
8+
loop /tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp /^void loop() {$/;" kind:function line:22 signature:() returntype:void

0 commit comments

Comments
 (0)