Skip to content

Commit

Permalink
Merge pull request #1490 from xushiwei/q
Browse files Browse the repository at this point in the history
ast: FuncDecl.Shadow
  • Loading branch information
xushiwei authored Oct 24, 2023
2 parents 27d8dc2 + ad92966 commit c53cbfa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)

Expand Down
16 changes: 9 additions & 7 deletions ast/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c53cbfa

Please sign in to comment.