X Tutup
Skip to content

Commit fe8730c

Browse files
authored
MathLib: renamed to{U}LongNumber() to toBig{U}Number() (danmar#5503)
The name was misleading as it was actually a `long long` and also if we ever move to an (optional) 128-bit value it wouldn't even less fitting. We should name it to match our alias type.
1 parent fc700b6 commit fe8730c

17 files changed

+298
-284
lines changed

lib/checkcondition.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void CheckCondition::assignIf()
106106

107107
if (Token::Match(tok->next(), "%num% [&|]")) {
108108
bitop = tok->strAt(2).at(0);
109-
num = MathLib::toLongNumber(tok->next()->str());
109+
num = MathLib::toBigNumber(tok->next()->str());
110110
} else {
111111
const Token *endToken = Token::findsimplematch(tok, ";");
112112

@@ -116,7 +116,7 @@ void CheckCondition::assignIf()
116116

117117
if (endToken && Token::Match(endToken->tokAt(-2), "[&|] %num% ;")) {
118118
bitop = endToken->strAt(-2).at(0);
119-
num = MathLib::toLongNumber(endToken->previous()->str());
119+
num = MathLib::toBigNumber(endToken->previous()->str());
120120
}
121121
}
122122

@@ -169,15 +169,15 @@ bool CheckCondition::assignIfParseScope(const Token * const assignTok,
169169

170170
for (const Token *tok2 = startTok; tok2; tok2 = tok2->next()) {
171171
if ((bitop == '&') && Token::Match(tok2->tokAt(2), "%varid% %cop% %num% ;", varid) && tok2->strAt(3) == std::string(1U, bitop)) {
172-
const MathLib::bigint num2 = MathLib::toLongNumber(tok2->strAt(4));
172+
const MathLib::bigint num2 = MathLib::toBigNumber(tok2->strAt(4));
173173
if (0 == (num & num2))
174174
mismatchingBitAndError(assignTok, num, tok2, num2);
175175
}
176176
if (Token::Match(tok2, "%varid% =", varid)) {
177177
return true;
178178
}
179179
if (bitop == '&' && Token::Match(tok2, "%varid% &= %num% ;", varid)) {
180-
const MathLib::bigint num2 = MathLib::toLongNumber(tok2->strAt(2));
180+
const MathLib::bigint num2 = MathLib::toBigNumber(tok2->strAt(2));
181181
if (0 == (num & num2))
182182
mismatchingBitAndError(assignTok, num, tok2, num2);
183183
}
@@ -212,7 +212,7 @@ bool CheckCondition::assignIfParseScope(const Token * const assignTok,
212212
}
213213
if (Token::Match(tok2,"&&|%oror%|( %varid% ==|!= %num% &&|%oror%|)", varid)) {
214214
const Token *vartok = tok2->next();
215-
const MathLib::bigint num2 = MathLib::toLongNumber(vartok->strAt(2));
215+
const MathLib::bigint num2 = MathLib::toBigNumber(vartok->strAt(2));
216216
if ((num & num2) != ((bitop=='&') ? num2 : num)) {
217217
const std::string& op(vartok->strAt(1));
218218
const bool alwaysTrue = op == "!=";
@@ -266,11 +266,11 @@ void CheckCondition::mismatchingBitAndError(const Token *tok1, const MathLib::bi
266266
static void getnumchildren(const Token *tok, std::list<MathLib::bigint> &numchildren)
267267
{
268268
if (tok->astOperand1() && tok->astOperand1()->isNumber())
269-
numchildren.push_back(MathLib::toLongNumber(tok->astOperand1()->str()));
269+
numchildren.push_back(MathLib::toBigNumber(tok->astOperand1()->str()));
270270
else if (tok->astOperand1() && tok->str() == tok->astOperand1()->str())
271271
getnumchildren(tok->astOperand1(), numchildren);
272272
if (tok->astOperand2() && tok->astOperand2()->isNumber())
273-
numchildren.push_back(MathLib::toLongNumber(tok->astOperand2()->str()));
273+
numchildren.push_back(MathLib::toBigNumber(tok->astOperand2()->str()));
274274
else if (tok->astOperand2() && tok->str() == tok->astOperand2()->str())
275275
getnumchildren(tok->astOperand2(), numchildren);
276276
}
@@ -371,7 +371,7 @@ void CheckCondition::comparison()
371371
std::swap(expr1,expr2);
372372
if (!expr2->isNumber())
373373
continue;
374-
const MathLib::bigint num2 = MathLib::toLongNumber(expr2->str());
374+
const MathLib::bigint num2 = MathLib::toBigNumber(expr2->str());
375375
if (num2 < 0)
376376
continue;
377377
if (!Token::Match(expr1,"[&|]"))
@@ -463,8 +463,8 @@ bool CheckCondition::isOverlappingCond(const Token * const cond1, const Token *
463463
if (!isSameExpression(mTokenizer->isCPP(), true, expr1, expr2, mSettings->library, pure, false))
464464
return false;
465465

466-
const MathLib::bigint value1 = MathLib::toLongNumber(num1->str());
467-
const MathLib::bigint value2 = MathLib::toLongNumber(num2->str());
466+
const MathLib::bigint value1 = MathLib::toBigNumber(num1->str());
467+
const MathLib::bigint value2 = MathLib::toBigNumber(num2->str());
468468
if (cond2->str() == "&")
469469
return ((value1 & value2) == value2);
470470
return ((value1 & value2) > 0);
@@ -1267,11 +1267,11 @@ void CheckCondition::checkIncorrectLogicOperator()
12671267

12681268
const double d1 = (isfloat) ? MathLib::toDoubleNumber(value1) : 0;
12691269
const double d2 = (isfloat) ? MathLib::toDoubleNumber(value2) : 0;
1270-
const MathLib::bigint i1 = (isfloat) ? 0 : MathLib::toLongNumber(value1);
1271-
const MathLib::bigint i2 = (isfloat) ? 0 : MathLib::toLongNumber(value2);
1270+
const MathLib::bigint i1 = (isfloat) ? 0 : MathLib::toBigNumber(value1);
1271+
const MathLib::bigint i2 = (isfloat) ? 0 : MathLib::toBigNumber(value2);
12721272
const bool useUnsignedInt = (std::numeric_limits<MathLib::bigint>::max()==i1) || (std::numeric_limits<MathLib::bigint>::max()==i2);
1273-
const MathLib::biguint u1 = (useUnsignedInt) ? MathLib::toLongNumber(value1) : 0;
1274-
const MathLib::biguint u2 = (useUnsignedInt) ? MathLib::toLongNumber(value2) : 0;
1273+
const MathLib::biguint u1 = (useUnsignedInt) ? MathLib::toBigNumber(value1) : 0;
1274+
const MathLib::biguint u2 = (useUnsignedInt) ? MathLib::toBigNumber(value2) : 0;
12751275
// evaluate if expression is always true/false
12761276
bool alwaysTrue = true, alwaysFalse = true;
12771277
bool firstTrue = true, secondTrue = true;

lib/checkfunctions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,12 @@ void CheckFunctions::checkMathFunctions()
438438
if (tok->strAt(-1) != "."
439439
&& Token::Match(tok, "log|logf|logl|log10|log10f|log10l|log2|log2f|log2l ( %num% )")) {
440440
const std::string& number = tok->strAt(2);
441-
if ((MathLib::isInt(number) && MathLib::toLongNumber(number) <= 0) ||
441+
if ((MathLib::isInt(number) && MathLib::toBigNumber(number) <= 0) ||
442442
(MathLib::isFloat(number) && MathLib::toDoubleNumber(number) <= 0.))
443443
mathfunctionCallWarning(tok);
444444
} else if (Token::Match(tok, "log1p|log1pf|log1pl ( %num% )")) {
445445
const std::string& number = tok->strAt(2);
446-
if ((MathLib::isInt(number) && MathLib::toLongNumber(number) <= -1) ||
446+
if ((MathLib::isInt(number) && MathLib::toBigNumber(number) <= -1) ||
447447
(MathLib::isFloat(number) && MathLib::toDoubleNumber(number) <= -1.))
448448
mathfunctionCallWarning(tok);
449449
}
@@ -575,7 +575,7 @@ void CheckFunctions::memsetInvalid2ndParam()
575575
}
576576

577577
if (printWarning && secondParamTok->isNumber()) { // Check if the second parameter is a literal and is out of range
578-
const long long int value = MathLib::toLongNumber(secondParamTok->str());
578+
const long long int value = MathLib::toBigNumber(secondParamTok->str());
579579
const long long sCharMin = mSettings->platform.signedCharMin();
580580
const long long uCharMax = mSettings->platform.unsignedCharMax();
581581
if (value < sCharMin || value > uCharMax)

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
435435

436436
// Assigning non-zero value variable. It might be used to
437437
// track the execution for a later if condition.
438-
if (Token::Match(varTok->tokAt(2), "%num% ;") && MathLib::toLongNumber(varTok->strAt(2)) != 0)
438+
if (Token::Match(varTok->tokAt(2), "%num% ;") && MathLib::toBigNumber(varTok->strAt(2)) != 0)
439439
notzero.insert(varTok->varId());
440440
else if (Token::Match(varTok->tokAt(2), "- %type% ;") && varTok->tokAt(3)->isUpperCaseName())
441441
notzero.insert(varTok->varId());

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3085,7 +3085,7 @@ void CheckOther::checkIncompleteArrayFill()
30853085
if (!var || !var->isArray() || var->dimensions().empty() || !var->dimension(0))
30863086
continue;
30873087

3088-
if (MathLib::toLongNumber(tok->linkAt(1)->strAt(-1)) == var->dimension(0)) {
3088+
if (MathLib::toBigNumber(tok->linkAt(1)->strAt(-1)) == var->dimension(0)) {
30893089
int size = mTokenizer->sizeOfType(var->typeStartToken());
30903090
if (size == 0 && var->valueType()->pointer)
30913091
size = mSettings->platform.sizeof_pointer;

lib/checkstring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ void CheckString::checkIncorrectStringCompare()
292292
tok = tok->next()->link();
293293

294294
if (Token::simpleMatch(tok, ". substr (") && Token::Match(tok->tokAt(3)->nextArgument(), "%num% )")) {
295-
const MathLib::biguint clen = MathLib::toULongNumber(tok->linkAt(2)->strAt(-1));
295+
const MathLib::biguint clen = MathLib::toBigUNumber(tok->linkAt(2)->strAt(-1));
296296
const Token* begin = tok->previous();
297297
for (;;) { // Find start of statement
298298
while (begin->link() && Token::Match(begin, "]|)|>"))

lib/checkuninitvar.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<nonneg i
315315
return;
316316

317317
if (tok->str() == "==")
318-
*alwaysTrue = (it->second == MathLib::toLongNumber(numtok->str()));
318+
*alwaysTrue = (it->second == MathLib::toBigNumber(numtok->str()));
319319
else if (tok->str() == "!=")
320-
*alwaysTrue = (it->second != MathLib::toLongNumber(numtok->str()));
320+
*alwaysTrue = (it->second != MathLib::toBigNumber(numtok->str()));
321321
else
322322
return;
323323
*alwaysFalse = !(*alwaysTrue);
@@ -517,7 +517,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
517517
if (Token::Match(tok2, "[;{}.] %name% = - %name% ;"))
518518
varValueIf[tok2->next()->varId()] = !VariableValue(0);
519519
else if (Token::Match(tok2, "[;{}.] %name% = %num% ;"))
520-
varValueIf[tok2->next()->varId()] = VariableValue(MathLib::toLongNumber(tok2->strAt(3)));
520+
varValueIf[tok2->next()->varId()] = VariableValue(MathLib::toBigNumber(tok2->strAt(3)));
521521
}
522522
}
523523

@@ -547,7 +547,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
547547
if (Token::Match(tok2, "[;{}.] %var% = - %name% ;"))
548548
varValueElse[tok2->next()->varId()] = !VariableValue(0);
549549
else if (Token::Match(tok2, "[;{}.] %var% = %num% ;"))
550-
varValueElse[tok2->next()->varId()] = VariableValue(MathLib::toLongNumber(tok2->strAt(3)));
550+
varValueElse[tok2->next()->varId()] = VariableValue(MathLib::toBigNumber(tok2->strAt(3)));
551551
}
552552
}
553553

lib/clangimport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
734734
if (nodeType == BreakStmt)
735735
return addtoken(tokenList, "break");
736736
if (nodeType == CharacterLiteral) {
737-
const int c = MathLib::toLongNumber(mExtTokens.back());
737+
const int c = MathLib::toBigNumber(mExtTokens.back());
738738
if (c == 0)
739739
return addtoken(tokenList, "\'\\0\'");
740740
if (c == '\r')

lib/library.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,13 +916,13 @@ bool Library::isIntArgValid(const Token *ftok, int argnr, const MathLib::bigint
916916
TokenList tokenList(nullptr);
917917
gettokenlistfromvalid(ac->valid, tokenList);
918918
for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
919-
if (tok->isNumber() && argvalue == MathLib::toLongNumber(tok->str()))
919+
if (tok->isNumber() && argvalue == MathLib::toBigNumber(tok->str()))
920920
return true;
921-
if (Token::Match(tok, "%num% : %num%") && argvalue >= MathLib::toLongNumber(tok->str()) && argvalue <= MathLib::toLongNumber(tok->strAt(2)))
921+
if (Token::Match(tok, "%num% : %num%") && argvalue >= MathLib::toBigNumber(tok->str()) && argvalue <= MathLib::toBigNumber(tok->strAt(2)))
922922
return true;
923-
if (Token::Match(tok, "%num% : ,") && argvalue >= MathLib::toLongNumber(tok->str()))
923+
if (Token::Match(tok, "%num% : ,") && argvalue >= MathLib::toBigNumber(tok->str()))
924924
return true;
925-
if ((!tok->previous() || tok->previous()->str() == ",") && Token::Match(tok,": %num%") && argvalue <= MathLib::toLongNumber(tok->strAt(1)))
925+
if ((!tok->previous() || tok->previous()->str() == ",") && Token::Match(tok,": %num%") && argvalue <= MathLib::toBigNumber(tok->strAt(1)))
926926
return true;
927927
}
928928
return false;

0 commit comments

Comments
 (0)
X Tutup