Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CTagsToPrototypes is now a class-method
Signed-off-by: Cristian Maglie <[email protected]>
  • Loading branch information
cmaglie committed Nov 16, 2016
commit f2cf4bd56debcb33bfb4b5b817d4835f45031d0a
1 change: 0 additions & 1 deletion src/arduino.cc/builder/container_add_prototypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
&CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
&ctags.CTagsRunner{},
&ctags.CTags{},
&ctags.CTagsToPrototypes{},
&PrototypesAdder{},
&SketchSaver{},
}
Expand Down
5 changes: 5 additions & 0 deletions src/arduino.cc/builder/ctags/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ type CTags struct{}
func (c *CTags) Run(ctx *types.Context) error {
parser := &CTagsParser{}
ctx.CTagsOfPreprocessedSource = parser.Parse(ctx.CTagsOutput)
protos, line := parser.GeneratePrototypes()
if line != -1 {
ctx.PrototypesLineWhereToInsert = line
}
ctx.Prototypes = protos
return nil
}
41 changes: 16 additions & 25 deletions src/arduino.cc/builder/ctags/ctags_to_prototypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,18 @@
package ctags

import (
"arduino.cc/builder/types"
"strings"
)

type CTagsToPrototypes struct{}

func (s *CTagsToPrototypes) Run(ctx *types.Context) error {
tags := ctx.CTagsOfPreprocessedSource

lineWhereToInsertPrototypes := findLineWhereToInsertPrototypes(tags)
if lineWhereToInsertPrototypes != -1 {
ctx.PrototypesLineWhereToInsert = lineWhereToInsertPrototypes
}
"arduino.cc/builder/types"
)

ctx.Prototypes = toPrototypes(tags)
return nil
func (p *CTagsParser) GeneratePrototypes() ([]*types.Prototype, int) {
return p.toPrototypes(), p.findLineWhereToInsertPrototypes()
}

func findLineWhereToInsertPrototypes(tags []*types.CTag) int {
firstFunctionLine := firstFunctionAtLine(tags)
firstFunctionPointerAsArgument := firstFunctionPointerUsedAsArgument(tags)
func (p *CTagsParser) findLineWhereToInsertPrototypes() int {
firstFunctionLine := p.firstFunctionAtLine()
firstFunctionPointerAsArgument := p.firstFunctionPointerUsedAsArgument()
if firstFunctionLine != -1 && firstFunctionPointerAsArgument != -1 {
if firstFunctionLine < firstFunctionPointerAsArgument {
return firstFunctionLine
Expand All @@ -64,9 +55,9 @@ func findLineWhereToInsertPrototypes(tags []*types.CTag) int {
}
}

func firstFunctionPointerUsedAsArgument(tags []*types.CTag) int {
functionNames := collectFunctionNames(tags)
for _, tag := range tags {
func (p *CTagsParser) firstFunctionPointerUsedAsArgument() int {
functionNames := p.collectFunctionNames()
for _, tag := range p.tags {
if functionNameUsedAsFunctionPointerIn(tag, functionNames) {
return tag.Line
}
Expand All @@ -83,28 +74,28 @@ func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionNames []string
return false
}

func collectFunctionNames(tags []*types.CTag) []string {
func (p *CTagsParser) collectFunctionNames() []string {
names := []string{}
for _, tag := range tags {
for _, tag := range p.tags {
if tag.Kind == KIND_FUNCTION {
names = append(names, tag.FunctionName)
}
}
return names
}

func firstFunctionAtLine(tags []*types.CTag) int {
for _, tag := range tags {
func (p *CTagsParser) firstFunctionAtLine() int {
for _, tag := range p.tags {
if !tagIsUnknown(tag) && isHandled(tag) && tag.Kind == KIND_FUNCTION {
return tag.Line
}
}
return -1
}

func toPrototypes(tags []*types.CTag) []*types.Prototype {
func (p *CTagsParser) toPrototypes() []*types.Prototype {
prototypes := []*types.Prototype{}
for _, tag := range tags {
for _, tag := range p.tags {
if strings.TrimSpace(tag.Prototype) == "" {
continue
}
Expand Down
Loading