Cppcheck
Functions
astutils.cpp File Reference
#include "astutils.h"
#include "config.h"
#include "errortypes.h"
#include "findtoken.h"
#include "infer.h"
#include "library.h"
#include "mathlib.h"
#include "settings.h"
#include "symboldatabase.h"
#include "token.h"
#include "utils.h"
#include "valueflow.h"
#include "valueptr.h"
#include "vfvalue.h"
#include "checkclass.h"
#include <algorithm>
#include <cassert>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <list>
#include <set>
#include <type_traits>
#include <unordered_map>
#include <utility>

Go to the source code of this file.

Functions

const TokenfindExpression (const nonneg int exprid, const Token *start, const Token *end, const std::function< bool(const Token *)> &pred)
 
static int findArgumentPosRecursive (const Token *tok, const Token *tokToFind, bool &found, nonneg int depth=0)
 
static int findArgumentPos (const Token *tok, const Token *tokToFind)
 
static int getArgumentPos (const Token *ftok, const Token *tokToFind)
 
std::vector< const Token * > astFlatten (const Token *tok, const char *op)
 
std::vector< Token * > astFlatten (Token *tok, const char *op)
 
nonneg int astCount (const Token *tok, const char *op, int depth)
 
bool astHasToken (const Token *root, const Token *tok)
 
bool astHasVar (const Token *tok, nonneg int varid)
 
bool astHasExpr (const Token *tok, nonneg int exprid)
 
static bool astIsCharWithSign (const Token *tok, ValueType::Sign sign)
 
bool astIsSignedChar (const Token *tok)
 Is expression a 'signed char' if no promotion is used. More...
 
bool astIsUnknownSignChar (const Token *tok)
 Is expression a 'char' if no promotion is used? More...
 
bool astIsGenericChar (const Token *tok)
 Is expression a char according to valueType? More...
 
bool astIsPrimitive (const Token *tok)
 
bool astIsIntegral (const Token *tok, bool unknown)
 Is expression of integral type? More...
 
bool astIsUnsigned (const Token *tok)
 
bool astIsFloat (const Token *tok, bool unknown)
 Is expression of floating point type? More...
 
bool astIsBool (const Token *tok)
 Is expression of boolean type? More...
 
bool astIsPointer (const Token *tok)
 
bool astIsSmartPointer (const Token *tok)
 
bool astIsUniqueSmartPointer (const Token *tok)
 
bool astIsIterator (const Token *tok)
 
bool astIsContainer (const Token *tok)
 
bool astIsNonStringContainer (const Token *tok)
 
bool astIsContainerView (const Token *tok)
 
bool astIsContainerOwned (const Token *tok)
 
bool astIsContainerString (const Token *tok)
 
static const TokengetContainerFunction (const Token *tok)
 
Library::Container::Action astContainerAction (const Token *tok, const Token **ftok)
 
Library::Container::Yield astContainerYield (const Token *tok, const Token **ftok)
 
Library::Container::Yield astFunctionYield (const Token *tok, const Settings &settings, const Token **ftok)
 
bool astIsRangeBasedForDecl (const Token *tok)
 Is given token a range-declaration in a range-based for loop. More...
 
std::string astCanonicalType (const Token *expr, bool pointedToType)
 Get canonical type of expression. More...
 
static bool match (const Token *tok, const std::string &rhs)
 
const TokenastIsVariableComparison (const Token *tok, const std::string &comp, const std::string &rhs, const Token **vartok)
 Is given syntax tree a variable comparison against value. More...
 
bool isVariableDecl (const Token *tok)
 
bool isStlStringType (const Token *tok)
 
bool isTemporary (const Token *tok, const Library *library, bool unknown)
 
static bool isFunctionCall (const Token *tok)
 
static bool hasToken (const Token *startTok, const Token *stopTok, const Token *tok)
 
template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T * previousBeforeAstLeftmostLeafGeneric (T *tok)
 
const TokenpreviousBeforeAstLeftmostLeaf (const Token *tok)
 
TokenpreviousBeforeAstLeftmostLeaf (Token *tok)
 
template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T * nextAfterAstRightmostLeafGeneric (T *tok)
 
const TokennextAfterAstRightmostLeaf (const Token *tok)
 
TokennextAfterAstRightmostLeaf (Token *tok)
 
const TokenastParentSkipParens (const Token *tok)
 
TokenastParentSkipParens (Token *tok)
 
const TokengetParentMember (const Token *tok)
 
const TokengetParentLifetime (const Token *tok)
 
static std::vector< const Token * > getParentMembers (const Token *tok)
 
static const TokengetParentLifetimeObject (const Token *tok)
 
const TokengetParentLifetime (const Token *tok, const Library &library)
 
static bool isInConstructorList (const Token *tok)
 
std::vector< ValueTypegetParentValueTypes (const Token *tok, const Settings &settings, const Token **parent)
 
bool astIsLHS (const Token *tok)
 
bool astIsRHS (const Token *tok)
 
template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T * getCondTokImpl (T *tok)
 
template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T * getCondTokFromEndImpl (T *endBlock)
 
template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T * getInitTokImpl (T *tok)
 
template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T * getStepTokImpl (T *tok)
 
TokengetCondTok (Token *tok)
 
const TokengetCondTok (const Token *tok)
 
TokengetCondTokFromEnd (Token *endBlock)
 
const TokengetCondTokFromEnd (const Token *endBlock)
 
TokengetInitTok (Token *tok)
 
const TokengetInitTok (const Token *tok)
 
TokengetStepTok (Token *tok)
 
const TokengetStepTok (const Token *tok)
 
const TokenfindNextTokenFromBreak (const Token *breakToken)
 For a "break" token, locate the next token to execute. More...
 
bool extractForLoopValues (const Token *forToken, nonneg int &varid, bool &knownInitValue, MathLib::bigint &initValue, bool &partialCond, MathLib::bigint &stepValue, MathLib::bigint &lastValue)
 Extract for loop values: loopvar varid, init value, step value, last value (inclusive) More...
 
static const TokengetVariableInitExpression (const Variable *var)
 
const TokenisInLoopCondition (const Token *tok)
 
bool precedes (const Token *tok1, const Token *tok2)
 If tok2 comes after tok1. More...
 
bool succeeds (const Token *tok1, const Token *tok2)
 If tok1 comes after tok2. More...
 
bool isAliasOf (const Token *tok, nonneg int varid, bool *inconclusive)
 If token is an alias if another variable. More...
 
bool isAliasOf (const Token *tok, const Token *expr, int *indirect, bool *inconclusive)
 
