Skip to content

Commit

Permalink
Merge pull request #1671 from xushiwei/class
Browse files Browse the repository at this point in the history
ast.Walk: support OverloadFuncDecl
  • Loading branch information
xushiwei committed Jan 26, 2024
2 parents 2c25669 + 4b1428b commit 182883e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
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

0 comments on commit 182883e

Please sign in to comment.