Skip to content

Commit e45519b

Browse files
committed
1 parent 786118a commit e45519b

File tree

9 files changed

+36
-42
lines changed

9 files changed

+36
-42
lines changed

cl/compile.go

-16
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package cl
1919

2020
import (
2121
"fmt"
22-
"go/constant"
2322
"go/types"
2423
"log"
2524
"reflect"
@@ -175,9 +174,6 @@ type Config struct {
175174
// Fset provides source position information for syntax trees and types (required).
176175
Fset *token.FileSet
177176

178-
// Context represents all things between packages (optional).
179-
Context *gox.Context
180-
181177
// RelativeBase is the root directory of relative path.
182178
RelativeBase string
183179

@@ -193,9 +189,6 @@ type Config struct {
193189
// See (*github.com/goplus/mod/gopmod.Module).LookupClass.
194190
LookupClass func(ext string) (c *Project, ok bool)
195191

196-
// IsPkgtStandard checks a pkgPath is a Go standard package or not.
197-
IsPkgtStandard func(pkgPath string) bool
198-
199192
// An Importer resolves import paths to Packages (optional).
200193
Importer types.Importer
201194

@@ -491,8 +484,6 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
491484
confGox := &gox.Config{
492485
Types: conf.Types,
493486
Fset: fset,
494-
Context: conf.Context,
495-
IsPkgtStandard: conf.IsPkgtStandard,
496487
Importer: conf.Importer,
497488
LoadNamed: ctx.loadNamed,
498489
HandleErr: ctx.handleErr,
@@ -625,10 +616,6 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
625616
return
626617
}
627618

628-
const (
629-
gopPackage = "GopPackage"
630-
)
631-
632619
func isOverloadFunc(name string) bool {
633620
n := len(name)
634621
return n > 3 && name[n-3:n-1] == "__"
@@ -652,9 +639,6 @@ func initGopPkg(ctx *pkgCtx, pkg *gox.Package, gopSyms map[string]bool) {
652639
ctx.loadType(lbi.(*ast.Ident).Name)
653640
}
654641
}
655-
if scope := pkg.Types.Scope(); scope.Lookup(gopPackage) == nil {
656-
scope.Insert(types.NewConst(token.NoPos, pkg.Types, gopPackage, types.Typ[types.UntypedBool], constant.MakeBool(true)))
657-
}
658642
gox.InitThisGopPkg(pkg.Types)
659643
}
660644

cl/compile_gop_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ println 10 * a
174174
175175
import "fmt"
176176
177+
const GopPackage = true
178+
177179
type foo struct {
178180
}
179181
@@ -226,6 +228,8 @@ var d = a.mul(c)
226228
227229
import "fmt"
228230
231+
const GopPackage = true
232+
229233
type foo struct {
230234
}
231235
@@ -263,6 +267,8 @@ println add("Hello", "World")
263267
264268
import "fmt"
265269
270+
const GopPackage = true
271+
266272
func add__0(a int, b int) int {
267273
return a + b
268274
}
@@ -297,6 +303,7 @@ println mul(1.2, 3.14)
297303
298304
import "fmt"
299305
306+
const GopPackage = true
300307
const Gopo_mul = "mulInt,mulFloat"
301308
302309
func mulInt(a int, b int) int {
@@ -557,6 +564,8 @@ n.onKey ["a"], nil, key => {
557564
n.onKey 100, 200
558565
`, `package main
559566
567+
const GopPackage = true
568+
560569
type Mesh struct {
561570
}
562571
@@ -709,6 +718,8 @@ a += b
709718
a += c
710719
`, `package main
711720
721+
const GopPackage = true
722+
712723
var a Vector3
713724
var b int
714725
var c float64
@@ -775,6 +786,8 @@ i.onKey ["1","2"], key => {
775786
776787
import "fmt"
777788
789+
const GopPackage = true
790+
778791
func main() {
779792
n := &N[int]{}
780793
n.OnKey__0("1", func() {
@@ -817,6 +830,8 @@ n.test
817830
n.test 100
818831
`, `package main
819832
833+
const GopPackage = true
834+
820835
func main() {
821836
Test__0()
822837
Test__1(100)
@@ -882,6 +897,8 @@ c := Var(string)
882897
d := Var(M)
883898
`, `package main
884899
900+
const GopPackage = true
901+
885902
var a Var__0[int]
886903
var b Var__1[map[string]interface {
887904
}]
@@ -1125,6 +1142,8 @@ tbl.col string, "foo"
11251142
tbl.col int, 100
11261143
`, `package main
11271144
1145+
const GopPackage = true
1146+
11281147
var tbl *Table
11291148
11301149
func main() {

cl/compile_spx_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func gopSpxTest(t *testing.T, gmx, spxcode, expected string) {
7979
}
8080

8181
func gopSpxTestEx(t *testing.T, gmx, spxcode, expected, gmxfile, spxfile string) {
82+
t.Helper()
8283
gopSpxTestExConf(t, "gopSpxTest", gblConf, gmx, spxcode, expected, gmxfile, spxfile, "")
8384
}
8485

@@ -87,6 +88,7 @@ func gopSpxTestEx2(t *testing.T, gmx, spxcode, expected, gmxfile, spxfile, resul
8788
}
8889

8990
func gopSpxTestExConf(t *testing.T, name string, conf *cl.Config, gmx, spxcode, expected, gmxfile, spxfile, resultFile string) {
91+
t.Helper()
9092
t.Run(name, func(t *testing.T) {
9193
cl.SetDisableRecover(true)
9294
defer cl.SetDisableRecover(false)

cl/internal/spx/game.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package spx
1818

1919
const (
20-
GopPackage = true
20+
GopPackage = "github.com/goplus/gop/cl/internal/spx/pkg"
2121
Gop_sched = "Sched,SchedNow"
2222
)
2323

cl/internal/spx/pkg/pkg.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package pkg
22

3-
var (
3+
const (
44
GopPackage = true
55
)
66

cl/outline/outline.go

-4
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ type Config struct {
4747
// LookupClass lookups a class by specified file extension.
4848
LookupClass func(ext string) (c *Project, ok bool)
4949

50-
// IsPkgtStandard checks a pkgPath is a Go standard package or not.
51-
IsPkgtStandard func(pkgPath string) bool
52-
5350
// An Importer resolves import paths to Packages.
5451
Importer types.Importer
5552
}
@@ -66,7 +63,6 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (_ Package, err
6663
C2goBase: conf.C2goBase,
6764
LookupPub: conf.LookupPub,
6865
LookupClass: conf.LookupClass,
69-
IsPkgtStandard: conf.IsPkgtStandard,
7066
Importer: conf.Importer,
7167
NoFileLine: true,
7268
NoAutoGenMain: true,

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/fsnotify/fsnotify v1.7.0
77
github.com/goplus/c2go v0.7.21
8-
github.com/goplus/gox v1.14.8
8+
github.com/goplus/gox v1.14.9
99
github.com/goplus/mod v0.13.0
1010
github.com/qiniu/x v1.13.3
1111
golang.org/x/tools v0.17.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
77
github.com/goplus/c2go v0.7.21 h1:bRWda6KtQdY0ph+tnPEOGzZMq3OUkAI9cJBzrr5N6AM=
88
github.com/goplus/c2go v0.7.21/go.mod h1:45zjbWGW8NDuGfTOrFchCIpH9TbiH7TPg8/zF6EdEyk=
99
github.com/goplus/gox v1.14.2/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
10-
github.com/goplus/gox v1.14.8 h1:Nyn9YhfsxoJmmUVq5XtHmQm+JbvhRb1Qk7X6t4rOZvU=
11-
github.com/goplus/gox v1.14.8/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
10+
github.com/goplus/gox v1.14.9 h1:BXbO79ac0t5jPZ1NVAShPwl+UKVkKyM0cue2Y8idFyY=
11+
github.com/goplus/gox v1.14.9/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
1212
github.com/goplus/mod v0.13.0 h1:M/VsI/NWTcs2+vtWBG7793zmlCimKlSMY5LXaiztXV8=
1313
github.com/goplus/mod v0.13.0/go.mod h1:Qin2SxKoK+3cNFwtg4Jnk1F9Qn5vR6Kwlvr6lTCRJNI=
1414
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=

load.go

+10-17
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ type Config struct {
121121
Filter func(fs.FileInfo) bool
122122
Importer types.Importer
123123

124-
// Context represents all things between packages (optional).
125-
Context *gox.Context
126-
127124
IgnoreNotatedError bool
128125
}
129126

@@ -186,13 +183,11 @@ func LoadDir(dir string, conf *Config, genTestPkg bool, promptGenGo ...bool) (ou
186183

187184
var pkgTest *ast.Package
188185
var clConf = &cl.Config{
189-
Fset: fset,
190-
Context: conf.Context,
191-
RelativeBase: relativeBaseOf(mod),
192-
Importer: imp,
193-
IsPkgtStandard: mod.IsPkgtStandard,
194-
LookupClass: mod.LookupClass,
195-
LookupPub: c2go.LookupPub(mod),
186+
Fset: fset,
187+
RelativeBase: relativeBaseOf(mod),
188+
Importer: imp,
189+
LookupClass: mod.LookupClass,
190+
LookupPub: c2go.LookupPub(mod),
196191
}
197192

198193
for name, pkg := range pkgs {
@@ -272,13 +267,11 @@ func LoadFiles(dir string, files []string, conf *Config) (out *gox.Package, err
272267
imp = NewImporter(mod, gop, fset)
273268
}
274269
clConf := &cl.Config{
275-
Fset: fset,
276-
Context: conf.Context,
277-
RelativeBase: relativeBaseOf(mod),
278-
Importer: imp,
279-
LookupClass: mod.LookupClass,
280-
IsPkgtStandard: mod.IsPkgtStandard,
281-
LookupPub: c2go.LookupPub(mod),
270+
Fset: fset,
271+
RelativeBase: relativeBaseOf(mod),
272+
Importer: imp,
273+
LookupClass: mod.LookupClass,
274+
LookupPub: c2go.LookupPub(mod),
282275
}
283276
out, err = cl.NewPackage("", pkg, clConf)
284277
if err != nil {

0 commit comments

Comments
 (0)