From ad929663a20aba86f58c02d57dc75cf840c50c39 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Tue, 24 Oct 2023 11:53:50 +0800 Subject: [PATCH] ast: FuncDecl.Shadow --- ast/ast.go | 1 + ast/walk.go | 16 +++++++++------- parser/parser.go | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ast/ast.go b/ast/ast.go index dbac1db09..f0b489532 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -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 } ) diff --git a/ast/walk.go b/ast/walk.go index ba6f4ff18..3cdc64e96 100644 --- a/ast/walk.go +++ b/ast/walk.go @@ -345,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) } diff --git a/parser/parser.go b/parser/parser.go index 43bb6efe8..6a9100d9d 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -3668,7 +3668,8 @@ func (p *parser) parseGlobalStmts(sync map[token.Token]bool, pos token.Pos, stmt Func: pos, Params: &ast.FieldList{}, }, - Body: &ast.BlockStmt{List: list}, + Body: &ast.BlockStmt{List: list}, + Shadow: true, } p.shadowEntry = f return f