3030package ctags
3131
3232import (
33- "arduino.cc/builder/types"
3433 "strings"
35- )
36-
37- type CTagsToPrototypes struct {}
38-
39- func (s * CTagsToPrototypes ) Run (ctx * types.Context ) error {
40- tags := ctx .CTagsOfPreprocessedSource
4134
42- lineWhereToInsertPrototypes := findLineWhereToInsertPrototypes (tags )
43- if lineWhereToInsertPrototypes != - 1 {
44- ctx .PrototypesLineWhereToInsert = lineWhereToInsertPrototypes
45- }
35+ "arduino.cc/builder/types"
36+ )
4637
47- ctx . Prototypes = toPrototypes ( tags )
48- return nil
38+ func ( p * CTagsParser ) GeneratePrototypes () ([] * types. Prototype , int ) {
39+ return p . toPrototypes (), p . findLineWhereToInsertPrototypes ()
4940}
5041
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 ()
5445 if firstFunctionLine != - 1 && firstFunctionPointerAsArgument != - 1 {
5546 if firstFunctionLine < firstFunctionPointerAsArgument {
5647 return firstFunctionLine
@@ -64,9 +55,9 @@ func findLineWhereToInsertPrototypes(tags []*types.CTag) int {
6455 }
6556}
6657
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 {
7061 if functionNameUsedAsFunctionPointerIn (tag , functionNames ) {
7162 return tag .Line
7263 }
@@ -83,28 +74,28 @@ func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionNames []string
8374 return false
8475}
8576
86- func collectFunctionNames ( tags [] * types. CTag ) []string {
77+ func ( p * CTagsParser ) collectFunctionNames ( ) []string {
8778 names := []string {}
88- for _ , tag := range tags {
79+ for _ , tag := range p . tags {
8980 if tag .Kind == KIND_FUNCTION {
9081 names = append (names , tag .FunctionName )
9182 }
9283 }
9384 return names
9485}
9586
96- func firstFunctionAtLine ( tags [] * types. CTag ) int {
97- for _ , tag := range tags {
87+ func ( p * CTagsParser ) firstFunctionAtLine ( ) int {
88+ for _ , tag := range p . tags {
9889 if ! tagIsUnknown (tag ) && isHandled (tag ) && tag .Kind == KIND_FUNCTION {
9990 return tag .Line
10091 }
10192 }
10293 return - 1
10394}
10495
105- func toPrototypes ( tags [] * types. CTag ) []* types.Prototype {
96+ func ( p * CTagsParser ) toPrototypes ( ) []* types.Prototype {
10697 prototypes := []* types.Prototype {}
107- for _ , tag := range tags {
98+ for _ , tag := range p . tags {
10899 if strings .TrimSpace (tag .Prototype ) == "" {
109100 continue
110101 }
0 commit comments