Cppcheck
|
#include <functional>
#include <list>
#include <stack>
#include <string>
#include <type_traits>
#include <vector>
#include "config.h"
#include "errortypes.h"
#include "library.h"
#include "mathlib.h"
#include "smallvector.h"
#include "symboldatabase.h"
#include "token.h"
Go to the source code of this file.
Classes | |
struct | ReferenceToken |
Enumerations | |
enum class | ChildrenToVisit { none , op1 , op2 , op1_and_op2 , done } |
enum class | ExprUsage { None , NotUsed , PassedByReference , Used , Inconclusive } |
Functions | |
template<class T , class TFunc , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) > | |
void | visitAstNodes (T *ast, const TFunc &visitor) |
Visit AST nodes recursively. More... | |
template<class TFunc > | |
const Token * | findAstNode (const Token *ast, const TFunc &pred) |
template<class TFunc > | |
const Token * | findParent (const Token *tok, const TFunc &pred) |
const Token * | findExpression (const nonneg int exprid, const Token *start, const Token *end, const std::function< bool(const Token *)> &pred) |
const Token * | findExpression (const Token *start, const nonneg int exprid) |
template<class T , class OuputIterator , REQUIRES("T must be a Token class", std::is_convertible< T *, const Token * >) > | |
void | astFlattenCopy (T *tok, const char *op, OuputIterator out, nonneg int depth=100) |
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=100) |
bool | astHasToken (const Token *root, const Token *tok) |
bool | astHasExpr (const Token *tok, nonneg int exprid) |
bool | astHasVar (const Token *tok, nonneg int varid) |
bool | astIsPrimitive (const Token *tok) |
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 | 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) |
Library::Container::Action | astContainerAction (const Token *tok, const Token **ftok=nullptr) |
Library::Container::Yield | astContainerYield (const Token *tok, const Token **ftok=nullptr) |
Library::Container::Yield | astFunctionYield (const Token *tok, const Settings &settings, const Token **ftok=nullptr) |
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... | |
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. More... | |
bool | isVariableDecl (const Token *tok) |
bool | isStlStringType (const Token *tok) |
bool | isTemporary (const Token *tok, const Library *library, bool unknown=false) |
const Token * | previousBeforeAstLeftmostLeaf (const Token *tok) |
Token * | previousBeforeAstLeftmostLeaf (Token *tok) |
CPPCHECKLIB const Token * | nextAfterAstRightmostLeaf (const Token *tok) |
Token * | nextAfterAstRightmostLeaf (Token *tok) |
Token * | astParentSkipParens (Token *tok) |
const Token * | astParentSkipParens (const Token *tok) |
const Token * | getParentMember (const Token *tok) |
const Token * | getParentLifetime (const Token *tok) |
const Token * | getParentLifetime (const Token *tok, const Library &library) |
std::vector< ValueType > | getParentValueTypes (const Token *tok, const Settings &settings, const Token **parent=nullptr) |
bool | astIsLHS (const Token *tok) |
bool | astIsRHS (const Token *tok) |
Token * | getCondTok (Token *tok) |
const Token * | getCondTok (const Token *tok) |
Token * | getInitTok (Token *tok) |
const Token * | getInitTok (const Token *tok) |
Token * | getStepTok (Token *tok) |
const Token * | getStepTok (const Token *tok) |
Token * | getCondTokFromEnd (Token *endBlock) |
const Token * | getCondTokFromEnd (const Token *endBlock) |
const Token * | findNextTokenFromBreak (const Token *breakToken) |
For a "break" token, locate the next token to execute. More... | |
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) More... | |
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 | exprDependsOnThis (const Token *expr, bool onVar=true, nonneg int depth=0) |
SmallVector< ReferenceToken > | followAllReferences (const Token *tok, bool temporary=true, bool inconclusive=true, ErrorPath errors=ErrorPath{}, int depth=20) |
const Token * | followReferences (const Token *tok, ErrorPath *errors=nullptr) |
CPPCHECKLIB bool | isSameExpression (bool macro, const Token *tok1, const Token *tok2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors=nullptr) |
bool | isEqualKnownValue (const Token *const tok1, const Token *const tok2) |
bool | isStructuredBindingVariable (const Variable *var) |
const Token * | isInLoopCondition (const Token *tok) |
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. More... | |
bool | compareTokenFlags (const Token *tok1, const Token *tok2, bool macro) |
Are the tokens' flags equal? More... | |
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. More... | |
bool | isOppositeExpression (const Token *const tok1, const Token *const tok2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors=nullptr) |
bool | isConstFunctionCall (const Token *ftok, const Library &library) |
bool | isConstExpression (const Token *tok, const Library &library) |
bool | isWithoutSideEffects (const Token *tok, bool checkArrayAccess=false, bool checkReference=true) |
bool | isUniqueExpression (const Token *tok) |
bool | isEscapeFunction (const Token *ftok, const Library *library) |
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) 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... | |
const Token * | getTokenArgumentFunction (const Token *tok, int &argn) |
Return the token to the function and the argument number. More... | |
Token * | getTokenArgumentFunction (Token *tok, int &argn) |
std::vector< const Variable * > | getArgumentVars (const Token *tok, int argnr) |
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... | |
CPPCHECKLIB 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... | |
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? More... | |
bool | isVariableChanged (const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth=20) |
bool | isVariableChanged (const Token *tok, int indirect, const Settings &settings, int depth=20) |
bool | isVariableChanged (const Variable *var, 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 | isThisChanged (const Token *tok, int indirect, const Settings &settings) |
const Token * | findVariableChanged (const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth=20) |
Token * | findVariableChanged (Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth=20) |
CPPCHECKLIB const Token * | findExpressionChanged (const Token *expr, const Token *start, const Token *end, const Settings &settings, int depth=20) |
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) |
bool | isExpressionChangedAt (const Token *expr, const Token *tok, int indirect, bool globalvar, const Settings &settings, int depth=20) |
bool | isAliasOf (const Token *tok, nonneg int varid, bool *inconclusive=nullptr) |
If token is an alias if another variable. More... | |
bool | isAliasOf (const Token *tok, const Token *expr, int *indirect=nullptr, bool *inconclusive=nullptr) |
bool | isAliased (const Variable *var) |
const Token * | getArgumentStart (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 Token * | getIteratorExpression (const Token *tok) |
bool | isIteratorPair (const std::vector< const Token * > &args) |
Are the arguments a pair of iterators/pointers? More... | |
CPPCHECKLIB const Token * | findLambdaStartToken (const Token *last) |
CPPCHECKLIB const Token * | findLambdaEndToken (const Token *first) |
find lambda function end token More... | |
CPPCHECKLIB Token * | findLambdaEndToken (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=nullptr) |
bool | isLeafDot (const Token *tok) |
ExprUsage | getExprUsage (const Token *tok, int indirect, const Settings &settings) |
const Variable * | getLHSVariable (const Token *tok) |
const Token * | getLHSVariableToken (const Token *tok) |
std::vector< const Variable * > | getLHSVariables (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. More... | |
bool | isScopeBracket (const Token *tok) |
CPPCHECKLIB bool | isNullOperand (const Token *expr) |
bool | isGlobalData (const Token *expr) |
bool | isUnevaluated (const Token *tok) |
|
strong |
Enumerator | |
---|---|
none | |
op1 | |
op2 | |
op1_and_op2 | |
done |
Definition at line 42 of file astutils.h.
|
strong |
Enumerator | |
---|---|
None | |
NotUsed | |
PassedByReference | |
Used | |
Inconclusive |
Definition at line 439 of file astutils.h.
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().
Library::Container::Action astContainerAction | ( | const Token * | tok, |
const Token ** | ftok = nullptr |
||
) |
Definition at line 287 of file astutils.cpp.
References ValueType::container, Library::Container::getAction(), getContainerFunction(), Library::Container::NO_ACTION, Token::str(), and Token::valueType().
Referenced by CheckFunctions::checkLibraryMatchFunctions(), Library::getUseRetValType(), ValueFlow::isContainerSizeChanged(), ValueFlowAnalyzer::isModified(), and Library::isnoreturn().
Library::Container::Yield astContainerYield | ( | const Token * | tok, |
const Token ** | ftok = nullptr |
||
) |
Definition at line 297 of file astutils.cpp.
References ValueType::container, getContainerFunction(), Library::Container::getYield(), Library::Container::NO_YIELD, Token::str(), and Token::valueType().
Referenced by CheckFunctions::checkLibraryMatchFunctions(), findIteratorYield(), Library::getUseRetValType(), ValueFlow::isContainerSizeChanged(), Library::isFunctionConst(), isLocalContainerBuffer(), Library::isnoreturn(), and isSameIteratorContainerExpression().
Definition at line 124 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), and Token::str().
Referenced by numberOfArguments().
Definition at line 110 of file astutils.cpp.
References astFlattenCopy().
Referenced by getArguments(), getConditions(), getParentMembers(), valueFlowAfterSwap(), and valueFlowLifetimeUserConstructor().
Definition at line 117 of file astutils.cpp.
References astFlattenCopy().
void astFlattenCopy | ( | T * | tok, |
const char * | op, | ||
OuputIterator | out, | ||
nonneg int | depth = 100 |
||
) |
Definition at line 120 of file astutils.h.
Referenced by astFlatten().
Library::Container::Yield astFunctionYield | ( | const Token * | tok, |
const Settings & | settings, | ||
const Token ** | ftok = nullptr |
||
) |
Definition at line 307 of file astutils.cpp.
References Library::getFunction(), Settings::library, and Library::Container::NO_YIELD.
Referenced by findIteratorYield(), SymbolDatabase::setValueTypeInTokenList(), and valueFlowLifetime().
Definition at line 152 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), and Token::exprId().
Definition at line 134 of file astutils.cpp.
References Token::astParent().
Referenced by followAllReferences().
Definition at line 143 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), and Token::varId().
bool astIsBool | ( | const Token * | tok | ) |
Is expression of boolean type?
Definition at line 215 of file astutils.cpp.
References Token::isBoolean(), ValueType::pointer, ValueType::type, and Token::valueType().
Referenced by astIsBoolLike(), CheckBool::checkAssignBoolToFloat(), CheckBool::checkAssignBoolToPointer(), CheckBool::checkBitwiseOnBoolean(), CheckBool::checkComparisonOfBoolExpressionWithInt(), CheckBool::checkIncrementBoolean(), CheckFunctions::invalidFunctionUsage(), ConditionHandler::Condition::isBool(), isConvertedToBool(), SymbolicConditionHandler::isNegatedBool(), isUsedAsBool(), CheckLeakAutoVar::ret(), ConditionHandler::skipNotAndCasts(), CheckStl::useStlAlgorithm(), valueFlowArrayBool(), valueFlowConditionExpressions(), and valueFlowImpossibleValues().
bool astIsContainer | ( | const Token * | tok | ) |
Definition at line 244 of file astutils.cpp.
References astIsIterator(), and getLibraryContainer().
Referenced by CheckBufferOverrun::arrayIndex(), astIsContainerOwned(), CheckStl::checkIteratorPair(), CheckUnusedVar::checkStructMemberUsage(), CheckOther::checkVariableScope(), SymbolDatabase::createSymbolDatabaseSetVariablePointers(), Library::getContainerFromAction(), Library::getContainerFromYield(), getContainerSizeFromConstructorArgs(), getLifetimeTokens(), getParentValueTypes(), CheckStl::invalidContainer(), isConstFunctionCall(), isContainerSizeChangedByFunction(), ValueFlowAnalyzer::isGlobalModified(), isMapFind(), ValueFlowAnalyzer::isModified(), ContainerExpressionAnalyzer::isModified(), isVariableChanged(), ContainerExpressionAnalyzer::isWritable(), CheckStl::mismatchingContainerIterator(), ContainerConditionHandler::parse(), setTokenValue(), Token::typeDecl(), CheckStl::useStlAlgorithm(), valueFlowAfterAssign(), valueFlowArrayElement(), valueFlowContainerSize(), valueFlowIterators(), valueFlowLifetime(), and ContainerExpressionAnalyzer::writeValue().
bool astIsContainerOwned | ( | const Token * | tok | ) |
Definition at line 260 of file astutils.cpp.
References astIsContainer(), and astIsContainerView().
Referenced by hasUniqueOwnership(), isSameIteratorContainerExpression(), valueFlowImpossibleValues(), valueFlowLifetime(), and valueFlowLifetimeConstructor().
bool astIsContainerString | ( | const Token * | tok | ) |
Definition at line 264 of file astutils.cpp.
References ValueType::container, Library::Container::stdStringLike, and Token::valueType().
Referenced by valueFlowContainerSetTokValue().
bool astIsContainerView | ( | const Token * | tok | ) |
Definition at line 254 of file astutils.cpp.
References astIsIterator(), getLibraryContainer(), and Library::Container::view.
Referenced by astIsContainerOwned(), CheckAutoVariables::checkVarLifetimeScope(), FwdAnalysis::unusedValue(), and valueFlowLifetime().
bool astIsFloat | ( | const Token * | tok, |
bool | unknown | ||
) |
Is expression of floating point type?
Definition at line 207 of file astutils.cpp.
References ValueType::pointer, ValueType::type, and Token::valueType().
Referenced by ConditionHandler::afterCondition(), CheckBool::checkAssignBoolToFloat(), CheckOther::checkDuplicateExpression(), CheckCondition::checkIncorrectLogicOperator(), CheckStl::checkIteratorPair(), CheckFunctions::memsetInvalid2ndParam(), parseCompareEachInt(), and valueFlowSymbolicInfer().
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().
bool astIsIntegral | ( | const Token * | tok, |
bool | unknown | ||
) |
Is expression of integral type?
Definition at line 194 of file astutils.cpp.
References ValueType::isIntegral(), ValueType::pointer, and Token::valueType().
Referenced by CheckStl::checkDereferenceInvalidIterator2(), CheckStl::checkIteratorPair(), CheckOther::checkKnownArgument(), getContainerSizeFromConstructorArgs(), getInitListSize(), isConstStatement(), isIntegralOrPointer(), isLikelyStream(), ValueFlowAnalyzer::isModified(), truncateImplicitConversion(), valueFlowSameExpressions(), and valueFlowSymbolicOperators().
bool astIsIterator | ( | const Token * | tok | ) |
Definition at line 239 of file astutils.cpp.
References ValueType::type, and Token::valueType().
Referenced by astIsContainer(), astIsContainerView(), astIsNonStringContainer(), findInsertValue(), getInitListSize(), isIteratorPair(), ContainerExpressionAnalyzer::isModified(), ContainerExpressionAnalyzer::isWritable(), CheckStl::knownEmptyContainerError(), ContainerExpressionAnalyzer::match(), CheckStl::mismatchingContainerIterator(), CheckStl::outOfBounds(), setTokenValue(), ExpressionAnalyzer::setupExprVarIds(), Token::typeDecl(), valueFlowInferCondition(), valueFlowLifetime(), valueFlowLifetimeConstructor(), and valueFlowLifetimeFunction().
bool astIsLHS | ( | const Token * | tok | ) |
Definition at line 784 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), and Token::astParent().
Referenced by ConditionHandler::afterCondition(), ValueFlowAnalyzer::analyzeToken(), assignExpr(), CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(), CheckUninitVar::checkScopeForVariable(), CheckStl::eraseIteratorOutOfBounds(), findTokensSkipDeadCodeImpl(), getContainerFunction(), getExprUsage(), getInvalidMethod(), SubExpressionAnalyzer::internalMatch(), CheckStl::invalidContainer(), ValueFlow::isContainerSizeChanged(), ValueFlowAnalyzer::isModified(), ContainerExpressionAnalyzer::isModified(), isUsedAsBool(), isVariableChanged(), ValueFlowAnalyzer::isWritable(), ContainerExpressionAnalyzer::isWritable(), CheckStl::mismatchingContainerIterator(), valueFlowAfterAssign(), valueFlowLifetime(), valueFlowSmartPointer(), valueFlowSymbolicOperators(), and ContainerExpressionAnalyzer::writeValue().
bool astIsNonStringContainer | ( | const Token * | tok | ) |
Definition at line 248 of file astutils.cpp.
References astIsIterator(), getLibraryContainer(), and Library::Container::stdStringLike.
Referenced by valueFlowLifetimeFunction().
bool astIsPointer | ( | const Token * | tok | ) |
Definition at line 220 of file astutils.cpp.
References ValueType::pointer, and Token::valueType().
Referenced by ValueFlowAnalyzer::analyzeMatch(), astIsGenericChar(), CheckBool::checkAssignBoolToPointer(), CheckOther::checkComparePointers(), CheckOther::checkKnownArgument(), CheckOther::checkKnownPointerToBool(), getContainerSizeFromConstructorArgs(), getFunctionUsage(), getInitListSize(), getLibraryContainer(), getParentValueTypes(), hasUniqueOwnership(), isAliasOf(), isDecayedPointer(), isIntegralOrPointer(), isIteratorPair(), isNullablePointer(), isVariableChanged(), lifetimeType(), setTokenValue(), ExpressionAnalyzer::setupExprVarIds(), valueFlowImpossibleValues(), valueFlowInferCondition(), valueFlowLifetime(), and valueFlowLifetimeFunction().
bool astIsPrimitive | ( | const Token * | tok | ) |
Definition at line 186 of file astutils.cpp.
References ValueType::isPrimitive(), and Token::valueType().
Referenced by getCastTypeStartToken(), ValueFlowAnalyzer::isGlobalModified(), and isVariableChangedByFunctionCall().
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().
bool astIsRHS | ( | const Token * | tok | ) |
Definition at line 797 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), and Token::astParent().
Referenced by ValueFlowAnalyzer::analyzeLifetime(), CheckUninitVar::checkLoopBodyRecursive(), CheckAutoVariables::checkVarLifetimeScope(), getExprUsage(), getParentMember(), CheckStl::invalidContainer(), isAssignedToNonLocal(), isDeadTemporary(), isInConstructorList(), CheckNullPointer::isPointerDeRef(), isUsedAsBool(), isVariableChanged(), setTokenValue(), ValueFlow::solveExprValue(), CheckUninitVar::uninitvarError(), valueFlowArray(), and valueFlowLifetimeFunction().
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().
bool astIsSmartPointer | ( | const Token * | tok | ) |
Definition at line 225 of file astutils.cpp.
References ValueType::smartPointerTypeToken, and Token::valueType().
Referenced by ValueFlowAnalyzer::analyzeMatch(), CheckAssert::assertWithSideEffects(), astIsUniqueSmartPointer(), isConstFunctionCall(), isNullablePointer(), isVariableChanged(), ExpressionAnalyzer::setupExprVarIds(), Token::typeDecl(), and valueFlowSmartPointer().
bool astIsUniqueSmartPointer | ( | const Token * | tok | ) |
Definition at line 230 of file astutils.cpp.
References astIsSmartPointer(), ValueType::smartPointer, Library::SmartPointer::unique, and Token::valueType().
Referenced by hasUniqueOwnership(), and valueFlowLifetime().
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().
bool astIsUnsigned | ( | const Token * | tok | ) |
Definition at line 202 of file astutils.cpp.
References ValueType::sign, ValueType::UNSIGNED, and Token::valueType().
Referenced by minUnsignedValue(), setTokenValue(), and valueFlowImpossibleValues().
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.
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().
Definition at line 557 of file astutils.cpp.
Referenced by astParentSkipParens(), CheckNullPointer::isPointerDeRef(), CheckStl::outOfBounds(), and valueFlowLifetime().
Definition at line 561 of file astutils.cpp.
References Token::astParent(), astParentSkipParens(), Token::link(), Token::Match(), nextAfterAstRightmostLeaf(), Token::previous(), and Token::simpleMatch().
Are the tokens' flags equal?
Definition at line 1537 of file astutils.cpp.
References Token::isComplex(), Token::isExpandedMacro(), Token::isLong(), Token::isSigned(), Token::isTemplateArg(), and Token::isUnsigned().
Referenced by SymbolDatabase::createSymbolDatabaseExprIds(), and isSameExpression().
Definition at line 1105 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), contains(), Scope::findAssociatedScopes(), Scope::function, Token::function(), Scope::functionOf, Scope::isClassOrStruct(), Variable::isPrivate(), Variable::isProtected(), Variable::isPublic(), Variable::isStatic(), Token::Match(), Scope::nestedIn, Token::scope(), Token::simpleMatch(), Token::str(), Function::token, and Token::variable().
Referenced by ValueFlowAnalyzer::analyze(), CheckOther::checkRedundantCopy(), ExpressionAnalyzer::ExpressionAnalyzer(), findExpressionChangedImpl(), findThisChanged(), getLifetimeTokens(), isConstFunctionCall(), isDanglingSubFunction(), valueFlowLifetime(), and valueFlowLifetimeFunction().
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)
Definition at line 926 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), getMinValue(), ValueFlow::Value::intvalue, Token::isBinaryOp(), Token::isUnaryOp(), ValueFlow::makeIntegralInferModel(), Token::Match(), Token::next(), none, op1_and_op2, Token::simpleMatch(), Token::str(), and visitAstNodes().
Referenced by valueFlowForLoop().
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().
Definition at line 88 of file astutils.h.
References done, op1_and_op2, and visitAstNodes().
Referenced by CheckOther::checkKnownArgument(), findExpressionChangedImpl(), ValueFlowAnalyzer::findMatch(), isAliasOf(), isExpression(), ValueFlowAnalyzer::isWritable(), valueFlowAfterAssign(), valueFlowForwardLifetime(), and valueFlowSymbolic().
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().
Definition at line 2774 of file astutils.cpp.
References Scope::bodyEnd, Scope::bodyStart, Function::functionScope, Scope::nestedInFunction(), Token::next(), and Token::scope().
CPPCHECKLIB const Token* findExpressionChanged | ( | const Token * | expr, |
const Token * | start, | ||
const Token * | end, | ||
const Settings & | settings, | ||
int | depth = 20 |
||
) |
Definition at line 3028 of file astutils.cpp.
References findExpressionChangedImpl().
Referenced by ConditionHandler::beforeCondition(), CheckOther::checkDuplicateExpression(), CheckUnusedVar::checkFunctionVariableUsage(), CheckCondition::duplicateCondition(), followVariableExpression(), isSameExpression(), isSimpleExpr(), isVariableChanged(), CheckCondition::multiCondition(), CheckCondition::multiCondition2(), and programMemoryParseCondition().
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 |
||
) |
Definition at line 3037 of file astutils.cpp.
References evaluate(), findExpressionChangedImpl(), and Settings::library.
Referenced by findVarBound(), and ProgramMemoryState::removeModifiedVars().
CPPCHECKLIB const Token* findLambdaEndToken | ( | const Token * | first | ) |
find lambda function end token
first | The [ token |
Definition at line 3195 of file astutils.cpp.
References findLambdaEndTokenGeneric().
Referenced by Function::addArguments(), CheckAutoVariables::autoVariables(), CheckUnusedVar::checkFunctionVariableUsage(), FwdAnalysis::checkRecursive(), CheckAutoVariables::checkVarLifetimeScope(), SymbolDatabase::createSymbolDatabaseFindAllScopes(), Token::findExpressionStartEndTokens(), Function::findReturns(), CheckMemoryLeak::functionReturnType(), CheckClass::initializationListUsage(), nextAfterAstRightmostLeafGeneric(), CheckUnusedFunctions::parseTokens(), CheckBool::returnValueOfFunctionReturningBool(), and CheckVaarg::va_list_usage().
CPPCHECKLIB Token* findLambdaEndToken | ( | Token * | first | ) |
Definition at line 3199 of file astutils.cpp.
References findLambdaEndTokenGeneric().
CPPCHECKLIB const Token* findLambdaStartToken | ( | const Token * | last | ) |
Definition at line 3145 of file astutils.cpp.
References Token::astParent(), Token::isCpp(), Token::link(), Token::simpleMatch(), and Token::str().
Referenced by isExecutableScope().
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().
Definition at line 102 of file astutils.h.
References Token::astParent().
Referenced by CheckOther::checkKnownPointerToBool(), and setTokenValue().
const Token* findVariableChanged | ( | const Token * | start, |
const Token * | end, | ||
int | indirect, | ||
const nonneg int | exprid, | ||
bool | globalvar, | ||
const Settings & | settings, | ||
int | depth = 20 |
||
) |
Definition at line 2872 of file astutils.cpp.
References findVariableChanged().
Token* findVariableChanged | ( | Token * | start, |
const Token * | end, | ||
int | indirect, | ||
const nonneg int | exprid, | ||
bool | globalvar, | ||
const Settings & | settings, | ||
int | depth = 20 |
||
) |
Definition at line 2856 of file astutils.cpp.
References findExpression(), isExpressionChangedAt(), memoize(), Token::next(), and precedes().
Referenced by CheckBufferOverrun::arrayIndex(), bifurcateVariableChanged(), findVariableChanged(), and isVariableChanged().
SmallVector<ReferenceToken> followAllReferences | ( | const Token * | tok, |
bool | temporary = true , |
||
bool | inconclusive = true , |
||
ErrorPath | errors = ErrorPath{} , |
||
int | depth = 20 |
||
) |
Definition at line 1236 of file astutils.cpp.
References astHasToken(), Token::astOperand1(), Token::astOperand2(), Variable::declarationId(), Variable::declEndToken(), Token::expressionString(), Function::findReturns(), Token::function(), getArgumentPos(), getArguments(), inconclusive, Variable::isArgument(), Variable::isConst(), Variable::isReference(), Variable::isRValueReference(), isStructuredBindingVariable(), isTemporary(), Token::Match(), Variable::nameToken(), Token::previous(), Function::returnsReference(), Token::simpleMatch(), ReferenceToken::token, Token::variable(), and Token::varId().
Referenced by ValueFlowAnalyzer::analyze(), followReferences(), isAliasOf(), valueFlowForwardConst(), and valueFlowLifetime().
Definition at line 1369 of file astutils.cpp.
References followAllReferences().
Referenced by isSameExpression().
Definition at line 3087 of file astutils.cpp.
References Function::argumentList.
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().
Definition at line 3048 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::link(), Token::Match(), Token::next(), and Token::simpleMatch().
Referenced by getArguments(), getLifetimeTokens(), and numberOfArguments().
Definition at line 2368 of file astutils.cpp.
References Type::classScope, Token::function(), Scope::functionList, Token::Match(), numberOfArguments(), Scope::numConstructors, Token::previous(), Token::simpleMatch(), Token::typeOf(), Token::variable(), and Scope::varlist.
Referenced by getFunctionUsage(), getParentValueTypes(), isVariableChangedByFunctionCall(), and Token::typeOf().
Definition at line 884 of file astutils.cpp.
References getCondTokImpl().
Definition at line 880 of file astutils.cpp.
References getCondTokImpl().
Referenced by findTokensSkipDeadCodeImpl(), PathAnalysis::forwardRange(), getCondTokFromEndImpl(), getCondTokImpl(), CheckFunctions::useStandardLibrary(), and CheckStl::useStlAlgorithm().
Definition at line 893 of file astutils.cpp.
References getCondTokFromEndImpl().
Definition at line 889 of file astutils.cpp.
References getCondTokFromEndImpl().
Referenced by fillProgramMemoryFromAssignments(), fillProgramMemoryFromConditions(), findTokensSkipDeadCodeImpl(), getCondTokFromEndImpl(), SingleValueFlowAnalyzer::updateScope(), and MultiValueFlowAnalyzer::updateScope().
Definition at line 3374 of file astutils.cpp.
References astIsLHS(), astIsRHS(), Token::astOperand1(), Token::astParent(), getFunctionUsage(), Token::isCast(), Token::isConstOp(), isLeafDot(), isLikelyStreamRead(), Token::isUnaryOp(), isUsedAsBool(), Token::Match(), NotUsed, precedes(), Token::simpleMatch(), Token::str(), Used, Token::valueType(), and Token::variable().
Referenced by CheckOther::checkAccessOfMovedVariable(), and CheckUninitVar::valueFlowUninit().
Definition at line 901 of file astutils.cpp.
References getInitTokImpl().
Definition at line 898 of file astutils.cpp.
References getInitTokImpl().
Referenced by ConditionHandler::afterCondition(), CheckFunctions::useStandardLibrary(), and CheckStl::useStlAlgorithm().
Definition at line 3097 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::isName(), Token::isUnaryOp(), Token::linkAt(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), and Token::str().
Referenced by CheckStl::checkIteratorPair(), and isIteratorPair().
Definition at line 3473 of file astutils.cpp.
References Token::astOperand1(), getLHSVariableRecursive(), Token::isAssignmentOp(), and Token::variable().
Referenced by isVariableChanged().
Definition at line 3445 of file astutils.cpp.
References Token::astOperand1(), getLHSVariablesRecursive(), and Token::Match().
Referenced by valueFlowAfterAssign(), and valueFlowSymbolic().
Definition at line 3487 of file astutils.cpp.
References Token::astOperand1(), getLHSVariableRecursive(), Token::Match(), and Token::variable().
Referenced by Token::typeOf(), and valueFlowForwardLifetime().
Definition at line 596 of file astutils.cpp.
References getParentMember(), Variable::isArgument(), Variable::isLocal(), Token::previous(), Token::simpleMatch(), and Token::variable().
Referenced by CheckOther::checkComparePointers(), CheckAutoVariables::checkVarLifetimeScope(), and valueFlowForwardLifetime().
Definition at line 642 of file astutils.cpp.
References getParentMembers().
Definition at line 576 of file astutils.cpp.
References astIsRHS(), Token::astOperand1(), Token::astOperand2(), Token::astParent(), and Token::simpleMatch().
Referenced by getParentLifetime().
std::vector<ValueType> getParentValueTypes | ( | const Token * | tok, |
const Settings & | settings, | ||
const Token ** | parent = nullptr |
||
) |
Definition at line 712 of file astutils.cpp.
References astIsContainer(), astIsPointer(), Token::astParent(), ValueType::containerTypeToken, Token::eType, Token::function(), getArgumentVars(), getTokenArgumentFunction(), isInConstructorList(), Token::Match(), numberOfArguments(), Scope::numConstructors, ValueType::parseDecl(), Token::simpleMatch(), Token::tokType(), Token::typeOf(), Token::valueType(), and Scope::varlist.
Referenced by getLifetimeTokens(), isConvertedToIntegral(), isConvertedToView(), ValueFlow::isLifetimeBorrowed(), isUsedAsBool(), and valueFlowLifetimeConstructor().
Definition at line 908 of file astutils.cpp.
References getStepTokImpl().
Definition at line 905 of file astutils.cpp.
References getStepTokImpl().
Referenced by ConditionHandler::afterCondition(), CheckFunctions::useStandardLibrary(), and CheckStl::useStlAlgorithm().
Return the token to the function and the argument number.
Definition at line 2360 of file astutils.cpp.
References getTokenArgumentFunctionImpl().
Referenced by CheckOther::checkConstPointer(), CheckOther::checkConstVariable(), CheckOther::checkInnerScope(), CheckOther::checkKnownArgument(), CheckLeakAutoVar::checkTokenInsideExpression(), getFunctionUsage(), getOutparamAllocation(), getParentValueTypes(), isContainerSizeChangedByFunction(), isMacroUsage(), isVariableChangedByFunctionCall(), and Token::typeOf().
Definition at line 2364 of file astutils.cpp.
References getTokenArgumentFunctionImpl().
bool isAliased | ( | const Variable * | var | ) |
Definition at line 1093 of file astutils.cpp.
References Scope::bodyEnd, Variable::declarationId(), Variable::declEndToken(), isAliased(), and Variable::scope().
bool isAliasOf | ( | const Token * | tok, |
const Token * | expr, | ||
int * | indirect = nullptr , |
||
bool * | inconclusive = nullptr |
||
) |
Definition at line 1038 of file astutils.cpp.
References astIsPointer(), Token::exprId(), findAstNode(), and followAllReferences().
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().
Definition at line 2049 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::eIncDecOp, Token::isAssignmentOp(), isConstFunctionCall(), isLikelyStreamRead(), Token::isName(), Token::next(), Token::str(), Token::tokType(), and Token::variable().
Referenced by CheckBool::checkBitwiseOnBoolean(), CheckOther::checkDuplicateExpression(), SymbolicConditionHandler::parse(), ConditionHandler::traverseCondition(), CheckFunctions::useStandardLibrary(), CheckStl::useStlAlgorithm(), valueFlowConditionExpressions(), and valueFlowSymbolic().
Definition at line 1969 of file astutils.cpp.
References astIsContainer(), astIsSmartPointer(), Token::astOperand1(), exprDependsOnThis(), Library::Container::FIND_CONST, Token::function(), functionModifiesArguments(), Library::Container::getAction(), getArguments(), Library::getFunction(), Library::Container::getYield(), Variable::isConst(), isUnevaluated(), Token::Match(), Token::next(), Library::Container::NO_YIELD, Token::originalName(), Token::previous(), Function::returnsConst(), Function::returnsVoid(), Token::simpleMatch(), Token::str(), Token::tokAt(), and Token::variable().
Referenced by isConstExpression(), and ValueFlowAnalyzer::isGlobalModified().
bool isConstVarExpression | ( | const Token * | tok, |
const std::function< bool(const Token *)> & | skipPredicate = nullptr |
||
) |
Definition at line 3252 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::function(), getArguments(), Token::hasKnownValue(), isCPPCast(), Token::isEnumerator(), Token::Match(), Token::previous(), Token::simpleMatch(), Token::str(), and Token::variable().
Referenced by CheckCondition::alwaysTrueFalse(), CheckOther::checkDuplicateExpression(), CheckOther::checkKnownArgument(), and isVariableChanged().
bool isCPPCast | ( | const Token * | tok | ) |
Definition at line 3247 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), isCPPCastKeyword(), Token::previous(), and Token::simpleMatch().
Referenced by CheckBool::checkComparisonOfFuncReturningBool(), CheckOther::checkKnownArgument(), CheckLeakAutoVar::checkTokenInsideExpression(), SymbolDatabase::createSymbolDatabaseIncompleteVars(), isConstStatement(), isConstVarExpression(), isTemporary(), isVoidStmt(), and CheckBufferOverrun::objectIndex().
Definition at line 1414 of file astutils.cpp.
References compareKnownValue(), ValueFlow::Value::equalValue(), and ValueFlow::Value::isIteratorValue().
Referenced by CheckOther::checkDuplicateExpression(), and isSameConstantValue().
Definition at line 2155 of file astutils.cpp.
References Token::function(), Library::isnoreturn(), and Token::Match().
bool isExpressionChangedAt | ( | const Token * | expr, |
const Token * | tok, | ||
int | indirect, | ||
bool | globalvar, | ||
const Settings & | settings, | ||
int | depth = 20 |
||
) |
Definition at line 2844 of file astutils.cpp.
References Token::exprId(), and isExpressionChangedAt().
bool isGlobalData | ( | const Token * | expr | ) |
Definition at line 3530 of file astutils.cpp.
References Token::astOperand1(), Token::isBinaryOp(), Token::isName(), Token::Match(), None, Token::originalName(), precedes(), Token::previous(), ValueType::reference, Token::str(), Token::valueType(), Token::variable(), Token::varId(), and visitAstNodes().
Referenced by FwdAnalysis::check(), and ExpressionAnalyzer::setupExprVarIds().
Definition at line 987 of file astutils.cpp.
References Token::astTop(), Token::Match(), and Token::previous().
Referenced by CheckOther::checkDuplicateExpression(), and followVariableExpression().
bool isIteratorPair | ( | const std::vector< const Token * > & | args | ) |
Are the arguments a pair of iterators/pointers?
Definition at line 3122 of file astutils.cpp.
References astIsIterator(), astIsPointer(), Token::exprId(), getIteratorExpression(), ValueFlow::getLifetimeObjValue(), and ValueFlow::Value::tokvalue.
Referenced by getContainerSizeFromConstructorArgs(), getInitListSize(), and valueFlowContainerSize().
bool isLeafDot | ( | const Token * | tok | ) |
Definition at line 3362 of file astutils.cpp.
References Token::astOperand2(), Token::astParent(), and Token::simpleMatch().
Referenced by getExprUsage(), isSimpleExpr(), and CheckUninitVar::valueFlowUninit().
bool isLikelyStream | ( | const Token * | stream | ) |
Definition at line 3204 of file astutils.cpp.
References astIsIntegral(), Token::astParent(), Token::isCpp(), and Token::Match().
Referenced by ValueFlowAnalyzer::analyzeCondition(), isConstStatement(), isTemporary(), and isVariableChanged().
bool isLikelyStreamRead | ( | const Token * | op | ) |
do we see a likely write of rhs through overloaded operator s >> x; a & x;
Definition at line 3221 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::astParent(), Token::isBinaryOp(), Token::isCpp(), Token::Match(), and Token::str().
Referenced by CheckClass::checkConstFunc(), CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(), getExprUsage(), CheckClass::initializeVarList(), isConstExpression(), CheckUninitVar::isMemberVariableAssignment(), ContainerExpressionAnalyzer::isModified(), isVariableChanged(), CheckUninitVar::isVariableUsage(), CheckCondition::multiCondition2(), and valueFlowGlobalStaticVar().
CPPCHECKLIB bool isNullOperand | ( | const Token * | expr | ) |
Definition at line 3516 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::astParent(), Token::isCast(), Token::isCpp(), MathLib::isInt(), MathLib::isNullValue(), Token::Match(), ValueType::pointer, Token::str(), and Token::valueType().
Referenced by CheckUnusedVar::checkFunctionVariableUsage(), CheckOther::checkRedundantAssignment(), and CheckOther::constStatementError().
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.
isNot | do you want to know if cond1 is !cond2 or if cond1 and cond2 are non-overlapping. true: cond1==!cond2 false: cond1==true => cond2==false |
cond1 | condition1 |
cond2 | condition2 |
settings | settings |
pure | boolean |
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().
bool isOppositeExpression | ( | const Token *const | tok1, |
const Token *const | tok2, | ||
const Settings & | settings, | ||
bool | pure, | ||
bool | followVar, | ||
ErrorPath * | errors = nullptr |
||
) |
Definition at line 1947 of file astutils.cpp.
References Token::astOperand1(), Token::astParent(), Token::eBitOp, isOppositeCond(), isSameExpression(), and Token::isUnaryOp().
Referenced by CheckOther::checkDuplicateExpression().
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)
Definition at line 2202 of file astutils.cpp.
References Token::astTop(), Token::findsimplematch(), hasNoreturnFunction(), isEscaped(), isEscapedOrJump(), Token::isIncompleteVar(), Token::isName(), Token::link(), Token::Match(), Token::previous(), Token::simpleMatch(), Token::str(), and Token::tokAt().
Referenced by ConditionHandler::afterCondition(), FwdAnalysis::checkRecursive(), SymbolDatabase::createSymbolDatabaseEscapeFunctions(), findTokensSkipDeadCodeImpl(), and CheckStl::invalidContainer().
CPPCHECKLIB bool isSameExpression | ( | bool | macro, |
const Token * | tok1, | ||
const Token * | tok2, | ||
const Settings & | settings, | ||
bool | pure, | ||
bool | followVar, | ||
ErrorPath * | errors = nullptr |
||
) |
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().
bool isScopeBracket | ( | const Token * | tok | ) |
Definition at line 2273 of file astutils.cpp.
References Token::Match(), Token::scope(), and Token::str().
Referenced by valueFlowForwardLifetime().
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().
bool isStructuredBindingVariable | ( | const Variable * | var | ) |
Definition at line 1153 of file astutils.cpp.
References Token::astParent(), Token::Match(), Variable::nameToken(), Token::previous(), Token::simpleMatch(), and Token::str().
Referenced by CheckOther::checkConstVariable(), followAllReferences(), and followVariableExpression().
Definition at line 415 of file astutils.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::astParent(), ValueType::container, Token::function(), Token::isCast(), Token::isCpp(), isCPPCast(), isLikelyStream(), Token::isUnaryOp(), Token::link(), Token::Match(), Token::next(), None, Token::originalName(), ValueType::pointer, Token::previous(), ValueType::reference, Function::returnsReference(), Library::returnValueType(), Token::simpleMatch(), Library::Container::stdStringLike, Token::type(), and Token::valueType().
Referenced by CheckOther::checkRedundantCopy(), followAllReferences(), getLifetimeTokens(), isDeadTemporary(), isEscapedReference(), and isSameIteratorContainerExpression().
Definition at line 2922 of file astutils.cpp.
References Token::astOperand1(), Token::function(), Token::isKeyword(), isVariableChanged(), Token::Match(), Token::previous(), Token::simpleMatch(), and Token::tokAt().
Referenced by findThisChanged(), and ValueFlowAnalyzer::isThisModified().
bool isUnevaluated | ( | const Token * | tok | ) |
Definition at line 3612 of file astutils.cpp.
References Token::Match().
Referenced by CheckUninitVar::checkExpr(), CheckIO::checkFileUsage(), CheckUninitVar::checkIfForWhileHead(), CheckUninitVar::checkLoopBodyRecursive(), CheckUninitVar::checkRhs(), CheckLeakAutoVar::checkScope(), CheckUninitVar::checkScopeForVariable(), isConstFunctionCall(), CheckNullPointer::isPointerDeRef(), CheckNullPointer::nullConstantDereference(), CheckNullPointer::nullPointerByDeRefAndChec(), and CheckUninitVar::valueFlowUninit().
bool isUniqueExpression | ( | const Token * | tok | ) |
Definition at line 2087 of file astutils.cpp.
References Function::argumentList, Token::astOperand1(), Token::astOperand2(), Scope::function, Token::function(), Scope::functionList, Variable::isArray(), Variable::isClass(), Variable::isEnumType(), Variable::isFloatingType(), Variable::isPointer(), Type::name(), Variable::name(), Function::nestedIn, Function::retDef, Function::retType, Variable::scope(), Token::stringifyList(), Function::tokenDef, Type::type(), Variable::type(), Function::type, Token::variable(), and Scope::varlist.
Referenced by CheckOther::checkDuplicateExpression().
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.
Definition at line 1489 of file astutils.cpp.
References astIsBool(), astIsLHS(), astIsRHS(), Token::astOperand1(), Token::astParent(), Token::astSibling(), getParentValueTypes(), Token::hasKnownIntValue(), Token::isCast(), isForLoopCondition(), isForLoopIncrement(), Token::isInitComma(), Token::isKeyword(), Token::isNumber(), Token::isUnaryOp(), Token::Match(), Token::simpleMatch(), Token::str(), and Token::values().
Referenced by CheckCondition::alwaysTrueFalse(), astIsBoolLike(), CheckString::checkIncorrectStringCompare(), CheckOther::checkKnownPointerToBool(), getExprUsage(), isOppositeCond(), and valueFlowInferCondition().
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?
Definition at line 2764 of file astutils.cpp.
References findVariableChanged().
bool isVariableChanged | ( | const Token * | start, |
const Token * | end, | ||
int | indirect, | ||
const nonneg int | exprid, | ||
bool | globalvar, | ||
const Settings & | settings, | ||
int | depth = 20 |
||
) |
Definition at line 2769 of file astutils.cpp.
References findVariableChanged().
bool isVariableChanged | ( | const Token * | tok, |
int | indirect, | ||
const Settings & | settings, | ||
int | depth = 20 |
||
) |
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().
Definition at line 2877 of file astutils.cpp.
References Scope::bodyEnd, Variable::declarationId(), Variable::declEndToken(), findExpressionChanged(), Token::Match(), Variable::nameToken(), Token::next(), nextAfterAstRightmostLeafGeneric(), Variable::scope(), Token::simpleMatch(), and Token::tokAt().
CPPCHECKLIB 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
tok | token of variable in function call |
settings | program settings |
inconclusive | pointer 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().
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
tok | ast tree |
varid | Variable Id |
settings | program settings |
inconclusive | pointer 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().
bool isVariableDecl | ( | const Token * | tok | ) |
Definition at line 396 of file astutils.cpp.
References Variable::declEndToken(), Token::Match(), Variable::nameToken(), Token::next(), and Token::variable().
Referenced by CheckStl::invalidContainer(), valueFlowForwardLifetime(), valueFlowLifetimeClassConstructor(), and valueFlowLifetimeConstructor().
bool isVariablesChanged | ( | const Token * | start, |
const Token * | end, | ||
int | indirect, | ||
const std::vector< const Variable * > & | vars, | ||
const Settings & | settings | ||
) |
Definition at line 2896 of file astutils.cpp.
References isVariableChanged(), Token::Match(), and Token::next().
Referenced by CheckFunctions::invalidFunctionUsage(), and CheckCondition::multiCondition2().
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().
bool isWithoutSideEffects | ( | const Token * | tok, |
bool | checkArrayAccess = false , |
||
bool | checkReference = true |
||
) |
Definition at line 2071 of file astutils.cpp.
References Token::astOperand2(), Variable::isClass(), Token::isCpp(), Variable::isPointer(), Variable::isReference(), Variable::isStlType(), CheckClass::stl_containers_not_const, Token::variable(), and Token::varId().
Referenced by CheckCondition::alwaysTrueFalse(), CheckOther::checkDuplicateExpression(), and isConstStatement().
CPPCHECKLIB const Token* nextAfterAstRightmostLeaf | ( | const Token * | tok | ) |
Definition at line 548 of file astutils.cpp.
References nextAfterAstRightmostLeafGeneric().
Referenced by astParentSkipParens(), CheckCondition::checkDuplicateConditionalAssign(), CheckOther::checkIncompleteStatement(), CheckOther::checkMisusedScopedObject(), CheckAutoVariables::checkVarLifetimeScope(), endOfExpression(), findEndOfFunctionCallForParameter(), Scope::findFunction(), findTokensSkipDeadCodeImpl(), followVariableExpression(), PathAnalysis::forwardRange(), getSingleExpressionInBlock(), isDeadTemporary(), skipLocalVars(), Token::typeDecl(), valueFlowAfterAssign(), valueFlowContainerSize(), valueFlowForLoopSimplify(), valueFlowForwardAssign(), valueFlowForwardLifetime(), and valueFlowSymbolic().
Definition at line 552 of file astutils.cpp.
References nextAfterAstRightmostLeafGeneric().
int numberOfArguments | ( | const Token * | ftok | ) |
Determines the number of arguments - if token is a function call or macro.
ftok | start token which is supposed to be the function/macro name. |
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().
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().
If tok2 comes after tok1.
Definition at line 994 of file astutils.cpp.
References Token::index().
Referenced by CheckCondition::alwaysTrueFalse(), CheckClass::checkConst(), CheckMemoryLeakNoVar::checkForUnusedReturnValue(), CheckUnusedVar::checkFunctionVariableUsage(), FwdAnalysis::checkRecursive(), CheckMemoryLeakStructMember::checkStructVariable(), CheckClass::constructors(), SymbolDatabase::createSymbolDatabaseExprIds(), findExpression(), findExpressionChangedImpl(), Token::findExpressionStartEndTokens(), findStartToken(), findThisChanged(), findTokensImpl(), findTokensSkipDeadCodeImpl(), findVariableChanged(), followVariableExpression(), PathAnalysis::forwardRange(), ProgramMemoryState::get(), getEnableIfReturnType(), getExprUsage(), isAliased(), isDeadScope(), isDeadTemporary(), isGlobalData(), isSameExpression(), nextAfterAstRightmostLeafGeneric(), CheckLeakAutoVar::ret(), CheckStl::useStlAlgorithm(), and valueFlowForwardConst().
Definition at line 514 of file astutils.cpp.
References previousBeforeAstLeftmostLeafGeneric().
Referenced by CheckClass::checkConstFunc(), ProgramMemoryState::get(), isConstStatement(), and Token::typeDecl().
Definition at line 518 of file astutils.cpp.
References previousBeforeAstLeftmostLeafGeneric().
If tok1 comes after tok2.
Definition at line 1006 of file astutils.cpp.
References Token::index().
Referenced by CheckLeakAutoVar::checkScope(), SymbolDatabase::createSymbolDatabaseFindAllScopes(), Token::findExpressionStartEndTokens(), isConstStatement(), and CheckLeakAutoVar::ret().
void visitAstNodes | ( | T * | ast, |
const TFunc & | visitor | ||
) |
Visit AST nodes recursively.
The order is not "well defined"
Definition at line 54 of file astutils.h.
References done, op1, op1_and_op2, and op2.
Referenced by CheckCondition::alwaysTrueFalse(), CheckOther::checkEvaluationOrder(), CheckOther::checkIncompleteStatement(), CheckOther::checkKnownArgument(), CheckUninitVar::checkLoopBodyRecursive(), CheckOther::checkOverlappingWrite(), CheckOther::checkRedundantAssignment(), CheckLeakAutoVar::checkScope(), CheckUninitVar::checkScopeForVariable(), extractForLoopValues(), ConditionHandler::fillFromPath(), findAstNode(), getDimensionsEtc(), ValueFlow::getEndOfExprScope(), FwdAnalysis::getExprVarIds(), getVariables(), getVarIds(), CheckClass::hasAssignSelf(), hasUnknownVars(), hasVolatileCastOrVar(), CheckClass::initializationListUsage(), isGlobalData(), CheckCondition::multiCondition2(), CheckString::overlappingStrcmp(), setTokenValue(), ExpressionAnalyzer::setupExprVarIds(), CheckStl::stlOutOfBounds(), and valueFlowForLoop2().