Cppcheck
astutils.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2024 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 //---------------------------------------------------------------------------
21 #ifndef astutilsH
22 #define astutilsH
23 //---------------------------------------------------------------------------
24 
25 #include <functional>
26 #include <list>
27 #include <stack>
28 #include <string>
29 #include <type_traits>
30 #include <vector>
31 
32 #include "config.h"
33 #include "errortypes.h"
34 #include "library.h"
35 #include "mathlib.h"
36 #include "smallvector.h"
37 #include "symboldatabase.h"
38 #include "token.h"
39 
40 class Settings;
41 
42 enum class ChildrenToVisit {
43  none,
44  op1,
45  op2,
47  done // found what we looked for, don't visit any more children
48 };
49 
50 /**
51  * Visit AST nodes recursively. The order is not "well defined"
52  */
53 template<class T, class TFunc, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
54 void visitAstNodes(T *ast, const TFunc &visitor)
55 {
56  if (!ast)
57  return;
58 
59  // the size of 8 was determined in tests to be sufficient to avoid excess allocations. also add 1 as a buffer.
60  // we might need to increase that value in the future.
61  std::stack<T *, SmallVector<T *, 8 + 1>> tokens;
62  T *tok = ast;
63  do {
64  const ChildrenToVisit c = visitor(tok);
65 
66  if (c == ChildrenToVisit::done)
67  break;
69  T *t2 = tok->astOperand2();
70  if (t2)
71  tokens.push(t2);
72  }
74  T *t1 = tok->astOperand1();
75  if (t1)
76  tokens.push(t1);
77  }
78 
79  if (tokens.empty())
80  break;
81 
82  tok = tokens.top();
83  tokens.pop();
84  } while (true);
85 }
86 
87 template<class TFunc>
88 const Token* findAstNode(const Token* ast, const TFunc& pred)
89 {
90  const Token* result = nullptr;
91  visitAstNodes(ast, [&](const Token* tok) {
92  if (pred(tok)) {
93  result = tok;
94  return ChildrenToVisit::done;
95  }
97  });
98  return result;
99 }
100 
101 template<class TFunc>
102 const Token* findParent(const Token* tok, const TFunc& pred)
103 {
104  if (!tok)
105  return nullptr;
106  const Token* parent = tok->astParent();
107  while (parent && !pred(parent)) {
108  parent = parent->astParent();
109  }
110  return parent;
111 }
112 
113 const Token* findExpression(const nonneg int exprid,
114  const Token* start,
115  const Token* end,
116  const std::function<bool(const Token*)>& pred);
117 const Token* findExpression(const Token* start, const nonneg int exprid);
118 
119 template<class T, class OuputIterator, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
120 void astFlattenCopy(T* tok, const char* op, OuputIterator out, nonneg int depth = 100)
121 {
122  --depth;
123  if (!tok || depth < 0)
124  return;
125  if (tok->str() == op) {
126  astFlattenCopy(tok->astOperand1(), op, out, depth);
127  astFlattenCopy(tok->astOperand2(), op, out, depth);
128  } else {
129  *out = tok;
130  ++out;
131  }
132 }
133 
134 std::vector<const Token*> astFlatten(const Token* tok, const char* op);
135 std::vector<Token*> astFlatten(Token* tok, const char* op);
136 
137 nonneg int astCount(const Token* tok, const char* op, int depth = 100);
138 
139 bool astHasToken(const Token* root, const Token * tok);
140 
141 bool astHasExpr(const Token* tok, nonneg int exprid);
142 bool astHasVar(const Token * tok, nonneg int varid);
143 
144 bool astIsPrimitive(const Token* tok);
145 /** Is expression a 'signed char' if no promotion is used */
146 bool astIsSignedChar(const Token *tok);
147 /** Is expression a 'char' if no promotion is used? */
148 bool astIsUnknownSignChar(const Token *tok);
149 /** Is expression a char according to valueType? */
150 bool astIsGenericChar(const Token* tok);
151 /** Is expression of integral type? */
152 bool astIsIntegral(const Token *tok, bool unknown);
153 bool astIsUnsigned(const Token* tok);
154 /** Is expression of floating point type? */
155 bool astIsFloat(const Token *tok, bool unknown);
156 /** Is expression of boolean type? */
157 bool astIsBool(const Token *tok);
158 
159 bool astIsPointer(const Token *tok);
160 
161 bool astIsSmartPointer(const Token* tok);
162 bool astIsUniqueSmartPointer(const Token* tok);
163 
164 bool astIsIterator(const Token *tok);
165 
166 bool astIsContainer(const Token *tok);
167 bool astIsNonStringContainer(const Token *tok);
168 
169 bool astIsContainerView(const Token* tok);
170 bool astIsContainerOwned(const Token* tok);
171 bool astIsContainerString(const Token* tok);
172 
173 Library::Container::Action astContainerAction(const Token* tok, const Token** ftok = nullptr);
174 Library::Container::Yield astContainerYield(const Token* tok, const Token** ftok = nullptr);
175 
176 Library::Container::Yield astFunctionYield(const Token* tok, const Settings& settings, const Token** ftok = nullptr);
177 
178 /** Is given token a range-declaration in a range-based for loop */
179 bool astIsRangeBasedForDecl(const Token* tok);
180 
181 /**
182  * Get canonical type of expression. const/static/etc are not included and neither *&.
183  * For example:
184  * Expression type Return
185  * std::string std::string
186  * int * int
187  * static const int int
188  * std::vector<T> std::vector
189  */
190 std::string astCanonicalType(const Token *expr, bool pointedToType);
191 
192 /** Is given syntax tree a variable comparison against value */
193 const Token * astIsVariableComparison(const Token *tok, const std::string &comp, const std::string &rhs, const Token **vartok=nullptr);
194 
195 bool isVariableDecl(const Token* tok);
196 bool isStlStringType(const Token* tok);
197 
198 bool isTemporary(const Token* tok, const Library* library, bool unknown = false);
199 
200 const Token* previousBeforeAstLeftmostLeaf(const Token* tok);
202 
203 CPPCHECKLIB const Token * nextAfterAstRightmostLeaf(const Token * tok);
205 
207 const Token* astParentSkipParens(const Token* tok);
208 
209 const Token* getParentMember(const Token * tok);
210 
211 const Token* getParentLifetime(const Token* tok);
212 const Token* getParentLifetime(const Token* tok, const Library& library);
213 
214 std::vector<ValueType> getParentValueTypes(const Token* tok,
215  const Settings& settings,
216  const Token** parent = nullptr);
217 
218 bool astIsLHS(const Token* tok);
219 bool astIsRHS(const Token* tok);
220 
221 Token* getCondTok(Token* tok);
222 const Token* getCondTok(const Token* tok);
223 
224 Token* getInitTok(Token* tok);
225 const Token* getInitTok(const Token* tok);
226 
227 Token* getStepTok(Token* tok);
228 const Token* getStepTok(const Token* tok);
229 
230 Token* getCondTokFromEnd(Token* endBlock);
231 const Token* getCondTokFromEnd(const Token* endBlock);
232 
233 /// For a "break" token, locate the next token to execute. The token will
234 /// be either a "}" or a ";".
235 const Token *findNextTokenFromBreak(const Token *breakToken);
236 
237 /**
238  * Extract for loop values: loopvar varid, init value, step value, last value (inclusive)
239  */
240 bool extractForLoopValues(const Token *forToken,
241  nonneg int &varid,
242  bool &knownInitValue,
243  long long &initValue,
244  bool &partialCond,
245  long long &stepValue,
246  long long &lastValue);
247 
248 bool precedes(const Token * tok1, const Token * tok2);
249 bool succeeds(const Token* tok1, const Token* tok2);
250 
251 bool exprDependsOnThis(const Token* expr, bool onVar = true, nonneg int depth = 0);
252 
254  const Token* token;
256 };
257 
259  bool temporary = true,
260  bool inconclusive = true,
261  ErrorPath errors = ErrorPath{},
262  int depth = 20);
263 const Token* followReferences(const Token* tok, ErrorPath* errors = nullptr);
264 
265 CPPCHECKLIB bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Settings& settings, bool pure, bool followVar, ErrorPath* errors=nullptr);
266 
267 bool isEqualKnownValue(const Token * const tok1, const Token * const tok2);
268 
269 bool isStructuredBindingVariable(const Variable* var);
270 
271 const Token* isInLoopCondition(const Token* tok);
272 
273 /**
274  * Is token used as boolean, that is to say cast to a bool, or used as a condition in a if/while/for
275  */
276 CPPCHECKLIB bool isUsedAsBool(const Token* const tok, const Settings& settings);
277 
278 /**
279  * Are the tokens' flags equal?
280  */
281 bool compareTokenFlags(const Token* tok1, const Token* tok2, bool macro);
282 
283 /**
284  * Are two conditions opposite
285  * @param 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
286  * @param cond1 condition1
287  * @param cond2 condition2
288  * @param settings settings
289  * @param pure boolean
290  */
291 bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const cond2, const Settings& settings, bool pure, bool followVar, ErrorPath* errors=nullptr);
292 
293 bool isOppositeExpression(const Token * const tok1, const Token * const tok2, const Settings& settings, bool pure, bool followVar, ErrorPath* errors=nullptr);
294 
295 bool isConstFunctionCall(const Token* ftok, const Library& library);
296 
297 bool isConstExpression(const Token *tok, const Library& library);
298 
299 bool isWithoutSideEffects(const Token* tok, bool checkArrayAccess = false, bool checkReference = true);
300 
301 bool isUniqueExpression(const Token* tok);
302 
303 bool isEscapeFunction(const Token* ftok, const Library* library);
304 
305 /** Is scope a return scope (scope will unconditionally return) */
306 CPPCHECKLIB bool isReturnScope(const Token* const endToken,
307  const Library& library,
308  const Token** unknownFunc = nullptr,
309  bool functionScope = false);
310 
311 /** Is tok within a scope of the given type, nested within var's scope? */
312 bool isWithinScope(const Token* tok,
313  const Variable* var,
314  Scope::ScopeType type);
315 
316 /// Return the token to the function and the argument number
317 const Token * getTokenArgumentFunction(const Token * tok, int& argn);
318 Token* getTokenArgumentFunction(Token* tok, int& argn);
319 
320 std::vector<const Variable*> getArgumentVars(const Token* tok, int argnr);
321 
322 /** Is variable changed by function call?
323  * In case the answer of the question is inconclusive, e.g. because the function declaration is not known
324  * the return value is false and the output parameter inconclusive is set to true
325  *
326  * @param tok ast tree
327  * @param varid Variable Id
328  * @param settings program settings
329  * @param inconclusive pointer to output variable which indicates that the answer of the question is inconclusive
330  */
331 bool isVariableChangedByFunctionCall(const Token *tok, int indirect, nonneg int varid, const Settings &settings, bool *inconclusive);
332 
333 /** Is variable changed by function call?
334  * In case the answer of the question is inconclusive, e.g. because the function declaration is not known
335  * the return value is false and the output parameter inconclusive is set to true
336  *
337  * @param tok token of variable in function call
338  * @param settings program settings
339  * @param inconclusive pointer to output variable which indicates that the answer of the question is inconclusive
340  */
341 CPPCHECKLIB bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Settings &settings, bool *inconclusive);
342 
343 /** Is variable changed in block of code? */
344 CPPCHECKLIB bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings &settings, int depth = 20);
345 bool isVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth = 20);
346 
347 bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, int depth = 20);
348 
349 bool isVariableChanged(const Variable * var, const Settings &settings, int depth = 20);
350 
351 bool isVariablesChanged(const Token* start,
352  const Token* end,
353  int indirect,
354  const std::vector<const Variable*> &vars,
355  const Settings& settings);
356 
357 bool isThisChanged(const Token* tok, int indirect, const Settings& settings);
358 
359 const Token* findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth = 20);
360 Token* findVariableChanged(Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth = 20);
361 
362 CPPCHECKLIB const Token* findExpressionChanged(const Token* expr,
363  const Token* start,
364  const Token* end,
365  const Settings& settings,
366  int depth = 20);
367 
369  const Token* start,
370  const Token* end,
371  const Settings& settings,
372  const std::function<std::vector<MathLib::bigint>(const Token* tok)>& evaluate,
373  int depth = 20);
374 
375 bool isExpressionChangedAt(const Token* expr,
376  const Token* tok,
377  int indirect,
378  bool globalvar,
379  const Settings& settings,
380  int depth = 20);
381 
382 /// If token is an alias if another variable
383 bool isAliasOf(const Token *tok, nonneg int varid, bool* inconclusive = nullptr);
384 
385 bool isAliasOf(const Token* tok, const Token* expr, int* indirect = nullptr, bool* inconclusive = nullptr);
386 
387 bool isAliased(const Variable *var);
388 
389 const Token* getArgumentStart(const Token* ftok);
390 
391 /** Determines the number of arguments - if token is a function call or macro
392  * @param ftok start token which is supposed to be the function/macro name.
393  * @return Number of arguments
394  */
395 int numberOfArguments(const Token* ftok);
396 
397 /// Get number of arguments without using AST
398 int numberOfArgumentsWithoutAst(const Token* start);
399 
400 /**
401  * Get arguments (AST)
402  */
403 std::vector<const Token *> getArguments(const Token *ftok);
404 
405 int getArgumentPos(const Variable* var, const Function* f);
406 
407 const Token* getIteratorExpression(const Token* tok);
408 
409 /**
410  * Are the arguments a pair of iterators/pointers?
411  */
412 bool isIteratorPair(const std::vector<const Token*>& args);
413 
414 CPPCHECKLIB const Token *findLambdaStartToken(const Token *last);
415 
416 /**
417  * find lambda function end token
418  * \param first The [ token
419  * \return nullptr or the }
420  */
421 CPPCHECKLIB const Token *findLambdaEndToken(const Token *first);
423 
424 bool isLikelyStream(const Token *stream);
425 
426 /**
427  * do we see a likely write of rhs through overloaded operator
428  * s >> x;
429  * a & x;
430  */
431 bool isLikelyStreamRead(const Token *op);
432 
433 bool isCPPCast(const Token* tok);
434 
435 bool isConstVarExpression(const Token* tok, const std::function<bool(const Token*)>& skipPredicate = nullptr);
436 
437 bool isLeafDot(const Token* tok);
438 
440 
441 ExprUsage getExprUsage(const Token* tok, int indirect, const Settings& settings);
442 
443 const Variable *getLHSVariable(const Token *tok);
444 
445 const Token* getLHSVariableToken(const Token* tok);
446 
447 std::vector<const Variable*> getLHSVariables(const Token* tok);
448 
449 /** Find a allocation function call in expression, so result of expression is allocated memory/resource. */
450 const Token* findAllocFuncCallToken(const Token *expr, const Library &library);
451 
452 bool isScopeBracket(const Token* tok);
453 
454 CPPCHECKLIB bool isNullOperand(const Token *expr);
455 
456 bool isGlobalData(const Token *expr);
457 
458 bool isUnevaluated(const Token *tok);
459 
460 #endif // astutilsH
Library::Container::Action astContainerAction(const Token *tok, const Token **ftok=nullptr)
Definition: astutils.cpp:287
int numberOfArgumentsWithoutAst(const Token *start)
Get number of arguments without using AST.
Definition: astutils.cpp:3067
bool astIsContainer(const Token *tok)
Definition: astutils.cpp:244
const Token * getIteratorExpression(const Token *tok)
Definition: astutils.cpp:3097
int getArgumentPos(const Variable *var, const Function *f)
Definition: astutils.cpp:3087
CPPCHECKLIB const Token * findExpressionChanged(const Token *expr, const Token *start, const Token *end, const Settings &settings, int depth=20)
Definition: astutils.cpp:3028
bool isOppositeExpression(const Token *const tok1, const Token *const tok2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors=nullptr)
Definition: astutils.cpp:1947
bool isWithoutSideEffects(const Token *tok, bool checkArrayAccess=false, bool checkReference=true)
Definition: astutils.cpp:2071
bool astIsPrimitive(const Token *tok)
Definition: astutils.cpp:186
bool astIsContainerView(const Token *tok)
Definition: astutils.cpp:254
bool astIsIntegral(const Token *tok, bool unknown)
Is expression of integral type?
Definition: astutils.cpp:194
bool isTemporary(const Token *tok, const Library *library, bool unknown=false)
Definition: astutils.cpp:415
bool isAliasOf(const Token *tok, nonneg int varid, bool *inconclusive=nullptr)
If token is an alias if another variable.
Definition: astutils.cpp:1017
bool astIsRangeBasedForDecl(const Token *tok)
Is given token a range-declaration in a range-based for loop.
Definition: astutils.cpp:321
bool precedes(const Token *tok1, const Token *tok2)
If tok2 comes after tok1.
Definition: astutils.cpp:994
const Token * getTokenArgumentFunction(const Token *tok, int &argn)
Return the token to the function and the argument number.
Definition: astutils.cpp:2360
bool astHasVar(const Token *tok, nonneg int varid)
Definition: astutils.cpp:143
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: astutils.cpp:926
void visitAstNodes(T *ast, const TFunc &visitor)
Visit AST nodes recursively.
Definition: astutils.h:54
bool astIsPointer(const Token *tok)
Definition: astutils.cpp:220
bool isExpressionChangedAt(const Token *expr, const Token *tok, int indirect, bool globalvar, const Settings &settings, int depth=20)
Definition: astutils.cpp:2844
bool exprDependsOnThis(const Token *expr, bool onVar=true, nonneg int depth=0)
Definition: astutils.cpp:1105
bool compareTokenFlags(const Token *tok1, const Token *tok2, bool macro)
Are the tokens' flags equal?
Definition: astutils.cpp:1537
const Token * isInLoopCondition(const Token *tok)
Definition: astutils.cpp:987
bool isStlStringType(const Token *tok)
Definition: astutils.cpp:409
bool isLikelyStreamRead(const Token *op)
do we see a likely write of rhs through overloaded operator s >> x; a & x;
Definition: astutils.cpp:3221
Library::Container::Yield astContainerYield(const Token *tok, const Token **ftok=nullptr)
Definition: astutils.cpp:297
bool isUniqueExpression(const Token *tok)
Definition: astutils.cpp:2087
bool astIsContainerOwned(const Token *tok)
Definition: astutils.cpp:260
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: astutils.cpp:3501
bool astIsLHS(const Token *tok)
Definition: astutils.cpp:784
bool isGlobalData(const Token *expr)
Definition: astutils.cpp:3530
bool isConstFunctionCall(const Token *ftok, const Library &library)
Definition: astutils.cpp:1969
bool astIsBool(const Token *tok)
Is expression of boolean type?
Definition: astutils.cpp:215
ExprUsage
Definition: astutils.h:439
@ PassedByReference
SmallVector< ReferenceToken > followAllReferences(const Token *tok, bool temporary=true, bool inconclusive=true, ErrorPath errors=ErrorPath{}, int depth=20)
Definition: astutils.cpp:1236
const Token * getArgumentStart(const Token *ftok)
Definition: astutils.cpp:3048
bool isScopeBracket(const Token *tok)
Definition: astutils.cpp:2273
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: astutils.cpp:2764
bool isEscapeFunction(const Token *ftok, const Library *library)
Definition: astutils.cpp:2155
bool isVariableDecl(const Token *tok)
Definition: astutils.cpp:396
CPPCHECKLIB const Token * nextAfterAstRightmostLeaf(const Token *tok)
Definition: astutils.cpp:548
const Token * followReferences(const Token *tok, ErrorPath *errors=nullptr)
Definition: astutils.cpp:1369
bool astIsGenericChar(const Token *tok)
Is expression a char according to valueType?
Definition: astutils.cpp:181
CPPCHECKLIB const Token * findLambdaEndToken(const Token *first)
find lambda function end token
Definition: astutils.cpp:3195
bool astHasExpr(const Token *tok, nonneg int exprid)
Definition: astutils.cpp:152
bool isStructuredBindingVariable(const Variable *var)
Definition: astutils.cpp:1153
Token * getInitTok(Token *tok)
Definition: astutils.cpp:898
const Token * findNextTokenFromBreak(const Token *breakToken)
For a "break" token, locate the next token to execute.
Definition: astutils.cpp:912
bool isLeafDot(const Token *tok)
Definition: astutils.cpp:3362
bool astIsUniqueSmartPointer(const Token *tok)
Definition: astutils.cpp:230
std::vector< const Token * > astFlatten(const Token *tok, const char *op)
Definition: astutils.cpp:110
bool astIsSmartPointer(const Token *tok)
Definition: astutils.cpp:225
Token * getCondTokFromEnd(Token *endBlock)
Definition: astutils.cpp:889
Token * astParentSkipParens(Token *tok)
Definition: astutils.cpp:561
bool astHasToken(const Token *root, const Token *tok)
Definition: astutils.cpp:134
bool astIsContainerString(const Token *tok)
Definition: astutils.cpp:264
Token * getCondTok(Token *tok)
Definition: astutils.cpp:880
bool astIsRHS(const Token *tok)
Definition: astutils.cpp:797
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: astutils.cpp:2250
nonneg int astCount(const Token *tok, const char *op, int depth=100)
Definition: astutils.cpp:124
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.
Definition: astutils.cpp:1785
const Variable * getLHSVariable(const Token *tok)
Definition: astutils.cpp:3473
bool astIsSignedChar(const Token *tok)
Is expression a 'signed char' if no promotion is used.
Definition: astutils.cpp:171
bool astIsFloat(const Token *tok, bool unknown)
Is expression of floating point type?
Definition: astutils.cpp:207
ExprUsage getExprUsage(const Token *tok, int indirect, const Settings &settings)
Definition: astutils.cpp:3374
Library::Container::Yield astFunctionYield(const Token *tok, const Settings &settings, const Token **ftok=nullptr)
Definition: astutils.cpp:307
bool isThisChanged(const Token *tok, int indirect, const Settings &settings)
Definition: astutils.cpp:2922
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: astutils.cpp:2202
bool astIsNonStringContainer(const Token *tok)
Definition: astutils.cpp:248
Token * getStepTok(Token *tok)
Definition: astutils.cpp:905
const Token * findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth=20)
Definition: astutils.cpp:2872
bool isVariablesChanged(const Token *start, const Token *end, int indirect, const std::vector< const Variable * > &vars, const Settings &settings)
Definition: astutils.cpp:2896
bool isIteratorPair(const std::vector< const Token * > &args)
Are the arguments a pair of iterators/pointers?
Definition: astutils.cpp:3122
CPPCHECKLIB bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Settings &settings, bool pure, bool followVar, ErrorPath *errors=nullptr)
Definition: astutils.cpp:1556
const Token * getParentMember(const Token *tok)
Definition: astutils.cpp:576
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,...
Definition: astutils.cpp:2263
CPPCHECKLIB const Token * findLambdaStartToken(const Token *last)
Definition: astutils.cpp:3145
bool astIsUnsigned(const Token *tok)
Definition: astutils.cpp:202
ChildrenToVisit
Definition: astutils.h:42
std::vector< const Token * > getArguments(const Token *ftok)
Get arguments (AST)
Definition: astutils.cpp:3083
bool astIsIterator(const Token *tok)
Definition: astutils.cpp:239
const Token * previousBeforeAstLeftmostLeaf(const Token *tok)
Definition: astutils.cpp:514
CPPCHECKLIB bool isNullOperand(const Token *expr)
Definition: astutils.cpp:3516
std::vector< ValueType > getParentValueTypes(const Token *tok, const Settings &settings, const Token **parent=nullptr)
Definition: astutils.cpp:712
bool isCPPCast(const Token *tok)
Definition: astutils.cpp:3247
bool isEqualKnownValue(const Token *const tok1, const Token *const tok2)
Definition: astutils.cpp:1414
std::vector< const Variable * > getLHSVariables(const Token *tok)
Definition: astutils.cpp:3445
void astFlattenCopy(T *tok, const char *op, OuputIterator out, nonneg int depth=100)
Definition: astutils.h:120
bool isConstExpression(const Token *tok, const Library &library)
Definition: astutils.cpp:2049
std::vector< const Variable * > getArgumentVars(const Token *tok, int argnr)
Definition: astutils.cpp:2368
bool isUnevaluated(const Token *tok)
Definition: astutils.cpp:3612
const Token * getLHSVariableToken(const Token *tok)
Definition: astutils.cpp:3487
bool isAliased(const Variable *var)
Definition: astutils.cpp:1093
const Token * getParentLifetime(const Token *tok)
Definition: astutils.cpp:596
bool isLikelyStream(const Token *stream)
Definition: astutils.cpp:3204
std::string astCanonicalType(const Token *expr, bool pointedToType)
Get canonical type of expression.
Definition: astutils.cpp:326
bool isConstVarExpression(const Token *tok, const std::function< bool(const Token *)> &skipPredicate=nullptr)
Definition: astutils.cpp:3252
bool astIsUnknownSignChar(const Token *tok)
Is expression a 'char' if no promotion is used?
Definition: astutils.cpp:176
const Token * findParent(const Token *tok, const TFunc &pred)
Definition: astutils.h:102
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: astutils.cpp:1489
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: astutils.cpp:351
bool succeeds(const Token *tok1, const Token *tok2)
If tok1 comes after tok2.
Definition: astutils.cpp:1006
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: astutils.cpp:3037
int numberOfArguments(const Token *ftok)
Determines the number of arguments - if token is a function call or macro.
Definition: astutils.cpp:3063
const Token * findExpression(const nonneg int exprid, const Token *start, const Token *end, const std::function< bool(const Token *)> &pred)
Definition: astutils.cpp:50
const Token * findAstNode(const Token *ast, const TFunc &pred)
Definition: astutils.h:88
Library definitions handling.
Definition: library.h:52
This is just a container for general settings so that we don't need to pass individual values to func...
Definition: settings.h:95
The token list that the TokenList generates is a linked-list of this class.
Definition: token.h:150
void astParent(Token *tok)
Definition: token.cpp:1437
Information about a member variable.
#define REQUIRES(msg,...)
Definition: config.h:124
#define CPPCHECKLIB
Definition: config.h:35
#define nonneg
Definition: config.h:138
std::list< ErrorPathItem > ErrorPath
Definition: errortypes.h:130
static ValueFlow::Value evaluate(const std::string &op, const ValueFlow::Value &lhs, const ValueFlow::Value &rhs)
ErrorPath errors
Definition: astutils.h:255
const Token * token
Definition: astutils.h:254