Skip to content

Commit

Permalink
Merge pull request #1530 from xushiwei/typesutil
Browse files Browse the repository at this point in the history
mv ClassFileExt: parser => cl
  • Loading branch information
xushiwei committed Nov 8, 2023
2 parents e02b880 + e4c1803 commit 6e9352d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 50 deletions.
14 changes: 14 additions & 0 deletions cl/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ func getGoxConf() *gox.Config {
return &gox.Config{Fset: fset, Importer: imp}
}

func TestExt(t *testing.T) {
cases := [][2]string{
{"t.spx.gox", ".spx"},
{"t.spx", ".spx"},
{"t.gox", ".gox"},
{"t.abc", ".abc"},
}
for _, c := range cases {
if ret := ClassFileExt(c[0]); ret != c[1] {
t.Fatal("ClassFileExt:", c[0], "expected:", c[1], "got:", ret)
}
}
}

func TestErrMultiStarRecv(t *testing.T) {
defer func() {
if e := recover(); e == nil {
Expand Down
16 changes: 14 additions & 2 deletions cl/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"strings"

"github.com/goplus/gop/ast"
"github.com/goplus/gop/parser"
"github.com/goplus/gop/token"
"github.com/goplus/gox"
)
Expand Down Expand Up @@ -61,7 +60,7 @@ func (p *gmxSettings) getScheds(cb *gox.CodeBuilder) []goast.Stmt {
}

func newGmx(ctx *pkgCtx, pkg *gox.Package, file string, f *ast.File, conf *Config) *gmxSettings {
ext := parser.ClassFileExt(file)
ext := ClassFileExt(file)
gt, ok := conf.LookupClass(ext)
if !ok {
panic("TODO: class not found")
Expand Down Expand Up @@ -177,3 +176,16 @@ func gmxMainFunc(p *gox.Package, ctx *pkgCtx) {
}

// -----------------------------------------------------------------------------

// ClassFileExt returns the classfile extension
func ClassFileExt(path string) (ext string) {
ext = filepath.Ext(path)
if ext == ".gox" {
if c := filepath.Ext(path[:len(path)-4]); c != "" {
return c
}
}
return
}

// -----------------------------------------------------------------------------
3 changes: 1 addition & 2 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/goplus/gop/ast"
"github.com/goplus/gop/ast/fromgo"
"github.com/goplus/gop/parser"
"github.com/goplus/gop/token"
"github.com/goplus/gox"
"github.com/goplus/gox/cpackages"
Expand Down Expand Up @@ -710,7 +709,7 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con
case f.IsClass:
classType = getDefaultClass(file)
if parent.gmxSettings != nil {
ext := parser.ClassFileExt(file)
ext := ClassFileExt(file)
o, ok := parent.sprite[ext]
if ok {
baseTypeName, baseType, spxClass = o.Name(), o.Type(), true
Expand Down
32 changes: 0 additions & 32 deletions parser/classfile.go

This file was deleted.

14 changes: 0 additions & 14 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ func TestAssert(t *testing.T) {
assert(false, "panic msg")
}

func TestExt(t *testing.T) {
cases := [][2]string{
{"t.spx.gox", ".spx"},
{"t.spx", ".spx"},
{"t.gox", ".gox"},
{"t.abc", ".abc"},
}
for _, c := range cases {
if ret := ClassFileExt(c[0]); ret != c[1] {
t.Fatal("ClassFileExt:", c[0], "expected:", c[1], "got:", ret)
}
}
}

func panicMsg(e interface{}) string {
switch v := e.(type) {
case string:
Expand Down

0 comments on commit 6e9352d

Please sign in to comment.