From 3c0ada52e64bc66c54b2bf695e3b5ad0e22a262b Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 8 Jan 2012 00:21:12 +0200 Subject: [PATCH] Refactoring: Extract sizeof simplifying from template simplifying --- lib/tokenize.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 32f644914..fd9b36f00 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2798,15 +2798,6 @@ void Tokenizer::simplifyTemplateInstantions(const Token *tok, if (tok2->str() != name) 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(sizeOfResult)); - } - if (Token::Match(tok2->previous(), "[;{}=]") && !TemplateSimplifier::simplifyTemplatesInstantiateMatch(*iter2, name, typeParametersInDeclaration.size(), isfunc ? "(" : "*| %var%")) continue; @@ -2920,6 +2911,17 @@ void Tokenizer::simplifyTemplateInstantions(const Token *tok, 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(sizeOfResult)); + } + } + std::set expandedtemplates(TemplateSimplifier::simplifyTemplatesExpandSpecialized(_tokens)); // Locate templates and set member variable _codeWithTemplates if the code has templates.