}
// Enter a scope to hold everything within the compound stmt. Compound
// statements can always hold declarations.
- EnterScope(Scope::DeclScope);
+ ParseScope BodyScope(this, Scope::DeclScope);
OwningStmtResult SynchBody(Actions, ParseCompoundStatementBody());
- ExitScope();
+ BodyScope.Exit();
if (SynchBody.isInvalid())
SynchBody = Actions.ActOnNullStmt(Tok.getLocation());
return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.release(),
}
OwningStmtResult CatchStmts(Actions);
OwningStmtResult FinallyStmt(Actions);
- EnterScope(Scope::DeclScope);
+ ParseScope TryScope(this, Scope::DeclScope);
OwningStmtResult TryBody(Actions, ParseCompoundStatementBody());
- ExitScope();
+ TryScope.Exit();
if (TryBody.isInvalid())
TryBody = Actions.ActOnNullStmt(Tok.getLocation());
ConsumeToken(); // consume catch
if (Tok.is(tok::l_paren)) {
ConsumeParen();
- EnterScope(Scope::DeclScope);
+ ParseScope CatchScope(this, Scope::DeclScope);
if (Tok.isNot(tok::ellipsis)) {
DeclSpec DS;
ParseDeclarationSpecifiers(DS);
CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc,
RParenLoc, FirstPart.release(), CatchBody.release(),
CatchStmts.release());
- ExitScope();
} else {
Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after)
<< "@catch clause";
} else {
assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?");
ConsumeToken(); // consume finally
- EnterScope(Scope::DeclScope);
-
+ ParseScope FinallyScope(this, Scope::DeclScope);
OwningStmtResult FinallyBody(Actions, true);
if (Tok.is(tok::l_brace))
FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
FinallyBody.release());
catch_or_finally_seen = true;
- ExitScope();
break;
}
}
SourceLocation BraceLoc = Tok.getLocation();
// Enter a scope for the method body.
- EnterScope(Scope::FnScope|Scope::DeclScope);
+ ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
// Tell the actions module that we have entered a method definition with the
// specified Declarator for the method.
FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 0, 0, false);
// Leave the function body scope.
- ExitScope();
+ BodyScope.Exit();
// TODO: Pass argument information.
Actions.ActOnFinishFunctionBody(MDecl, FnBody.release());
// Enter a scope to hold everything within the compound stmt. Compound
// statements can always hold declarations.
- EnterScope(Scope::DeclScope);
+ ParseScope CompoundScope(this, Scope::DeclScope);
// Parse the statements in the body.
OwningStmtResult Body(Actions, ParseCompoundStatementBody(isStmtExpr));
-
- ExitScope();
return Body.result();
}
// while, for, and switch statements are local to the if, while, for, or
// switch statement (including the controlled statement).
//
- if (C99orCXX)
- EnterScope(Scope::DeclScope | Scope::ControlScope);
+ ParseScope IfScope(this, Scope::DeclScope | Scope::ControlScope, C99orCXX);
// Parse the condition.
OwningExprResult CondExp(Actions);
if (CondExp.isInvalid()) {
SkipUntil(tok::semi);
- if (C99orCXX)
- ExitScope();
return true;
}
// 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);
+ ParseScope InnerScope(this, Scope::DeclScope,
+ C99orCXX && Tok.isNot(tok::l_brace));
// Read the 'then' stmt.
SourceLocation ThenStmtLoc = Tok.getLocation();
OwningStmtResult ThenStmt(Actions, ParseStatement());
// Pop the 'if' scope if needed.
- if (NeedsInnerScope) ExitScope();
+ InnerScope.Exit();
// If it has an else, parse it.
SourceLocation ElseLoc;
// 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);
+ ParseScope InnerScope(this, Scope::DeclScope,
+ C99orCXX && Tok.isNot(tok::l_brace));
ElseStmtLoc = Tok.getLocation();
ElseStmt = ParseStatement();
// Pop the 'else' scope if needed.
- if (NeedsInnerScope) ExitScope();
+ InnerScope.Exit();
}
- if (C99orCXX)
- ExitScope();
+ IfScope.Exit();
// If the then or else stmt is invalid and the other is valid (and present),
// make turn the invalid one into a null stmt to avoid dropping the other
// while, for, and switch statements are local to the if, while, for, or
// switch statement (including the controlled statement).
//
- if (C99orCXX)
- EnterScope(Scope::BreakScope | Scope::DeclScope | Scope::ControlScope);
- else
- EnterScope(Scope::BreakScope);
+ unsigned ScopeFlags
+ = C99orCXX? Scope::BreakScope | Scope::DeclScope | Scope::ControlScope
+ : Scope::BreakScope;
+ ParseScope SwitchScope(this, ScopeFlags);
// Parse the condition.
OwningExprResult Cond(Actions);
Cond = ParseSimpleParenExpression();
}
- if (Cond.isInvalid()) {
- ExitScope();
+ if (Cond.isInvalid())
return true;
- }
OwningStmtResult Switch(Actions,
Actions.ActOnStartOfSwitchStmt(Cond.release()));
// 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);
+ ParseScope InnerScope(this, Scope::DeclScope,
+ C99orCXX && Tok.isNot(tok::l_brace));
// Read the body statement.
OwningStmtResult Body(Actions, ParseStatement());
// Pop the body scope if needed.
- if (NeedsInnerScope) ExitScope();
+ InnerScope.Exit();
if (Body.isInvalid()) {
Body = Actions.ActOnNullStmt(Tok.getLocation());
// FIXME: Remove the case statement list from the Switch statement.
}
-
- ExitScope();
+
+ SwitchScope.Exit();
return Actions.ActOnFinishSwitchStmt(SwitchLoc, Switch.release(),
Body.release());
// while, for, and switch statements are local to the if, while, for, or
// switch statement (including the controlled statement).
//
+ unsigned ScopeFlags;
if (C99orCXX)
- EnterScope(Scope::BreakScope | Scope::ContinueScope |
- Scope::DeclScope | Scope::ControlScope);
+ ScopeFlags = Scope::BreakScope | Scope::ContinueScope |
+ Scope::DeclScope | Scope::ControlScope;
else
- EnterScope(Scope::BreakScope | Scope::ContinueScope);
+ ScopeFlags = Scope::BreakScope | Scope::ContinueScope;
+ ParseScope WhileScope(this, ScopeFlags);
// Parse the condition.
OwningExprResult Cond(Actions);
// 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);
+ ParseScope InnerScope(this, Scope::DeclScope,
+ C99orCXX && Tok.isNot(tok::l_brace));
// Read the body statement.
OwningStmtResult Body(Actions, ParseStatement());
// Pop the body scope if needed.
- if (NeedsInnerScope) ExitScope();
-
- ExitScope();
+ InnerScope.Exit();
+ WhileScope.Exit();
if (Cond.isInvalid() || Body.isInvalid()) return true;
// C99 6.8.5p5 - In C99, the do statement is a block. This is not
// the case for C90. Start the loop scope.
+ unsigned ScopeFlags;
if (getLang().C99)
- EnterScope(Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope);
+ ScopeFlags = Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope;
else
- EnterScope(Scope::BreakScope | Scope::ContinueScope);
+ ScopeFlags = Scope::BreakScope | Scope::ContinueScope;
+
+ ParseScope DoScope(this, ScopeFlags);
// 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
// The substatement in an iteration-statement implicitly defines a local scope
// which is entered and exited each time through the loop.
//
- bool NeedsInnerScope =
- (getLang().C99 || getLang().CPlusPlus) && Tok.isNot(tok::l_brace);
- if (NeedsInnerScope) EnterScope(Scope::DeclScope);
+ ParseScope InnerScope(this, Scope::DeclScope,
+ (getLang().C99 || getLang().CPlusPlus) &&
+ Tok.isNot(tok::l_brace));
// Read the body statement.
OwningStmtResult Body(Actions, ParseStatement());
// Pop the body scope if needed.
- if (NeedsInnerScope) ExitScope();
+ InnerScope.Exit();
if (Tok.isNot(tok::kw_while)) {
- ExitScope();
if (!Body.isInvalid()) {
Diag(Tok, diag::err_expected_while);
Diag(DoLoc, diag::note_matching) << "do";
SourceLocation WhileLoc = ConsumeToken();
if (Tok.isNot(tok::l_paren)) {
- ExitScope();
Diag(Tok, diag::err_expected_lparen_after) << "do/while";
SkipUntil(tok::semi, false, true);
return true;
// Parse the condition.
OwningExprResult Cond(Actions, ParseSimpleParenExpression());
-
- ExitScope();
+ DoScope.Exit();
if (Cond.isInvalid() || Body.isInvalid()) return true;
// Names declared in the for-init-statement are in the same declarative-region
// as those declared in the condition.
//
+ unsigned ScopeFlags;
if (C99orCXX)
- EnterScope(Scope::BreakScope | Scope::ContinueScope |
- Scope::DeclScope | Scope::ControlScope);
+ ScopeFlags = Scope::BreakScope | Scope::ContinueScope |
+ Scope::DeclScope | Scope::ControlScope;
else
- EnterScope(Scope::BreakScope | Scope::ContinueScope);
+ ScopeFlags = Scope::BreakScope | Scope::ContinueScope;
+
+ ParseScope ForScope(this, ScopeFlags);
SourceLocation LParenLoc = ConsumeParen();
OwningExprResult Value(Actions);
// 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);
+ ParseScope InnerScope(this, Scope::DeclScope,
+ C99orCXX && Tok.isNot(tok::l_brace));
// Read the body statement.
OwningStmtResult Body(Actions, ParseStatement());
// Pop the body scope if needed.
- if (NeedsInnerScope) ExitScope();
+ InnerScope.Exit();
// Leave the for-scope.
- ExitScope();
+ ForScope.Exit();
if (Body.isInvalid())
return true;
if (FnBody.isInvalid())
FnBody = Actions.ActOnCompoundStmt(L, R, 0, 0, false);
- // Leave the function body scope.
- ExitScope();
-
return Actions.ActOnFinishFunctionBody(Decl, FnBody.release());
}