2222
2323// cxx
2424#include < cxx/ast.h>
25+ #include < cxx/binder.h>
2526#include < cxx/control.h>
2627#include < cxx/decl.h>
2728#include < cxx/decl_specs.h>
29+ #include < cxx/symbols.h>
2830#include < cxx/translation_unit.h>
2931#include < cxx/type_checker.h>
32+ #include < cxx/types.h>
3033
3134namespace cxx {
3235
@@ -2016,6 +2019,15 @@ auto ASTRewriter::StatementVisitor::operator()(CompoundStatementAST* ast)
20162019 -> StatementAST* {
20172020 auto copy = make_node<CompoundStatementAST>(arena ());
20182021
2022+ auto _ = Binder::ScopeGuard (&rewrite.binder_ );
2023+
2024+ if (ast->symbol ) {
2025+ copy->symbol = control ()->newBlockSymbol (rewrite.binder_ .scope (),
2026+ ast->symbol ->location ());
2027+
2028+ rewrite.binder_ .setScope (copy->symbol );
2029+ }
2030+
20192031 copy->lbraceLoc = ast->lbraceLoc ;
20202032
20212033 if (auto it = ast->statementList ) {
@@ -2028,7 +2040,6 @@ auto ASTRewriter::StatementVisitor::operator()(CompoundStatementAST* ast)
20282040 }
20292041
20302042 copy->rbraceLoc = ast->rbraceLoc ;
2031- copy->symbol = ast->symbol ;
20322043
20332044 return copy;
20342045}
@@ -2037,6 +2048,15 @@ auto ASTRewriter::StatementVisitor::operator()(IfStatementAST* ast)
20372048 -> StatementAST* {
20382049 auto copy = make_node<IfStatementAST>(arena ());
20392050
2051+ auto _ = Binder::ScopeGuard (&rewrite.binder_ );
2052+
2053+ if (ast->symbol ) {
2054+ copy->symbol = control ()->newBlockSymbol (rewrite.binder_ .scope (),
2055+ ast->symbol ->location ());
2056+
2057+ rewrite.binder_ .setScope (copy->symbol );
2058+ }
2059+
20402060 copy->ifLoc = ast->ifLoc ;
20412061 copy->constexprLoc = ast->constexprLoc ;
20422062 copy->lparenLoc = ast->lparenLoc ;
@@ -2069,6 +2089,15 @@ auto ASTRewriter::StatementVisitor::operator()(SwitchStatementAST* ast)
20692089 -> StatementAST* {
20702090 auto copy = make_node<SwitchStatementAST>(arena ());
20712091
2092+ auto _ = Binder::ScopeGuard (&rewrite.binder_ );
2093+
2094+ if (ast->symbol ) {
2095+ copy->symbol = control ()->newBlockSymbol (rewrite.binder_ .scope (),
2096+ ast->symbol ->location ());
2097+
2098+ rewrite.binder_ .setScope (copy->symbol );
2099+ }
2100+
20722101 copy->switchLoc = ast->switchLoc ;
20732102 copy->lparenLoc = ast->lparenLoc ;
20742103 copy->initializer = rewrite (ast->initializer );
@@ -2083,6 +2112,15 @@ auto ASTRewriter::StatementVisitor::operator()(WhileStatementAST* ast)
20832112 -> StatementAST* {
20842113 auto copy = make_node<WhileStatementAST>(arena ());
20852114
2115+ auto _ = Binder::ScopeGuard (&rewrite.binder_ );
2116+
2117+ if (ast->symbol ) {
2118+ copy->symbol = control ()->newBlockSymbol (rewrite.binder_ .scope (),
2119+ ast->symbol ->location ());
2120+
2121+ rewrite.binder_ .setScope (copy->symbol );
2122+ }
2123+
20862124 copy->whileLoc = ast->whileLoc ;
20872125 copy->lparenLoc = ast->lparenLoc ;
20882126 copy->condition = rewrite (ast->condition );
@@ -2111,6 +2149,15 @@ auto ASTRewriter::StatementVisitor::operator()(ForRangeStatementAST* ast)
21112149 -> StatementAST* {
21122150 auto copy = make_node<ForRangeStatementAST>(arena ());
21132151
2152+ auto _ = Binder::ScopeGuard (&rewrite.binder_ );
2153+
2154+ if (ast->symbol ) {
2155+ copy->symbol = control ()->newBlockSymbol (rewrite.binder_ .scope (),
2156+ ast->symbol ->location ());
2157+
2158+ rewrite.binder_ .setScope (copy->symbol );
2159+ }
2160+
21142161 copy->forLoc = ast->forLoc ;
21152162 copy->lparenLoc = ast->lparenLoc ;
21162163 copy->initializer = rewrite (ast->initializer );
@@ -2127,6 +2174,15 @@ auto ASTRewriter::StatementVisitor::operator()(ForStatementAST* ast)
21272174 -> StatementAST* {
21282175 auto copy = make_node<ForStatementAST>(arena ());
21292176
2177+ auto _ = Binder::ScopeGuard (&rewrite.binder_ );
2178+
2179+ if (ast->symbol ) {
2180+ copy->symbol = control ()->newBlockSymbol (rewrite.binder_ .scope (),
2181+ ast->symbol ->location ());
2182+
2183+ rewrite.binder_ .setScope (copy->symbol );
2184+ }
2185+
21302186 copy->forLoc = ast->forLoc ;
21312187 copy->lparenLoc = ast->lparenLoc ;
21322188 copy->initializer = rewrite (ast->initializer );
0 commit comments