Skip to content

Commit e66f921

Browse files
committed
reduced usage of Tokenizer::isCPP()
1 parent c211665 commit e66f921

28 files changed

Lines changed: 395 additions & 425 deletions

lib/astutils.cpp

Lines changed: 109 additions & 111 deletions
Large diffs are not rendered by default.

lib/astutils.h

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ const Token * astIsVariableComparison(const Token *tok, const std::string &comp,
194194
bool isVariableDecl(const Token* tok);
195195
bool isStlStringType(const Token* tok);
196196

197-
bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknown = false);
197+
bool isTemporary(const Token* tok, const Library* library, bool unknown = false);
198198

199199
const Token* previousBeforeAstLeftmostLeaf(const Token* tok);
200200
Token* previousBeforeAstLeftmostLeaf(Token* tok);
@@ -208,7 +208,7 @@ const Token* astParentSkipParens(const Token* tok);
208208
const Token* getParentMember(const Token * tok);
209209

210210
const Token* getParentLifetime(const Token* tok);
211-
const Token* getParentLifetime(bool cpp, const Token* tok, const Library* library);
211+
const Token* getParentLifetime(const Token* tok, const Library* library);
212212

213213
std::vector<ValueType> getParentValueTypes(const Token* tok,
214214
const Settings* settings = nullptr,
@@ -261,7 +261,7 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
261261
int depth = 20);
262262
const Token* followReferences(const Token* tok, ErrorPath* errors = nullptr);
263263

264-
CPPCHECKLIB bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
264+
CPPCHECKLIB bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
265265

266266
bool isEqualKnownValue(const Token * const tok1, const Token * const tok2);
267267

@@ -277,21 +277,20 @@ CPPCHECKLIB bool isUsedAsBool(const Token* const tok, const Settings* settings =
277277
/**
278278
* Are two conditions opposite
279279
* @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
280-
* @param cpp c++ file
281280
* @param cond1 condition1
282281
* @param cond2 condition2
283282
* @param library files data
284283
* @param pure boolean
285284
*/
286-
bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token * const cond2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
285+
bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const cond2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
287286

288-
bool isOppositeExpression(bool cpp, const Token * const tok1, const Token * const tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
287+
bool isOppositeExpression(const Token * const tok1, const Token * const tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
289288

290289
bool isConstFunctionCall(const Token* ftok, const Library& library);
291290

292-
bool isConstExpression(const Token *tok, const Library& library, bool cpp);
291+
bool isConstExpression(const Token *tok, const Library& library);
293292

294-
bool isWithoutSideEffects(bool cpp, const Token* tok, bool checkArrayAccess = false, bool checkReference = true);
293+
bool isWithoutSideEffects(const Token* tok, bool checkArrayAccess = false, bool checkReference = true);
295294

296295
bool isUniqueExpression(const Token* tok);
297296

@@ -336,38 +335,35 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, nonneg int
336335
CPPCHECKLIB bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Settings *settings, bool *inconclusive);
337336

338337
/** Is variable changed in block of code? */
339-
CPPCHECKLIB bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth = 20);
340-
bool isVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth = 20);
338+
CPPCHECKLIB bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
339+
bool isVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
341340

342-
bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, bool cpp, int depth = 20);
341+
bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, int depth = 20);
343342

344-
bool isVariableChanged(const Variable * var, const Settings *settings, bool cpp, int depth = 20);
343+
bool isVariableChanged(const Variable * var, const Settings *settings, int depth = 20);
345344

346345
bool isVariablesChanged(const Token* start,
347346
const Token* end,
348347
int indirect,
349348
const std::vector<const Variable*> &vars,
350-
const Settings* settings,
351-
bool cpp);
349+
const Settings* settings);
352350

353-
bool isThisChanged(const Token* tok, int indirect, const Settings* settings, bool cpp);
354-
const Token* findThisChanged(const Token* start, const Token* end, int indirect, const Settings* settings, bool cpp);
351+
bool isThisChanged(const Token* tok, int indirect, const Settings* settings);
352+
const Token* findThisChanged(const Token* start, const Token* end, int indirect, const Settings* settings);
355353

