@@ -31,8 +31,6 @@ package builder
31
31
32
32
import (
33
33
"arduino.cc/builder/constants"
34
- "arduino.cc/builder/types"
35
- "arduino.cc/builder/utils"
36
34
"strconv"
37
35
"strings"
38
36
)
@@ -42,7 +40,6 @@ const FIELD_LINE = "line"
42
40
const FIELD_SIGNATURE = "signature"
43
41
const FIELD_RETURNTYPE = "returntype"
44
42
const FIELD_CODE = "code"
45
- const FIELD_FUNCTION_NAME = "functionName"
46
43
const FIELD_CLASS = "class"
47
44
const FIELD_STRUCT = "struct"
48
45
const FIELD_NAMESPACE = "namespace"
@@ -61,7 +58,7 @@ var KNOWN_TAG_KINDS = map[string]bool{"prototype": true, "function": true}
61
58
var FIELDS_MARKING_UNHANDLED_TAGS = []string {FIELD_CLASS , FIELD_STRUCT , FIELD_NAMESPACE }
62
59
63
60
type CTagsParser struct {
64
- PrototypesField string
61
+ CTagsField string
65
62
}
66
63
67
64
func (s * CTagsParser ) Run (context map [string ]interface {}) error {
@@ -82,92 +79,11 @@ func (s *CTagsParser) Run(context map[string]interface{}) error {
82
79
removeDuplicate (tags )
83
80
skipTagsWhere (tags , prototypeAndCodeDontMatch )
84
81
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
96
83
97
84
return nil
98
85
}
99
86
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
-
171
87
func addPrototypes (tags []map [string ]string ) {
172
88
for _ , tag := range tags {
173
89
if tag [FIELD_SKIP ] != TRUE {
@@ -188,7 +104,7 @@ func addPrototype(tag map[string]string) {
188
104
return
189
105
}
190
106
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 ] + ";"
192
108
193
109
tag [KIND_PROTOTYPE_MODIFIERS ] = ""
194
110
if strings .Index (tag [FIELD_CODE ], STATIC + " " ) != - 1 {
@@ -289,7 +205,7 @@ func parseTag(row string) map[string]string {
289
205
tag := make (map [string ]string )
290
206
parts := strings .Split (row , "\t " )
291
207
292
- tag [FIELD_FUNCTION_NAME ] = parts [0 ]
208
+ tag [constants . CTAGS_FIELD_FUNCTION_NAME ] = parts [0 ]
293
209
parts = parts [1 :]
294
210
295
211
for _ , part := range parts {
0 commit comments