MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / simplifyTemplateInstantiations

Method simplifyTemplateInstantiations

lib/templatesimplifier.cpp:3122–3384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3120}
3121
3122bool TemplateSimplifier::simplifyTemplateInstantiations(
3123 const TokenAndName &templateDeclaration,
3124 const std::list<const Token *> &specializations,
3125 const std::time_t maxtime,
3126 std::set<std::string> &expandedtemplates)
3127{
3128 // this variable is not used at the moment. The intention was to
3129 // allow continuous instantiations until all templates has been expanded
3130 //bool done = false;
3131
3132 // Contains tokens such as "T"
3133 std::vector<const Token *> typeParametersInDeclaration;
3134 getTemplateParametersInDeclaration(templateDeclaration.token()->tokAt(2), typeParametersInDeclaration);
3135 const bool printDebug = mSettings.debugwarnings;
3136 const bool specialized = templateDeclaration.isSpecialization();
3137 const bool isfunc = templateDeclaration.isFunction();
3138 const bool isVar = templateDeclaration.isVariable();
3139
3140 // locate template usage..
3141 std::string::size_type numberOfTemplateInstantiations = mTemplateInstantiations.size();
3142 unsigned int recursiveCount = 0;
3143
3144 bool instantiated = false;
3145
3146 for (const TokenAndName &instantiation : mTemplateInstantiations) {
3147 // skip deleted instantiations
3148 if (!instantiation.token())
3149 continue;
3150 if (numberOfTemplateInstantiations != mTemplateInstantiations.size()) {
3151 numberOfTemplateInstantiations = mTemplateInstantiations.size();
3152 ++recursiveCount;
3153 if (recursiveCount > mSettings.maxTemplateRecursion) {
3154 if (mSettings.severity.isEnabled(Severity::information)) {
3155 std::list<std::string> typeStringsUsedInTemplateInstantiation;
3156 const std::string typeForNewName = templateDeclaration.name() + "<" + getNewName(instantiation.token(), typeStringsUsedInTemplateInstantiation) + ">";
3157
3158 const std::list<const Token *> callstack(1, instantiation.token());
3159 const ErrorMessage errmsg(callstack,
3160 &mTokenizer.list,
3161 Severity::information,
3162 "templateRecursion",
3163 "TemplateSimplifier: max template recursion ("
3164 + std::to_string(mSettings.maxTemplateRecursion)
3165 + ") reached for template '"+typeForNewName+"'.",
3166 Certainty::normal);
3167 mErrorLogger.reportErr(errmsg);
3168 }
3169
3170 // bail out..
3171 break;
3172 }
3173 }
3174
3175 // already simplified
3176 if (!Token::Match(instantiation.token(), "%name% <"))
3177 continue;
3178
3179 if (!((instantiation.fullName() == templateDeclaration.fullName()) ||

Callers

nothing calls this directly

Calls 15

getFunctionArgumentsFunction · 0.85
tokenMethod · 0.80
isSpecializationMethod · 0.80
isVariableMethod · 0.80
fullNameMethod · 0.80
scopeMethod · 0.80
linkAtMethod · 0.80
nextMethod · 0.80
validateTokenMethod · 0.80
findOpeningBracketMethod · 0.80
isVariadicMethod · 0.80
simpleMatchFunction · 0.70

Tested by

no test coverage detected