356-
const Token* findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth = 20);
357-
Token* findVariableChanged(Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth = 20);
354+
const Token* findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
355+
Token* findVariableChanged(Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
358356

359357
CPPCHECKLIB const Token* findExpressionChanged(const Token* expr,
360358
const Token* start,
361359
const Token* end,
362360
const Settings* settings,
363-
bool cpp,
364361
int depth = 20);
365362

366363
const Token* findExpressionChangedSkipDeadCode(const Token* expr,
367364
const Token* start,
368365
const Token* end,
369366
const Settings* settings,
370-
bool cpp,
371367
const std::function<std::vector<MathLib::bigint>(const Token* tok)>& evaluate,
372368
int depth = 20);
373369

@@ -376,7 +372,6 @@ bool isExpressionChangedAt(const Token* expr,
376372
int indirect,
377373
bool globalvar,
378374
const Settings* settings,
379-
bool cpp,
380375
int depth = 20);
381376

382377
/// If token is an alias if another variable
@@ -421,14 +416,14 @@ CPPCHECKLIB const Token *findLambdaStartToken(const Token *last);
421416
CPPCHECKLIB const Token *findLambdaEndToken(const Token *first);
422417
CPPCHECKLIB Token* findLambdaEndToken(Token* first);
423418

424-
bool isLikelyStream(bool cpp, const Token *stream);
419+
bool isLikelyStream(const Token *stream);
425420

426421
/**
427422
* do we see a likely write of rhs through overloaded operator
428423
* s >> x;
429424
* a & x;
430425
*/
431-
bool isLikelyStreamRead(bool cpp, const Token *op);
426+
bool isLikelyStreamRead(const Token *op);
432427

433428
bool isCPPCast(const Token* tok);
434429

@@ -438,7 +433,7 @@ bool isLeafDot(const Token* tok);
438433

439434
enum class ExprUsage { None, NotUsed, PassedByReference, Used, Inconclusive };
440435

441-
ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings, bool cpp);
436+
ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings);
442437

443438
const Variable *getLHSVariable(const Token *tok);
444439

@@ -453,7 +448,7 @@ bool isScopeBracket(const Token* tok);
453448

454449
CPPCHECKLIB bool isNullOperand(const Token *expr);
455450

456-
bool isGlobalData(const Token *expr, bool cpp);
451+
bool isGlobalData(const Token *expr);
457452

458453
bool isUnevaluated(const Token *tok);
459454

