Skip to content

Commit d0af3bc

Browse files
committed
Reduced public API surface of CTags parser
1 parent 3324404 commit d0af3bc

6 files changed

+9
-14
lines changed

legacy/builder/ctags/ctags_has_issues.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"golang.org/x/exp/slices"
2424
)
2525

26-
func (p *CTagsParser) FixCLinkageTagsDeclarations() {
26+
func (p *CTagsParser) fixCLinkageTagsDeclarations() {
2727
linesMap := p.FindCLinkageLines(p.tags)
2828
for i := range p.tags {
2929
if slices.Contains(linesMap[p.tags[i].Filename], p.tags[i].Line) &&

legacy/builder/ctags/ctags_parser.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type CTag struct {
5858
PrototypeModifiers string
5959
}
6060

61-
func (p *CTagsParser) Parse(ctagsOutput []byte, mainFile *paths.Path) []*CTag {
61+
func (p *CTagsParser) Parse(ctagsOutput []byte, mainFile *paths.Path) ([]*Prototype, int) {
6262
rows := strings.Split(string(ctagsOutput), "\n")
6363
rows = removeEmpty(rows)
6464

@@ -74,8 +74,9 @@ func (p *CTagsParser) Parse(ctagsOutput []byte, mainFile *paths.Path) []*CTag {
7474
p.removeDefinedProtypes()
7575
p.skipDuplicates()
7676
p.skipTagsWhere(p.prototypeAndCodeDontMatch)
77+
p.fixCLinkageTagsDeclarations()
7778

78-
return p.tags
79+
return p.toPrototypes(), p.findLineWhereToInsertPrototypes()
7980
}
8081

8182
func (p *CTagsParser) addPrototypes() {

legacy/builder/ctags/ctags_parser_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path/filepath"
2121
"testing"
2222

23+
"github.com/arduino/go-paths-helper"
2324
"github.com/stretchr/testify/require"
2425
)
2526

@@ -28,7 +29,8 @@ func produceTags(t *testing.T, filename string) []*CTag {
2829
require.NoError(t, err)
2930

3031
parser := CTagsParser{}
31-
return parser.Parse(bytes, nil)
32+
parser.Parse(bytes, paths.New("sketch.ino"))
33+
return parser.tags
3234
}
3335

3436
func TestCTagsParserShouldListPrototypes(t *testing.T) {

legacy/builder/ctags/ctags_to_prototypes.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ func (proto *Prototype) String() string {
3232
return proto.Modifiers + " " + proto.Prototype + " @ " + strconv.Itoa(proto.Line)
3333
}
3434

35-
func (p *CTagsParser) GeneratePrototypes() ([]*Prototype, int) {
36-
return p.toPrototypes(), p.findLineWhereToInsertPrototypes()
37-
}
38-
3935
func (p *CTagsParser) findLineWhereToInsertPrototypes() int {
4036
firstFunctionLine := p.firstFunctionAtLine()
4137
firstFunctionPointerAsArgument := p.firstFunctionPointerUsedAsArgument()

legacy/builder/ctags/ctags_to_prototypes_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ func producePrototypes(t *testing.T, filename string, mainFile string) ([]*Proto
2929
require.NoError(t, err)
3030

3131
parser := &CTagsParser{}
32-
parser.Parse(bytes, paths.New(mainFile))
33-
return parser.GeneratePrototypes()
32+
return parser.Parse(bytes, paths.New(mainFile))
3433
}
3534

3635
func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) {

legacy/builder/prototypes_adder.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ var DebugPreprocessor bool
3030

3131
func PrototypesAdder(sketch *sketch.Sketch, source string, ctagsStdout []byte, lineOffset int) string {
3232
parser := &ctags.CTagsParser{}
33-
parser.Parse(ctagsStdout, sketch.MainFile)
34-
parser.FixCLinkageTagsDeclarations()
35-
36-
prototypes, firstFunctionLine := parser.GeneratePrototypes()
33+
prototypes, firstFunctionLine := parser.Parse(ctagsStdout, sketch.MainFile)
3734
if firstFunctionLine == -1 {
3835
firstFunctionLine = 0
3936
}

0 commit comments

Comments
 (0)