Skip to content

Commit 7d1567d

Browse files
authored
Merge pull request #1811 from xushiwei/q
astFnClassfname, astEmptyFunc
2 parents 84cd007 + 25a049d commit 7d1567d

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

cl/classfile.go

+39
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"go/types"
2323
"log"
2424
"path/filepath"
25+
"strconv"
2526
"strings"
2627

2728
"github.com/goplus/gogen"
@@ -338,4 +339,42 @@ func makeMainSig(recv *types.Var, f *types.Func) *types.Signature {
338339
return types.NewSignatureType(recv, nil, nil, types.NewTuple(params...), nil, false)
339340
}
340341

342+
func astFnClassfname(c *gmxClass) *ast.FuncDecl {
343+
return &ast.FuncDecl{
344+
Name: &ast.Ident{
345+
Name: "Classfname",
346+
},
347+
Type: &ast.FuncType{
348+
Params: &ast.FieldList{},
349+
Results: &ast.FieldList{
350+
List: []*ast.Field{
351+
{Type: &ast.Ident{Name: "string"}},
352+
},
353+
},
354+
},
355+
Body: &ast.BlockStmt{
356+
List: []ast.Stmt{
357+
&ast.ReturnStmt{
358+
Results: []ast.Expr{
359+
&ast.BasicLit{Kind: token.STRING, Value: strconv.Quote(c.clsfile)},
360+
},
361+
},
362+
},
363+
},
364+
}
365+
}
366+
367+
func astEmptyFunc(entry string) *ast.FuncDecl {
368+
return &ast.FuncDecl{
369+
Name: &ast.Ident{
370+
Name: entry,
371+
},
372+
Type: &ast.FuncType{
373+
Params: &ast.FieldList{},
374+
},
375+
Body: &ast.BlockStmt{},
376+
Shadow: true,
377+
}
378+
}
379+
341380
// -----------------------------------------------------------------------------

cl/compile.go

+2-32
Original file line numberDiff line numberDiff line change
@@ -854,28 +854,7 @@ func preloadGopFile(p *gogen.Package, ctx *blockCtx, file string, f *ast.File, c
854854
}}}
855855
// func Classfname() string
856856
if spxClass {
857-
f.Decls = append(f.Decls, &ast.FuncDecl{
858-
Name: &ast.Ident{
859-
Name: "Classfname",
860-
},
861-
Type: &ast.FuncType{
862-
Params: &ast.FieldList{},
863-
Results: &ast.FieldList{
864-
List: []*ast.Field{
865-
{Type: &ast.Ident{Name: "string"}},
866-
},
867-
},
868-
},
869-
Body: &ast.BlockStmt{
870-
List: []ast.Stmt{
871-
&ast.ReturnStmt{
872-
Results: []ast.Expr{
873-
&ast.BasicLit{Kind: token.STRING, Value: strconv.Quote(c.clsfile)},
874-
},
875-
},
876-
},
877-
},
878-
})
857+
f.Decls = append(f.Decls, astFnClassfname(c))
879858
}
880859
}
881860
if d := f.ShadowEntry; d != nil {
@@ -892,16 +871,7 @@ func preloadGopFile(p *gogen.Package, ctx *blockCtx, file string, f *ast.File, c
892871
}
893872
}
894873
if !hasEntry {
895-
f.Decls = append(f.Decls, &ast.FuncDecl{
896-
Name: &ast.Ident{
897-
Name: entry,
898-
},
899-
Type: &ast.FuncType{
900-
Params: &ast.FieldList{},
901-
},
902-
Body: &ast.BlockStmt{},
903-
Shadow: true,
904-
})
874+
f.Decls = append(f.Decls, astEmptyFunc(entry))
905875
}
906876
}
907877
preloadFile(p, ctx, f, goFile, !conf.Outline)

0 commit comments

Comments
 (0)