27 #include <type_traits>
44 template<
class T,
class Predicate,
class Found,
REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
47 for (T* tok = start;
precedes(tok, end); tok = tok->next()) {
55 template<
class T,
class Predicate,
REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
58 std::vector<T*> result;
60 result.push_back(tok);
66 template<
class T,
class Predicate,
REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
81 REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
85 const Predicate& pred,
89 for (T* tok = start;
precedes(tok, end); tok = tok->next()) {
103 T* thenStart = tok->linkAt(1)->next();
104 T* elseStart =
nullptr;
106 elseStart = thenStart->link()->tokAt(2);
108 int r = result.front();
115 tok = elseStart->link();
117 tok = thenStart->link();
124 tok = thenStart->link();
130 const bool cond = result.front() != 0;
136 T* colon = tok->astParent()->astOperand2();
156 int r = result.front();
158 tok = tok->linkAt(2);
161 T* afterCapture = tok->link()->next();
163 tok = afterCapture->link()->next();
171 template<
class T,
class Predicate,
class Evaluate,
REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
175 const Predicate& pred,
178 std::vector<T*> result;
185 result.push_back(tok);
192 template<
class T,
class Predicate,
REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
198 template<
class T,
class Predicate,
class Evaluate,
REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
215 template<
class T,
class Predicate,
REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
bool precedes(const Token *tok1, const Token *tok2)
If tok2 comes after tok1.
bool astIsLHS(const Token *tok)
Token * getCondTokFromEnd(Token *endBlock)
Token * getCondTok(Token *tok)
const Token * nextAfterAstRightmostLeaf(const Token *tok)
bool isReturnScope(const Token *const endToken, const Library &library, const Token **unknownFunc, bool functionScope)
Is scope a return scope (scope will unconditionally return)
Library definitions handling.
The token list that the TokenList generates is a linked-list of this class.
static bool Match(const Token *tok, const char pattern[], nonneg int varid=0)
Match given token (or list of tokens) to a pattern list.
bool hasKnownIntValue() const
MathLib::bigint getKnownIntValue() const
static bool simpleMatch(const Token *tok, const char(&pattern)[count])
Match given token (or list of tokens) to a pattern list.
#define REQUIRES(msg,...)
T * findToken(T *start, const Token *end, const Predicate &pred)
T * findTokenSkipDeadCode(const Library &library, T *start, const Token *end, const Predicate &pred, const Evaluate &evaluate)
void findTokensImpl(T *start, const Token *end, const Predicate &pred, Found found)
std::vector< MathLib::bigint > evaluateKnownValues(const Token *tok)
std::vector< T * > findTokensSkipDeadCode(const Library &library, T *start, const Token *end, const Predicate &pred, const Evaluate &evaluate)
bool findTokensSkipDeadCodeImpl(const Library &library, T *start, const Token *end, const Predicate &pred, Found found, const Evaluate &evaluate)
std::vector< T * > findTokens(T *start, const Token *end, const Predicate &pred)
static ValueFlow::Value evaluate(const std::string &op, const ValueFlow::Value &lhs, const ValueFlow::Value &rhs)