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

cl.compileIdent: rec.Use for builtin objects #1498

Merged
merged 3 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const (

const errorPkgPath = "github.com/qiniu/x/errors"

func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (obj *gox.PkgRef, kind int) {
func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (pkg *gox.PkgRef, kind int) {
fvalue := (flags&clIdentSelectorExpr) != 0 || (flags&clIdentLHS) == 0
name := ident.Name
if name == "_" {
Expand All @@ -85,6 +85,7 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (obj *gox.PkgRef,
return
}

var oldo types.Object
scope := ctx.pkg.Types.Scope()
at, o := ctx.cb.Scope().LookupParent(name, token.NoPos)
if o != nil {
Expand Down Expand Up @@ -137,7 +138,7 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (obj *gox.PkgRef,
if (flags&clIdentAllowBuiltin) == 0 && isBuiltin(o) && !strings.HasPrefix(o.Name(), "print") {
panic(ctx.newCodeErrorf(ident.Pos(), "use of builtin %s not in function call", name))
}
o = obj
oldo, o = o, obj
} else if o == nil {
if (clIdentGoto & flags) != 0 {
l := ident.Obj.Data.(*ast.Ident)
Expand All @@ -153,12 +154,14 @@ find:
ctx.cb.VarRef(o, ident)
}
if rec := ctx.recorder(); rec != nil {
rec.Use(ident, o)
e := ctx.cb.Get(-1)
tv := types.TypeAndValue{Type: e.Type, Value: e.CVal}
if !fvalue {
tv.Type = o.Type()
if oldo != nil && gox.IsTypeEx(e.Type) {
rec.Use(ident, oldo)
return
}
rec.Use(ident, o)
typ, _ := gox.DerefType(e.Type)
tv := types.TypeAndValue{Type: typ, Value: e.CVal}
rec.Type(ident, tv)
}
return
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/fsnotify/fsnotify v1.7.0
github.com/goplus/c2go v0.7.16
github.com/goplus/gox v1.12.2-0.20231026084726-48d24f42e91f
github.com/goplus/gox v1.12.2-0.20231028071646-bb6d796d66cf
github.com/goplus/mod v0.11.8-0.20231019172744-da5848421263
github.com/qiniu/x v1.13.1
golang.org/x/tools v0.14.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/goplus/c2go v0.7.16 h1:B9jRNNytoq7yDBQOZSm2qENQhRQMfNhgOea5XHWNUnI=
github.com/goplus/c2go v0.7.16/go.mod h1:XODEFX2PeEEJXNLLdykWeZgMSaKJ51fVm+C9IM3FxNQ=
github.com/goplus/gox v1.12.1/go.mod h1:wymoQJ7ydd42cTlaXb4wNbvn4LlKjR+j8PZehI7v1zQ=
github.com/goplus/gox v1.12.2-0.20231026084726-48d24f42e91f h1:WGAwExBl2dwEopwlAdnnfbTRiStvTUasONduDWxirlU=
github.com/goplus/gox v1.12.2-0.20231026084726-48d24f42e91f/go.mod h1:Ek1YIy3wRaZ1i0DD2XG29i3r5AFdhcOradK0/GGs1YQ=
github.com/goplus/gox v1.12.2-0.20231028071646-bb6d796d66cf h1:67Lz2V9Nj6pZz+u4d9uq5rCfw2t/zE34Qo6AF5dJN3c=
github.com/goplus/gox v1.12.2-0.20231028071646-bb6d796d66cf/go.mod h1:Ek1YIy3wRaZ1i0DD2XG29i3r5AFdhcOradK0/GGs1YQ=
github.com/goplus/mod v0.11.5/go.mod h1:NDC5E+XOT8vcJCMjqKhLDJHTHX7lyVN4Vbfi2U7dBhs=
github.com/goplus/mod v0.11.8-0.20231019172744-da5848421263 h1:PE0HveOss5mai9pa52L4/ZvVqZtltogJ9rIUIsdlG/I=
github.com/goplus/mod v0.11.8-0.20231019172744-da5848421263/go.mod h1:yl2QncBKTdXk+8UaNsdo4u2zSpGEJYA5JKjgD3K2h00=
Expand Down