static bool isAliased (const Token *startTok, const Token *endTok, nonneg int varid)
 
bool isAliased (const Variable *var)
 
bool exprDependsOnThis (const Token *expr, bool onVar, nonneg int depth)
 
static bool hasUnknownVars (const Token *startTok)
 
bool isStructuredBindingVariable (const Variable *var)
 
static const TokenfollowVariableExpression (const Settings &settings, const Token *tok, const Token *end=nullptr)
 This takes a token that refers to a variable and it will return the token to the expression that the variable is assigned to. More...
 
static void followVariableExpressionError (const Token *tok1, const Token *tok2, ErrorPath *errors)
 
SmallVector< ReferenceTokenfollowAllReferences (const Token *tok, bool temporary, bool inconclusive, ErrorPath errors, int depth)
 
const TokenfollowReferences (const Token *tok, ErrorPath *errors)
 
static bool isSameLifetime (const Token *const tok1, const Token *const tok2)
 
static bool compareKnownValue (const Token *const tok1, const Token *const tok2, const std::function< bool(const ValueFlow::Value &, const ValueFlow::Value &, bool)> &compare)
 
bool isEqualKnownValue (const Token *const tok1, const Token *const tok2)
 
static bool isDifferentKnownValues (const Token *const tok1, const Token *const tok2)
 
static bool isSameConstantValue (bool macro, const Token *tok1, const Token *tok2)
 
static bool isForLoopCondition (const Token *const tok)
 
static bool isForLoopIncrement (const Token *const tok)
 
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. More...
 
bool compareTokenFlags (const Token *tok1, const Token *tok2, bool macro)
 Are the tokens' flags equal? More...
 
static bool astIsBoolLike (const Token *tok, const Settings &settings)
 
bool isSameExpression (bool macro, const Token *tok1, const Token *tok2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors)
 
static bool isZeroBoundCond (const Token *const cond)
 
bool isOppositeCond (bool isNot, const Token *const cond1, const Token *const cond2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors)
 Are two conditions opposite. More...
 
bool isOppositeExpression (const Token *const tok1, const Token *const tok2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors)
 
static bool functionModifiesArguments (const Function *f)
 
bool isConstFunctionCall (const Token *ftok, const Library &library)
 
bool isConstExpression (const Token *tok, const Library &library)
 
bool isWithoutSideEffects (const Token *tok, bool checkArrayAccess, bool checkReference)
 
bool isUniqueExpression (const Token *tok)
 
static bool isEscaped (const Token *tok, bool functionsScope, const Library &library)
 
static bool isEscapedOrJump (const Token *tok, bool functionsScope, const Library &library)
 
bool isEscapeFunction (const Token *ftok, const Library *library)
 
static bool hasNoreturnFunction (const Token *tok, const Library &library, const Token **unknownFunc)
 
bool isReturnScope (const Token *const endToken, const Library &library, const Token **unknownFunc, bool functionScope)
 Is scope a return scope (scope will unconditionally return) More...
 
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? More...
 
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, e.g. More...
 
bool isScopeBracket (const Token *tok)
 
template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T * getTokenArgumentFunctionImpl (T *tok, int &argn)
 
const TokengetTokenArgumentFunction (const Token *tok, int &argn)
 Return the token to the function and the argument number. More...
 
TokengetTokenArgumentFunction (Token *tok, int &argn)
 
std::vector< const Variable * > getArgumentVars (const Token *tok, int argnr)
 
static bool isCPPCastKeyword (const Token *tok)
 
static bool isTrivialConstructor (const Token *tok)
 
static bool isArray (const Token *tok)
 
bool isVariableChangedByFunctionCall (const Token *tok, int indirect, const Settings &settings, bool *inconclusive)
 Is variable changed by function call? In case the answer of the question is inconclusive, e.g. More...
 
bool isVariableChanged (const Token *tok, int indirect, const Settings &settings, int depth)
 
bool isVariableChanged (const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings &settings, int depth)
 Is variable changed in block of code? More...
 
bool isVariableChanged (const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth)
 
const TokenfindExpression (const Token *start, const nonneg int exprid)
 
template<class F , class R = decltype(std::declval<F>()())>
static std::function< R()> memoize (F f)
 
template<class F , REQUIRES("F must be a function that returns a Token class", std::is_convertible< decltype(std::declval< F >()()), const Token * >) >
static bool isExpressionChangedAt (const F &getExprTok, const Token *tok, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth)
 
bool isExpressionChangedAt (const Token *expr, const Token *tok, int indirect, bool globalvar, const Settings &settings, int depth)
 
TokenfindVariableChanged (Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth)
 
const TokenfindVariableChanged (const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth)
 
bool isVariableChanged (const Variable *var, const Settings &settings, int depth)
 
bool isVariablesChanged (const Token *start, const Token *end, int indirect, const std::vector< const Variable * > &vars, const Settings &settings)
 
bool isThisChanged (const Token *tok, int indirect, const Settings &settings)
 
static const TokenfindThisChanged (const Token *start, const Token *end, int indirect, const Settings &settings)
 
template<class Find >
static const TokenfindExpressionChangedImpl (const Token *expr, const Token *start, const Token *end, const Settings &settings, int depth, Find find)
 
const TokenfindExpressionChanged (const Token *expr, const Token *start, const Token *end, const Settings &settings, int depth)
 
const TokenfindExpressionChangedSkipDeadCode (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)
 
const TokengetArgumentStart (const Token *ftok)
 
int numberOfArguments (const Token *ftok)
 Determines the number of arguments - if token is a function call or macro. More...
 
int numberOfArgumentsWithoutAst (const Token *start)
 Get number of arguments without using AST. More...
 
std::vector< const Token * > getArguments (const Token *ftok)
 Get arguments (AST) More...
 
int getArgumentPos (const Variable *var, const Function *f)
 
const TokengetIteratorExpression (const Token *tok)
 
bool isIteratorPair (const std::vector< const Token * > &args)
 Are the arguments a pair of iterators/pointers? More...
 
const TokenfindLambdaStartToken (const Token *last)
 
template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T * findLambdaEndTokenGeneric (T *first)
 
const TokenfindLambdaEndToken (const Token *first)
 find lambda function end token More...
 
TokenfindLambdaEndToken (Token *first)
 
bool isLikelyStream (const Token *stream)
 
bool isLikelyStreamRead (const Token *op)
 do we see a likely write of rhs through overloaded operator s >> x; a & x; More...
 
bool isCPPCast (const Token *tok)
 
bool isConstVarExpression (const Token *tok, const std::function< bool(const Token *)> &skipPredicate)
 
static ExprUsage getFunctionUsage (const Token *tok, int indirect, const Settings &settings)
 
bool isLeafDot (const Token *tok)
 
ExprUsage getExprUsage (const Token *tok, int indirect, const Settings &settings)
 
static void getLHSVariablesRecursive (std::vector< const Variable * > &vars, const Token *tok)
 
std::vector< const Variable * > getLHSVariables (const Token *tok)
 
static const TokengetLHSVariableRecursive (const Token *tok)
 
const VariablegetLHSVariable (const Token *tok)
 
const TokengetLHSVariableToken (const Token *tok)
 
const TokenfindAllocFuncCallToken (const Token *expr, const Library &library)
 Find a allocation function call in expression, so result of expression is allocated memory/resource. More...
 
bool isNullOperand (const Token *expr)
 
bool isGlobalData (const Token *expr)
 
bool isUnevaluated (const Token *tok)
 

Function Documentation

◆ astCanonicalType()

std::string astCanonicalType ( const Token expr,
bool  pointedToType 
)

Get canonical type of expression.

const/static/etc are not included and neither *&. For example: Expression type Return std::string std::string int * int static const int int std::vector<T> std::vector

Definition at line 326 of file astutils.cpp.

References Token::Match(), and Token::typeDecl().

Referenced by Library::getFunctionName().

◆ astContainerAction()

Library::Container::Action astContainerAction ( const Token tok,
const Token **  ftok 
)

◆ astContainerYield()

Library::Container::Yield astContainerYield ( const Token tok,
const Token **  ftok 
)

◆ astCount()

nonneg int astCount ( const Token tok,
const char *  op,
int  depth 
)

Definition at line 124 of file astutils.cpp.

References Token::astOperand1(), Token::astOperand2(), and Token::str().

Referenced by numberOfArguments().

◆ astFlatten() [1/2]

std::vector<const Token*> astFlatten ( const Token tok,
const char *  op 
)

◆ astFlatten() [2/2]

std::vector<Token*> astFlatten ( Token tok,
const char *  op 
)

Definition at line 117 of file astutils.cpp.

References astFlattenCopy().

◆ astFunctionYield()

Library::Container::Yield astFunctionYield ( const Token tok,
const Settings settings,
const Token **  ftok 
)

◆ astHasExpr()

bool astHasExpr ( const Token tok,
nonneg int  exprid 
)

Definition at line 152 of file astutils.cpp.

References Token::astOperand1(), Token::astOperand2(), and Token::exprId().

◆ astHasToken()

bool astHasToken ( const Token root,
const Token tok 
)

Definition at line 134 of file astutils.cpp.

References Token::astParent().

Referenced by followAllReferences().

◆ astHasVar()

bool astHasVar ( const Token tok,
nonneg int  varid 
)

Definition at line 143 of file astutils.cpp.

References Token::astOperand1(), Token::astOperand2(), and Token::varId().

◆ astIsBool()

bool astIsBool ( const Token tok)

◆ astIsBoolLike()

static bool astIsBoolLike ( const Token tok,
const Settings settings 
)
static

Definition at line 1551 of file astutils.cpp.

References astIsBool(), and isUsedAsBool().

Referenced by isSameExpression().

◆ astIsCharWithSign()

static bool astIsCharWithSign ( const Token tok,
ValueType::Sign  sign 
)
static

◆ astIsContainer()

bool astIsContainer ( const Token tok)

◆ astIsContainerOwned()

bool astIsContainerOwned ( const Token tok)

◆ astIsContainerString()

bool astIsContainerString ( const Token tok)

◆ astIsContainerView()

bool astIsContainerView ( const Token tok)

◆ astIsFloat()

bool astIsFloat ( const Token tok,
bool  unknown 
)

◆ astIsGenericChar()

bool astIsGenericChar ( const Token tok)

Is expression a char according to valueType?

Definition at line 181 of file astutils.cpp.

References astIsPointer(), ValueType::type, and Token::valueType().

Referenced by getInitListSize(), and valueFlowGetStrLength().

◆ astIsIntegral()

bool astIsIntegral ( const Token tok,
bool  unknown 
)

◆ astIsIterator()

bool astIsIterator ( const Token tok)

◆ astIsLHS()

bool astIsLHS ( const Token tok)

◆ astIsNonStringContainer()

bool astIsNonStringContainer ( const Token tok)

◆ astIsPointer()

bool astIsPointer ( const Token tok)

◆ astIsPrimitive()

bool astIsPrimitive ( const Token tok)

◆ astIsRangeBasedForDecl()

bool astIsRangeBasedForDecl ( const Token tok)

Is given token a range-declaration in a range-based for loop.

Definition at line 321 of file astutils.cpp.

References Token::astParent(), and Token::simpleMatch().

Referenced by CheckOther::checkConstPointer(), CheckOther::checkConstVariable(), CheckOther::checkPassByReference(), CheckClass::initializeVarList(), and Token::typeDecl().

◆ astIsRHS()

bool astIsRHS ( const Token tok)

◆ astIsSignedChar()

bool astIsSignedChar ( const Token tok)

Is expression a 'signed char' if no promotion is used.

Definition at line 171 of file astutils.cpp.

References astIsCharWithSign().

Referenced by CheckOther::checkCharVariable().

◆ astIsSmartPointer()

bool astIsSmartPointer ( const Token tok)

◆ astIsUniqueSmartPointer()

bool astIsUniqueSmartPointer ( const Token tok)

◆ astIsUnknownSignChar()

bool astIsUnknownSignChar ( const Token tok)

Is expression a 'char' if no promotion is used?

Definition at line 176 of file astutils.cpp.

References astIsCharWithSign().

Referenced by CheckOther::checkCharVariable().

◆ astIsUnsigned()

bool astIsUnsigned ( const Token tok)

◆ astIsVariableComparison()

const Token* astIsVariableComparison ( const Token tok,
const std::string &  comp,
const std::string &  rhs,
const Token **  vartok 
)

Is given syntax tree a variable comparison against value.

Definition at line 351 of file astutils.cpp.

References Token::astOperand1(), Token::astOperand2(), Token::isComparisonOp(), match(), Token::str(), and Token::varId().

Referenced by CheckLeakAutoVar::checkScope(), CheckUninitVar::checkScopeForVariable(), ifvar(), and notvar().

◆ astParentSkipParens() [1/2]

const Token* astParentSkipParens ( const Token tok)

◆ astParentSkipParens() [2/2]

Token* astParentSkipParens ( Token tok)

◆ compareKnownValue()

static bool compareKnownValue ( const Token *const  tok1,
const Token *const  tok2,
const std::function< bool(const ValueFlow::Value &, const ValueFlow::Value &, bool)> &  compare 
)
static

◆ compareTokenFlags()

bool compareTokenFlags ( const Token tok1,
const Token tok2,
bool  macro 
)

◆ exprDependsOnThis()

bool exprDependsOnThis ( const Token expr,
bool  onVar,
nonneg int  depth 
)

◆ extractForLoopValues()

bool extractForLoopValues ( const Token forToken,
nonneg int &  varid,
bool &  knownInitValue,
MathLib::bigint initValue,
bool &  partialCond,
MathLib::bigint stepValue,
MathLib::bigint lastValue 
)

◆ findAllocFuncCallToken()

const Token* findAllocFuncCallToken ( const Token expr,
const Library library 
)

Find a allocation function call in expression, so result of expression is allocated memory/resource.

Definition at line 3501 of file astutils.cpp.

References Token::astOperand1(), Token::astOperand2(), Library::getAllocFuncInfo(), Token::isCast(), Token::Match(), Token::previous(), and Token::simpleMatch().

Referenced by CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(), and CheckUninitVar::checkScope().

◆ findArgumentPos()

static int findArgumentPos ( const Token tok,
const Token tokToFind 
)
static

Definition at line 90 of file astutils.cpp.

References findArgumentPosRecursive().

Referenced by getArgumentPos().

◆ findArgumentPosRecursive()

static int findArgumentPosRecursive ( const Token tok,
const Token tokToFind,
bool &  found,
nonneg int  depth = 0 
)
static

Definition at line 68 of file astutils.cpp.

References Token::astOperand1(), Token::astOperand2(), and Token::str().

Referenced by findArgumentPos().

◆ findExpression() [1/2]

const Token* findExpression ( const nonneg int  exprid,
const Token start,
const Token end,
const std::function< bool(const Token *)> &  pred 
)

Definition at line 50 of file astutils.cpp.

References Token::next(), and precedes().

Referenced by CheckOther::checkInnerScope(), and findVariableChanged().

◆ findExpression() [2/2]

const Token* findExpression ( const Token start,
const nonneg int  exprid 
)

◆ findExpressionChanged()

const Token* findExpressionChanged ( const Token expr,
const Token start,
const Token end,
const Settings settings,
int  depth 
)

◆ findExpressionChangedImpl()

template<class Find >
static const Token* findExpressionChangedImpl ( const Token expr,
const Token start,
const Token end,
const Settings settings,
int  depth,
Find  find 
)
static

◆ findExpressionChangedSkipDeadCode()

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 
)

◆ findLambdaEndToken() [1/2]

const Token* findLambdaEndToken ( const Token first)

◆ findLambdaEndToken() [2/2]

Token* findLambdaEndToken ( Token first)

Definition at line 3199 of file astutils.cpp.

References findLambdaEndTokenGeneric().

◆ findLambdaEndTokenGeneric()

template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T* findLambdaEndTokenGeneric ( T *  first)
static

Definition at line 3158 of file astutils.cpp.

References Token::link(), Token::Match(), and Token::str().

Referenced by findLambdaEndToken().

◆ findLambdaStartToken()

const Token* findLambdaStartToken ( const Token last)

◆ findNextTokenFromBreak()

const Token* findNextTokenFromBreak ( const Token breakToken)

For a "break" token, locate the next token to execute.

The token will be either a "}" or a ";".

Definition at line 912 of file astutils.cpp.

References Scope::bodyEnd, Scope::isLoopScope(), Token::linkAt(), Scope::nestedIn, Token::next(), Token::scope(), Token::simpleMatch(), and Scope::type.

Referenced by FwdAnalysis::check(), FwdAnalysis::checkRecursive(), and CheckVaarg::va_list_usage().

◆ findThisChanged()

static const Token* findThisChanged ( const Token start,
const Token end,
int  indirect,
const Settings settings 
)
static

Definition at line 2938 of file astutils.cpp.

References exprDependsOnThis(), isThisChanged(), Token::next(), and precedes().

Referenced by findExpressionChangedImpl().

◆ findVariableChanged() [1/2]

const Token* findVariableChanged ( const Token start,
const Token end,
int  indirect,
const nonneg int  exprid,
bool  globalvar,
const Settings settings,
int  depth 
)

Definition at line 2872 of file astutils.cpp.

References findVariableChanged().

◆ findVariableChanged() [2/2]

Token* findVariableChanged ( Token start,
const Token end,
int  indirect,
const nonneg int  exprid,
bool  globalvar,
const Settings settings,
int  depth 
)

◆ followAllReferences()

SmallVector<ReferenceToken> followAllReferences ( const Token tok,
bool  temporary,
bool  inconclusive,
ErrorPath  errors,
int  depth 
)

◆ followReferences()

const Token* followReferences ( const Token tok,
ErrorPath errors 
)

Definition at line 1369 of file astutils.cpp.

References followAllReferences().

Referenced by isSameExpression().

◆ followVariableExpression()

static const Token* followVariableExpression ( const Settings settings,
const Token tok,
const Token end = nullptr 
)
static

◆ followVariableExpressionError()

static void followVariableExpressionError ( const Token tok1,
const Token tok2,
ErrorPath errors 
)
static

Definition at line 1222 of file astutils.cpp.

References Token::expressionString(), and Token::str().

Referenced by isSameExpression().

◆ functionModifiesArguments()

static bool functionModifiesArguments ( const Function f)
static

Definition at line 1960 of file astutils.cpp.

References Function::argumentList.

Referenced by isConstFunctionCall().

◆ getArgumentPos() [1/2]

static int getArgumentPos ( const Token ftok,
const Token tokToFind 
)
static

◆ getArgumentPos() [2/2]

int getArgumentPos ( const Variable var,
const Function f 
)

Definition at line 3087 of file astutils.cpp.

References Function::argumentList.

◆ getArguments()

std::vector<const Token*> getArguments ( const Token ftok)

Get arguments (AST)

Definition at line 3083 of file astutils.cpp.

References astFlatten(), and getArgumentStart().

Referenced by ValueFlowAnalyzer::analyzeCondition(), CheckBufferOverrun::argumentSize(), CheckBufferOverrun::bufferOverflow(), CheckLeakAutoVar::changeAllocStatusIfRealloc(), CheckClass::checkConstFunc(), CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(), CheckOther::checkOverlappingWrite(), CheckMemoryLeakInFunction::checkReallocUsage(), FwdAnalysis::checkRecursive(), CheckClass::checkUselessOverride(), CheckStl::eraseIteratorOutOfBounds(), Scope::findFunction(), followAllReferences(), LifetimeStore::fromFunctionArg(), Lambda::getCaptures(), getContainerSizeFromConstructor(), CTU::getFileInfo(), getInitListSize(), getLifetimeTokens(), CheckMemoryLeak::getReallocationType(), CheckFunctions::invalidFunctionUsage(), isConstFunctionCall(), isConstVarExpression(), CheckMemoryLeak::isOpenDevNull(), CheckMemoryLeak::isReopenStandardStream(), ContainerExpressionAnalyzer::isWritable(), CheckStl::knownEmptyContainer(), CheckFunctions::memsetInvalid2ndParam(), CheckFunctions::memsetZeroBytes(), CheckStl::mismatchingContainerIterator(), CheckStl::mismatchingContainers(), CheckNullPointer::nullConstantDereference(), CheckString::overlappingStrcmp(), CheckNullPointer::parseFunctionCall(), FwdAnalysis::possiblyAliased(), SymbolDatabase::setValueTypeInTokenList(), CheckString::sprintfOverlappingData(), CheckBufferOverrun::stringNotZeroTerminated(), CheckStl::uselessCalls(), valueFlowArrayElement(), valueFlowContainerSize(), valueFlowDynamicBufferSize(), valueFlowFunctionReturn(), valueFlowLibraryFunction(), valueFlowLifetimeClassConstructor(), valueFlowLifetimeConstructor(), valueFlowLifetimeFunction(), valueFlowSmartPointer(), and valueFlowSubFunction().

◆ getArgumentStart()

const Token* getArgumentStart ( const Token ftok)

◆ getArgumentVars()

std::vector<const Variable*> getArgumentVars ( const Token tok,
int  argnr 
)

◆ getCondTok() [1/2]

const Token* getCondTok ( const Token tok)

Definition at line 884 of file astutils.cpp.

References getCondTokImpl().

◆ getCondTok() [2/2]

Token* getCondTok ( Token tok)

◆ getCondTokFromEnd() [1/2]

const Token* getCondTokFromEnd ( const Token endBlock)

Definition at line 893 of file astutils.cpp.

References getCondTokFromEndImpl().

◆ getCondTokFromEnd() [2/2]

Token* getCondTokFromEnd ( Token endBlock)

◆ getCondTokFromEndImpl()

template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T* getCondTokFromEndImpl ( T *  endBlock)
static

Definition at line 832 of file astutils.cpp.

References getCondTok(), getCondTokFromEnd(), and Token::simpleMatch().

Referenced by getCondTokFromEnd().

◆ getCondTokImpl()

template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T* getCondTokImpl ( T *  tok)
static

Definition at line 812 of file astutils.cpp.

References getCondTok(), and Token::simpleMatch().

Referenced by getCondTok().

◆ getContainerFunction()

static const Token* getContainerFunction ( const Token tok)
static

◆ getExprUsage()

ExprUsage getExprUsage ( const Token tok,
int  indirect,
const Settings settings 
)

◆ getFunctionUsage()

static ExprUsage getFunctionUsage ( const Token tok,
int  indirect,
const Settings settings 
)
static

◆ getInitTok() [1/2]

const Token* getInitTok ( const Token tok)

Definition at line 901 of file astutils.cpp.

References getInitTokImpl().

◆ getInitTok() [2/2]

Token* getInitTok ( Token tok)

◆ getInitTokImpl()

template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T* getInitTokImpl ( T *  tok)
static

Definition at line 849 of file astutils.cpp.

References Token::Match(), and Token::simpleMatch().

Referenced by getInitTok().

◆ getIteratorExpression()

const Token* getIteratorExpression ( const Token tok)

◆ getLHSVariable()

const Variable* getLHSVariable ( const Token tok)

◆ getLHSVariableRecursive()

static const Token* getLHSVariableRecursive ( const Token tok)
static

◆ getLHSVariables()

std::vector<const Variable*> getLHSVariables ( const Token tok)

◆ getLHSVariablesRecursive()

static void getLHSVariablesRecursive ( std::vector< const Variable * > &  vars,
const Token tok 
)
static

◆ getLHSVariableToken()

const Token* getLHSVariableToken ( const Token tok)

◆ getParentLifetime() [1/2]

const Token* getParentLifetime ( const Token tok)

◆ getParentLifetime() [2/2]

const Token* getParentLifetime ( const Token tok,
const Library library 
)

Definition at line 642 of file astutils.cpp.

References getParentMembers().

◆ getParentLifetimeObject()

static const Token* getParentLifetimeObject ( const Token tok)
static

Definition at line 635 of file astutils.cpp.

References Token::astOperand1(), and Token::simpleMatch().

◆ getParentMember()

const Token* getParentMember ( const Token tok)

◆ getParentMembers()

static std::vector<const Token*> getParentMembers ( const Token tok)
static

Definition at line 615 of file astutils.cpp.

References astFlatten(), Token::astParent(), and Token::simpleMatch().

Referenced by getParentLifetime().

◆ getParentValueTypes()

std::vector<ValueType> getParentValueTypes ( const Token tok,
const Settings settings,
const Token **  parent 
)

◆ getStepTok() [1/2]

const Token* getStepTok ( const Token tok)

Definition at line 908 of file astutils.cpp.

References getStepTokImpl().

◆ getStepTok() [2/2]

Token* getStepTok ( Token tok)

◆ getStepTokImpl()

template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T* getStepTokImpl ( T *  tok)
static

Definition at line 865 of file astutils.cpp.

References Token::Match(), and Token::simpleMatch().

Referenced by getStepTok().

◆ getTokenArgumentFunction() [1/2]

const Token* getTokenArgumentFunction ( const Token tok,
int &  argn 
)

◆ getTokenArgumentFunction() [2/2]

Token* getTokenArgumentFunction ( Token tok,
int &  argn 
)

Definition at line 2364 of file astutils.cpp.

References getTokenArgumentFunctionImpl().

◆ getTokenArgumentFunctionImpl()

template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T* getTokenArgumentFunctionImpl ( T *  tok,
int &  argn 
)
static

Definition at line 2287 of file astutils.cpp.

References getArgumentPos(), Token::Match(), and Token::simpleMatch().

Referenced by getTokenArgumentFunction().

◆ getVariableInitExpression()

static const Token* getVariableInitExpression ( const Variable var)
static

◆ hasNoreturnFunction()

static bool hasNoreturnFunction ( const Token tok,
const Library library,
const Token **  unknownFunc 
)
static

◆ hasToken()

static bool hasToken ( const Token startTok,
const Token stopTok,
const Token tok 
)
static

Definition at line 494 of file astutils.cpp.

References Token::next().

Referenced by nextAfterAstRightmostLeafGeneric().

◆ hasUnknownVars()

static bool hasUnknownVars ( const Token startTok)
static

Definition at line 1140 of file astutils.cpp.

References op1_and_op2, Token::variable(), Token::varId(), and visitAstNodes().

Referenced by followVariableExpression().

◆ isAliased() [1/2]

static bool isAliased ( const Token startTok,
const Token endTok,
nonneg int  varid 
)
static

Definition at line 1080 of file astutils.cpp.

References isAliasOf(), Token::Match(), Token::next(), and precedes().

Referenced by followVariableExpression(), and isAliased().

◆ isAliased() [2/2]

bool isAliased ( const Variable var)

◆ isAliasOf() [1/2]

bool isAliasOf ( const Token tok,
const Token expr,
int *  indirect,
bool *  inconclusive 
)

Definition at line 1038 of file astutils.cpp.

References astIsPointer(), Token::exprId(), findAstNode(), and followAllReferences().

◆ isAliasOf() [2/2]

bool isAliasOf ( const Token tok,
nonneg int  varid,
bool *  inconclusive 
)

If token is an alias if another variable.

Definition at line 1017 of file astutils.cpp.

References inconclusive, Token::values(), and Token::varId().

Referenced by isAliased(), and isExpressionChangedAt().

◆ isArray()

static bool isArray ( const Token tok)
static

◆ isConstExpression()

bool isConstExpression ( const Token tok,
const Library library 
)

◆ isConstFunctionCall()

bool isConstFunctionCall ( const Token ftok,
const Library library 
)

◆ isConstVarExpression()

bool isConstVarExpression ( const Token tok,
const std::function< bool(const Token *)> &  skipPredicate 
)

◆ isCPPCast()

bool isCPPCast ( const Token tok)

◆ isCPPCastKeyword()

static bool isCPPCastKeyword ( const Token tok)
static

Definition at line 2409 of file astutils.cpp.

References endsWith(), and Token::str().

Referenced by isCPPCast(), and isVariableChangedByFunctionCall().

◆ isDifferentKnownValues()

static bool isDifferentKnownValues ( const Token *const  tok1,
const Token *const  tok2 
)
inlinestatic

◆ isEqualKnownValue()

bool isEqualKnownValue ( const Token *const  tok1,
const Token *const  tok2 
)

◆ isEscaped()

static bool isEscaped ( const Token tok,
bool  functionsScope,
const Library library 
)
static

Definition at line 2137 of file astutils.cpp.

References Library::isnoreturn(), Token::Match(), and Token::simpleMatch().

Referenced by isReturnScope().

◆ isEscapedOrJump()

static bool isEscapedOrJump ( const Token tok,
bool  functionsScope,
const Library library 
)
static

Definition at line 2146 of file astutils.cpp.

References Library::isnoreturn(), Token::Match(), and Token::simpleMatch().

Referenced by isReturnScope().

◆ isEscapeFunction()

bool isEscapeFunction ( const Token ftok,
const Library library 
)

Definition at line 2155 of file astutils.cpp.

References Token::function(), Library::isnoreturn(), and Token::Match().

◆ isExpressionChangedAt() [1/2]

template<class F , REQUIRES("F must be a function that returns a Token class", std::is_convertible< decltype(std::declval< F >()()), const Token * >) >
static bool isExpressionChangedAt ( const F &  getExprTok,
const Token tok,
int  indirect,
const nonneg int  exprid,
bool  globalvar,
const Settings settings,
int  depth 
)
static

◆ isExpressionChangedAt() [2/2]

bool isExpressionChangedAt ( const Token expr,
const Token tok,
int  indirect,
bool  globalvar,
const Settings settings,
int  depth 
)

Definition at line 2844 of file astutils.cpp.

References Token::exprId(), and isExpressionChangedAt().

◆ isForLoopCondition()

static bool isForLoopCondition ( const Token *const  tok)
static

Definition at line 1467 of file astutils.cpp.

References Token::astOperand1(), Token::astParent(), and Token::simpleMatch().

Referenced by isUsedAsBool().

◆ isForLoopIncrement()

static bool isForLoopIncrement ( const Token *const  tok)
static

Definition at line 1478 of file astutils.cpp.

References Token::astOperand2(), Token::astParent(), and Token::simpleMatch().

Referenced by isUsedAsBool().

◆ isFunctionCall()

static bool isFunctionCall ( const Token tok)
static

Definition at line 483 of file astutils.cpp.

References Token::link(), Token::Match(), Token::next(), Token::simpleMatch(), and Token::tokAt().

Referenced by isVariableChanged().

◆ isGlobalData()

bool isGlobalData ( const Token expr)

◆ isInConstructorList()

static bool isInConstructorList ( const Token tok)
static

◆ isInLoopCondition()

const Token* isInLoopCondition ( const Token tok)

◆ isIteratorPair()

bool isIteratorPair ( const std::vector< const Token * > &  args)

◆ isLeafDot()

bool isLeafDot ( const Token tok)

◆ isLikelyStream()

bool isLikelyStream ( const Token stream)

◆ isLikelyStreamRead()

bool isLikelyStreamRead ( const Token op)

◆ isNullOperand()

bool isNullOperand ( const Token expr)

◆ isOppositeCond()

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.

Parameters
isNotdo you want to know if cond1 is !cond2 or if cond1 and cond2 are non-overlapping. true: cond1==!cond2 false: cond1==true => cond2==false
cond1condition1
cond2condition2
settingssettings
pureboolean

Definition at line 1785 of file astutils.cpp.

References Token::astOperand1(), Token::astOperand2(), Token::astSibling(), Library::Container::EMPTY, ValueFlow::Value::intvalue, Token::isComparisonOp(), Library::isContainerYield(), isDifferentKnownValues(), isSameExpression(), isUsedAsBool(), isZeroBoundCond(), op1, op2, Library::Container::SIZE, and Token::str().

Referenced by CheckCondition::checkIncorrectLogicOperator(), isOppositeExpression(), OppositeExpressionAnalyzer::match(), and CheckCondition::multiCondition().

◆ isOppositeExpression()

bool isOppositeExpression ( const Token *const  tok1,
const Token *const  tok2,
const Settings settings,
bool  pure,
bool  followVar,
ErrorPath errors 
)

