30
30
package ctags
31
31
32
32
import (
33
- "arduino.cc/builder/types"
34
33
"strings"
35
- )
36
-
37
- type CTagsToPrototypes struct {}
38
-
39
- func (s * CTagsToPrototypes ) Run (ctx * types.Context ) error {
40
- tags := ctx .CTagsOfPreprocessedSource
41
34
42
- lineWhereToInsertPrototypes := findLineWhereToInsertPrototypes (tags )
43
- if lineWhereToInsertPrototypes != - 1 {
44
- ctx .PrototypesLineWhereToInsert = lineWhereToInsertPrototypes
45
- }
35
+ "arduino.cc/builder/types"
36
+ )
46
37
47
- ctx . Prototypes = toPrototypes ( tags )
48
- return nil
38
+ func ( p * CTagsParser ) GeneratePrototypes () ([] * types. Prototype , int ) {
39
+ return p . toPrototypes (), p . findLineWhereToInsertPrototypes ()
49
40
}
50
41
51
- func findLineWhereToInsertPrototypes ( tags [] * types. CTag ) int {
52
- firstFunctionLine := firstFunctionAtLine (tags )
53
- firstFunctionPointerAsArgument := firstFunctionPointerUsedAsArgument (tags )
42
+ func ( p * CTagsParser ) findLineWhereToInsertPrototypes ( ) int {
43
+ firstFunctionLine := p . firstFunctionAtLine ()
44
+ firstFunctionPointerAsArgument := p . firstFunctionPointerUsedAsArgument ()
54
45
if firstFunctionLine != - 1 && firstFunctionPointerAsArgument != - 1 {
55
46
if firstFunctionLine < firstFunctionPointerAsArgument {
56
47
return firstFunctionLine
@@ -64,9 +55,9 @@ func findLineWhereToInsertPrototypes(tags []*types.CTag) int {
64
55
}
65
56
}
66
57
67
- func firstFunctionPointerUsedAsArgument ( tags [] * types. CTag ) int {
68
- functionNames := collectFunctionNames (tags )
69
- for _ , tag := range tags {
58
+ func ( p * CTagsParser ) firstFunctionPointerUsedAsArgument ( ) int {
59
+ functionNames := p . collectFunctionNames ()
60
+ for _ , tag := range p . tags {
70
61
if functionNameUsedAsFunctionPointerIn (tag , functionNames ) {
71
62
return tag .Line
72
63
}
@@ -83,28 +74,28 @@ func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionNames []string
83
74
return false
84
75
}
85
76
86
- func collectFunctionNames ( tags [] * types. CTag ) []string {
77
+ func ( p * CTagsParser ) collectFunctionNames ( ) []string {
87
78
names := []string {}
88
- for _ , tag := range tags {
79
+ for _ , tag := range p . tags {
89
80
if tag .Kind == KIND_FUNCTION {
90
81
names = append (names , tag .FunctionName )
91
82
}
92
83
}
93
84
return names
94
85
}
95
86
96
- func firstFunctionAtLine ( tags [] * types. CTag ) int {
97
- for _ , tag := range tags {
87
+ func ( p * CTagsParser ) firstFunctionAtLine ( ) int {
88
+ for _ , tag := range p . tags {
98
89
if ! tagIsUnknown (tag ) && isHandled (tag ) && tag .Kind == KIND_FUNCTION {
99
90
return tag .Line
100
91
}
101
92
}
102
93
return - 1
103
94
}
104
95
105
- func toPrototypes ( tags [] * types. CTag ) []* types.Prototype {
96
+ func ( p * CTagsParser ) toPrototypes ( ) []* types.Prototype {
106
97
prototypes := []* types.Prototype {}
107
- for _ , tag := range tags {
98
+ for _ , tag := range p . tags {
108
99
if strings .TrimSpace (tag .Prototype ) == "" {
109
100
continue
110
101
}
0 commit comments