30
30
package ctags
31
31
32
32
import (
33
- "arduino.cc/builder/constants"
34
- "arduino.cc/builder/types"
35
33
"bufio"
36
34
"os"
37
- "reflect"
38
- "runtime"
39
35
"strconv"
40
36
"strings"
37
+
38
+ "arduino.cc/builder/types"
41
39
)
42
40
43
41
const KIND_PROTOTYPE = "prototype"
@@ -54,32 +52,30 @@ var KNOWN_TAG_KINDS = map[string]bool{
54
52
"function" : true ,
55
53
}
56
54
57
- type CTagsParser struct {}
58
-
59
- func (s * CTagsParser ) Run (ctx * types.Context ) error {
60
- rows := strings .Split (ctx .CTagsOutput , "\n " )
55
+ type CTagsParser struct {
56
+ tags []* types.CTag
57
+ }
61
58
59
+ func (p * CTagsParser ) Parse (ctagsOutput string ) []* types.CTag {
60
+ rows := strings .Split (ctagsOutput , "\n " )
62
61
rows = removeEmpty (rows )
63
62
64
- var tags []* types.CTag
65
63
for _ , row := range rows {
66
- tags = append (tags , parseTag (row ))
64
+ p . tags = append (p . tags , parseTag (row ))
67
65
}
68
66
69
- skipTagsWhere (tags , tagIsUnknown , ctx )
70
- skipTagsWhere (tags , tagIsUnhandled , ctx )
71
- addPrototypes (tags )
72
- removeDefinedProtypes (tags , ctx )
73
- removeDuplicate (tags )
74
- skipTagsWhere (tags , prototypeAndCodeDontMatch , ctx )
75
-
76
- ctx .CTagsOfPreprocessedSource = tags
67
+ p .skipTagsWhere (tagIsUnknown )
68
+ p .skipTagsWhere (tagIsUnhandled )
69
+ p .addPrototypes ()
70
+ p .removeDefinedProtypes ()
71
+ p .skipDuplicates ()
72
+ p .skipTagsWhere (prototypeAndCodeDontMatch )
77
73
78
- return nil
74
+ return p . tags
79
75
}
80
76
81
- func addPrototypes ( tags [] * types. CTag ) {
82
- for _ , tag := range tags {
77
+ func ( p * CTagsParser ) addPrototypes ( ) {
78
+ for _ , tag := range p . tags {
83
79
if ! tag .SkipMe {
84
80
addPrototype (tag )
85
81
}
@@ -108,28 +104,28 @@ func addPrototype(tag *types.CTag) {
108
104
tag .PrototypeModifiers = strings .TrimSpace (tag .PrototypeModifiers )
109
105
}
110
106
111
- func removeDefinedProtypes ( tags [] * types. CTag , ctx * types. Context ) {
107
+ func ( p * CTagsParser ) removeDefinedProtypes ( ) {
112
108
definedPrototypes := make (map [string ]bool )
113
- for _ , tag := range tags {
109
+ for _ , tag := range p . tags {
114
110
if tag .Kind == KIND_PROTOTYPE {
115
111
definedPrototypes [tag .Prototype ] = true
116
112
}
117
113
}
118
114
119
- for _ , tag := range tags {
115
+ for _ , tag := range p . tags {
120
116
if definedPrototypes [tag .Prototype ] {
121
- if ctx .DebugLevel >= 10 {
122
- ctx .GetLogger ().Fprintln (os .Stdout , constants .LOG_LEVEL_DEBUG , constants .MSG_SKIPPING_TAG_ALREADY_DEFINED , tag .FunctionName )
123
- }
117
+ // if ctx.DebugLevel >= 10 {
118
+ // ctx.GetLogger().Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_ALREADY_DEFINED, tag.FunctionName)
119
+ // }
124
120
tag .SkipMe = true
125
121
}
126
122
}
127
123
}
128
124
129
- func removeDuplicate ( tags [] * types. CTag ) {
125
+ func ( p * CTagsParser ) skipDuplicates ( ) {
130
126
definedPrototypes := make (map [string ]bool )
131
127
132
- for _ , tag := range tags {
128
+ for _ , tag := range p . tags {
133
129
if ! definedPrototypes [tag .Prototype ] && tag .SkipMe == false {
134
130
definedPrototypes [tag .Prototype ] = true
135
131
} else {
@@ -140,13 +136,13 @@ func removeDuplicate(tags []*types.CTag) {
140
136
141
137
type skipFuncType func (tag * types.CTag ) bool
142
138
143
- func skipTagsWhere ( tags [] * types. CTag , skipFunc skipFuncType , ctx * types. Context ) {
144
- for _ , tag := range tags {
139
+ func ( p * CTagsParser ) skipTagsWhere ( skipFunc skipFuncType ) {
140
+ for _ , tag := range p . tags {
145
141
if ! tag .SkipMe {
146
142
skip := skipFunc (tag )
147
- if skip && ctx . DebugLevel >= 10 {
148
- ctx .GetLogger ().Fprintln (os .Stdout , constants .LOG_LEVEL_DEBUG , constants .MSG_SKIPPING_TAG_WITH_REASON , tag .FunctionName , runtime .FuncForPC (reflect .ValueOf (skipFunc ).Pointer ()).Name ())
149
- }
143
+ // if skip && p.debugLevel >= 10 {
144
+ // ctx.GetLogger().Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_WITH_REASON, tag.FunctionName, runtime.FuncForPC(reflect.ValueOf(skipFunc).Pointer()).Name())
145
+ // }
150
146
tag .SkipMe = skip
151
147
}
152
148
}
0 commit comments