Skip to content

Commit

Permalink
Merge pull request #1481 from xushiwei/q
Browse files Browse the repository at this point in the history
typeDecl: rec.Def
  • Loading branch information
xushiwei committed Oct 21, 2023
2 parents 3b5675b + d6f7c4c commit 568cdda
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
16 changes: 9 additions & 7 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 @@ -375,12 +377,6 @@ func Walk(v Visitor, node Node) {
case *SliceLit:
walkExprList(v, n.Elts)

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

case *LambdaExpr:
walkIdentList(v, n.Lhs)
walkExprList(v, n.Rhs)
Expand Down Expand Up @@ -427,6 +423,12 @@ func Walk(v Visitor, node Node) {
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 Down
6 changes: 3 additions & 3 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,14 +916,14 @@ func preloadFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, gopFil
} else if d.Doc != nil {
defs.SetComments(d.Doc)
}
if rec := ctx.recorder(); rec != nil {
rec.Def(t.Name, decl.Type().Obj())
}
ld.typInit = func() { // decycle
if debugLoad {
log.Println("==> Load > InitType", name)
}
decl.InitType(ctx.pkg, toType(ctx, t.Type))
if rec := ctx.recorder(); rec != nil {
rec.Def(t.Name, decl.Type().Obj())
}
}
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions x/typesutil/gopinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"go/types"

"github.com/goplus/gop/ast"
"github.com/goplus/gox"
"github.com/qiniu/x/log"
)

Expand Down Expand Up @@ -223,6 +224,9 @@ func (info gopRecorder) Def(id *ast.Ident, obj types.Object) {
//
// Invariant: Uses[id].Pos() != id.Pos()
func (info gopRecorder) Use(id *ast.Ident, obj types.Object) {
if f, ok := obj.(*gox.Func); ok {
obj = &f.Func
}
if debugVerbose {
log.Println("==> Use:", id, obj)
}
Expand Down

0 comments on commit 568cdda

Please sign in to comment.