Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.1.9 #1508

Merged
merged 102 commits into from
Nov 1, 2023
Merged

v1.1.9 #1508

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
e941bda
go.mod: update gox
visualfc Oct 12, 2023
4f52124
cl: add TestSpxErrorSel/TestSpxMethodSel/TestSpxPkgOverload
visualfc Oct 12, 2023
d1956ff
Merge pull request #1468 from visualfc/deps
xushiwei Oct 12, 2023
e1370eb
gop/env.Installed(); gop/ast.File.Pos()
xushiwei Oct 18, 2023
d17024e
gop/env: initEnvByGop
xushiwei Oct 18, 2023
7aba2e9
gop/env
xushiwei Oct 18, 2023
ae7cf50
Merge pull request #1471 from xushiwei/q
xushiwei Oct 18, 2023
4a859b3
gop/x/typesutil
xushiwei Oct 19, 2023
cc4b858
gop/x/typesutil
xushiwei Oct 19, 2023
d3e1fa3
github.com/goplus/gox@main
xushiwei Oct 19, 2023
8ee9016
go1.18
xushiwei Oct 19, 2023
f56162e
cl/recorder_test
xushiwei Oct 19, 2023
8aaba9d
go1.18
xushiwei Oct 19, 2023
c42b314
Merge pull request #1472 from xushiwei/typesutil
xushiwei Oct 19, 2023
613a552
github.com/goplus/mod@main
xushiwei Oct 19, 2023
d3e28de
github.com/goplus/mod@main
xushiwei Oct 19, 2023
aba7fd7
gop.LoadMod: fix std package
xushiwei Oct 19, 2023
d6343a7
Merge pull request #1473 from xushiwei/typesutil
xushiwei Oct 19, 2023
588a70b
update gox version
visualfc Oct 20, 2023
8593c3b
x
visualfc Oct 20, 2023
4869e15
Merge pull request #1474 from visualfc/update
xushiwei Oct 20, 2023
bd43aa4
gox: pkg.TryImport; typesutil.SetDebug
xushiwei Oct 20, 2023
0ef3e73
x/build: TestContext
xushiwei Oct 20, 2023
49a91fa
gop fmt -t: test if Go+ files are formatted or not
xushiwei Oct 20, 2023
ec773c8
Merge pull request #1475 from xushiwei/typesutil
xushiwei Oct 20, 2023
4992fd2
Merge pull request #1476 from xushiwei/fmt
xushiwei Oct 20, 2023
5a4bb59
typesutil: def func
xushiwei Oct 20, 2023
fa6ae33
Merge branch 'fmt' into def
xushiwei Oct 20, 2023
3a0dc5e
Merge pull request #1477 from xushiwei/def
xushiwei Oct 20, 2023
3de5907
typesutil: rec.Use; gox.Recorder
xushiwei Oct 20, 2023
8875764
fromgo: TestCheckIdent
xushiwei Oct 20, 2023
d0f4cc8
Merge pull request #1478 from xushiwei/def
xushiwei Oct 20, 2023
c93d724
ast: walk add Go+ expr and stmt
visualfc Oct 21, 2023
3b5675b
Merge pull request #1480 from visualfc/ast
xushiwei Oct 21, 2023
b8e59aa
typeDecl: rec.Def
xushiwei Oct 21, 2023
d6f7c4c
Use: fix *gox.Func
xushiwei Oct 21, 2023
568cdda
Merge pull request #1481 from xushiwei/q
xushiwei Oct 21, 2023
3faae92
typeDecl: rec.Use
xushiwei Oct 21, 2023
f2ac2be
gox: defs.AliasType
xushiwei Oct 21, 2023
8245eb7
Merge pull request #1482 from xushiwei/q
xushiwei Oct 21, 2023
ab46425
externType: rec.Use
xushiwei Oct 21, 2023
caf1d4b
Merge pull request #1483 from xushiwei/q
xushiwei Oct 21, 2023
3707f9b
toIdentType: rec.Use
xushiwei Oct 21, 2023
dc26c66
Merge pull request #1484 from xushiwei/q
xushiwei Oct 21, 2023
9bc730b
parser: parseGlobalStmts set main.FuncType.Pos
xushiwei Oct 22, 2023
10fb4f7
Merge pull request #1485 from xushiwei/q
xushiwei Oct 22, 2023
24b2024
parser: ParseExprFrom/ParseExpr; readSource
xushiwei Oct 22, 2023
835672a
readSource: readSourceLocal/readSourceFS
xushiwei Oct 22, 2023
9d593fb
TestParseExprFrom
xushiwei Oct 22, 2023
94efdcd
TestAssert
xushiwei Oct 22, 2023
2f66dc5
typesutil.Check: ident/selectorExpr rec.Type
xushiwei Oct 22, 2023
225a72d
Merge pull request #1486 from xushiwei/q
xushiwei Oct 22, 2023
7ef9255
build(deps): bump github.com/fsnotify/fsnotify from 1.6.0 to 1.7.0
dependabot[bot] Oct 23, 2023
3edf20b
cl: rec.Use PkgName
xushiwei Oct 23, 2023
cd2bd07
Merge pull request #1487 from goplus/dependabot/go_modules/github.com…
xushiwei Oct 23, 2023
3aacc65
Merge pull request #1488 from xushiwei/q
xushiwei Oct 23, 2023
ac456c8
update gox version
visualfc Oct 23, 2023
c2f160e
x
visualfc Oct 23, 2023
27d8dc2
Merge pull request #1489 from visualfc/import_name
xushiwei Oct 23, 2023
ad92966
ast: FuncDecl.Shadow
xushiwei Oct 24, 2023
c53cbfa
Merge pull request #1490 from xushiwei/q
xushiwei Oct 24, 2023
87266ff
gox: newScope support start..end
xushiwei Oct 24, 2023
e7edc29
merge main
xushiwei Oct 24, 2023
09e2200
Merge pull request #1491 from xushiwei/q
xushiwei Oct 24, 2023
df6221e
parser: parsePrimaryExpr fix LiteralValue check
visualfc Oct 26, 2023
3363ba1
parser: add test _instance/instance5
visualfc Oct 26, 2023
15ad484
Merge pull request #1493 from visualfc/parser_lit
xushiwei Oct 26, 2023
5c75e59
typesutil.Check fix: exprLHS
xushiwei Oct 26, 2023
6a8bf80
compileAssignStmt small rollback
xushiwei Oct 26, 2023
17c4a9a
TestErrAssign
xushiwei Oct 26, 2023
f3cc127
Merge pull request #1494 from xushiwei/typesutil
xushiwei Oct 26, 2023
556fc3f
update gox; TestGenericTypeCompositeLit
visualfc Oct 26, 2023
78088ce
Merge pull request #1495 from visualfc/gox_update
xushiwei Oct 26, 2023
14856b7
toStructType: add field pos
visualfc Oct 27, 2023
51060d8
toStructType: record.Def field
visualfc Oct 27, 2023
6d3596d
cl: loadFunc fix ctx.pkg.NewFuncWith use name pos
visualfc Oct 27, 2023
de2b8cb
x
visualfc Oct 27, 2023
918d5c8
Merge pull request #1496 from visualfc/field
xushiwei Oct 28, 2023
6c79697
goxRecorder.Member: rec.Type
xushiwei Oct 28, 2023
74d272b
Merge pull request #1497 from xushiwei/typesutil
xushiwei Oct 28, 2023
dff1b75
cl.compileIdent: rec.Use for builtin objects
xushiwei Oct 28, 2023
519478a
gox.IsTypeEx
xushiwei Oct 28, 2023
08a2b3b
merge upstream
xushiwei Oct 28, 2023
70c4570
Merge pull request #1498 from xushiwei/typesutil
xushiwei Oct 28, 2023
f1b1a10
toInterfaceType: rec.Def fields
xushiwei Oct 29, 2023
eef71f9
toStructType: fix fld.pos
xushiwei Oct 29, 2023
2d02f1a
Merge pull request #1499 from xushiwei/typesutil
xushiwei Oct 29, 2023
b984687
typesutil.Check: support Go/Go+ mixed project
xushiwei Oct 29, 2023
33c2b21
rm gopdecl
xushiwei Oct 29, 2023
7c44294
Merge pull request #1500 from xushiwei/typesutil
xushiwei Oct 29, 2023
1774107
use gox.ObjectDocs
xushiwei Oct 30, 2023
51cce14
rec.Scope fileScope; gox#298: use gox.ObjectDocs
xushiwei Oct 30, 2023
850ff81
Merge pull request #1501 from xushiwei/typesutil
xushiwei Oct 30, 2023
eec1130
gop: fix restore mod
visualfc Oct 30, 2023
d40c1e2
Merge pull request #1502 from visualfc/gop_mod
xushiwei Oct 30, 2023
07b7dec
typesutil: avoid two instances for same Go object
xushiwei Oct 31, 2023
362ff94
objMap[old] maybe nil
xushiwei Oct 31, 2023
7625a67
Merge pull request #1503 from xushiwei/typesutil
xushiwei Oct 31, 2023
39e344c
build(deps): bump github.com/goplus/mod
dependabot[bot] Nov 1, 2023
2a315b7
Merge pull request #1507 from goplus/dependabot/go_modules/github.com…
xushiwei Nov 1, 2023
c5f4b15
build(deps): bump github.com/goplus/gox
dependabot[bot] Nov 1, 2023
340a9ec
Merge pull request #1506 from goplus/dependabot/go_modules/github.com…
xushiwei Nov 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
Test:
strategy:
matrix:
go-version: [1.17.x, 1.18.x, 1.19.x, 1.20.x]
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x]
os: [ubuntu-latest, windows-latest, macos-11]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ For more details, see [Quick Start](doc/docs.md).

