зеркало из https://github.com/microsoft/clang-1.git
optimize scope push/pop to avoid work in the common case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41265 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
0ecea03077
Коммит
38484403c8
|
@ -434,8 +434,10 @@ Parser::StmtResult Parser::ParseIfStatement() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// C99 6.8.4p3 - In C99, the body of the if statement is a scope, even if
|
// 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.
|
// there is no compound stmt. C90 does not have this clause. We only do this
|
||||||
if (getLang().C99) EnterScope(0);
|
// if the body isn't a compound statement to avoid push/pop in common cases.
|
||||||
|
bool NeedsInnerScope = getLang().C99 && Tok.getKind() != tok::l_brace;
|
||||||
|
if (NeedsInnerScope) EnterScope(0);
|
||||||
|
|
||||||
// Read the if condition.
|
// Read the if condition.
|
||||||
StmtResult CondStmt = ParseStatement();
|
StmtResult CondStmt = ParseStatement();
|
||||||
|
@ -445,7 +447,7 @@ Parser::StmtResult Parser::ParseIfStatement() {
|
||||||
CondStmt = Actions.ParseNullStmt(Tok.getLocation());
|
CondStmt = Actions.ParseNullStmt(Tok.getLocation());
|
||||||
|
|
||||||
// Pop the 'if' scope if needed.
|
// Pop the 'if' scope if needed.
|
||||||
if (getLang().C99) ExitScope();
|
if (NeedsInnerScope) ExitScope();
|
||||||
|
|
||||||
// If it has an else, parse it.
|
// If it has an else, parse it.
|
||||||
SourceLocation ElseLoc;
|
SourceLocation ElseLoc;
|
||||||
|
@ -454,13 +456,16 @@ Parser::StmtResult Parser::ParseIfStatement() {
|
||||||
ElseLoc = ConsumeToken();
|
ElseLoc = ConsumeToken();
|
||||||
|
|
||||||
// C99 6.8.4p3 - In C99, the body of the if statement is a scope, even if
|
// 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.
|
// there is no compound stmt. C90 does not have this clause. We only do
|
||||||
if (getLang().C99) EnterScope(0);
|
// this if the body isn't a compound statement to avoid push/pop in common
|
||||||
|
// cases.
|
||||||
|
NeedsInnerScope = getLang().C99 && Tok.getKind() != tok::l_brace;
|
||||||
|
if (NeedsInnerScope) EnterScope(0);
|
||||||
|
|
||||||
ElseStmt = ParseStatement();
|
ElseStmt = ParseStatement();
|
||||||
|
|
||||||
// Pop the 'else' scope if needed.
|
// Pop the 'else' scope if needed.
|
||||||
if (getLang().C99) ExitScope();
|
if (NeedsInnerScope) ExitScope();
|
||||||
|
|
||||||
if (ElseStmt.isInvalid)
|
if (ElseStmt.isInvalid)
|
||||||
ElseStmt = Actions.ParseNullStmt(ElseLoc);
|
ElseStmt = Actions.ParseNullStmt(ElseLoc);
|
||||||
|
@ -497,14 +502,16 @@ Parser::StmtResult Parser::ParseSwitchStatement() {
|
||||||
StmtResult Switch = Actions.StartSwitchStmt(Cond.Val);
|
StmtResult Switch = Actions.StartSwitchStmt(Cond.Val);
|
||||||
|
|
||||||
// C99 6.8.4p3 - In C99, the body of the switch statement is a scope, even if
|
// 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.
|
// there is no compound stmt. C90 does not have this clause. We only do this
|
||||||
if (getLang().C99) EnterScope(0);
|
// if the body isn't a compound statement to avoid push/pop in common cases.
|
||||||
|
bool NeedsInnerScope = getLang().C99 && Tok.getKind() != tok::l_brace;
|
||||||
|
if (NeedsInnerScope) EnterScope(0);
|
||||||
|
|
||||||
// Read the body statement.
|
// Read the body statement.
|
||||||
StmtResult Body = ParseStatement();
|
StmtResult Body = ParseStatement();
|
||||||
|
|
||||||
// Pop the body scope if needed.
|
// Pop the body scope if needed.
|
||||||
if (getLang().C99) ExitScope();
|
if (NeedsInnerScope) ExitScope();
|
||||||
|
|
||||||
if (Body.isInvalid) {
|
if (Body.isInvalid) {
|
||||||
Body = Actions.ParseNullStmt(Tok.getLocation());
|
Body = Actions.ParseNullStmt(Tok.getLocation());
|
||||||
|
@ -537,14 +544,16 @@ Parser::StmtResult Parser::ParseWhileStatement() {
|
||||||
ExprResult Cond = ParseSimpleParenExpression();
|
ExprResult Cond = ParseSimpleParenExpression();
|
||||||
|
|
||||||
// C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
|
// 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.
|
// there is no compound stmt. C90 does not have this clause. We only do this
|
||||||
if (getLang().C99) EnterScope(0);
|
// if the body isn't a compound statement to avoid push/pop in common cases.
|
||||||
|
bool NeedsInnerScope = getLang().C99 && Tok.getKind() != tok::l_brace;
|
||||||
|
if (NeedsInnerScope) EnterScope(0);
|
||||||
|
|
||||||
// Read the body statement.
|
// Read the body statement.
|
||||||
StmtResult Body = ParseStatement();
|
StmtResult Body = ParseStatement();
|
||||||
|
|
||||||
// Pop the body scope if needed.
|
// Pop the body scope if needed.
|
||||||
if (getLang().C99) ExitScope();
|
if (NeedsInnerScope) ExitScope();
|
||||||
|
|
||||||
ExitScope();
|
ExitScope();
|
||||||
|
|
||||||
|
@ -565,14 +574,16 @@ Parser::StmtResult Parser::ParseDoStatement() {
|
||||||
EnterScope(Scope::BreakScope | Scope::ContinueScope);
|
EnterScope(Scope::BreakScope | Scope::ContinueScope);
|
||||||
|
|
||||||
// C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
|
// 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.
|
// there is no compound stmt. C90 does not have this clause. We only do this
|
||||||
if (getLang().C99) EnterScope(0);
|
// if the body isn't a compound statement to avoid push/pop in common cases.
|
||||||
|
bool NeedsInnerScope = getLang().C99 && Tok.getKind() != tok::l_brace;
|
||||||
|
if (NeedsInnerScope) EnterScope(0);
|
||||||
|
|
||||||
// Read the body statement.
|
// Read the body statement.
|
||||||
StmtResult Body = ParseStatement();
|
StmtResult Body = ParseStatement();
|
||||||
|
|
||||||
// Pop the body scope if needed.
|
// Pop the body scope if needed.
|
||||||
if (getLang().C99) ExitScope();
|
if (NeedsInnerScope) ExitScope();
|
||||||
|
|
||||||
if (Tok.getKind() != tok::kw_while) {
|
if (Tok.getKind() != tok::kw_while) {
|
||||||
ExitScope();
|
ExitScope();
|
||||||
|
@ -687,14 +698,16 @@ Parser::StmtResult Parser::ParseForStatement() {
|
||||||
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
||||||
|
|
||||||
// C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
|
// 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.
|
// there is no compound stmt. C90 does not have this clause. We only do this
|
||||||
if (getLang().C99) EnterScope(0);
|
// if the body isn't a compound statement to avoid push/pop in common cases.
|
||||||
|
bool NeedsInnerScope = getLang().C99 && Tok.getKind() != tok::l_brace;
|
||||||
|
if (NeedsInnerScope) EnterScope(0);
|
||||||
|
|
||||||
// Read the body statement.
|
// Read the body statement.
|
||||||
StmtResult Body = ParseStatement();
|
StmtResult Body = ParseStatement();
|
||||||
|
|
||||||
// Pop the body scope if needed.
|
// Pop the body scope if needed.
|
||||||
if (getLang().C99) ExitScope();
|
if (NeedsInnerScope) ExitScope();
|
||||||
|
|
||||||
// Leave the for-scope.
|
// Leave the for-scope.
|
||||||
ExitScope();
|
ExitScope();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче