diff --git a/cl/builtin_test.go b/cl/builtin_test.go index 3f09e167d..ac3e07076 100644 --- a/cl/builtin_test.go +++ b/cl/builtin_test.go @@ -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 { diff --git a/cl/classfile.go b/cl/classfile.go index 7c6b5f1c3..91cbb18fc 100644 --- a/cl/classfile.go +++ b/cl/classfile.go @@ -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" ) @@ -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") @@ -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 +} + +// ----------------------------------------------------------------------------- diff --git a/cl/compile.go b/cl/compile.go index 25a34f279..830aa5c97 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -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" @@ -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 diff --git a/parser/classfile.go b/parser/classfile.go deleted file mode 100644 index d4a3e3d82..000000000 --- a/parser/classfile.go +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021 The GoPlus Authors (goplus.org). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package parser - -import ( - "path/filepath" -) - -// 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 -} diff --git a/parser/parser_test.go b/parser/parser_test.go index a387edc41..9a90a7de9 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -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: