Refactoring: Allow TemplateSimplifier to throw InternalErrors by itself.

This commit is contained in:
Alexander Mai 2015-06-23 20:53:57 +02:00
parent 69f91ac187
commit f806d945a1
4 changed files with 19 additions and 13 deletions

View File

@ -212,12 +212,13 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke
}
if (level > 0) {
errorToken=tok;
syntaxError(tok);
return true;
}
}
}
return 0;
return false;
}
unsigned int TemplateSimplifier::templateParameters(const Token *tok)
@ -1421,7 +1422,7 @@ void TemplateSimplifier::simplifyTemplates(
templates2.push_back(*iter1);
}
for (std::list<Token *>::iterator it = templates2.begin(); it != templates2.end(); ++it) {
for (std::list<Token *>::const_iterator it = templates2.begin(); it != templates2.end(); ++it) {
std::list<Token *>::iterator it1 = std::find(templates.begin(), templates.end(), *it);
if (it1 != templates.end()) {
templates.erase(it1);
@ -1430,3 +1431,8 @@ void TemplateSimplifier::simplifyTemplates(
}
}
}
void TemplateSimplifier::syntaxError(const Token *tok)
{
throw InternalError(tok, "syntax error", InternalError::SYNTAX);
}

View File

@ -187,6 +187,9 @@ private:
*/
static bool removeTemplate(Token *tok);
/** Syntax error */
static void syntaxError(const Token *tok);
};
/// @}

View File

@ -973,14 +973,12 @@ void Tokenizer::simplifyTypedef()
argEnd = tokOffset->link();
argFuncRetStart = argEnd->tokAt(2);
if (!argFuncRetStart)
{
if (!argFuncRetStart) {
syntaxError(tokOffset);
return;
}
argFuncRetEnd = argFuncRetStart->link();
if (!argFuncRetEnd)
{
if (!argFuncRetEnd) {
syntaxError(tokOffset);
return;
}
@ -994,14 +992,12 @@ void Tokenizer::simplifyTypedef()
argEnd = tokOffset->link();
argFuncRetStart = argEnd->tokAt(2);
if (!argFuncRetStart)
{
if (!argFuncRetStart) {
syntaxError(tokOffset);
return;
}
argFuncRetEnd = argFuncRetStart->link();
if (!argFuncRetEnd)
{
if (!argFuncRetEnd) {
syntaxError(tokOffset);
return;
}
@ -7537,8 +7533,10 @@ void Tokenizer::simplifyEnum()
++classLevel;
} else if (tok->str() == "enum") {
Token *temp = tok->next();
if (!temp)
if (!temp) {
syntaxError(tok);
break;
}
if (Token::Match(temp, "class|struct"))
temp = temp->next();
if (!temp)

View File

@ -3278,8 +3278,7 @@ private:
void enum26() { // ticket #2975 (segmentation fault)
const char code[] = "enum E {} e enum\n";
checkSimplifyEnum(code);
ASSERT_EQUALS("", errout.str());
ASSERT_THROW(checkSimplifyEnum(code), InternalError);
}
void enum27() { // ticket #3005 (segmentation fault)