From 6c324013e7ef68b1d13aa04265c5ea4bd802e20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 12 Feb 2016 12:05:32 +0100 Subject: [PATCH] Use MAXTIME in templatesimplifier --- lib/templatesimplifier.cpp | 9 +++++++++ lib/templatesimplifier.h | 5 +++++ lib/tokenize.cpp | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 1c79411c1..ab84ab1c9 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1222,6 +1222,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( ErrorLogger* errorlogger, const Settings *_settings, const Token *tok, + const std::time_t maxtime, std::list &templateInstantiations, std::set &expandedtemplates) { @@ -1274,6 +1275,12 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( Token * const tok2 = *iter2; if (errorlogger && !tokenlist.getFiles().empty()) errorlogger->reportProgress(tokenlist.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue()); +#ifdef MAXTIME + if (std::time(0) > maxtime) + return false; +#else + (void)maxtime; +#endif assert(tokenlist.validateToken(tok2)); // that assertion fails on examples from #6021 if (tok2->str() != name) continue; @@ -1404,6 +1411,7 @@ void TemplateSimplifier::simplifyTemplates( TokenList& tokenlist, ErrorLogger* errorlogger, const Settings *_settings, + const std::time_t maxtime, bool &_codeWithTemplates ) { @@ -1450,6 +1458,7 @@ void TemplateSimplifier::simplifyTemplates( errorlogger, _settings, *iter1, + maxtime, templateInstantiations, expandedtemplates); if (instantiated) diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 52aee3c8d..bf28813ae 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "config.h" @@ -137,6 +138,7 @@ public: * @param errorlogger error logger * @param _settings settings * @param tok token where the template declaration begins + * @param maxtime time when the simplification will stop * @param templateInstantiations a list of template usages (not necessarily just for this template) * @param expandedtemplates all templates that has been expanded so far. The full names are stored. * @return true if the template was instantiated @@ -146,6 +148,7 @@ public: ErrorLogger* errorlogger, const Settings *_settings, const Token *tok, + const std::time_t maxtime, std::list &templateInstantiations, std::set &expandedtemplates); @@ -154,12 +157,14 @@ public: * @param tokenlist token list * @param errorlogger error logger * @param _settings settings + * @param maxtime time when the simplification should be stopped * @param _codeWithTemplates output parameter that is set if code contains templates */ static void simplifyTemplates( TokenList& tokenlist, ErrorLogger* errorlogger, const Settings *_settings, + const std::time_t maxtime, bool &_codeWithTemplates); /** diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9686b8b33..1ef5be3c5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2357,6 +2357,11 @@ void Tokenizer::simplifyTemplates() list, _errorLogger, _settings, +#ifdef MAXTIME + maxtime, +#else + 0, // ignored +#endif _codeWithTemplates); } //---------------------------------------------------------------------------