]> granicus.if.org Git - clang/commitdiff
-getLang().C99 is true in C++ too, remove the use of the C99orCXX variable.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 10 Sep 2008 23:46:08 +0000 (23:46 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 10 Sep 2008 23:46:08 +0000 (23:46 +0000)
-Scoping in C99 works good for C++ too, remove the C++-specific comments.

If someone thinks that the C++-specific comments are necessary for clarification, let me know and I'll put them back on.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56078 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseStmt.cpp

index 875634daa679912b7a33e10f7c6900ab75d37b82..eb8a074d5a863c2269bbf3e9b757758268a1a61e 100644 (file)
@@ -430,17 +430,9 @@ Parser::StmtResult Parser::ParseIfStatement() {
     return true;
   }
 
-  bool C99orCXX = getLang().C99 || getLang().CPlusPlus;
-
   // 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)
+  if (getLang().C99)
     EnterScope(Scope::DeclScope | Scope::ControlScope);
 
   // Parse the condition.
@@ -455,7 +447,7 @@ Parser::StmtResult Parser::ParseIfStatement() {
 
   if (CondExp.isInvalid) {
     SkipUntil(tok::semi);
-    if (C99orCXX)
+    if (getLang().C99)
       ExitScope();
     return true;
   }
@@ -463,22 +455,7 @@ 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);
+  bool NeedsInnerScope = getLang().C99 && Tok.isNot(tok::l_brace);
   if (NeedsInnerScope) EnterScope(Scope::DeclScope);
 
   // Read the 'then' stmt.
@@ -500,12 +477,7 @@ 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);
+    NeedsInnerScope = getLang().C99 && Tok.isNot(tok::l_brace);
     if (NeedsInnerScope) EnterScope(Scope::DeclScope);
     
     ElseStmtLoc = Tok.getLocation();
@@ -515,7 +487,7 @@ Parser::StmtResult Parser::ParseIfStatement() {
     if (NeedsInnerScope) ExitScope();
   }
   
-  if (C99orCXX)
+  if (getLang().C99)
     ExitScope();
 
   // If the then or else stmt is invalid and the other is valid (and present),
@@ -554,17 +526,9 @@ Parser::StmtResult Parser::ParseSwitchStatement() {
     return true;
   }
 
-  bool C99orCXX = getLang().C99 || getLang().CPlusPlus;
-
   // 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)
+  if (getLang().C99)
     EnterScope(Scope::BreakScope | Scope::DeclScope | Scope::ControlScope);
   else
     EnterScope(Scope::BreakScope);
@@ -589,15 +553,7 @@ 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);
+  bool NeedsInnerScope = getLang().C99 && Tok.isNot(tok::l_brace);
   if (NeedsInnerScope) EnterScope(Scope::DeclScope);
   
   // Read the body statement.
@@ -631,17 +587,9 @@ Parser::StmtResult Parser::ParseWhileStatement() {
     return true;
   }
   
-  bool C99orCXX = getLang().C99 || getLang().CPlusPlus;
-
   // 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)
+  if (getLang().C99)
     EnterScope(Scope::BreakScope | Scope::ContinueScope |
                Scope::DeclScope  | Scope::ControlScope);
   else
@@ -660,15 +608,7 @@ 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);
+  bool NeedsInnerScope = getLang().C99 && Tok.isNot(tok::l_brace);
   if (NeedsInnerScope) EnterScope(Scope::DeclScope);
   
   // Read the body statement.
@@ -760,20 +700,9 @@ Parser::StmtResult Parser::ParseForStatement() {
     return true;
   }
   
-  bool C99orCXX = getLang().C99 || getLang().CPlusPlus;
-
   // 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)
+  if (getLang().C99)
     EnterScope(Scope::BreakScope | Scope::ContinueScope |
                Scope::DeclScope  | Scope::ControlScope);
   else
@@ -793,7 +722,7 @@ Parser::StmtResult Parser::ParseForStatement() {
     ConsumeToken();
   } else if (isDeclarationSpecifier()) {  // for (int X = 4;
     // Parse declaration, which eats the ';'.
-    if (!C99orCXX)   // Use of C99-style for loops in C90 mode?
+    if (!getLang().C99)   // Use of C99-style for loops in C90 mode?
       Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
     
     SourceLocation DeclStart = Tok.getLocation();
@@ -871,15 +800,7 @@ 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);
+  bool NeedsInnerScope = getLang().C99 && Tok.isNot(tok::l_brace);
   if (NeedsInnerScope) EnterScope(Scope::DeclScope);
   
   // Read the body statement.