Skip to content

Commit f2cf4bd

Browse files
committed
CTagsToPrototypes is now a class-method
Signed-off-by: Cristian Maglie <[email protected]>
1 parent 9a7ee4a commit f2cf4bd

File tree

4 files changed

+56
-292
lines changed

4 files changed

+56
-292
lines changed

src/arduino.cc/builder/container_add_prototypes.go

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
4949
&CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
5050
&ctags.CTagsRunner{},
5151
&ctags.CTags{},
52-
&ctags.CTagsToPrototypes{},
5352
&PrototypesAdder{},
5453
&SketchSaver{},
5554
}

src/arduino.cc/builder/ctags/command.go

+5
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ type CTags struct{}
77
func (c *CTags) Run(ctx *types.Context) error {
88
parser := &CTagsParser{}
99
ctx.CTagsOfPreprocessedSource = parser.Parse(ctx.CTagsOutput)
10+
protos, line := parser.GeneratePrototypes()
11+
if line != -1 {
12+
ctx.PrototypesLineWhereToInsert = line
13+
}
14+
ctx.Prototypes = protos
1015
return nil
1116
}

src/arduino.cc/builder/ctags/ctags_to_prototypes.go

+16-25
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,18 @@
3030
package ctags
3131

3232
import (
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

Comments
 (0)