Refactoring: Extract sizeof simplifying from template simplifying

This commit is contained in:
Reijo Tomperi 2012-01-08 00:21:12 +02:00
parent 93e3e7361e
commit 3c0ada52e6
1 changed files with 11 additions and 9 deletions

View File

@ -2798,15 +2798,6 @@ void Tokenizer::simplifyTemplateInstantions(const Token *tok,
if (tok2->str() != name) if (tok2->str() != name)
continue; continue;
// #2648 - simple fix for sizeof used as template parameter
// TODO: this is a bit hardcoded. make a bit more generic
if (Token::Match(tok2, "%var% < sizeof ( %type% ) >") && tok2->tokAt(4)->isStandardType()) {
Token * const tok3 = tok2->next();
const unsigned int sizeOfResult = sizeOfType(tok3->tokAt(3));
tok3->deleteNext(4);
tok3->insertToken(MathLib::toString<unsigned int>(sizeOfResult));
}
if (Token::Match(tok2->previous(), "[;{}=]") && if (Token::Match(tok2->previous(), "[;{}=]") &&
!TemplateSimplifier::simplifyTemplatesInstantiateMatch(*iter2, name, typeParametersInDeclaration.size(), isfunc ? "(" : "*| %var%")) !TemplateSimplifier::simplifyTemplatesInstantiateMatch(*iter2, name, typeParametersInDeclaration.size(), isfunc ? "(" : "*| %var%"))
continue; continue;
@ -2920,6 +2911,17 @@ void Tokenizer::simplifyTemplateInstantions(const Token *tok,
void Tokenizer::simplifyTemplates() void Tokenizer::simplifyTemplates()
{ {
for (Token *tok = _tokens; tok; tok = tok->next()) {
// #2648 - simple fix for sizeof used as template parameter
// TODO: this is a bit hardcoded. make a bit more generic
if (Token::Match(tok, "%var% < sizeof ( %type% ) >") && tok->tokAt(4)->isStandardType()) {
Token * const tok3 = tok->next();
const unsigned int sizeOfResult = sizeOfType(tok3->tokAt(3));
tok3->deleteNext(4);
tok3->insertToken(MathLib::toString<unsigned int>(sizeOfResult));
}
}
std::set<std::string> expandedtemplates(TemplateSimplifier::simplifyTemplatesExpandSpecialized(_tokens)); std::set<std::string> expandedtemplates(TemplateSimplifier::simplifyTemplatesExpandSpecialized(_tokens));
// Locate templates and set member variable _codeWithTemplates if the code has templates. // Locate templates and set member variable _codeWithTemplates if the code has templates.