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) { if (level > 0) {
errorToken=tok; errorToken=tok;
syntaxError(tok);
return true; return true;
} }
} }
} }
return 0; return false;
} }
unsigned int TemplateSimplifier::templateParameters(const Token *tok) unsigned int TemplateSimplifier::templateParameters(const Token *tok)
@ -1421,7 +1422,7 @@ void TemplateSimplifier::simplifyTemplates(
templates2.push_back(*iter1); 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); std::list<Token *>::iterator it1 = std::find(templates.begin(), templates.end(), *it);
if (it1 != templates.end()) { if (it1 != templates.end()) {
templates.erase(it1); 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); 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(); argEnd = tokOffset->link();
argFuncRetStart = argEnd->tokAt(2); argFuncRetStart = argEnd->tokAt(2);
if (!argFuncRetStart) if (!argFuncRetStart) {
{
syntaxError(tokOffset); syntaxError(tokOffset);
return; return;
} }
argFuncRetEnd = argFuncRetStart->link(); argFuncRetEnd = argFuncRetStart->link();
if (!argFuncRetEnd) if (!argFuncRetEnd) {
{
syntaxError(tokOffset); syntaxError(tokOffset);
return; return;
} }
@ -994,14 +992,12 @@ void Tokenizer::simplifyTypedef()
argEnd = tokOffset->link(); argEnd = tokOffset->link();
argFuncRetStart = argEnd->tokAt(2); argFuncRetStart = argEnd->tokAt(2);
if (!argFuncRetStart) if (!argFuncRetStart) {
{
syntaxError(tokOffset); syntaxError(tokOffset);
return; return;
} }
argFuncRetEnd = argFuncRetStart->link(); argFuncRetEnd = argFuncRetStart->link();
if (!argFuncRetEnd) if (!argFuncRetEnd) {
{
syntaxError(tokOffset); syntaxError(tokOffset);
return; return;
} }
@ -7537,8 +7533,10 @@ void Tokenizer::simplifyEnum()
++classLevel; ++classLevel;
} else if (tok->str() == "enum") { } else if (tok->str() == "enum") {
Token *temp = tok->next(); Token *temp = tok->next();
if (!temp) if (!temp) {
syntaxError(tok);
break; break;
}
if (Token::Match(temp, "class|struct")) if (Token::Match(temp, "class|struct"))
temp = temp->next(); temp = temp->next();
if (!temp) if (!temp)

View File

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