29 #include <type_traits>
53 template<
class T,
class TFunc,
REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
61 std::stack<T *, SmallVector<T *, 8 + 1>> tokens;
69 T *t2 = tok->astOperand2();
74 T *t1 = tok->astOperand1();
90 const Token* result =
nullptr;
101 template<
class TFunc>
107 while (parent && !pred(parent)) {
116 const std::function<
bool(
const Token*)>& pred);
119 template<
class T,
class OuputIterator,
REQUIRES(
"T must be a Token class", std::is_convertible<T*, const Token*> )>
123 if (!tok || depth < 0)
125 if (tok->str() == op) {
134 std::vector<const Token*>
astFlatten(
const Token* tok,
const char* op);
216 const Token** parent =
nullptr);
242 bool &knownInitValue,
243 long long &initValue,
245 long long &stepValue,
246 long long &lastValue);
259 bool temporary =
true,
260 bool inconclusive =
true,
308 const Token** unknownFunc =
nullptr,
309 bool functionScope =
false);
354 const std::vector<const Variable*> &vars,
372 const std::function<std::vector<MathLib::bigint>(
const Token* tok)>&
evaluate,
385 bool isAliasOf(
const Token* tok,
const Token* expr,
int* indirect =
nullptr,
bool* inconclusive =
nullptr);
Library::Container::Action astContainerAction(const Token *tok, const Token **ftok=nullptr)
int numberOfArgumentsWithoutAst(const Token *start)
Get number of arguments without using AST.
bool astIsContainer(const Token *tok)
const Token * getIteratorExpression(const Token *tok)
int getArgumentPos(const Variable *var, const Function *f)
CPPCHECKLIB const Token * findExpressionChanged(const Token *expr, const Token *start, const Token *end, const Settings &settings, int depth=20)
bool isOppositeExpression(const Token *const tok1, const Token *const tok2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors=nullptr)
bool isWithoutSideEffects(const Token *tok, bool checkArrayAccess=false, bool checkReference=true)
bool astIsPrimitive(const Token *tok)
bool astIsContainerView(const Token *tok)
bool astIsIntegral(const Token *tok, bool unknown)
Is expression of integral type?
bool isTemporary(const Token *tok, const Library *library, bool unknown=false)
bool isAliasOf(const Token *tok, nonneg int varid, bool *inconclusive=nullptr)
If token is an alias if another variable.
bool astIsRangeBasedForDecl(const Token *tok)
Is given token a range-declaration in a range-based for loop.
bool precedes(const Token *tok1, const Token *tok2)
If tok2 comes after tok1.
const Token * getTokenArgumentFunction(const Token *tok, int &argn)
Return the token to the function and the argument number.
bool astHasVar(const Token *tok, nonneg int varid)
bool extractForLoopValues(const Token *forToken, nonneg int &varid, bool &knownInitValue, long long &initValue, bool &partialCond, long long &stepValue, long long &lastValue)
Extract for loop values: loopvar varid, init value, step value, last value (inclusive)
void visitAstNodes(T *ast, const TFunc &visitor)
Visit AST nodes recursively.
bool astIsPointer(const Token *tok)
bool isExpressionChangedAt(const Token *expr, const Token *tok, int indirect, bool globalvar, const Settings &settings, int depth=20)
bool exprDependsOnThis(const Token *expr, bool onVar=true, nonneg int depth=0)
bool compareTokenFlags(const Token *tok1, const Token *tok2, bool macro)
Are the tokens' flags equal?
const Token * isInLoopCondition(const Token *tok)
bool isStlStringType(const Token *tok)
bool isLikelyStreamRead(const Token *op)
do we see a likely write of rhs through overloaded operator s >> x; a & x;
Library::Container::Yield astContainerYield(const Token *tok, const Token **ftok=nullptr)
bool isUniqueExpression(const Token *tok)
bool astIsContainerOwned(const Token *tok)
const Token * findAllocFuncCallToken(const Token *expr, const Library &library)
Find a allocation function call in expression, so result of expression is allocated memory/resource.
bool astIsLHS(const Token *tok)
bool isGlobalData(const Token *expr)
bool isConstFunctionCall(const Token *ftok, const Library &library)
bool astIsBool(const Token *tok)
Is expression of boolean type?
SmallVector< ReferenceToken > followAllReferences(const Token *tok, bool temporary=true, bool inconclusive=true, ErrorPath errors=ErrorPath{}, int depth=20)
const Token * getArgumentStart(const Token *ftok)
bool isScopeBracket(const Token *tok)
CPPCHECKLIB bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings &settings, int depth=20)
Is variable changed in block of code?
bool isEscapeFunction(const Token *ftok, const Library *library)
bool isVariableDecl(const Token *tok)
CPPCHECKLIB const Token * nextAfterAstRightmostLeaf(const Token *tok)
const Token * followReferences(const Token *tok, ErrorPath *errors=nullptr)
bool astIsGenericChar(const Token *tok)
Is expression a char according to valueType?
CPPCHECKLIB const Token * findLambdaEndToken(const Token *first)
find lambda function end token
bool astHasExpr(const Token *tok, nonneg int exprid)
bool isStructuredBindingVariable(const Variable *var)
Token * getInitTok(Token *tok)
const Token * findNextTokenFromBreak(const Token *breakToken)
For a "break" token, locate the next token to execute.
bool isLeafDot(const Token *tok)
bool astIsUniqueSmartPointer(const Token *tok)
std::vector< const Token * > astFlatten(const Token *tok, const char *op)
bool astIsSmartPointer(const Token *tok)
Token * getCondTokFromEnd(Token *endBlock)
Token * astParentSkipParens(Token *tok)
bool astHasToken(const Token *root, const Token *tok)
bool astIsContainerString(const Token *tok)
Token * getCondTok(Token *tok)
bool astIsRHS(const Token *tok)
bool isWithinScope(const Token *tok, const Variable *var, Scope::ScopeType type)
Is tok within a scope of the given type, nested within var's scope?
nonneg int astCount(const Token *tok, const char *op, int depth=100)
bool isOppositeCond(bool isNot, const Token *const cond1, const Token *const cond2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors=nullptr)
Are two conditions opposite.
const Variable * getLHSVariable(const Token *tok)
bool astIsSignedChar(const Token *tok)
Is expression a 'signed char' if no promotion is used.
bool astIsFloat(const Token *tok, bool unknown)
Is expression of floating point type?
ExprUsage getExprUsage(const Token *tok, int indirect, const Settings &settings)
Library::Container::Yield astFunctionYield(const Token *tok, const Settings &settings, const Token **ftok=nullptr)
bool isThisChanged(const Token *tok, int indirect, const Settings &settings)
CPPCHECKLIB bool isReturnScope(const Token *const endToken, const Library &library, const Token **unknownFunc=nullptr, bool functionScope=false)
Is scope a return scope (scope will unconditionally return)
bool astIsNonStringContainer(const Token *tok)
Token * getStepTok(Token *tok)
const Token * findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth=20)
bool isVariablesChanged(const Token *start, const Token *end, int indirect, const std::vector< const Variable * > &vars, const Settings &settings)
bool isIteratorPair(const std::vector< const Token * > &args)
Are the arguments a pair of iterators/pointers?
CPPCHECKLIB bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors=nullptr)
const Token * getParentMember(const Token *tok)
bool isVariableChangedByFunctionCall(const Token *tok, int indirect, nonneg int varid, const Settings &settings, bool *inconclusive)
Is variable changed by function call? In case the answer of the question is inconclusive,...
CPPCHECKLIB const Token * findLambdaStartToken(const Token *last)
bool astIsUnsigned(const Token *tok)
std::vector< const Token * > getArguments(const Token *ftok)
Get arguments (AST)
bool astIsIterator(const Token *tok)
const Token * previousBeforeAstLeftmostLeaf(const Token *tok)
CPPCHECKLIB bool isNullOperand(const Token *expr)
std::vector< ValueType > getParentValueTypes(const Token *tok, const Settings &settings, const Token **parent=nullptr)
bool isCPPCast(const Token *tok)
bool isEqualKnownValue(const Token *const tok1, const Token *const tok2)
std::vector< const Variable * > getLHSVariables(const Token *tok)
void astFlattenCopy(T *tok, const char *op, OuputIterator out, nonneg int depth=100)
bool isConstExpression(const Token *tok, const Library &library)
std::vector< const Variable * > getArgumentVars(const Token *tok, int argnr)
bool isUnevaluated(const Token *tok)
const Token * getLHSVariableToken(const Token *tok)
bool isAliased(const Variable *var)
const Token * getParentLifetime(const Token *tok)
bool isLikelyStream(const Token *stream)
std::string astCanonicalType(const Token *expr, bool pointedToType)
Get canonical type of expression.
bool isConstVarExpression(const Token *tok, const std::function< bool(const Token *)> &skipPredicate=nullptr)
bool astIsUnknownSignChar(const Token *tok)
Is expression a 'char' if no promotion is used?
const Token * findParent(const Token *tok, const TFunc &pred)
CPPCHECKLIB bool isUsedAsBool(const Token *const tok, const Settings &settings)
Is token used as boolean, that is to say cast to a bool, or used as a condition in a if/while/for.
const Token * astIsVariableComparison(const Token *tok, const std::string &comp, const std::string &rhs, const Token **vartok=nullptr)
Is given syntax tree a variable comparison against value.
bool succeeds(const Token *tok1, const Token *tok2)
If tok1 comes after tok2.
const Token * findExpressionChangedSkipDeadCode(const Token *expr, const Token *start, const Token *end, const Settings &settings, const std::function< std::vector< MathLib::bigint >(const Token *tok)> &evaluate, int depth=20)
int numberOfArguments(const Token *ftok)
Determines the number of arguments - if token is a function call or macro.
const Token * findExpression(const nonneg int exprid, const Token *start, const Token *end, const std::function< bool(const Token *)> &pred)
const Token * findAstNode(const Token *ast, const TFunc &pred)
Library definitions handling.
This is just a container for general settings so that we don't need to pass individual values to func...
The token list that the TokenList generates is a linked-list of this class.
void astParent(Token *tok)
Information about a member variable.
#define REQUIRES(msg,...)
std::list< ErrorPathItem > ErrorPath
static ValueFlow::Value evaluate(const std::string &op, const ValueFlow::Value &lhs, const ValueFlow::Value &rhs)