@@ -31,8 +31,6 @@ package builder
3131
3232import (
3333 "arduino.cc/builder/constants"
34- "arduino.cc/builder/types"
35- "arduino.cc/builder/utils"
3634 "strconv"
3735 "strings"
3836)
@@ -42,7 +40,6 @@ const FIELD_LINE = "line"
4240const FIELD_SIGNATURE = "signature"
4341const FIELD_RETURNTYPE = "returntype"
4442const FIELD_CODE = "code"
45- const FIELD_FUNCTION_NAME = "functionName"
4643const FIELD_CLASS = "class"
4744const FIELD_STRUCT = "struct"
4845const FIELD_NAMESPACE = "namespace"
@@ -61,7 +58,7 @@ var KNOWN_TAG_KINDS = map[string]bool{"prototype": true, "function": true}
6158var FIELDS_MARKING_UNHANDLED_TAGS = []string {FIELD_CLASS , FIELD_STRUCT , FIELD_NAMESPACE }
6259
6360type CTagsParser struct {
64- PrototypesField string
61+ CTagsField string
6562}
6663
6764func (s * CTagsParser ) Run (context map [string ]interface {}) error {
@@ -82,92 +79,11 @@ func (s *CTagsParser) Run(context map[string]interface{}) error {
8279 removeDuplicate (tags )
8380 skipTagsWhere (tags , prototypeAndCodeDontMatch )
8481
85- lineWhereToInsertPrototypes , err := findLineWhereToInsertPrototypes (tags )
86- if err != nil {
87- return utils .WrapError (err )
88- }
89- if lineWhereToInsertPrototypes != - 1 {
90- context [constants .CTX_LINE_WHERE_TO_INSERT_PROTOTYPES ] = lineWhereToInsertPrototypes
91- }
92-
93- prototypes := toPrototypes (tags )
94-
95- context [s .PrototypesField ] = prototypes
82+ context [s .CTagsField ] = tags
9683
9784 return nil
9885}
9986
100- func findLineWhereToInsertPrototypes (tags []map [string ]string ) (int , error ) {
101- firstFunctionLine , err := firstFunctionAtLine (tags )
102- if err != nil {
103- return - 1 , utils .WrapError (err )
104- }
105- firstFunctionPointerAsArgument , err := firstFunctionPointerUsedAsArgument (tags )
106- if err != nil {
107- return - 1 , utils .WrapError (err )
108- }
109- if firstFunctionLine != - 1 && firstFunctionPointerAsArgument != - 1 {
110- if firstFunctionLine < firstFunctionPointerAsArgument {
111- return firstFunctionLine , nil
112- } else {
113- return firstFunctionPointerAsArgument , nil
114- }
115- } else if firstFunctionLine == - 1 {
116- return firstFunctionPointerAsArgument , nil
117- } else {
118- return firstFunctionLine , nil
119- }
120- }
121-
122- func firstFunctionPointerUsedAsArgument (tags []map [string ]string ) (int , error ) {
123- functionNames := collectFunctionNames (tags )
124- for _ , tag := range tags {
125- if functionNameUsedAsFunctionPointerIn (tag , functionNames ) {
126- return strconv .Atoi (tag [FIELD_LINE ])
127- }
128- }
129- return - 1 , nil
130- }
131-
132- func functionNameUsedAsFunctionPointerIn (tag map [string ]string , functionNames []string ) bool {
133- for _ , functionName := range functionNames {
134- if strings .Index (tag [FIELD_CODE ], "&" + functionName ) != - 1 {
135- return true
136- }
137- }
138- return false
139- }
140-
141- func collectFunctionNames (tags []map [string ]string ) []string {
142- names := []string {}
143- for _ , tag := range tags {
144- if tag [FIELD_KIND ] == KIND_FUNCTION {
145- names = append (names , tag [FIELD_FUNCTION_NAME ])
146- }
147- }
148- return names
149- }
150-
151- func firstFunctionAtLine (tags []map [string ]string ) (int , error ) {
152- for _ , tag := range tags {
153- if ! tagIsUnknown (tag ) && ! tagHasAtLeastOneField (tag , FIELDS_MARKING_UNHANDLED_TAGS ) && tag [FIELD_KIND ] == KIND_FUNCTION {
154- return strconv .Atoi (tag [FIELD_LINE ])
155- }
156- }
157- return - 1 , nil
158- }
159-
160- func toPrototypes (tags []map [string ]string ) []* types.Prototype {
161- prototypes := []* types.Prototype {}
162- for _ , tag := range tags {
163- if tag [FIELD_SKIP ] != TRUE {
164- ctag := types.Prototype {FunctionName : tag [FIELD_FUNCTION_NAME ], Prototype : tag [KIND_PROTOTYPE ], Modifiers : tag [KIND_PROTOTYPE_MODIFIERS ], Fields : tag }
165- prototypes = append (prototypes , & ctag )
166- }
167- }
168- return prototypes
169- }
170-
17187func addPrototypes (tags []map [string ]string ) {
17288 for _ , tag := range tags {
17389 if tag [FIELD_SKIP ] != TRUE {
@@ -188,7 +104,7 @@ func addPrototype(tag map[string]string) {
188104 return
189105 }
190106
191- tag [KIND_PROTOTYPE ] = tag [FIELD_RETURNTYPE ] + " " + tag [FIELD_FUNCTION_NAME ] + tag [FIELD_SIGNATURE ] + ";"
107+ tag [KIND_PROTOTYPE ] = tag [FIELD_RETURNTYPE ] + " " + tag [constants . CTAGS_FIELD_FUNCTION_NAME ] + tag [FIELD_SIGNATURE ] + ";"
192108
193109 tag [KIND_PROTOTYPE_MODIFIERS ] = ""
194110 if strings .Index (tag [FIELD_CODE ], STATIC + " " ) != - 1 {
@@ -289,7 +205,7 @@ func parseTag(row string) map[string]string {
289205 tag := make (map [string ]string )
290206 parts := strings .Split (row , "\t " )
291207
292- tag [FIELD_FUNCTION_NAME ] = parts [0 ]
208+ tag [constants . CTAGS_FIELD_FUNCTION_NAME ] = parts [0 ]
293209 parts = parts [1 :]
294210
295211 for _ , part := range parts {
0 commit comments