Commit 069091ee authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Rewind the memory pool only after parsing a toplevel expression statements.

parent c24fd59c
......@@ -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)
......
......@@ -315,9 +315,10 @@ private:
bool _objCEnabled: 1;
bool _inFunctionBody: 1;
bool _inObjCImplementationContext: 1;
bool _inExpressionStatement: 1;
int _expressionDepth;
MemoryPool _tempPool;
MemoryPool _expressionStatementTempPool;
std::map<unsigned, TemplateArgumentListEntry> _templateArgumentList;
class Rewind;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment