Skip to content

Commit

Permalink
MathLib: renamed to{U}LongNumber() to toBig{U}Number() (danmar#5503)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
firewave authored Oct 5, 2023
1 parent fc700b6 commit fe8730c
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 284 deletions.
28 changes: 14 additions & 14 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void CheckCondition::assignIf()

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

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

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

Expand Down Expand Up @@ -169,15 +169,15 @@ bool CheckCondition::assignIfParseScope(const Token * const assignTok,

for (const Token *tok2 = startTok; tok2; tok2 = tok2->next()) {
if ((bitop == '&') && Token::Match(tok2->tokAt(2), "%varid% %cop% %num% ;", varid) && tok2->strAt(3) == std::string(1U, bitop)) {
const MathLib::bigint num2 = MathLib::toLongNumber(tok2->strAt(4));
const MathLib::bigint num2 = MathLib::toBigNumber(tok2->strAt(4));
if (0 == (num & num2))
mismatchingBitAndError(assignTok, num, tok2, num2);
}
if (Token::Match(tok2, "%varid% =", varid)) {
return true;
}
if (bitop == '&' && Token::Match(tok2, "%varid% &= %num% ;", varid)) {
const MathLib::bigint num2 = MathLib::toLongNumber(tok2->strAt(2));
const MathLib::bigint num2 = MathLib::toBigNumber(tok2->strAt(2));
if (0 == (num & num2))
mismatchingBitAndError(assignTok, num, tok2, num2);
}
Expand Down Expand Up @@ -212,7 +212,7 @@ bool CheckCondition::assignIfParseScope(const Token * const assignTok,
}
if (Token::Match(tok2,"&&|%oror%|( %varid% ==|!= %num% &&|%oror%|)", varid)) {
const Token *vartok = tok2->next();
const MathLib::bigint num2 = MathLib::toLongNumber(vartok->strAt(2));
const MathLib::bigint num2 = MathLib::toBigNumber(vartok->strAt(2));
if ((num & num2) != ((bitop=='&') ? num2 : num)) {
const std::string& op(vartok->strAt(1));
const bool alwaysTrue = op == "!=";
Expand Down Expand Up @@ -266,11 +266,11 @@ void CheckCondition::mismatchingBitAndError(const Token *tok1, const MathLib::bi
static void getnumchildren(const Token *tok, std::list<MathLib::bigint> &numchildren)
{
if (tok->astOperand1() && tok->astOperand1()->isNumber())
numchildren.push_back(MathLib::toLongNumber(tok->astOperand1()->str()));
numchildren.push_back(MathLib::toBigNumber(tok->astOperand1()->str()));
else if (tok->astOperand1() && tok->str() == tok->astOperand1()->str())
getnumchildren(tok->astOperand1(), numchildren);
if (tok->astOperand2() && tok->astOperand2()->isNumber())
numchildren.push_back(MathLib::toLongNumber(tok->astOperand2()->str()));
numchildren.push_back(MathLib::toBigNumber(tok->astOperand2()->str()));
else if (tok->astOperand2() && tok->str() == tok->astOperand2()->str())
getnumchildren(tok->astOperand2(), numchildren);
}
Expand Down Expand Up @@ -371,7 +371,7 @@ void CheckCondition::comparison()
std::swap(expr1,expr2);
if (!expr2->isNumber())
continue;
const MathLib::bigint num2 = MathLib::toLongNumber(expr2->str());
const MathLib::bigint num2 = MathLib::toBigNumber(expr2->str());
if (num2 < 0)
continue;
if (!Token::Match(expr1,"[&|]"))
Expand Down Expand Up @@ -463,8 +463,8 @@ bool CheckCondition::isOverlappingCond(const Token * const cond1, const Token *
if (!isSameExpression(mTokenizer->isCPP(), true, expr1, expr2, mSettings->library, pure, false))
return false;

const MathLib::bigint value1 = MathLib::toLongNumber(num1->str());
const MathLib::bigint value2 = MathLib::toLongNumber(num2->str());
const MathLib::bigint value1 = MathLib::toBigNumber(num1->str());
const MathLib::bigint value2 = MathLib::toBigNumber(num2->str());
if (cond2->str() == "&")
return ((value1 & value2) == value2);
return ((value1 & value2) > 0);
Expand Down Expand Up @@ -1267,11 +1267,11 @@ void CheckCondition::checkIncorrectLogicOperator()

const double d1 = (isfloat) ? MathLib::toDoubleNumber(value1) : 0;
const double d2 = (isfloat) ? MathLib::toDoubleNumber(value2) : 0;
const MathLib::bigint i1 = (isfloat) ? 0 : MathLib::toLongNumber(value1);
const MathLib::bigint i2 = (isfloat) ? 0 : MathLib::toLongNumber(value2);
const MathLib::bigint i1 = (isfloat) ? 0 : MathLib::toBigNumber(value1);
const MathLib::bigint i2 = (isfloat) ? 0 : MathLib::toBigNumber(value2);
const bool useUnsignedInt = (std::numeric_limits<MathLib::bigint>::max()==i1) || (std::numeric_limits<MathLib::bigint>::max()==i2);
const MathLib::biguint u1 = (useUnsignedInt) ? MathLib::toLongNumber(value1) : 0;
const MathLib::biguint u2 = (useUnsignedInt) ? MathLib::toLongNumber(value2) : 0;
const MathLib::biguint u1 = (useUnsignedInt) ? MathLib::toBigNumber(value1) : 0;
const MathLib::biguint u2 = (useUnsignedInt) ? MathLib::toBigNumber(value2) : 0;
// evaluate if expression is always true/false
bool alwaysTrue = true, alwaysFalse = true;
bool firstTrue = true, secondTrue = true;
Expand Down
6 changes: 3 additions & 3 deletions lib/checkfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,12 @@ void CheckFunctions::checkMathFunctions()
if (tok->strAt(-1) != "."
&& Token::Match(tok, "log|logf|logl|log10|log10f|log10l|log2|log2f|log2l ( %num% )")) {
const std::string& number = tok->strAt(2);
if ((MathLib::isInt(number) && MathLib::toLongNumber(number) <= 0) ||
if ((MathLib::isInt(number) && MathLib::toBigNumber(number) <= 0) ||
(MathLib::isFloat(number) && MathLib::toDoubleNumber(number) <= 0.))
mathfunctionCallWarning(tok);
} else if (Token::Match(tok, "log1p|log1pf|log1pl ( %num% )")) {
const std::string& number = tok->strAt(2);
if ((MathLib::isInt(number) && MathLib::toLongNumber(number) <= -1) ||
if ((MathLib::isInt(number) && MathLib::toBigNumber(number) <= -1) ||
(MathLib::isFloat(number) && MathLib::toDoubleNumber(number) <= -1.))
mathfunctionCallWarning(tok);
}
Expand Down Expand Up @@ -575,7 +575,7 @@ void CheckFunctions::memsetInvalid2ndParam()
}

if (printWarning && secondParamTok->isNumber()) { // Check if the second parameter is a literal and is out of range
const long long int value = MathLib::toLongNumber(secondParamTok->str());
const long long int value = MathLib::toBigNumber(secondParamTok->str());
const long long sCharMin = mSettings->platform.signedCharMin();
const long long uCharMax = mSettings->platform.unsignedCharMax();
if (value < sCharMin || value > uCharMax)
Expand Down
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,

// Assigning non-zero value variable. It might be used to
// track the execution for a later if condition.
if (Token::Match(varTok->tokAt(2), "%num% ;") && MathLib::toLongNumber(varTok->strAt(2)) != 0)
if (Token::Match(varTok->tokAt(2), "%num% ;") && MathLib::toBigNumber(varTok->strAt(2)) != 0)
notzero.insert(varTok->varId());
else if (Token::Match(varTok->tokAt(2), "- %type% ;") && varTok->tokAt(3)->isUpperCaseName())
notzero.insert(varTok->varId());
Expand Down
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3085,7 +3085,7 @@ void CheckOther::checkIncompleteArrayFill()
if (!var || !var->isArray() || var->dimensions().empty() || !var->dimension(0))
continue;

if (MathLib::toLongNumber(tok->linkAt(1)->strAt(-1)) == var->dimension(0)) {
if (MathLib::toBigNumber(tok->linkAt(1)->strAt(-1)) == var->dimension(0)) {
int size = mTokenizer->sizeOfType(var->typeStartToken());
if (size == 0 && var->valueType()->pointer)
size = mSettings->platform.sizeof_pointer;
Expand Down
2 changes: 1 addition & 1 deletion lib/checkstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void CheckString::checkIncorrectStringCompare()
tok = tok->next()->link();

if (Token::simpleMatch(tok, ". substr (") && Token::Match(tok->tokAt(3)->nextArgument(), "%num% )")) {
const MathLib::biguint clen = MathLib::toULongNumber(tok->linkAt(2)->strAt(-1));
const MathLib::biguint clen = MathLib::toBigUNumber(tok->linkAt(2)->strAt(-1));
const Token* begin = tok->previous();
for (;;) { // Find start of statement
while (begin->link() && Token::Match(begin, "]|)|>"))
Expand Down
8 changes: 4 additions & 4 deletions lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<nonneg i
return;

if (tok->str() == "==")
*alwaysTrue = (it->second == MathLib::toLongNumber(numtok->str()));
*alwaysTrue = (it->second == MathLib::toBigNumber(numtok->str()));
else if (tok->str() == "!=")
*alwaysTrue = (it->second != MathLib::toLongNumber(numtok->str()));
*alwaysTrue = (it->second != MathLib::toBigNumber(numtok->str()));
else
return;
*alwaysFalse = !(*alwaysTrue);
Expand Down Expand Up @@ -517,7 +517,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
if (Token::Match(tok2, "[;{}.] %name% = - %name% ;"))
varValueIf[tok2->next()->varId()] = !VariableValue(0);
else if (Token::Match(tok2, "[;{}.] %name% = %num% ;"))
varValueIf[tok2->next()->varId()] = VariableValue(MathLib::toLongNumber(tok2->strAt(3)));
varValueIf[tok2->next()->varId()] = VariableValue(MathLib::toBigNumber(tok2->strAt(3)));
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
if (nodeType == BreakStmt)
return addtoken(tokenList, "break");
if (nodeType == CharacterLiteral) {
const int c = MathLib::toLongNumber(mExtTokens.back());
const int c = MathLib::toBigNumber(mExtTokens.back());
if (c == 0)
return addtoken(tokenList, "\'\\0\'");
if (c == '\r')
Expand Down
8 changes: 4 additions & 4 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,13 @@ bool Library::isIntArgValid(const Token *ftok, int argnr, const MathLib::bigint
TokenList tokenList(nullptr);
gettokenlistfromvalid(ac->valid, tokenList);
for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
if (tok->isNumber() && argvalue == MathLib::toLongNumber(tok->str()))
if (tok->isNumber() && argvalue == MathLib::toBigNumber(tok->str()))
return true;
if (Token::Match(tok, "%num% : %num%") && argvalue >= MathLib::toLongNumber(tok->str()) && argvalue <= MathLib::toLongNumber(tok->strAt(2)))
if (Token::Match(tok, "%num% : %num%") && argvalue >= MathLib::toBigNumber(tok->str()) && argvalue <= MathLib::toBigNumber(tok->strAt(2)))
return true;
if (Token::Match(tok, "%num% : ,") && argvalue >= MathLib::toLongNumber(tok->str()))
if (Token::Match(tok, "%num% : ,") && argvalue >= MathLib::toBigNumber(tok->str()))
return true;
if ((!tok->previous() || tok->previous()->str() == ",") && Token::Match(tok,": %num%") && argvalue <= MathLib::toLongNumber(tok->strAt(1)))
if ((!tok->previous() || tok->previous()->str() == ",") && Token::Match(tok,": %num%") && argvalue <= MathLib::toBigNumber(tok->strAt(1)))
return true;
}
return false;
Expand Down
Loading

0 comments on commit fe8730c

Please sign in to comment.