summaryrefslogtreecommitdiff
path: root/src/shared/cplusplus/Parser.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-03-23 10:17:51 +0100
committerRoberto Raggi <roberto.raggi@nokia.com>2010-03-23 10:18:17 +0100
commit069091eece084e7e27eb02a85fb3da14eb08beeb (patch)
treea8db51773fe396af1515f683017fdef6925fd8eb /src/shared/cplusplus/Parser.cpp
parentc24fd59cb180c0cdd743a0bc5844037a417d0308 (diff)
downloadqt-creator-069091eece084e7e27eb02a85fb3da14eb08beeb.tar.gz
Rewind the memory pool only after parsing a toplevel expression statements.
Diffstat (limited to 'src/shared/cplusplus/Parser.cpp')
-rw-r--r--src/shared/cplusplus/Parser.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp
index 39af8bc96b..363eb5e808 100644
--- a/src/shared/cplusplus/Parser.cpp
+++ b/src/shared/cplusplus/Parser.cpp
@@ -200,6 +200,7 @@ Parser::Parser(TranslationUnit *unit)
_objCEnabled(false),
_inFunctionBody(false),
_inObjCImplementationContext(false),
+ _inExpressionStatement(false),
_expressionDepth(0)
{ }
@@ -2450,21 +2451,34 @@ bool Parser::parseExpressionStatement(StatementAST *&node)
return true;
}
+ const bool wasInExpressionStatement = _inExpressionStatement;
+ _inExpressionStatement = true;
+
+ // switch to the temp pool
+ MemoryPool *previousPool = _pool;
+ _pool = &_expressionStatementTempPool;
+
+ bool parsed = false;
+
ExpressionAST *expression = 0;
- MemoryPool *oldPool = _pool;
- _pool = &_tempPool;
- RecursiveMemoryPool rec(&_tempPool);
if (parseExpression(expression)) {
- ExpressionStatementAST *ast = new (oldPool) ExpressionStatementAST;
- ast->expression = expression->clone(oldPool);
+ ExpressionStatementAST *ast = new (previousPool) ExpressionStatementAST;
+ ast->expression = expression->clone(previousPool);
match(T_SEMICOLON, &ast->semicolon_token);
node = ast;
- _pool = oldPool;
- return true;
+ parsed = true;
}
- _pool = oldPool;
- return false;
+ _inExpressionStatement = wasInExpressionStatement;
+
+ if (! _inExpressionStatement) {
+ // rewind the memory pool after parsing a toplevel expression statement.
+ _expressionStatementTempPool.reset();
+ }
+
+ // restore the pool
+ _pool = previousPool;
+ return parsed;
}
bool Parser::parseStatement(StatementAST *&node)