Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

astFnClassfname, astEmptyFunc #1811

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 39 additions & 0 deletions cl/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go/types"
"log"
"path/filepath"
"strconv"
"strings"

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

func astFnClassfname(c *gmxClass) *ast.FuncDecl {
return &ast.FuncDecl{
Name: &ast.Ident{
Name: "Classfname",
},
Type: &ast.FuncType{
Params: &ast.FieldList{},
Results: &ast.FieldList{
List: []*ast.Field{
{Type: &ast.Ident{Name: "string"}},
},
},
},
Body: &ast.BlockStmt{
List: []ast.Stmt{
&ast.ReturnStmt{
Results: []ast.Expr{
&ast.BasicLit{Kind: token.STRING, Value: strconv.Quote(c.clsfile)},
},
},
},
},
}
}

func astEmptyFunc(entry string) *ast.FuncDecl {
return &ast.FuncDecl{
Name: &ast.Ident{
Name: entry,
},
Type: &ast.FuncType{
Params: &ast.FieldList{},
},
Body: &ast.BlockStmt{},
Shadow: true,
}
}

// -----------------------------------------------------------------------------
34 changes: 2 additions & 32 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,28 +854,7 @@ func preloadGopFile(p *gogen.Package, ctx *blockCtx, file string, f *ast.File, c
}}}
// func Classfname() string
if spxClass {
f.Decls = append(f.Decls, &ast.FuncDecl{
Name: &ast.Ident{
Name: "Classfname",
},
Type: &ast.FuncType{
Params: &ast.FieldList{},
Results: &ast.FieldList{
List: []*ast.Field{
{Type: &ast.Ident{Name: "string"}},
},
},
},
Body: &ast.BlockStmt{
List: []ast.Stmt{
&ast.ReturnStmt{
Results: []ast.Expr{
&ast.BasicLit{Kind: token.STRING, Value: strconv.Quote(c.clsfile)},
},
},
},
},
})
f.Decls = append(f.Decls, astFnClassfname(c))
}
}
if d := f.ShadowEntry; d != nil {
Expand All @@ -892,16 +871,7 @@ func preloadGopFile(p *gogen.Package, ctx *blockCtx, file string, f *ast.File, c
}
}
if !hasEntry {
f.Decls = append(f.Decls, &ast.FuncDecl{
Name: &ast.Ident{
Name: entry,
},
Type: &ast.FuncType{
Params: &ast.FieldList{},
},
Body: &ast.BlockStmt{},
Shadow: true,
})
f.Decls = append(f.Decls, astEmptyFunc(entry))
}
}
preloadFile(p, ctx, f, goFile, !conf.Outline)
Expand Down