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

ast.Walk: support OverloadFuncDecl #1671

Merged
merged 1 commit into from
Jan 26, 2024
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
23 changes: 21 additions & 2 deletions ast/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,18 @@ func Walk(v Visitor, node Node) {
}

// Expressions
case *BadExpr, *Ident, *BasicLit:
case *BadExpr, *Ident:
// nothing to do

case *BasicLit:
if n.Extra != nil { // Go+ extended
for _, part := range n.Extra.Parts {
if e, ok := part.(Expr); ok {
Walk(v, e)
}
}
}

case *Ellipsis:
if n.Elt != nil {
Walk(v, n.Elt)
Expand Down Expand Up @@ -377,7 +386,7 @@ func Walk(v Visitor, node Node) {
Walk(v, f)
}

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

Expand Down Expand Up @@ -433,6 +442,16 @@ func Walk(v Visitor, node Node) {
Walk(v, n.Default)
}

case *OverloadFuncDecl:
if n.Doc != nil {
Walk(v, n.Doc)
}
if n.Recv != nil {
Walk(v, n.Recv)
}
Walk(v, n.Name)
walkExprList(v, n.Funcs)

default:
panic(fmt.Sprintf("ast.Walk: unexpected node type %T", n))
}
Expand Down
2 changes: 1 addition & 1 deletion cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ func compileErrWrapExpr(ctx *blockCtx, v *ast.ErrWrapExpr, inFlags int) {
retName = "_gop_ret" + strconv.Itoa(i+1)
}
}
sig := types.NewSignature(nil, nil, types.NewTuple(ret...), false)
sig := types.NewSignatureType(nil, nil, nil, nil, types.NewTuple(ret...), false)
if useClosure {
cb.NewClosureWith(sig).BodyStart(pkg)
} else {
Expand Down
3 changes: 3 additions & 0 deletions parser/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ const (
AllErrors = Mode(goparser.AllErrors)
// SkipObjectResolution - don't resolve identifiers to objects - see ParseFile
SkipObjectResolution = Mode(goparser.SkipObjectResolution)

// ParseGoAsGoPlus - parse Go files by gop/parser
ParseGoAsGoPlus Mode = 1 << 16
// ParserGoPlusClass - parse Go+ classfile by gop/parser
ParseGoPlusClass Mode = 1 << 17
// SaveAbsFile - parse and save absolute path to pkg.Files
SaveAbsFile Mode = 1 << 18

goReservedFlags Mode = ((1 << 16) - 1)
)

// -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion parser/parser_gop.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func ParseFSDir(fset *token.FileSet, fs FileSystem, dir string, conf Config) (pk
filename := fs.Join(dir, fname)
if useGoParser {
if filedata, err := fs.ReadFile(filename); err == nil {
if src, err := goparser.ParseFile(fset, filename, filedata, goparser.Mode(conf.Mode)); err == nil {
if src, err := goparser.ParseFile(fset, filename, filedata, goparser.Mode(conf.Mode&goReservedFlags)); err == nil {
pkg := reqPkg(pkgs, src.Name.Name)
if pkg.GoFiles == nil {
pkg.GoFiles = make(map[string]*goast.File)
Expand Down