◆ isReturnScope()

bool isReturnScope ( const Token *const  endToken,
const Library library,
const Token **  unknownFunc,
bool  functionScope 
)

◆ isSameConstantValue()

static bool isSameConstantValue ( bool  macro,
const Token tok1,
const Token tok2 
)
inlinestatic

◆ isSameExpression()

bool isSameExpression ( bool  macro,
const Token tok1,
const Token tok2,
const Settings settings,
bool  pure,
bool  followVar,
ErrorPath errors 
)

Definition at line 1556 of file astutils.cpp.

References astIsBoolLike(), Token::astOperand1(), Token::astOperand2(), Token::astParent(), compareTokenFlags(), ValueType::constness, Token::eIncDecOp, Token::enumerator(), findExpressionChanged(), followReferences(), followVariableExpression(), followVariableExpressionError(), Token::function(), ValueFlow::Value::intvalue, Token::isAssignmentOp(), Token::isAttributeConst(), Token::isAttributePure(), Token::isBinaryOp(), Token::isCpp(), isDifferentKnownValues(), Library::isFunctionConst(), Token::isName(), isSameConstantValue(), Settings::library, Token::link(), Token::Match(), Token::next(), Token::originalName(), ValueType::pointer, precedes(), Token::previous(), Token::simpleMatch(), Token::str(), Token::tokAt(), Token::tokType(), ValueType::type, Token::valueType(), Token::variable(), Token::varId(), and ValueType::VOID.

Referenced by CheckCondition::alwaysTrueFalse(), CheckOther::checkDuplicateBranch(), CheckCondition::checkDuplicateConditionalAssign(), CheckOther::checkDuplicateExpression(), CheckOther::checkEvaluationOrder(), CheckStl::checkFindInsert(), CheckCondition::checkIncorrectLogicOperator(), CheckCondition::checkInvalidTestForOverflow(), CheckOther::checkKnownArgument(), CheckOther::checkOverlappingWrite(), FwdAnalysis::checkRecursive(), CheckCondition::duplicateCondition(), findInsertValue(), FwdAnalysis::hasOperand(), CheckStl::isContainerSize(), isOppositeCond(), isOppositeExpression(), CheckCondition::isOverlappingCond(), isSameIteratorContainerExpression(), SameExpressionAnalyzer::match(), CheckStl::mismatchingContainers(), CheckCondition::multiCondition2(), CheckString::overlappingStrcmp(), FwdAnalysis::possiblyAliased(), CheckString::sprintfOverlappingData(), CheckBufferOverrun::stringNotZeroTerminated(), and valueFlowSameExpressions().

◆ isSameLifetime()

static bool isSameLifetime ( const Token *const  tok1,
const Token *const  tok2 
)
static

◆ isScopeBracket()

bool isScopeBracket ( const Token tok)

Definition at line 2273 of file astutils.cpp.

References Token::Match(), Token::scope(), and Token::str().

Referenced by valueFlowForwardLifetime().

◆ isStlStringType()

bool isStlStringType ( const Token tok)

Definition at line 409 of file astutils.cpp.

References Token::linkAt(), Token::Match(), and Token::simpleMatch().

Referenced by CheckStl::string_c_str().

◆ isStructuredBindingVariable()

bool isStructuredBindingVariable ( const Variable var)

◆ isTemporary()

bool isTemporary ( const Token tok,
const Library library,
bool  unknown 
)

◆ isThisChanged()

bool isThisChanged ( const Token tok,
int  indirect,
const Settings settings 
)

◆ isTrivialConstructor()

static bool isTrivialConstructor ( const Token tok)
static

◆ isUnevaluated()

bool isUnevaluated ( const Token tok)

◆ isUniqueExpression()

bool isUniqueExpression ( const Token tok)

◆ isUsedAsBool()

bool isUsedAsBool ( const Token *const  tok,
const Settings settings 
)

◆ isVariableChanged() [1/4]

bool isVariableChanged ( const Token start,
const Token end,
const nonneg int  exprid,
bool  globalvar,
const Settings settings,
int  depth 
)

Is variable changed in block of code?

Definition at line 2764 of file astutils.cpp.

References findVariableChanged().

◆ isVariableChanged() [2/4]

bool isVariableChanged ( const Token start,
const Token end,
int  indirect,
const nonneg int  exprid,
bool  globalvar,
const Settings settings,
int  depth 
)

Definition at line 2769 of file astutils.cpp.

References findVariableChanged().

◆ isVariableChanged() [3/4]

bool isVariableChanged ( const Token tok,
int  indirect,
const Settings settings,
int  depth 
)

Definition at line 2546 of file astutils.cpp.

References astIsContainer(), astIsLHS(), astIsPointer(), astIsRHS(), astIsSmartPointer(), Token::astOperand1(), Token::astParent(), Library::Container::AT_INDEX, Library::Container::BUFFER, Library::Container::BUFFER_NT, Library::Container::CHANGE, Library::Container::CHANGE_CONTENT, Library::Container::CHANGE_INTERNAL, Library::Container::CLEAR, ValueType::container, contains(), Token::eIncDecOp, Library::Container::EMPTY, Library::Container::END_ITERATOR, Library::Container::ERASE, Library::Container::FIND, Token::function(), Library::Container::getAction(), getLHSVariable(), Library::Container::getYield(), inconclusive, Library::Container::INSERT, Token::isArithmeticalOp(), Token::isBinaryOp(), Token::isCast(), Variable::isConst(), Function::isConst(), ValueType::isConst(), isConstVarExpression(), Token::isCpp(), isFunctionCall(), Library::isFunctionConst(), Token::isIncDecOp(), isLikelyStream(), isLikelyStreamRead(), Variable::isLocal(), Variable::isPointer(), Variable::isReference(), Token::isUnaryOp(), isVariableChangedByFunctionCall(), Library::Container::ITEM, Library::Container::ITERATOR, Settings::library, Token::link(), Token::Match(), Variable::nameToken(), Token::next(), Library::Container::POP, Token::previous(), Library::Container::PUSH, Library::Container::RESIZE, Token::simpleMatch(), Library::Container::SIZE, Library::Container::START_ITERATOR, Library::Container::stdAssociativeLike, Token::str(), Token::tokAt(), Token::tokType(), Token::valueType(), and Token::variable().