lib/checkautovariables.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void CheckAutoVariables::autoVariables()
296296
}
297297
// Invalid pointer deallocation
298298
else if ((Token::Match(tok, "%name% ( %var%|%str% ) ;") && mSettings->library.getDeallocFuncInfo(tok)) ||
299-
(mTokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| %var%|%str% !!["))) {
299+
(tok->isCpp() && Token::Match(tok, "delete [| ]| (| %var%|%str% !!["))) {
300300
tok = Token::findmatch(tok->next(), "%var%|%str%");
301301
if (Token::simpleMatch(tok->astParent(), "."))
302302
continue;
@@ -314,7 +314,7 @@ void CheckAutoVariables::autoVariables()
314314
}
315315
}
316316
} else if ((Token::Match(tok, "%name% ( & %var% ) ;") && mSettings->library.getDeallocFuncInfo(tok)) ||
317-
(mTokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| & %var% !!["))) {
317+
(tok->isCpp() && Token::Match(tok, "delete [| ]| (| & %var% !!["))) {
318318
tok = Token::findmatch(tok->next(), "%var%");
319319
if (isAutoVar(tok))
320320
errorInvalidDeallocation(tok, nullptr);
@@ -463,9 +463,9 @@ static int getPointerDepth(const Token *tok)
463463
return n;
464464
}
465465

466-
static bool isDeadTemporary(bool cpp, const Token* tok, const Token* expr, const Library* library)
466+
static bool isDeadTemporary(const Token* tok, const Token* expr, const Library* library)
467467
{
468-
if (!isTemporary(cpp, tok, library))
468+
if (!isTemporary(tok, library))
469469
return false;
470470
if (expr) {
471471
if (!precedes(nextAfterAstRightmostLeaf(tok->astTop()), nextAfterAstRightmostLeaf(expr->astTop())))
@@ -495,7 +495,7 @@ static bool isEscapedReference(const Variable* var)
495495
if (!Token::simpleMatch(varDeclEndToken, "="))
496496
return false;
497497
const Token* vartok = varDeclEndToken->astOperand2();
498-
return !isTemporary(true, vartok, nullptr, false);
498+
return !isTemporary(vartok, nullptr, false);
499499
}
500500

501501
static bool isDanglingSubFunction(const Token* tokvalue, const Token* tok)
@@ -562,7 +562,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
562562
errorReturnReference(tok, lt.errorPath, lt.inconclusive);
563563
break;
564564
}
565-
if (isDeadTemporary(mTokenizer->isCPP(), lt.token, nullptr, &mSettings->library)) {
565+
if (isDeadTemporary(lt.token, nullptr, &mSettings->library)) {
566566
errorReturnTempReference(tok, lt.errorPath, lt.inconclusive);
567567
break;
568568
}
@@ -584,7 +584,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
584584
if (!printInconclusive && lt.inconclusive)
585585
continue;
586586
const Token * tokvalue = lt.token;
587-
if (isDeadTemporary(mTokenizer->isCPP(), tokvalue, tok, &mSettings->library)) {
587+
if (isDeadTemporary(tokvalue, tok, &mSettings->library)) {
588588
errorDanglingTempReference(tok, lt.errorPath, lt.inconclusive);
589589
break;
590590
}
@@ -598,7 +598,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
598598
continue;
599599
if (!printInconclusive && val.isInconclusive())
600600
continue;
601-
const Token* parent = getParentLifetime(mTokenizer->isCPP(), val.tokvalue, &mSettings->library);
601+
const Token* parent = getParentLifetime(val.tokvalue, &mSettings->library);
602602
if (!exprs.insert(parent).second)
603603
continue;
604604
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(parent, escape || isAssignedToNonLocal(tok))) {
@@ -614,15 +614,15 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
614614
continue;
615615
if ((tokvalue->variable() && !isEscapedReference(tokvalue->variable()) &&
616616
isInScope(tokvalue->variable()->nameToken(), scope)) ||
617-
isDeadTemporary(mTokenizer->isCPP(), tokvalue, nullptr, &mSettings->library)) {
617+
isDeadTemporary(tokvalue, nullptr, &mSettings->library)) {
618618
errorReturnDanglingLifetime(tok, &val);
619619
break;
620620
}
621621
} else if (tokvalue->variable() && isDeadScope(tokvalue->variable()->nameToken(), tok->scope())) {
622622
errorInvalidLifetime(tok, &val);
623623
break;
624624
} else if (!tokvalue->variable() &&
625-
isDeadTemporary(mTokenizer->isCPP(), tokvalue, tok, &mSettings->library)) {
625+
isDeadTemporary(tokvalue, tok, &mSettings->library)) {
626626
if (!diag(tokvalue))
627627
errorDanglingTemporaryLifetime(tok, &val, tokvalue);
628628
break;
@@ -650,8 +650,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
650650
tok->scope()->bodyEnd,
651651
var->declarationId(),
652652
var->isGlobal(),
653-
mSettings,
654-
mTokenizer->isCPP())) {
653+
mSettings)) {
655654
errorDanglngLifetime(tok2, &val);
656655
break;
657656
}

lib/checkbool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void CheckBool::checkBitwiseOnBoolean()
120120
if (tok->str() == "|" && !isConvertedToBool(tok) && !(isBoolOp1 && isBoolOp2))
121121
continue;
122122
// first operand will always be evaluated
123-
if (!isConstExpression(tok->astOperand2(), mSettings->library, mTokenizer->isCPP()))
123+
if (!isConstExpression(tok->astOperand2(), mSettings->library))
124124
continue;
125125
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2())
126126
continue;

