aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/ParseStmt.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-09-10 17:38:35 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-09-10 17:38:35 +0000
commit957163829d04d89177b97be11a05a21242f4e10e (patch)
tree62a3303131ef968d3901c4655d65ea35cbce18db /lib/Parse/ParseStmt.cpp
parent639ffe47097d01249b98b7acd102aaad6697b43a (diff)
Add some C++-specific comments in the parsing methods of if/switch/while/for.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56060 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseStmt.cpp')
-rw-r--r--lib/Parse/ParseStmt.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 83ec302fc4..875634daa6 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -434,6 +434,12 @@ Parser::StmtResult Parser::ParseIfStatement() {
// C99 6.8.4p3 - In C99, the if statement is a block. This is not
// the case for C90.
+ //
+ // C++ 6.4p3:
+ // A name introduced by a declaration in a condition is in scope from its
+ // point of declaration until the end of the substatements controlled by the
+ // condition.
+ //
if (C99orCXX)
EnterScope(Scope::DeclScope | Scope::ControlScope);
@@ -457,6 +463,21 @@ Parser::StmtResult Parser::ParseIfStatement() {
// C99 6.8.4p3 - In C99, the body of the if statement is a scope, even if
// there is no compound stmt. C90 does not have this clause. We only do this
// if the body isn't a compound statement to avoid push/pop in common cases.
+ //
+ // C++ 6.4p1:
+ // The substatement in a selection-statement (each substatement, in the else
+ // form of the if statement) implicitly defines a local scope.
+ //
+ // For C++ we create a scope for the condition and a new scope for
+ // substatements because:
+ // -When the 'then' scope exits, we want the condition declaration to still be
+ // active for the 'else' scope too.
+ // -Sema will detect name clashes by considering declarations of a
+ // 'ControlScope' as part of its direct subscope.
+ // -If we wanted the condition and substatement to be in the same scope, we
+ // would have to notify ParseStatement not to create a new scope. It's
+ // simpler to let it create a new scope.
+ //
bool NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
if (NeedsInnerScope) EnterScope(Scope::DeclScope);
@@ -479,6 +500,11 @@ Parser::StmtResult Parser::ParseIfStatement() {
// there is no compound stmt. C90 does not have this clause. We only do
// this if the body isn't a compound statement to avoid push/pop in common
// cases.
+ //
+ // C++ 6.4p1:
+ // The substatement in a selection-statement (each substatement, in the else
+ // form of the if statement) implicitly defines a local scope.
+ //
NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
if (NeedsInnerScope) EnterScope(Scope::DeclScope);
@@ -532,6 +558,12 @@ Parser::StmtResult Parser::ParseSwitchStatement() {
// C99 6.8.4p3 - In C99, the switch statement is a block. This is
// not the case for C90. Start the switch scope.
+ //
+ // C++ 6.4p3:
+ // A name introduced by a declaration in a condition is in scope from its
+ // point of declaration until the end of the substatements controlled by the
+ // condition.
+ //
if (C99orCXX)
EnterScope(Scope::BreakScope | Scope::DeclScope | Scope::ControlScope);
else
@@ -557,6 +589,14 @@ Parser::StmtResult Parser::ParseSwitchStatement() {
// C99 6.8.4p3 - In C99, the body of the switch statement is a scope, even if
// there is no compound stmt. C90 does not have this clause. We only do this
// if the body isn't a compound statement to avoid push/pop in common cases.
+ //
+ // C++ 6.4p1:
+ // The substatement in a selection-statement (each substatement, in the else
+ // form of the if statement) implicitly defines a local scope.
+ //
+ // See comments in ParseIfStatement for why we create a scope for the
+ // condition and a new scope for substatement in C++.
+ //
bool NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
if (NeedsInnerScope) EnterScope(Scope::DeclScope);
@@ -595,6 +635,12 @@ Parser::StmtResult Parser::ParseWhileStatement() {
// C99 6.8.5p5 - In C99, the while statement is a block. This is not
// the case for C90. Start the loop scope.
+ //
+ // C++ 6.4p3:
+ // A name introduced by a declaration in a condition is in scope from its
+ // point of declaration until the end of the substatements controlled by the
+ // condition.
+ //
if (C99orCXX)
EnterScope(Scope::BreakScope | Scope::ContinueScope |
Scope::DeclScope | Scope::ControlScope);
@@ -614,6 +660,14 @@ Parser::StmtResult Parser::ParseWhileStatement() {
// C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
// there is no compound stmt. C90 does not have this clause. We only do this
// if the body isn't a compound statement to avoid push/pop in common cases.
+ //
+ // C++ 6.5p2:
+ // The substatement in an iteration-statement implicitly defines a local scope
+ // which is entered and exited each time through the loop.
+ //
+ // See comments in ParseIfStatement for why we create a scope for the
+ // condition and a new scope for substatement in C++.
+ //
bool NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
if (NeedsInnerScope) EnterScope(Scope::DeclScope);
@@ -710,6 +764,15 @@ Parser::StmtResult Parser::ParseForStatement() {
// C99 6.8.5p5 - In C99, the for statement is a block. This is not
// the case for C90. Start the loop scope.
+ //
+ // C++ 6.4p3:
+ // A name introduced by a declaration in a condition is in scope from its
+ // point of declaration until the end of the substatements controlled by the
+ // condition.
+ // C++ 6.5.3p1:
+ // Names declared in the for-init-statement are in the same declarative-region
+ // as those declared in the condition.
+ //
if (C99orCXX)
EnterScope(Scope::BreakScope | Scope::ContinueScope |
Scope::DeclScope | Scope::ControlScope);
@@ -808,6 +871,14 @@ Parser::StmtResult Parser::ParseForStatement() {
// C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
// there is no compound stmt. C90 does not have this clause. We only do this
// if the body isn't a compound statement to avoid push/pop in common cases.
+ //
+ // C++ 6.5p2:
+ // The substatement in an iteration-statement implicitly defines a local scope
+ // which is entered and exited each time through the loop.
+ //
+ // See comments in ParseIfStatement for why we create a scope for
+ // for-init-statement/condition and a new scope for substatement in C++.
+ //
bool NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
if (NeedsInnerScope) EnterScope(Scope::DeclScope);