From 662ada69305daed07ba5b8643946e6d64667d642 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Mon, 8 Nov 2021 00:46:52 -0600 Subject: [PATCH] Refactor: Use a template instead of std::function in forward analyzer to help improve debugging (#3551) --- lib/forwardanalyzer.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index d9c7ebb29..cda1516dc 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -93,8 +93,8 @@ struct ForwardTraversal { return evalCond(tok, ctx).second; } - template )> - Progress traverseTok(T* tok, std::function f, bool traverseUnknown, T** out = nullptr) { + template )> + Progress traverseTok(T* tok, F f, bool traverseUnknown, T** out = nullptr) { if (Token::Match(tok, "asm|goto|setjmp|longjmp")) return Break(Analyzer::Terminate::Bail); else if (Token::simpleMatch(tok, "continue")) { @@ -134,8 +134,8 @@ struct ForwardTraversal { return Progress::Continue; } - template )> - Progress traverseRecursive(T* tok, std::function f, bool traverseUnknown, unsigned int recursion=0) { + template )> + Progress traverseRecursive(T* tok, F f, bool traverseUnknown, unsigned int recursion=0) { if (!tok) return Progress::Continue; if (recursion > 10000) @@ -206,7 +206,7 @@ struct ForwardTraversal { } Progress updateTok(Token* tok, Token** out = nullptr) { - std::function f = [this](Token* tok2) { + auto f = [this](Token* tok2) { return update(tok2); }; return traverseTok(tok, f, false, out); @@ -214,14 +214,14 @@ struct ForwardTraversal { Progress updateRecursive(Token* tok) { forked = false; - std::function f = [this](Token* tok2) { + auto f = [this](Token* tok2) { return update(tok2); }; return traverseRecursive(tok, f, false); } - template - T* findRange(T* start, const Token* end, std::function pred) { + template + T* findRange(T* start, const Token* end, F pred) { for (T* tok = start; tok && tok != end; tok = tok->next()) { Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Forward); if (pred(action)) @@ -232,7 +232,7 @@ struct ForwardTraversal { Analyzer::Action analyzeRecursive(const Token* start) { Analyzer::Action result = Analyzer::Action::None; - std::function f = [&](const Token* tok) { + auto f = [&](const Token* tok) { result = analyzer->analyze(tok, Analyzer::Direction::Forward); if (result.isModified() || result.isInconclusive()) return Break();