lib/checkbufferoverrun.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void CheckBufferOverrun::arrayIndex()
326326
const Token* changeTok = var->scope()->bodyStart;
327327
bool isChanged = false;
328328
while ((changeTok = findVariableChanged(changeTok->next(), var->scope()->bodyEnd, /*indirect*/ 0, var->declarationId(),
329-
/*globalvar*/ false, mSettings, mTokenizer->isCPP()))) {
329+
/*globalvar*/ false, mSettings))) {
330330
if (!Token::simpleMatch(changeTok->astParent(), "[")) {
331331
isChanged = true;
332332
break;
@@ -792,7 +792,7 @@ void CheckBufferOverrun::stringNotZeroTerminated()
792792
const Token *rhs = tok2->next()->astOperand2();
793793
if (!rhs || !rhs->hasKnownIntValue() || rhs->getKnownIntValue() != 0)
794794
continue;
795-
if (isSameExpression(mTokenizer->isCPP(), false, args[0], tok2->link()->astOperand1(), mSettings->library, false, false))
795+
if (isSameExpression(false, args[0], tok2->link()->astOperand1(), mSettings->library, false, false))
796796
isZeroTerminated = true;
797797
}
798798
if (isZeroTerminated)
@@ -1088,7 +1088,7 @@ void CheckBufferOverrun::objectIndex()
10881088
if (var->valueType()->pointer > obj->valueType()->pointer)
10891089
continue;
10901090
}
1091-
if (obj->valueType() && var->valueType() && (obj->isCast() || (mTokenizer->isCPP() && isCPPCast(obj)) || obj->valueType()->pointer)) { // allow cast to a different type
1091+
if (obj->valueType() && var->valueType() && (obj->isCast() || (obj->isCpp() && isCPPCast(obj)) || obj->valueType()->pointer)) { // allow cast to a different type
10921092
const auto varSize = var->valueType()->typeSize(mSettings->platform);
10931093
if (varSize == 0)
10941094
continue;

lib/checkclass.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void CheckClass::copyconstructors()
503503
}
504504
}
505505
for (tok = func.functionScope->bodyStart; tok != func.functionScope->bodyEnd; tok = tok->next()) {
506-
if ((mTokenizer->isCPP() && Token::Match(tok, "%var% = new")) ||
506+
if ((tok->isCpp() && Token::Match(tok, "%var% = new")) ||
507507
(Token::Match(tok, "%var% = %name% (") && (mSettings->library.getAllocFuncInfo(tok->tokAt(2)) || mSettings->library.getReallocFuncInfo(tok->tokAt(2))))) {
508508
allocatedVars.erase(tok->varId());
509509
} else if (Token::Match(tok, "%var% = %name% . %name% ;") && allocatedVars.find(tok->varId()) != allocatedVars.end()) {
@@ -817,7 +817,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
817817
continue;
818818

819819
// Variable getting value from stream?
820-
if (Token::Match(ftok, ">>|& %name%") && isLikelyStreamRead(true, ftok)) {
820+
if (Token::Match(ftok, ">>|& %name%") && isLikelyStreamRead(ftok)) {
821821
assignVar(usage, ftok->next()->varId());
822822
}
823823

@@ -1767,7 +1767,7 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope, const T
17671767
if (!end)
17681768
end = func->functionScope->bodyEnd;
17691769
for (const Token *tok = start; tok && (tok != end); tok = tok->next()) {
1770-
if (((mTokenizer->isCPP() && Token::Match(tok, "%var% = new")) ||
1770+
if (((tok->isCpp() && Token::Match(tok, "%var% = new")) ||
17711771
(Token::Match(tok, "%var% = %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2)))) &&
17721772
isMemberVar(scope, tok))
17731773
return true;
@@ -1776,9 +1776,9 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope, const T
17761776
const Token *var;
17771777
if (Token::Match(tok, "%name% ( %var%") && mSettings->library.getDeallocFuncInfo(tok))
17781778
var = tok->tokAt(2);
1779-
else if (mTokenizer->isCPP() && Token::Match(tok, "delete [ ] %var%"))
1779+
else if (tok->isCpp() && Token::Match(tok, "delete [ ] %var%"))
17801780
var = tok->tokAt(3);
1781-
else if (mTokenizer->isCPP() && Token::Match(tok, "delete %var%"))
1781+
else if (tok->isCpp() && Token::Match(tok, "delete %var%"))
17821782
var = tok->next();
17831783
else
17841784
continue;
@@ -2546,7 +2546,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
25462546
// Streaming
25472547
else if (end->strAt(1) == "<<" && tok1->strAt(-1) != "<<")
25482548
return false;
2549-
else if (isLikelyStreamRead(true, tok1->previous()))
2549+
else if (isLikelyStreamRead(tok1->previous()))
25502550
return false;
25512551

25522552
// ++/--
@@ -2575,7 +2575,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
25752575
}
25762576

25772577
// streaming: >> *this
2578-
else if (Token::simpleMatch(tok1, ">> * this") && isLikelyStreamRead(true, tok1)) {
2578+
else if (Token::simpleMatch(tok1, ">> * this") && isLikelyStreamRead(tok1)) {
25792579
return false;
25802580
}
25812581

0 commit comments

Comments
 (0)