3030package ctags
3131
3232import (
33- "arduino.cc/builder/constants"
34- "arduino.cc/builder/types"
3533 "bufio"
3634 "os"
37- "reflect"
38- "runtime"
3935 "strconv"
4036 "strings"
37+
38+ "arduino.cc/builder/types"
4139)
4240
4341const KIND_PROTOTYPE = "prototype"
@@ -54,32 +52,30 @@ var KNOWN_TAG_KINDS = map[string]bool{
5452 "function" : true ,
5553}
5654
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+ }
6158
59+ func (p * CTagsParser ) Parse (ctagsOutput string ) []* types.CTag {
60+ rows := strings .Split (ctagsOutput , "\n " )
6261 rows = removeEmpty (rows )
6362
64- var tags []* types.CTag
6563 for _ , row := range rows {
66- tags = append (tags , parseTag (row ))
64+ p . tags = append (p . tags , parseTag (row ))
6765 }
6866
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 )
7773
78- return nil
74+ return p . tags
7975}
8076
81- func addPrototypes ( tags [] * types. CTag ) {
82- for _ , tag := range tags {
77+ func ( p * CTagsParser ) addPrototypes ( ) {
78+ for _ , tag := range p . tags {
8379 if ! tag .SkipMe {
8480 addPrototype (tag )
8581 }
@@ -108,28 +104,28 @@ func addPrototype(tag *types.CTag) {
108104 tag .PrototypeModifiers = strings .TrimSpace (tag .PrototypeModifiers )
109105}
110106
111- func removeDefinedProtypes ( tags [] * types. CTag , ctx * types. Context ) {
107+ func ( p * CTagsParser ) removeDefinedProtypes ( ) {
112108 definedPrototypes := make (map [string ]bool )
113- for _ , tag := range tags {
109+ for _ , tag := range p . tags {
114110 if tag .Kind == KIND_PROTOTYPE {
115111 definedPrototypes [tag .Prototype ] = true
116112 }
117113 }
118114
119- for _ , tag := range tags {
115+ for _ , tag := range p . tags {
120116 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+ // }
124120 tag .SkipMe = true
125121 }
126122 }
127123}
128124
129- func removeDuplicate ( tags [] * types. CTag ) {
125+ func ( p * CTagsParser ) skipDuplicates ( ) {
130126 definedPrototypes := make (map [string ]bool )
131127
132- for _ , tag := range tags {
128+ for _ , tag := range p . tags {
133129 if ! definedPrototypes [tag .Prototype ] && tag .SkipMe == false {
134130 definedPrototypes [tag .Prototype ] = true
135131 } else {
@@ -140,13 +136,13 @@ func removeDuplicate(tags []*types.CTag) {
140136
141137type skipFuncType func (tag * types.CTag ) bool
142138
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 {
145141 if ! tag .SkipMe {
146142 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+ // }
150146 tag .SkipMe = skip
151147 }
152148 }
0 commit comments