TokenList::createAst() doesn't validate itself anymore. Remove some duplicated code and fix glitch in TestGarbage::garbageCode162

This commit is contained in:
Alexander Mai 2015-12-12 20:01:03 +01:00
parent 9cb8e9a07e
commit 96531d6ffe
3 changed files with 5 additions and 15 deletions

View File

@ -1742,17 +1742,7 @@ bool Tokenizer::tokenize(std::istream &code,
}
list.createAst();
// Verify that ast looks ok
for (const Token *tok = list.front(); tok; tok = tok->next()) {
// Syntax error if binary operator only has 1 operand
if ((tok->isAssignmentOp() || tok->isComparisonOp() || Token::Match(tok,"[|^/%]")) && tok->astOperand1() && !tok->astOperand2())
throw InternalError(tok, "Syntax Error: AST broken, binary operator has only one operand.", InternalError::SYNTAX);
// Syntax error if we encounter "?" with operand2 that is not ":"
if (tok->astOperand2() && tok->str() == "?" && tok->astOperand2()->str() != ":")
throw InternalError(tok, "Syntax Error: AST broken, ternary operator lacks ':'.", InternalError::SYNTAX);
}
list.validateAst();
SymbolDatabase::setValueTypeInTokenList(list.front());
ValueFlow::setValues(&list, _symbolDatabase, _errorLogger, _settings);
@ -3844,6 +3834,8 @@ bool Tokenizer::simplifyTokenList2()
simplifyPointerConst();
list.createAst();
// skipping this here may help improve performance. Might be enabled later on demand. #7208
// list.validateAst();
ValueFlow::setValues(&list, _symbolDatabase, _errorLogger, _settings);

View File

@ -1054,11 +1054,9 @@ static Token * createAstAtToken(Token *tok, bool cpp)
void TokenList::createAst()
{
for (Token *tok = _front; tok; tok = tok ? tok->next() : NULL) {
for (Token *tok = _front; tok; tok = tok ? tok->next() : nullptr) {
tok = createAstAtToken(tok, isCPP());
}
validateAst();
}
void TokenList::validateAst()

View File

@ -1390,7 +1390,7 @@ private:
void garbageCode162() {
//7208
ASSERT_THROW(checkCode("return << >> x return << >> x ", "test.c"), InternalError);
ASSERT_THROW(checkCode("return << >> x return << >> x ", false), InternalError);
}
};