For now, we suggest you install Go+ from source code.

Note: Requires go1.17 or later
Note: Requires go1.18 or later

```bash
git clone https://github.com/goplus/gop.git
Expand Down
15 changes: 13 additions & 2 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ type (
Type *FuncType // function signature: parameters, results, and position of "func" keyword
Body *BlockStmt // function body; or nil for external (non-Go) function
Operator bool // is operator or not
Shadow bool // is a shadow entry
}
)

Expand Down Expand Up @@ -1123,7 +1124,7 @@ type FileType = int16
// are "free-floating" (see also issues #18593, #20744).
type File struct {
Doc *CommentGroup // associated documentation; or nil
Package token.Pos // position of "package" keyword
Package token.Pos // position of "package" keyword; or NoPos
Name *Ident // package name
Decls []Decl // top-level declarations; or nil

Expand All @@ -1144,8 +1145,18 @@ func (f *File) NoEntrypoint() bool {
return f.ShadowEntry != nil
}

// HasPkgDecl checks if `package xxx` exists or not.
func (f *File) HasPkgDecl() bool {
return f.Package != token.NoPos
}

// Pos returns position of first character belonging to the node.
func (f *File) Pos() token.Pos { return f.Package }
func (f *File) Pos() token.Pos {
if f.Package != token.NoPos {
return f.Package
}
return f.Name.NamePos
}

// End returns position of first character immediately after the node.
func (f *File) End() token.Pos {
Expand Down
11 changes: 11 additions & 0 deletions ast/fromgo/gopast.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,19 @@ func gopIdent(v *ast.Ident) *gopast.Ident {
return &gopast.Ident{
NamePos: v.NamePos,
Name: v.Name,
Obj: &gopast.Object{Data: v},
}
}

// CheckIdent checks if a Go+ ast.Ident is converted from a Go ast.Ident or not.
// If it is, CheckIdent returns the original Go ast.Ident object.
func CheckIdent(v *gopast.Ident) (id *ast.Ident, ok bool) {
if o := v.Obj; o != nil && o.Kind == 0 && o.Data != nil {
id, ok = o.Data.(*ast.Ident)
}
return
}

func gopIdents(names []*ast.Ident) []*gopast.Ident {
ret := make([]*gopast.Ident, len(names))
for i, v := range names {
Expand Down Expand Up @@ -332,6 +342,7 @@ const (
KeepCgo
)

// ASTFile converts a Go ast.File into a Go+ ast.File object.
func ASTFile(f *ast.File, mode int) *gopast.File {
if (mode & KeepFuncBody) != 0 {
log.Panicln("ASTFile: doesn't support keeping func body now")
Expand Down
12 changes: 12 additions & 0 deletions ast/fromgo/gopast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go/token"
"testing"

gopast "github.com/goplus/gop/ast"
"github.com/goplus/gop/format"
)

Expand Down Expand Up @@ -125,3 +126,14 @@ type foo int
func (a foo) Str() (string) {}
`)
}

func TestCheckIdent(t *testing.T) {
if _, ok := CheckIdent(&gopast.Ident{}); ok {
t.Fatal("CheckIdent: found?")
}
if _, ok := CheckIdent(&gopast.Ident{Obj: &gopast.Object{
Data: &ast.Ident{},
}}); !ok {
t.Fatal("CheckIdent: not found?")
}
}
78 changes: 68 additions & 10 deletions ast/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package ast

import "fmt"
import (
"fmt"
)

// Visitor - A Visitor's Visit method is invoked for each node encountered by Walk.
// If the result visitor w is not nil, Walk visits each of the children
Expand Down Expand Up @@ -59,7 +61,6 @@ func walkDeclList(v Visitor, list []Decl) {
// v.Visit(node) is not nil, Walk is invoked recursively with visitor
// w for each of the non-nil children of node, followed by a call of
// w.Visit(nil).
//
func Walk(v Visitor, node Node) {
if v = v.Visit(node); v == nil {
return
Expand Down Expand Up @@ -344,14 +345,16 @@ func Walk(v Visitor, node Node) {
}

case *FuncDecl:
if n.Doc != nil {
Walk(v, n.Doc)
}
if n.Recv != nil {
Walk(v, n.Recv)
if !n.Shadow { // not a shadow entry
if n.Doc != nil {
Walk(v, n.Doc)
}
if n.Recv != nil {
Walk(v, n.Recv)
}
Walk(v, n.Name)
Walk(v, n.Type)
}
Walk(v, n.Name)
Walk(v, n.Type)
if n.Body != nil {
Walk(v, n.Body)
}
Expand All @@ -372,6 +375,62 @@ func Walk(v Visitor, node Node) {
Walk(v, f)
}

// Go+ expr and stmt
case *SliceLit:
walkExprList(v, n.Elts)

case *LambdaExpr:
walkIdentList(v, n.Lhs)
walkExprList(v, n.Rhs)

case *LambdaExpr2:
walkIdentList(v, n.Lhs)
Walk(v, n.Body)

case *ForPhrase:
if n.Key != nil {
Walk(v, n.Key)
}
if n.Value != nil {
Walk(v, n.Value)
}
if n.Init != nil {
Walk(v, n.Init)
}
if n.Cond != nil {
Walk(v, n.Cond)
}
Walk(v, n.X)

case *ComprehensionExpr:
if n.Elt != nil {
Walk(v, n.Elt)
}
for _, x := range n.Fors {
Walk(v, x)
}

case *ForPhraseStmt:
Walk(v, n.ForPhrase)
Walk(v, n.Body)

case *RangeExpr:
if n.First != nil {
Walk(v, n.First)
}
if n.Last != nil {
Walk(v, n.Last)
}
if n.Expr3 != nil {
Walk(v, n.Expr3)
}

case *ErrWrapExpr:
Walk(v, n.X)
if n.Default != nil {
Walk(v, n.Default)
}

default:
panic(fmt.Sprintf("ast.Walk: unexpected node type %T", n))
}
Expand All @@ -392,7 +451,6 @@ func (f inspector) Visit(node Node) Visitor {
// f(node); node must not be nil. If f returns true, Inspect invokes f
// recursively for each of the non-nil children of node, followed by a
// call of f(nil).
//
func Inspect(node Node, f func(Node) bool) {
Walk(inspector(f), node)
}
21 changes: 13 additions & 8 deletions build_install_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func BuildPkgPath(workDir, pkgPath string, conf *Config, build *gocmd.BuildConfi
if err != nil {
return errors.NewWith(err, `GenGoPkgPath(workDir, pkgPath, conf, false)`, -2, "gop.GenGoPkgPath", workDir, pkgPath, conf, false)
}
old := chdirAndMod(localDir)
defer restoreDirAndMod(old)
old, mod := chdirAndMod(localDir)
defer restoreDirAndMod(old, mod)
return gocmd.Build(cwdParam(recursively), build)
}

Expand All @@ -99,13 +99,18 @@ func BuildFiles(files []string, conf *Config, build *gocmd.BuildConfig) (err err
return gocmd.BuildFiles(files, build)
}

func chdirAndMod(dir string) string {
func chdirAndMod(dir string) (old string, mod os.FileMode) {
mod = 0755
if info, err := os.Stat(dir); err == nil {
mod = info.Mode().Perm()
}
os.Chmod(dir, 0777)
return chdir(dir)
old = chdir(dir)
return
}

func restoreDirAndMod(old string) {
os.Chmod(".", 0555)
func restoreDirAndMod(old string, mod os.FileMode) {
os.Chmod(".", mod)
os.Chdir(old)
}

Expand Down Expand Up @@ -158,8 +163,8 @@ func TestPkgPath(workDir, pkgPath string, conf *Config, test *gocmd.TestConfig)
if err != nil {
return errors.NewWith(err, `GenGoPkgPath(workDir, pkgPath, conf, false)`, -2, "gop.GenGoPkgPath", workDir, pkgPath, conf, false)
}
old := chdirAndMod(localDir)
defer restoreDirAndMod(old)
old, mod := chdirAndMod(localDir)
defer restoreDirAndMod(old, mod)
return gocmd.Test(cwdParam(recursively), test)
}

Expand Down
66 changes: 39 additions & 27 deletions cl/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,51 @@ func initBuiltinFns(builtin *types.Package, scope *types.Scope, pkg *gox.PkgRef,

func initBuiltin(pkg *gox.Package, builtin *types.Package, os, fmt, ng, iox, buil *gox.PkgRef) {
scope := builtin.Scope()
typs := []string{"bigint", "bigrat", "bigfloat"}
for _, typ := range typs {
name := string(typ[0]-('a'-'A')) + typ[1:]
scope.Insert(types.NewTypeName(token.NoPos, builtin, typ, ng.Ref(name).Type()))
if ng != nil {
typs := []string{"bigint", "bigrat", "bigfloat"}
for _, typ := range typs {
name := string(typ[0]-('a'-'A')) + typ[1:]
scope.Insert(types.NewTypeName(token.NoPos, builtin, typ, ng.Ref(name).Type()))
}
scope.Insert(types.NewTypeName(token.NoPos, builtin, "uint128", ng.Ref("Uint128").Type()))
scope.Insert(types.NewTypeName(token.NoPos, builtin, "int128", ng.Ref("Int128").Type()))
}
if fmt != nil {
initBuiltinFns(builtin, scope, fmt, []string{
"print", "println", "printf", "errorf",
"fprint", "fprintln", "fprintf",
"sprint", "sprintln", "sprintf",
})
}
if os != nil {
initBuiltinFns(builtin, scope, os, []string{
"open", "create",
})
}
if iox != nil {
initBuiltinFns(builtin, scope, iox, []string{
"lines",
})
scope.Insert(gox.NewOverloadFunc(token.NoPos, builtin, "blines", iox.Ref("BLines")))
}
if buil != nil {
scope.Insert(gox.NewOverloadFunc(token.NoPos, builtin, "newRange", buil.Ref("NewRange__0")))
}
initBuiltinFns(builtin, scope, fmt, []string{
"print", "println", "printf", "errorf",
"fprint", "fprintln", "fprintf",
"sprint", "sprintln", "sprintf",
})
initBuiltinFns(builtin, scope, os, []string{
"open", "create",
})
initBuiltinFns(builtin, scope, iox, []string{
"lines",
})
scope.Insert(gox.NewOverloadFunc(token.NoPos, builtin, "blines", iox.Ref("BLines")))
scope.Insert(gox.NewOverloadFunc(token.NoPos, builtin, "newRange", buil.Ref("NewRange__0")))
scope.Insert(types.NewTypeName(token.NoPos, builtin, "uint128", ng.Ref("Uint128").Type()))
scope.Insert(types.NewTypeName(token.NoPos, builtin, "int128", ng.Ref("Int128").Type()))
scope.Insert(types.NewTypeName(token.NoPos, builtin, "any", gox.TyEmptyInterface))
}

func newBuiltinDefault(pkg *gox.Package, conf *gox.Config) *types.Package {
builtin := types.NewPackage("", "")
fmt := pkg.Import("fmt")
os := pkg.Import("os")
buil := pkg.Import("github.com/goplus/gop/builtin")
ng := pkg.Import("github.com/goplus/gop/builtin/ng")
iox := pkg.Import("github.com/goplus/gop/builtin/iox")
pkg.Import("strconv")
pkg.Import("strings")
initMathBig(pkg, conf, ng)
fmt := pkg.TryImport("fmt")
os := pkg.TryImport("os")
buil := pkg.TryImport("github.com/goplus/gop/builtin")
ng := pkg.TryImport("github.com/goplus/gop/builtin/ng")
iox := pkg.TryImport("github.com/goplus/gop/builtin/iox")
pkg.TryImport("strconv")
pkg.TryImport("strings")
if ng != nil {
initMathBig(pkg, conf, ng)
}
initBuiltin(pkg, builtin, os, fmt, ng, iox, buil)
gox.InitBuiltin(pkg, builtin, conf)
return builtin
Expand Down
Loading