Skip to content

Commit

Permalink
Merge pull request #1811 from xushiwei/q
Browse files Browse the repository at this point in the history
astFnClassfname, astEmptyFunc
  • Loading branch information
xushiwei authored Mar 9, 2024
2 parents 84cd007 + 25a049d commit 7d1567d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
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

0 comments on commit 7d1567d

Please sign in to comment.