Repository: goplus/gop
Pull request #1650 (2024-01-20 15:15:36)

AddMarkStmt => cl.SetDebug(FlagNoMarkAutogen)


Patch:
diff --git a/cl/compile.go b/cl/compile.go
index 232fc237..567b0f14 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -41,6 +41,7 @@ type dbgFlags int
 const (
 	DbgFlagLoad dbgFlags = 1 << iota
 	DbgFlagLookup
+	FlagNoMarkAutogen
 	DbgFlagAll = DbgFlagLoad | DbgFlagLookup
 )
 
@@ -49,8 +50,9 @@ var (
 )
 
 var (
-	debugLoad   bool
-	debugLookup bool
+	debugLoad     bool
+	debugLookup   bool
+	noMarkAutogen bool // add const _ = true
 )
 
 func SetDisableRecover(disableRecover bool) {
@@ -60,6 +62,7 @@ func SetDisableRecover(disableRecover bool) {
 func SetDebug(flags dbgFlags) {
 	debugLoad = (flags & DbgFlagLoad) != 0
 	debugLookup = (flags & DbgFlagLookup) != 0
+	noMarkAutogen = (flags & FlagNoMarkAutogen) != 0
 }
 
 // -----------------------------------------------------------------------------
@@ -208,9 +211,6 @@ type Config struct {
 
 	// Outline = true means to skip compiling function bodies.
 	Outline bool
-
-	// AddMarkStmt = true means to add const _ = true.
-	AddMarkStmt bool
 }
 
 type nodeInterp struct {
@@ -502,7 +502,7 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
 	}
 	p = gox.NewPackage(pkgPath, pkg.Name, confGox)
 
-	if conf.AddMarkStmt {
+	if !noMarkAutogen {
 		p.CB().NewConstStart(nil, "_").Val(true).EndInit(1)
 	}
 
@@ -539,7 +539,7 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
 	}
 
 	gopSyms := make(map[string]bool)
-	for name, _ := range ctx.syms {
+	for name := range ctx.syms {
 		gopSyms[name] = true
 	}
 
diff --git a/load.go b/load.go
index fe369393..f5706c99 100644
--- a/load.go
+++ b/load.go
@@ -192,7 +192,6 @@ func LoadDir(dir string, conf *Config, genTestPkg bool, promptGenGo ...bool) (ou
 		Importer:     imp,
 		LookupClass:  mod.LookupClass,
 		LookupPub:    c2go.LookupPub(mod),
-		AddMarkStmt:  true,
 	}
 
 	for name, pkg := range pkgs {
@@ -278,7 +277,6 @@ func LoadFiles(dir string, files []string, conf *Config) (out *gox.Package, err
 			Importer:     imp,
 			LookupClass:  mod.LookupClass,
 			LookupPub:    c2go.LookupPub(mod),
-			AddMarkStmt:  true,
 		}
 		out, err = cl.NewPackage("", pkg, clConf)
 		if err != nil {


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index 02e6afe8..3e157d12 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -45,7 +45,7 @@ var (
 
 func init() {
 	gox.SetDebug(gox.DbgFlagAll)
-	cl.SetDebug(cl.DbgFlagAll)
+	cl.SetDebug(cl.DbgFlagAll | cl.FlagNoMarkAutogen)
 	gblFset = token.NewFileSet()
 	imp := gop.NewImporter(nil, &env.Gop{Root: gopRootDir, Version: "1.0"}, gblFset)
 	gblConf = &cl.Config{
diff --git a/x/build/build_test.go b/x/build/build_test.go
index cb867bd2..e4c692fc 100644
--- a/x/build/build_test.go
+++ b/x/build/build_test.go
@@ -21,7 +21,6 @@ import (
 	"fmt"
 	"go/printer"
 	"go/types"
-	"io/ioutil"
 	"os"
 	"path"
 	"path/filepath"
@@ -38,6 +37,7 @@ var (
 )
 
 func init() {
+	cl.SetDebug(cl.FlagNoMarkAutogen)
 	ctx.LoadConfig = func(cfg *cl.Config) {
 		cfg.NoFileLine = true
 	}
@@ -407,7 +407,7 @@ func testFromDir(t *testing.T, relDir string) {
 		t.Fatal("Getwd failed:", err)
 	}
 	dir = path.Join(dir, relDir)
-	fis, err := ioutil.ReadDir(dir)
+	fis, err := os.ReadDir(dir)
 	if err != nil {
 		t.Fatal("ReadDir failed:", err)
 	}