Skip to content

Commit 34fa1d3

Browse files
committed
fix: delete ParseUntilEnd (cloudwego#25)
1 parent 5cb50a7 commit 34fa1d3

2 files changed

Lines changed: 2 additions & 88 deletions

File tree

src/compress/golang/plugin/go_ast.go

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -112,43 +112,6 @@ func (p *goParser) associateStructWithMethods() {
112112
}
113113
}
114114

115-
// TODO: Parallel transformation
116-
// ParseTilTheEnd parse the all go files from the starDir,
117-
// and their related go files in the project recursively
118-
func (p *goParser) ParseTilTheEnd(startDir string) error {
119-
if err := p.ParseDir(startDir); err != nil {
120-
return err
121-
}
122-
for path, pkg := range p.repo.Packages {
123-
// ignore third-party packages
124-
if !strings.Contains(path, p.modName) {
125-
continue
126-
}
127-
for _, f := range pkg.Functions {
128-
// Notice: local funcs has been parsed in ParseDir
129-
for _, fc := range f.InternalFunctionCalls {
130-
if p.visited[fc.PkgPath] {
131-
continue
132-
}
133-
if err := p.ParseTilTheEnd(p.pkgPathToABS(fc.PkgPath)); err != nil {
134-
return err
135-
}
136-
}
137-
for _, fc := range f.InternalMethodCalls {
138-
if p.visited[fc.PkgPath] {
139-
continue
140-
}
141-
if err := p.ParseTilTheEnd(p.pkgPathToABS(fc.PkgPath)); err != nil {
142-
return err
143-
}
144-
}
145-
}
146-
}
147-
148-
p.associateStructWithMethods()
149-
return nil
150-
}
151-
152115
type MainStream struct {
153116
MainFunc string
154117

@@ -303,7 +266,7 @@ func main() {
303266
homeDir := os.Args[1]
304267

305268
p := newGoParser("", homeDir)
306-
if err := p.ParseTilTheEnd(p.homePageDir); err != nil {
269+
if err := p.ParseRepo(); err != nil {
307270
fmt.Println("Error parsing go files:", err)
308271
os.Exit(1)
309272
}

src/compress/golang/plugin/go_ast_test.go

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,6 @@ import (
77
"github.com/davecgh/go-spew/spew"
88
)
99

10-
func Test_goParser_ParseTilTheEnd(t *testing.T) {
11-
type fields struct {
12-
modName string
13-
homePageDir string
14-
}
15-
type args struct {
16-
startDir string
17-
}
18-
tests := []struct {
19-
name string
20-
fields fields
21-
args args
22-
}{
23-
{
24-
name: "test",
25-
fields: fields{
26-
homePageDir: "/Users/bytedance/GOPATH/work/hertz",
27-
},
28-
args: args{
29-
startDir: "cmd/hz",
30-
},
31-
},
32-
}
33-
for _, tt := range tests {
34-
t.Run(tt.name, func(t *testing.T) {
35-
p := newGoParser(tt.fields.modName, tt.fields.homePageDir)
36-
err := p.ParseTilTheEnd(tt.args.startDir)
37-
if err != nil {
38-
t.Fatalf("goParser.ParseTilTheEnd() error = %v", err)
39-
}
40-
// spew.Dump(p)
41-
out, fun := p.getMain(2)
42-
if fun.Name != "main" {
43-
t.Fail()
44-
}
45-
if out, err := json.MarshalIndent(fun, "", " "); err != nil {
46-
t.Fatal(err)
47-
} else {
48-
println("func size:", len(out), string(out))
49-
}
50-
if out, err := json.MarshalIndent(out, "", " "); err != nil {
51-
t.Fatalf("json.Marshal() error = %v", err)
52-
} else {
53-
println("size:", len(out), string(out))
54-
}
55-
})
56-
}
57-
}
58-
5910
func Test_goParser_ParseRepo(t *testing.T) {
6011
type fields struct {
6112
modName string
@@ -82,7 +33,7 @@ func Test_goParser_ParseRepo(t *testing.T) {
8233
spew.Dump(p)
8334
x := p.repo.GetType(Identity{"a.b/c/pkg/entity", "MyStruct"})
8435
spew.Dump(x.InlineStruct, x.SubStruct)
85-
out, fun := p.getMain(2)
36+
out, fun := p.getMain(-1)
8637
if fun.Name != "main" {
8738
t.Fail()
8839
}

0 commit comments

Comments
 (0)