|
Cppcheck
|
Simplify templates from the preprocessed and partially simplified code. More...
#include <templatesimplifier.h>
Static Public Member Functions | |
| static void | cleanupAfterSimplify (Token *tokens) |
| Used after simplifyTemplates to perform a little cleanup. | |
| static const Token * | hasComplicatedSyntaxErrorsInTemplates (Token *tokens) |
| static unsigned int | templateParameters (const Token *tok) |
| is the token pointing at a template parameters block < int , 3 > => yes | |
| static std::set< std::string > | expandSpecialized (Token *tokens) |
| Expand specialized templates : "template<>..". | |
| static std::list< Token * > | getTemplateDeclarations (Token *tokens, bool &codeWithTemplates) |
| Get template declarations. | |
| static std::list< Token * > | getTemplateInstantiations (Token *tokens) |
| Get template instantiations. | |
| static void | useDefaultArgumentValues (const std::list< Token * > &templates, const std::list< Token * > &templateInstantiations) |
| simplify template instantiations (use default argument values) | |
| static bool | instantiateMatch (const Token *instance, const std::string &name, std::size_t numberOfArguments, const char patternAfter[]) |
| Match template declaration/instantiation. | |
| static int | getTemplateNamePosition (const Token *tok) |
| Match template declaration/instantiation. | |
| static void | expandTemplate (TokenList &tokenlist, const Token *tok, const std::string &name, std::vector< const Token * > &typeParametersInDeclaration, const std::string &newName, std::vector< const Token * > &typesUsedInTemplateInstantiation, std::list< Token * > &templateInstantiations) |
| static bool | simplifyTemplateInstantiations (TokenList &tokenlist, ErrorLogger &errorlogger, const Settings *_settings, const Token *tok, std::list< Token * > &templateInstantiations, std::set< std::string > &expandedtemplates) |
| Simplify templates : expand all instantiations for a template. | |
| static void | simplifyTemplates (TokenList &tokenlist, ErrorLogger &errorlogger, const Settings *_settings, bool &_codeWithTemplates) |
| Simplify templates. | |
| static bool | simplifyNumericCalculations (Token *tok) |
| Simplify constant calculations such as "1+2" => "3". | |
| static bool | simplifyCalculations (Token *_tokens) |
| Simplify constant calculations such as "1+2" => "3". | |
Private Member Functions | |
| TemplateSimplifier () | |
| ~TemplateSimplifier () | |
Static Private Member Functions | |
| static bool | removeTemplate (Token *tok) |
| Remove a specific "template < ..." template class/function. | |
Simplify templates from the preprocessed and partially simplified code.
Definition at line 41 of file templatesimplifier.h.
| TemplateSimplifier::TemplateSimplifier | ( | ) | [private] |
| TemplateSimplifier::~TemplateSimplifier | ( | ) | [private] |
| void TemplateSimplifier::cleanupAfterSimplify | ( | Token * | tokens | ) | [static] |
Used after simplifyTemplates to perform a little cleanup.
Sometimes the simplifyTemplates isn't fully successful and then there are function calls etc with "wrong" syntax.
Definition at line 36 of file templatesimplifier.cpp.
References Token::eraseTokens(), Token::Match(), Token::next(), Token::str(), Token::tokAt(), and Scope::type.
Referenced by Tokenizer::tokenize().
| std::set< std::string > TemplateSimplifier::expandSpecialized | ( | Token * | tokens | ) | [static] |
Expand specialized templates : "template<>..".
Definition at line 322 of file templatesimplifier.cpp.
References Token::eraseTokens(), Token::findmatch(), Token::findsimplematch(), Token::isName(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), templateParameters(), and Token::tokAt().
Referenced by simplifyTemplates().
| void TemplateSimplifier::expandTemplate | ( | TokenList & | tokenlist, |
| const Token * | tok, | ||
| const std::string & | name, | ||
| std::vector< const Token * > & | typeParametersInDeclaration, | ||
| const std::string & | newName, | ||
| std::vector< const Token * > & | typesUsedInTemplateInstantiation, | ||
| std::list< Token * > & | templateInstantiations | ||
| ) | [static] |
Definition at line 582 of file templatesimplifier.cpp.
References TokenList::addtoken(), TokenList::back(), Token::createMutualLinks(), TokenList::front(), instantiateMatch(), Token::Match(), and Token::next().
Referenced by simplifyTemplateInstantiations().
| std::list< Token * > TemplateSimplifier::getTemplateDeclarations | ( | Token * | tokens, |
| bool & | codeWithTemplates | ||
| ) | [static] |
Get template declarations.
Definition at line 384 of file templatesimplifier.cpp.
References Token::Match(), Token::next(), and Token::simpleMatch().
Referenced by simplifyTemplates().
| std::list< Token * > TemplateSimplifier::getTemplateInstantiations | ( | Token * | tokens | ) | [static] |
Get template instantiations.
Definition at line 412 of file templatesimplifier.cpp.
References Token::findClosingBracket(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), templateParameters(), and Token::tokAt().
Referenced by simplifyTemplates().
| int TemplateSimplifier::getTemplateNamePosition | ( | const Token * | tok | ) | [static] |
Match template declaration/instantiation.
| tok | The ">" token e.g. before "class" |
Definition at line 561 of file templatesimplifier.cpp.
References Token::Match(), and Token::strAt().
Referenced by simplifyTemplateInstantiations().
| const Token * TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates | ( | Token * | tokens | ) | [static] |
Definition at line 67 of file templatesimplifier.cpp.
References Token::link(), Token::Match(), Token::next(), Token::simpleMatch(), and Token::tokAt().
| bool TemplateSimplifier::instantiateMatch | ( | const Token * | instance, |
| const std::string & | name, | ||
| std::size_t | numberOfArguments, | ||
| const char | patternAfter[] | ||
| ) | [static] |
Match template declaration/instantiation.
| instance | template instantiation |
| name | name of template |
| numberOfArguments | number of template arguments |
| patternAfter | pattern that must match the tokens after the ">" |
Definition at line 543 of file templatesimplifier.cpp.
References Token::findsimplematch(), Token::Match(), Token::next(), Token::simpleMatch(), and templateParameters().
Referenced by expandTemplate(), and simplifyTemplateInstantiations().
| bool TemplateSimplifier::removeTemplate | ( | Token * | tok | ) | [static, private] |
Remove a specific "template < ..." template class/function.
Definition at line 256 of file templatesimplifier.cpp.
References Token::deleteNext(), Token::deleteThis(), Token::eraseTokens(), Token::Match(), Token::next(), and Token::simpleMatch().
Referenced by simplifyTemplates().
| bool TemplateSimplifier::simplifyCalculations | ( | Token * | _tokens | ) | [static] |
Simplify constant calculations such as "1+2" => "3".
This also performs simple cleanup of parentheses etc.
| _tokens | start token |
Definition at line 780 of file templatesimplifier.cpp.
References MathLib::divide(), Token::eraseTokens(), MathLib::isInt(), MathLib::longToString(), Token::Match(), MathLib::multiply(), Token::next(), Token::simpleMatch(), simplifyNumericCalculations(), Token::str(), and MathLib::toLongNumber().
Referenced by simplifyTemplateInstantiations().
| bool TemplateSimplifier::simplifyNumericCalculations | ( | Token * | tok | ) | [static] |
Simplify constant calculations such as "1+2" => "3".
| tok | start token |
Definition at line 711 of file templatesimplifier.cpp.
References MathLib::add(), MathLib::calculate(), Token::deleteNext(), MathLib::divide(), isLowerEqualThanMulDiv(), isLowerThanAnd(), isLowerThanMulDiv(), isLowerThanPlusMinus(), isLowerThanShift(), isLowerThanXor(), Token::isNumber(), MathLib::longToString(), Token::Match(), MathLib::multiply(), Token::next(), Token::previous(), Token::str(), Token::strAt(), MathLib::subtract(), Token::tokAt(), InternalError::token, and MathLib::toLongNumber().
Referenced by EnumValue::simplify(), simplifyCalculations(), Tokenizer::tokenize(), and Tokenizer::tokenizeCondition().
| bool TemplateSimplifier::simplifyTemplateInstantiations | ( | TokenList & | tokenlist, |
| ErrorLogger & | errorlogger, | ||
| const Settings * | _settings, | ||
| const Token * | tok, | ||
| std::list< Token * > & | templateInstantiations, | ||
| std::set< std::string > & | expandedtemplates | ||
| ) | [static] |
Simplify templates : expand all instantiations for a template.
| tokenlist | token list |
| errorlogger | error logger |
| _settings | settings |
| tok | token where the template declaration begins |
| templateInstantiations | a list of template usages (not necessarily just for this template) |
| expandedtemplates | all templates that has been expanded so far. The full names are stored. |
Definition at line 965 of file templatesimplifier.cpp.
References Severity::debug, Settings::debugwarnings, Token::eraseTokens(), expandTemplate(), TokenList::front(), getTemplateNamePosition(), instantiateMatch(), Token::isLong(), Token::isSigned(), Token::isUnsigned(), Token::Match(), Token::next(), Token::previous(), ErrorLogger::reportErr(), Token::simpleMatch(), simplifyCalculations(), Token::str(), Token::strAt(), templateParameters(), and Token::tokAt().
Referenced by simplifyTemplates().
| void TemplateSimplifier::simplifyTemplates | ( | TokenList & | tokenlist, |
| ErrorLogger & | errorlogger, | ||
| const Settings * | _settings, | ||
| bool & | _codeWithTemplates | ||
| ) | [static] |
Simplify templates.
| tokenlist | token list |
| errorlogger | error logger |
| _settings | settings |
| _codeWithTemplates | output parameter that is set if code contains templates |
Definition at line 1143 of file templatesimplifier.cpp.
References expandSpecialized(), TokenList::front(), getTemplateDeclarations(), getTemplateInstantiations(), Token::next(), removeTemplate(), Token::simpleMatch(), simplifyTemplateInstantiations(), and useDefaultArgumentValues().
| unsigned int TemplateSimplifier::templateParameters | ( | const Token * | tok | ) | [static] |
is the token pointing at a template parameters block < int , 3 > => yes
| tok | start token that must point at "<" |
Definition at line 165 of file templatesimplifier.cpp.
References Token::eChar, Token::isName(), Token::isNumber(), Token::link(), Token::Match(), Token::next(), Token::str(), Token::tokAt(), and Token::type().
Referenced by expandSpecialized(), getTemplateInstantiations(), instantiateMatch(), setVarIdParseDeclaration(), setVarIdStructMembers(), Tokenizer::simplifyConstTernaryOp(), simplifyTemplateInstantiations(), and Tokenizer::simplifyVarDecl().
| void TemplateSimplifier::useDefaultArgumentValues | ( | const std::list< Token * > & | templates, |
| const std::list< Token * > & | templateInstantiations | ||
| ) | [static] |
simplify template instantiations (use default argument values)
| templates | list of template declarations |
| templateInstantiations | list of template instantiations |
Definition at line 448 of file templatesimplifier.cpp.
References Token::createMutualLinks(), Token::deleteThis(), Token::eraseTokens(), Token::insertToken(), Token::link(), Token::Match(), Token::next(), Token::previous(), Token::str(), and Token::tokAt().
Referenced by simplifyTemplates().
1.7.6.1