Cppcheck
checkbool.cpp
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 #include "checkbool.h"
22 
23 #include "astutils.h"
24 #include "errortypes.h"
25 #include "settings.h"
26 #include "symboldatabase.h"
27 #include "token.h"
28 #include "tokenize.h"
29 #include "vfvalue.h"
30 
31 #include <list>
32 #include <vector>
33 //---------------------------------------------------------------------------
34 
35 // Register this check class (by creating a static instance of it)
36 namespace {
37  CheckBool instance;
38 }
39 
40 static const CWE CWE398(398U); // Indicator of Poor Code Quality
41 static const CWE CWE571(571U); // Expression is Always True
42 static const CWE CWE587(587U); // Assignment of a Fixed Address to a Pointer
43 static const CWE CWE704(704U); // Incorrect Type Conversion or Cast
44 
45 static bool isBool(const Variable* var)
46 {
47  return (var && Token::Match(var->typeEndToken(), "bool|_Bool"));
48 }
49 
50 //---------------------------------------------------------------------------
52 {
53  if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("incrementboolean"))
54  return;
55 
56  logChecker("CheckBool::checkIncrementBoolean"); // style
57 
58  const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
59  for (const Scope * scope : symbolDatabase->functionScopes) {
60  for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
61  if (astIsBool(tok) && tok->astParent() && tok->astParent()->str() == "++") {
63  }
64  }
65  }
66 }
67 
69 {
71  tok,
73  "incrementboolean",
74  "Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n"
75  "The operand of a postfix increment operator may be of type bool but it is deprecated by C++ Standard (Annex D-1) and the operand is always set to true. You should assign it the value 'true' instead.",
77  );
78 }
79 
80 static bool isConvertedToBool(const Token* tok)
81 {
82  if (!tok->astParent())
83  return false;
84  return astIsBool(tok->astParent()) || Token::Match(tok->astParent()->previous(), "if|while (");
85 }
86 
87 //---------------------------------------------------------------------------
88 // if (bool & bool) -> if (bool && bool)
89 // if (bool | bool) -> if (bool || bool)
90 //---------------------------------------------------------------------------
92 {
94  return;
95 
96  // danmar: this is inconclusive because I don't like that there are
97  // warnings for calculations. Example: set_flag(a & b);
99  return;
100 
101  logChecker("CheckBool::checkBitwiseOnBoolean"); // style,inconclusive
102 
103  const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
104  for (const Scope * scope : symbolDatabase->functionScopes) {
105  for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
106  if (tok->isBinaryOp()) {
107  bool isCompound{};
108  if (tok->str() == "&" || tok->str() == "|")
109  isCompound = false;
110  else if (tok->str() == "&=" || tok->str() == "|=")
111  isCompound = true;
112  else
113  continue;
114  const bool isBoolOp1 = astIsBool(tok->astOperand1());
115  const bool isBoolOp2 = astIsBool(tok->astOperand2());
116  if (!tok->astOperand1()->valueType() || !tok->astOperand2()->valueType())
117  continue;
118  if (!(isBoolOp1 || isBoolOp2))
119  continue;
120  if (isCompound && (!isBoolOp1 || isBoolOp2))
121  continue;
122  if (tok->str() == "|" && !isConvertedToBool(tok) && !(isBoolOp1 && isBoolOp2))
123  continue;
124  // first operand will always be evaluated
125  if (!isConstExpression(tok->astOperand2(), mSettings->library))
126  continue;
127  if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2())
128  continue;
129  const std::string expression = (isBoolOp1 ? tok->astOperand1() : tok->astOperand2())->expressionString();
130  bitwiseOnBooleanError(tok, expression, tok->str() == "&" ? "&&" : "||", isCompound);
131  }
132  }
133  }
134 }
135 
136 void CheckBool::bitwiseOnBooleanError(const Token* tok, const std::string& expression, const std::string& op, bool isCompound)
137 {
138  std::string msg = "Boolean expression '" + expression + "' is used in bitwise operation.";
139  if (!isCompound)
140  msg += " Did you mean '" + op + "'?";
141  reportError(tok,
143  "bitwiseOnBoolean",
144  msg,
145  CWE398,
147 }
148 
149 //---------------------------------------------------------------------------
150 // if (!x==3) <- Probably meant to be "x!=3"
151 //---------------------------------------------------------------------------
152 
154 {
156  return;
157 
158  logChecker("CheckBool::checkComparisonOfBoolWithInt"); // warning,c++
159 
160  const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
161  for (const Scope * scope : symbolDatabase->functionScopes) {
162  for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
163  if (!tok->isComparisonOp() || !tok->isBinaryOp())
164  continue;
165  const Token* const left = tok->astOperand1();
166  const Token* const right = tok->astOperand2();
167  if (left->isBoolean() && right->varId()) { // Comparing boolean constant with variable
168  if (tok->str() != "==" && tok->str() != "!=") {
170  }
171  } else if (left->varId() && right->isBoolean()) { // Comparing variable with boolean constant
172  if (tok->str() != "==" && tok->str() != "!=") {
174  }
175  }
176  }
177  }
178 }
179 
180 void CheckBool::comparisonOfBoolWithInvalidComparator(const Token *tok, const std::string &expression)
181 {
182  reportError(tok, Severity::warning, "comparisonOfBoolWithInvalidComparator",
183  "Comparison of a boolean value using relational operator (<, >, <= or >=).\n"
184  "The result of the expression '" + expression + "' is of type 'bool'. "
185  "Comparing 'bool' value using relational (<, >, <= or >=)"
186  " operator could cause unexpected results.");
187 }
188 
189 //-------------------------------------------------------------------------------
190 // Comparing functions which are returning value of type bool
191 //-------------------------------------------------------------------------------
192 
193 static bool tokenIsFunctionReturningBool(const Token* tok)
194 {
195  const Function* func = tok ? tok->function() : nullptr;
196  if (func && Token::Match(tok, "%name% (")) {
197  if (func->tokenDef && Token::Match(func->tokenDef->previous(), "bool|_Bool")) {
198  return true;
199  }
200  }
201  return false;
202 }
203 
205 {
207  return;
208 
209  if (!mTokenizer->isCPP())
210  return;
211 
212  logChecker("CheckBool::checkComparisonOfFuncReturningBool"); // style,c++
213 
214  const SymbolDatabase * const symbolDatabase = mTokenizer->getSymbolDatabase();
215  auto getFunctionTok = [](const Token* tok) -> const Token* {
216  while (Token::simpleMatch(tok, "!") || (tok && tok->isCast() && !isCPPCast(tok)))
217  tok = tok->astOperand1();
218  if (isCPPCast(tok))
219  tok = tok->astOperand2();
220  if (tok)
221  return tok->previous();
222  return nullptr;
223  };
224 
225  for (const Scope * scope : symbolDatabase->functionScopes) {
226  for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
227  if (!tok->isComparisonOp() || tok->str() == "==" || tok->str() == "!=")
228  continue;
229 
230  const Token* firstToken = getFunctionTok(tok->astOperand1());
231  const Token* secondToken = getFunctionTok(tok->astOperand2());
232  if (!firstToken || !secondToken)
233  continue;
234 
235  const bool firstIsFunctionReturningBool = tokenIsFunctionReturningBool(firstToken);
236  const bool secondIsFunctionReturningBool = tokenIsFunctionReturningBool(secondToken);
237  if (firstIsFunctionReturningBool && secondIsFunctionReturningBool) {
238  comparisonOfTwoFuncsReturningBoolError(firstToken->next(), firstToken->str(), secondToken->str());
239  } else if (firstIsFunctionReturningBool) {
240  comparisonOfFuncReturningBoolError(firstToken->next(), firstToken->str());
241  } else if (secondIsFunctionReturningBool) {
242  comparisonOfFuncReturningBoolError(secondToken->previous(), secondToken->str());
243  }
244  }
245  }
246 }
247 
248 void CheckBool::comparisonOfFuncReturningBoolError(const Token *tok, const std::string &expression)
249 {
250  reportError(tok, Severity::style, "comparisonOfFuncReturningBoolError",
251  "Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n"
252  "The return type of function '" + expression + "' is 'bool' "
253  "and result is of type 'bool'. Comparing 'bool' value using relational (<, >, <= or >=)"
254  " operator could cause unexpected results.", CWE398, Certainty::normal);
255 }
256 
257 void CheckBool::comparisonOfTwoFuncsReturningBoolError(const Token *tok, const std::string &expression1, const std::string &expression2)
258 {
259  reportError(tok, Severity::style, "comparisonOfTwoFuncsReturningBoolError",
260  "Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n"
261  "The return type of function '" + expression1 + "' and function '" + expression2 + "' is 'bool' "
262  "and result is of type 'bool'. Comparing 'bool' value using relational (<, >, <= or >=)"
263  " operator could cause unexpected results.", CWE398, Certainty::normal);
264 }
265 
266 //-------------------------------------------------------------------------------
267 // Comparison of bool with bool
268 //-------------------------------------------------------------------------------
269 
271 {
273  return;
274 
275  if (!mTokenizer->isCPP())
276  return;
277 
278  logChecker("CheckBool::checkComparisonOfBoolWithBool"); // style,c++
279 
280  const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
281 
282  for (const Scope * scope : symbolDatabase->functionScopes) {
283  for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
284  if (!tok->isComparisonOp() || tok->str() == "==" || tok->str() == "!=")
285  continue;
286  bool firstTokenBool = false;
287 
288  const Token *firstToken = tok->previous();
289  if (firstToken->varId()) {
290  if (isBool(firstToken->variable())) {
291  firstTokenBool = true;
292  }
293  }
294  if (!firstTokenBool)
295  continue;
296 
297  bool secondTokenBool = false;
298  const Token *secondToken = tok->next();
299  if (secondToken->varId()) {
300  if (isBool(secondToken->variable())) {
301  secondTokenBool = true;
302  }
303  }
304  if (secondTokenBool) {
305  comparisonOfBoolWithBoolError(firstToken->next(), secondToken->str());
306  }
307  }
308  }
309 }
310 
311 void CheckBool::comparisonOfBoolWithBoolError(const Token *tok, const std::string &expression)
312 {
313  reportError(tok, Severity::style, "comparisonOfBoolWithBoolError",
314  "Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n"
315  "The variable '" + expression + "' is of type 'bool' "
316  "and comparing 'bool' value using relational (<, >, <= or >=)"
317  " operator could cause unexpected results.", CWE398, Certainty::normal);
318 }
319 
320 //-----------------------------------------------------------------------------
322 {
323  logChecker("CheckBool::checkAssignBoolToPointer");
324  const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
325  for (const Scope * scope : symbolDatabase->functionScopes) {
326  for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
327  if (tok->str() == "=" && astIsPointer(tok->astOperand1()) && astIsBool(tok->astOperand2())) {
329  }
330  }
331  }
332 }
333 
335 {
336  reportError(tok, Severity::error, "assignBoolToPointer",
337  "Boolean value assigned to pointer.", CWE587, Certainty::normal);
338 }
339 
340 //-----------------------------------------------------------------------------
341 //-----------------------------------------------------------------------------
343 {
344  if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("compareBoolExpressionWithInt"))
345  return;
346 
347  logChecker("CheckBool::checkComparisonOfBoolExpressionWithInt"); // warning
348 
349  const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
350 
351  for (const Scope * scope : symbolDatabase->functionScopes) {
352  for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
353  if (!tok->isComparisonOp())
354  continue;
355 
356  const Token* numTok = nullptr;
357  const Token* boolExpr = nullptr;
358  bool numInRhs;
359  if (astIsBool(tok->astOperand1())) {
360  boolExpr = tok->astOperand1();
361  numTok = tok->astOperand2();
362  numInRhs = true;
363  } else if (astIsBool(tok->astOperand2())) {
364  boolExpr = tok->astOperand2();
365  numTok = tok->astOperand1();
366  numInRhs = false;
367  } else {
368  continue;
369  }
370 
371  if (!numTok || !boolExpr)
372  continue;
373 
374  if (boolExpr->isOp() && numTok->isName() && Token::Match(tok, "==|!="))
375  // there is weird code such as: ((a<b)==c)
376  // but it is probably written this way by design.
377  continue;
378 
379  if (astIsBool(numTok))
380  continue;
381 
382  const ValueFlow::Value *minval = numTok->getValueLE(0, *mSettings);
383  if (minval && minval->intvalue == 0 &&
384  (numInRhs ? Token::Match(tok, ">|==|!=")
385  : Token::Match(tok, "<|==|!=")))
386  minval = nullptr;
387 
388  const ValueFlow::Value *maxval = numTok->getValueGE(1, *mSettings);
389  if (maxval && maxval->intvalue == 1 &&
390  (numInRhs ? Token::Match(tok, "<|==|!=")
391  : Token::Match(tok, ">|==|!=")))
392  maxval = nullptr;
393 
394  if (minval || maxval) {
395  const bool not0or1 = (minval && minval->intvalue < 0) || (maxval && maxval->intvalue > 1);
397  }
398  }
399  }
400 }
401 
403 {
404  if (not0or1)
405  reportError(tok, Severity::warning, "compareBoolExpressionWithInt",
406  "Comparison of a boolean expression with an integer other than 0 or 1.", CWE398, Certainty::normal);
407  else
408  reportError(tok, Severity::warning, "compareBoolExpressionWithInt",
409  "Comparison of a boolean expression with an integer.", CWE398, Certainty::normal);
410 }
411 
412 
414 {
415  logChecker("CheckBool::pointerArithBool");
416 
417  const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
418 
419  for (const Scope &scope : symbolDatabase->scopeList) {
420  if (scope.type != Scope::eIf && !scope.isLoopScope())
421  continue;
422  const Token* tok = scope.classDef->next()->astOperand2();
423  if (scope.type == Scope::eFor) {
424  tok = Token::findsimplematch(scope.classDef->tokAt(2), ";");
425  if (tok)
426  tok = tok->astOperand2();
427  if (tok)
428  tok = tok->astOperand1();
429  } else if (scope.type == Scope::eDo)
430  tok = (scope.bodyEnd->tokAt(2)) ? scope.bodyEnd->tokAt(2)->astOperand2() : nullptr;
431 
433  }
434 }
435 
437 {
438  if (!tok)
439  return;
440  if (Token::Match(tok, "&&|%oror%")) {
443  return;
444  }
445  if (tok->str() != "+" && tok->str() != "-")
446  return;
447 
448  if (tok->isBinaryOp() &&
449  tok->astOperand1()->isName() &&
450  tok->astOperand1()->variable() &&
451  tok->astOperand1()->variable()->isPointer() &&
452  tok->astOperand2()->isNumber())
454 }
455 
457 {
458  reportError(tok,
460  "pointerArithBool",
461  "Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n"
462  "Converting pointer arithmetic result to bool. The boolean result is always true unless there is pointer arithmetic overflow, and overflow is undefined behaviour. Probably a dereference is forgotten.", CWE571, Certainty::normal);
463 }
464 
466 {
467  if (!mTokenizer->isCPP())
468  return;
470  return;
471  logChecker("CheckBool::checkAssignBoolToFloat"); // style,c++
472  const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
473  for (const Scope * scope : symbolDatabase->functionScopes) {
474  for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
475  if (tok->str() == "=" && astIsFloat(tok->astOperand1(), false) && astIsBool(tok->astOperand2())) {
477  }
478  }
479  }
480 }
481 
483 {
484  reportError(tok, Severity::style, "assignBoolToFloat",
485  "Boolean value assigned to floating point variable.", CWE704, Certainty::normal);
486 }
487 
489 {
491  return;
492 
493  logChecker("CheckBool::returnValueOfFunctionReturningBool"); // style
494 
495  const SymbolDatabase * const symbolDatabase = mTokenizer->getSymbolDatabase();
496 
497  for (const Scope * scope : symbolDatabase->functionScopes) {
498  if (!(scope->function && Token::Match(scope->function->retDef, "bool|_Bool")))
499  continue;
500 
501  for (const Token* tok = scope->bodyStart->next(); tok && (tok != scope->bodyEnd); tok = tok->next()) {
502  // Skip lambdas
503  const Token* tok2 = findLambdaEndToken(tok);
504  if (tok2)
505  tok = tok2;
506  else if (tok->scope() && tok->scope()->isClassOrStruct())
507  tok = tok->scope()->bodyEnd;
508  else if (Token::simpleMatch(tok, "return") && tok->astOperand1() &&
509  (tok->astOperand1()->getValueGE(2, *mSettings) || tok->astOperand1()->getValueLE(-1, *mSettings)) &&
510  !(tok->astOperand1()->astOperand1() && Token::Match(tok->astOperand1(), "&|%or%")))
512  }
513  }
514 }
515 
517 {
518  reportError(tok, Severity::style, "returnNonBoolInBooleanFunction", "Non-boolean value returned from function returning bool");
519 }
bool astIsPointer(const Token *tok)
Definition: astutils.cpp:220
bool astIsBool(const Token *tok)
Is expression of boolean type?
Definition: astutils.cpp:215
bool astIsFloat(const Token *tok, bool unknown)
Is expression of floating point type?
Definition: astutils.cpp:207
const Token * findLambdaEndToken(const Token *first)
find lambda function end token
Definition: astutils.cpp:3195
bool isCPPCast(const Token *tok)
Definition: astutils.cpp:3247
bool isConstExpression(const Token *tok, const Library &library)
Definition: astutils.cpp:2049
static const CWE CWE571(571U)
static bool isConvertedToBool(const Token *tok)
Definition: checkbool.cpp:80
static const CWE CWE398(398U)
static bool isBool(const Variable *var)
Definition: checkbool.cpp:45
static const CWE CWE704(704U)
static bool tokenIsFunctionReturningBool(const Token *tok)
Definition: checkbool.cpp:193
static const CWE CWE587(587U)
checks dealing with suspicious usage of boolean type (not for evaluating conditions)
Definition: checkbool.h:41
void assignBoolToPointerError(const Token *tok)
Definition: checkbool.cpp:334
void checkBitwiseOnBoolean()
Check for using bool in bitwise expression
Definition: checkbool.cpp:91
void pointerArithBoolError(const Token *tok)
Definition: checkbool.cpp:456
void comparisonOfFuncReturningBoolError(const Token *tok, const std::string &expression)
Definition: checkbool.cpp:248
void pointerArithBool()
Check for 'if (p+1)' etc.
Definition: checkbool.cpp:413
void checkComparisonOfBoolWithBool()
Check for comparison of variable of type bool
Definition: checkbool.cpp:270
void incrementBooleanError(const Token *tok)
Definition: checkbool.cpp:68
void checkComparisonOfBoolWithInt()
Check for suspicious comparison of a bool and a non-zero (and non-one) value (e.g.
Definition: checkbool.cpp:153
void comparisonOfBoolWithBoolError(const Token *tok, const std::string &expression)
Definition: checkbool.cpp:311
void pointerArithBoolCond(const Token *tok)
Definition: checkbool.cpp:436
void checkAssignBoolToPointer()
assigning bool to pointer
Definition: checkbool.cpp:321
void comparisonOfBoolExpressionWithIntError(const Token *tok, bool not0or1)
Definition: checkbool.cpp:402
void bitwiseOnBooleanError(const Token *tok, const std::string &expression, const std::string &op, bool isCompound=false)
Definition: checkbool.cpp:136
void returnValueBoolError(const Token *tok)
Definition: checkbool.cpp:516
void checkComparisonOfFuncReturningBool()
Check for comparison of function returning bool
Definition: checkbool.cpp:204
void comparisonOfBoolWithInvalidComparator(const Token *tok, const std::string &expression)
Definition: checkbool.cpp:180
void checkComparisonOfBoolExpressionWithInt()
Check for comparing a bool expression with an integer other than 0 or 1
Definition: checkbool.cpp:342
void checkIncrementBoolean()
Check for using postfix increment on bool
Definition: checkbool.cpp:51
void returnValueOfFunctionReturningBool()
Check if a function returning bool returns an integer other than 0 or 1
Definition: checkbool.cpp:488
void assignBoolToFloatError(const Token *tok)
Definition: checkbool.cpp:482
void comparisonOfTwoFuncsReturningBoolError(const Token *tok, const std::string &expression1, const std::string &expression2)
Definition: checkbool.cpp:257
void checkAssignBoolToFloat()
assigning bool to float
Definition: checkbool.cpp:465
void reportError(const Token *tok, const Severity severity, const std::string &id, const std::string &msg)
report an error
Definition: check.h:138
const Settings *const mSettings
Definition: check.h:134
const Tokenizer *const mTokenizer
Definition: check.h:133
void logChecker(const char id[])
log checker
Definition: check.cpp:129
const Token * retDef
function return type token
const Token * tokenDef
function name token in class definition
ScopeType type
Function * function
function info for this function
bool isLoopScope() const
const Token * classDef
class/struct/union/namespace token
const Token * bodyStart
'{' token
const Token * bodyEnd
'}' token
Library library
Library.
Definition: settings.h:237
bool isPremiumEnabled(const char id[]) const
Is checker id enabled by premiumArgs.
Definition: settings.cpp:608
SimpleEnableGroup< Certainty > certainty
Definition: settings.h:359
SimpleEnableGroup< Severity > severity
Definition: settings.h:358
bool isEnabled(T flag) const
Definition: settings.h:66
std::vector< const Scope * > functionScopes
Fast access to function scopes.
std::list< Scope > scopeList
Information about all namespaces/classes/structures.
The token list that the TokenList generates is a linked-list of this class.
Definition: token.h:150
void str(T &&s)
Definition: token.h:179
static bool Match(const Token *tok, const char pattern[], nonneg int varid=0)
Match given token (or list of tokens) to a pattern list.
Definition: token.cpp:688
bool isName() const
Definition: token.h:361
bool isBoolean() const
Definition: token.h:404
void astOperand1(Token *tok)
Definition: token.cpp:1456
void function(const Function *f)
Associate this token with given function.
Definition: token.cpp:1093
nonneg int varId() const
Definition: token.h:870
const ValueFlow::Value * getValueGE(const MathLib::bigint val, const Settings &settings) const
Definition: token.cpp:1954
bool isOp() const
Definition: token.h:380
static const Token * findsimplematch(const Token *const startTok, const char(&pattern)[count])
Definition: token.h:763
const Token * tokAt(int index) const
Definition: token.cpp:393
void astOperand2(Token *tok)
Definition: token.cpp:1468
void scope(const Scope *s)
Associate this token with given scope.
Definition: token.h:1042
Token * previous()
Definition: token.h:862
bool isBinaryOp() const
Definition: token.h:410
const ValueFlow::Value * getValueLE(const MathLib::bigint val, const Settings &settings) const
Definition: token.cpp:1945
void variable(const Variable *v)
Associate this token with given variable.
Definition: token.h:1070
Token * next()
Definition: token.h:830
static bool simpleMatch(const Token *tok, const char(&pattern)[count])
Match given token (or list of tokens) to a pattern list.
Definition: token.h:252
void astParent(Token *tok)
Definition: token.cpp:1437
const SymbolDatabase * getSymbolDatabase() const
Definition: tokenize.h:563
bool isCPP() const
Is the code CPP.
Definition: tokenize.h:69
long long intvalue
int value (or sometimes bool value?)
Definition: vfvalue.h:268
Information about a member variable.
const Token * typeEndToken() const
Get type end token.
@ warning
Warning.
@ style
Style warning.
@ error
Programming error.