Referenced by ConditionHandler::afterCondition(), CheckCondition::assignIfParseScope(), CheckOther::checkConstPointer(), CheckOther::checkConstVariable(), CheckOther::checkDuplicateExpression(), CheckOther::checkPassByReference(), CheckOther::checkRedundantCopy(), CheckAutoVariables::checkVarLifetimeScope(), ExpressionAnalyzer::ExpressionAnalyzer(), fillProgramMemoryFromAssignments(), followVariableExpression(), getUnsafeFunction(), ValueFlowAnalyzer::isAliasModified(), isExpressionChangedAt(), CheckUnusedVar::isFunctionWithoutSideEffects(), ValueFlowAnalyzer::isModified(), isThisChanged(), isVariablesChanged(), removeModifiedVars(), singleAssignInScope(), singleConditionalInScope(), singleMemberCallInScope(), valueFlowContainerSize(), valueFlowForLoopSimplify(), valueFlowLifetimeFunction(), and CheckUninitVar::valueFlowUninit().

◆ isVariableChanged() [4/4]

bool isVariableChanged ( const Variable var,
const Settings settings,
int  depth 
)

◆ isVariableChangedByFunctionCall() [1/2]

bool isVariableChangedByFunctionCall ( const Token tok,
int  indirect,
const Settings settings,
bool *  inconclusive 
)

Is variable changed by function call? In case the answer of the question is inconclusive, e.g.

because the function declaration is not known the return value is false and the output parameter inconclusive is set to true

Parameters
toktoken of variable in function call
settingsprogram settings
inconclusivepointer to output variable which indicates that the answer of the question is inconclusive

Definition at line 2438 of file astutils.cpp.

References astIsPrimitive(), Token::astParent(), Library::ArgumentChecks::DIR_IN, Library::ArgumentChecks::DIR_INOUT, Library::ArgumentChecks::DIR_OUT, Token::eType, Token::function(), Library::getArgDirection(), getArgumentVars(), getTokenArgumentFunction(), inconclusive, isArray(), Token::isCpp(), isCPPCastKeyword(), ValueType::isIntegral(), Token::isKeyword(), Token::isName(), Library::isnullargbad(), isTrivialConstructor(), Library::isuninitargbad(), Settings::library, Token::link(), Token::Match(), Token::next(), ValueType::pointer, Token::previous(), Token::simpleMatch(), startsWith(), Token::str(), Token::tokAt(), Token::tokType(), ValueType::UNKNOWN_TYPE, Token::valueType(), and Token::variable().

◆ isVariableChangedByFunctionCall() [2/2]

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, e.g.

because the function declaration is not known the return value is false and the output parameter inconclusive is set to true

Parameters
tokast tree
varidVariable Id
settingsprogram settings
inconclusivepointer to output variable which indicates that the answer of the question is inconclusive

Definition at line 2263 of file astutils.cpp.

References Token::astOperand1(), Token::astOperand2(), inconclusive, and Token::varId().

Referenced by CheckOther::checkAccessOfMovedVariable(), CheckOther::checkConstPointer(), CheckOther::checkConstVariable(), CheckClass::initializeVarList(), isContainerSizeChangedByFunction(), ValueFlowAnalyzer::isModified(), isVariableChanged(), and CheckUninitVar::valueFlowUninit().

◆ isVariableDecl()

bool isVariableDecl ( const Token tok)

◆ isVariablesChanged()

bool isVariablesChanged ( const Token start,
const Token end,
int  indirect,
const std::vector< const Variable * > &  vars,
const Settings settings 
)

◆ isWithinScope()

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?

Definition at line 2250 of file astutils.cpp.

References Scope::nestedIn, Variable::scope(), Token::scope(), and Scope::type.

Referenced by CheckOther::checkVariableScope().

◆ isWithoutSideEffects()

bool isWithoutSideEffects ( const Token tok,
bool  checkArrayAccess,
bool  checkReference 
)

◆ isZeroBoundCond()

static bool isZeroBoundCond ( const Token *const  cond)
static

Definition at line 1767 of file astutils.cpp.

References Token::astOperand2(), isZero(), and Token::str().

Referenced by isOppositeCond().

◆ match()

static bool match ( const Token tok,
const std::string &  rhs 
)
static

◆ memoize()

template<class F , class R = decltype(std::declval<F>()())>
static std::function<R()> memoize ( f)
static

Definition at line 2792 of file astutils.cpp.

Referenced by findVariableChanged().

◆ nextAfterAstRightmostLeaf() [1/2]

const Token* nextAfterAstRightmostLeaf ( const Token tok)

◆ nextAfterAstRightmostLeaf() [2/2]

Token* nextAfterAstRightmostLeaf ( Token tok)

Definition at line 552 of file astutils.cpp.

References nextAfterAstRightmostLeafGeneric().

◆ nextAfterAstRightmostLeafGeneric()

template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T* nextAfterAstRightmostLeafGeneric ( T *  tok)
static

◆ numberOfArguments()

int numberOfArguments ( const Token ftok)

Determines the number of arguments - if token is a function call or macro.

Parameters
ftokstart token which is supposed to be the function/macro name.
Returns
Number of arguments

Definition at line 3063 of file astutils.cpp.

References astCount(), and getArgumentStart().

Referenced by CheckLeakAutoVar::changeAllocStatusIfRealloc(), CheckMemoryLeak::getAllocationType(), getArgumentVars(), getParentValueTypes(), CheckMemoryLeak::getReallocationType(), TemplateSimplifier::instantiateMatch(), CheckMemoryLeak::isOpenDevNull(), CheckMemoryLeak::isReopenStandardStream(), and CheckFunctions::memsetZeroBytes().

◆ numberOfArgumentsWithoutAst()

int numberOfArgumentsWithoutAst ( const Token start)

Get number of arguments without using AST.

Definition at line 3067 of file astutils.cpp.

References Token::next(), Token::nextArgument(), Token::simpleMatch(), and Token::str().

Referenced by Library::matchArguments().

◆ precedes()

bool precedes ( const Token tok1,
const Token tok2 
)

◆ previousBeforeAstLeftmostLeaf() [1/2]

const Token* previousBeforeAstLeftmostLeaf ( const Token tok)

◆ previousBeforeAstLeftmostLeaf() [2/2]

Token* previousBeforeAstLeftmostLeaf ( Token tok)

Definition at line 518 of file astutils.cpp.

References previousBeforeAstLeftmostLeafGeneric().

◆ previousBeforeAstLeftmostLeafGeneric()

template<class T , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) >
static T* previousBeforeAstLeftmostLeafGeneric ( T *  tok)
static

Definition at line 504 of file astutils.cpp.

Referenced by previousBeforeAstLeftmostLeaf().

◆ succeeds()

bool succeeds ( const Token tok1,
const Token tok2 
)