Cppcheck
|
simple math functions that uses operands stored in std::string. More...
#include <mathlib.h>
Classes | |
class | value |
value class More... | |
Public Types | |
using | bigint = long long |
using | biguint = unsigned long long |
Static Public Member Functions | |
static bigint | toBigNumber (const std::string &str) |
for conversion of numeric literals - for atoi-like conversions please use strToInt() More... | |
static biguint | toBigUNumber (const std::string &str) |
for conversion of numeric literals - for atoi-like conversions please use strToInt() More... | |
template<class T > | |
static std::string | toString (T value)=delete |
static double | toDoubleNumber (const std::string &str) |
for conversion of numeric literals More... | |
static bool | isInt (const std::string &str) |
static bool | isFloat (const std::string &str) |
static bool | isDecimalFloat (const std::string &str) |
static bool | isNegative (const std::string &str) |
static bool | isPositive (const std::string &str) |
static bool | isDec (const std::string &str) |
static bool | isFloatHex (const std::string &str) |
static bool | isIntHex (const std::string &str) |
static bool | isOct (const std::string &str) |
Does the string represent an octal number? In case leading or trailing white space is provided, the function returns false. Additional information can be found here: http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html. More... | |
static bool | isBin (const std::string &str) |
Does the string represent a binary number? In case leading or trailing white space is provided, the function returns false. Additional information can be found here: http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html. More... | |
static std::string | getSuffix (const std::string &value) |
static bool | isValidIntegerSuffix (const std::string &str, bool supportMicrosoftExtensions=true) |
Only used in unit tests. More... | |
static std::string | add (const std::string &first, const std::string &second) |
static std::string | subtract (const std::string &first, const std::string &second) |
static std::string | multiply (const std::string &first, const std::string &second) |
static std::string | divide (const std::string &first, const std::string &second) |
static std::string | mod (const std::string &first, const std::string &second) |
static std::string | calculate (const std::string &first, const std::string &second, char action) |
static std::string | sin (const std::string &tok) |
static std::string | cos (const std::string &tok) |
static std::string | tan (const std::string &tok) |
static std::string | abs (const std::string &tok) |
static bool | isEqual (const std::string &first, const std::string &second) |
static bool | isNotEqual (const std::string &first, const std::string &second) |
static bool | isGreater (const std::string &first, const std::string &second) |
static bool | isGreaterEqual (const std::string &first, const std::string &second) |
static bool | isLess (const std::string &first, const std::string &second) |
static bool | isLessEqual (const std::string &first, const std::string &second) |
static bool | isNullValue (const std::string &str) |
Does the string represent the numerical value of 0? In case leading or trailing white space is provided, the function returns false. Requirement for this function: More... | |
static bool | isOctalDigit (char c) |
Return true if given character is 0,1,2,3,4,5,6 or 7. More... | |
static unsigned int | encodeMultiChar (const std::string &str) |
static bool | isDigitSeparator (const std::string &iCode, std::string::size_type iPos) |
template<> | |
std::string | toString (double value) |
template<> | |
CPPCHECKLIB std::string | toString (double value) |
Static Public Attributes | |
static const int | bigint_bits = 64 |
Friends | |
class | TestMathLib |
simple math functions that uses operands stored in std::string.
useful when performing math on tokens.
using MathLib::bigint = long long |
using MathLib::biguint = unsigned long long |
|
static |
Definition at line 1202 of file mathlib.cpp.
References isNegative().
Referenced by SymbolDatabase::setValueTypeInTokenList().
|
static |
Definition at line 1056 of file mathlib.cpp.
References intsuffix(), isInt(), toBigNumber(), toDoubleNumber(), and toString().
Referenced by calculate(), and TemplateSimplifier::simplifyNumericCalculations().
|
static |
Definition at line 1153 of file mathlib.cpp.
References add(), divide(), intsuffix(), mod(), multiply(), subtract(), and toBigNumber().
Referenced by TemplateSimplifier::simplifyNumericCalculations().
|
static |
Definition at line 1191 of file mathlib.cpp.
References toDoubleNumber(), and toString().
|
static |
Definition at line 1103 of file mathlib.cpp.
References intsuffix(), isInt(), isNullValue(), isPositive(), toBigNumber(), toDoubleNumber(), and toString().
Referenced by calculate(), and TemplateSimplifier::simplifyNumericCalculations().
|
static |
Definition at line 360 of file mathlib.cpp.
Referenced by calculate().
|
static |
Definition at line 1012 of file mathlib.cpp.
Referenced by TemplateSimplifier::getTemplateInstantiations(), intsuffix(), and TemplateSimplifier::simplifyCalculations().
|
static |
Does the string represent a binary number? In case leading or trailing white space is provided, the function returns false. Additional information can be found here: http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html.
str | The string to check. In case the string is empty, the function returns false. |
Definition at line 937 of file mathlib.cpp.
References isValidIntegerSuffixIt().
Referenced by isInt(), toBigNumber(), and toBigUNumber().
|
static |
Definition at line 978 of file mathlib.cpp.
References isValidIntegerSuffixIt().
Referenced by isInt(), and SymbolDatabase::setValueTypeInTokenList().
|
static |
Definition at line 540 of file mathlib.cpp.
Referenced by isFloat(), and toDoubleNumber().
|
static |
[in] | iCode | Code being considered |
[in] | iPos | A posision within iCode |
Definition at line 1277 of file mathlib.cpp.
|
static |
Definition at line 1209 of file mathlib.cpp.
References toDoubleNumber(), and toString().
Referenced by Library::isFloatArgValid(), and isNotEqual().
|
static |
Definition at line 535 of file mathlib.cpp.
References isDecimalFloat(), and isFloatHex().
Referenced by CheckCondition::checkIncorrectLogicOperator(), CheckFunctions::checkMathFunctions(), Tokenizer::dump(), Library::isFloatArgValid(), isNullValue(), isNumberOneOf(), parseComparison(), MathLib::value::promote(), SymbolDatabase::setValueTypeInTokenList(), TemplateSimplifier::simplifyCalculations(), toBigNumber(), toBigUNumber(), toDoubleNumber(), Token::update_property_info(), MathLib::value::value(), and valueFlowSetConstantValue().
|
static |
Definition at line 847 of file mathlib.cpp.
Referenced by isFloat(), isNullValue(), and toDoubleNumber().
|
static |
Definition at line 1222 of file mathlib.cpp.
References toDoubleNumber().
|
static |
Definition at line 1228 of file mathlib.cpp.
References toDoubleNumber().
|
static |
Definition at line 1007 of file mathlib.cpp.
References isBin(), isDec(), isIntHex(), and isOct().
Referenced by add(), CheckFunctions::checkMathFunctions(), divide(), Tokenizer::dump(), isNullOperand(), isNullValue(), isNumberOneOf(), mod(), multiply(), parseComparison(), MathLib::value::promote(), SymbolDatabase::setValueTypeInTokenList(), MathLib::value::shiftLeft(), MathLib::value::shiftRight(), TemplateSimplifier::simplifyCalculations(), TemplateSimplifier::simplifyTemplateArgs(), subtract(), Token::update_property_info(), MathLib::value::value(), valueFlowBitAnd(), and valueFlowSetConstantValue().
|
static |
Definition at line 806 of file mathlib.cpp.
References isValidIntegerSuffixIt().
Referenced by isInt(), isNullValue(), toBigNumber(), toBigUNumber(), toDoubleNumber(), and MathLib::value::value().
|
static |
Definition at line 1234 of file mathlib.cpp.
References toDoubleNumber().
|
static |
Definition at line 1239 of file mathlib.cpp.
References toDoubleNumber().
Referenced by CheckCondition::checkModuloAlwaysTrueFalse().
|
static |
Definition at line 636 of file mathlib.cpp.
Referenced by abs(), CheckFunctions::checkMathFunctions(), CheckCondition::isOverlappingCond(), isPositive(), and TemplateSimplifier::simplifyNumericCalculations().
|
static |
Definition at line 1216 of file mathlib.cpp.
References isEqual().
Referenced by Library::isFloatArgValid().
|
static |
Does the string represent the numerical value of 0? In case leading or trailing white space is provided, the function returns false. Requirement for this function:
[in] | str | The string to check. In case the string is empty, the function returns false. |
Definition at line 1253 of file mathlib.cpp.
References isFloat(), isFloatHex(), isInt(), and isIntHex().
Referenced by CheckFunctions::checkMathFunctions(), CheckOther::checkRedundantAssignment(), divide(), Scope::findFunction(), isNullOperand(), CheckFunctions::memsetInvalid2ndParam(), CheckFunctions::memsetZeroBytes(), and TemplateSimplifier::simplifyNumericCalculations().
|
static |
Does the string represent an octal number? In case leading or trailing white space is provided, the function returns false. Additional information can be found here: http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html.
str | The string to check. In case the string is empty, the function returns false. |
Definition at line 771 of file mathlib.cpp.
References isOctalDigit(), and isValidIntegerSuffixIt().
Referenced by isInt(), toBigNumber(), and toBigUNumber().
|
static |
Return true if given character is 0,1,2,3,4,5,6 or 7.
[in] | c | The character to check |
Definition at line 1272 of file mathlib.cpp.
Referenced by isOct().
|
static |
Definition at line 643 of file mathlib.cpp.
References isNegative().
Referenced by divide(), and Tokenizer::isOneNumber().
|
static |
Only used in unit tests.
[in] | str | string |
[in] | supportMicrosoftExtensions | support Microsoft extension: i64 |
Definition at line 755 of file mathlib.cpp.
References isValidIntegerSuffixIt().
Referenced by toBigNumber(), toBigUNumber(), and toDoubleNumber().
|
static |
Definition at line 1138 of file mathlib.cpp.
References intsuffix(), isInt(), toBigNumber(), toDoubleNumber(), and toString().
Referenced by calculate().
|
static |
Definition at line 1126 of file mathlib.cpp.
References intsuffix(), isInt(), toBigNumber(), toDoubleNumber(), and toString().
Referenced by calculate(), and TemplateSimplifier::simplifyNumericCalculations().
|
static |
Definition at line 1185 of file mathlib.cpp.
References toDoubleNumber(), and toString().
|
static |
Definition at line 1078 of file mathlib.cpp.
References intsuffix(), isInt(), toBigNumber(), toDoubleNumber(), and toString().
Referenced by calculate(), and TemplateSimplifier::simplifyNumericCalculations().
|
static |
Definition at line 1196 of file mathlib.cpp.
References toDoubleNumber(), and toString().
|
static |
for conversion of numeric literals - for atoi-like conversions please use strToInt()
Definition at line 368 of file mathlib.cpp.
References isBin(), isCharLiteral(), isFloat(), isIntHex(), isOct(), isValidIntegerSuffix(), and toDoubleNumber().
Referenced by add(), Variable::arrayDimensions(), CheckCondition::assignIf(), CheckCondition::assignIfParseScope(), calculate(), CheckOther::checkIncompleteArrayFill(), CheckCondition::checkIncorrectLogicOperator(), CheckFunctions::checkMathFunctions(), CheckLeakAutoVar::checkScope(), CheckCondition::comparison(), conditionAlwaysTrueOrFalse(), clangimport::AstNode::createTokens(), divide(), getnumchildren(), Library::isIntArgValid(), isNumberOneOf(), CheckCondition::isOverlappingCond(), CheckFunctions::memsetInvalid2ndParam(), mod(), multiply(), SymbolDatabase::setArrayDimensionsUsingValueFlow(), TemplateSimplifier::simplifyCalculations(), Tokenizer::simplifyCaseRange(), TemplateSimplifier::simplifyTemplateArgs(), subtract(), toDoubleNumber(), MathLib::value::value(), valueFlowBitAnd(), valueFlowSetConstantValue(), valueFlowSwitchVariable(), and Variable::Variable().
|
static |
for conversion of numeric literals - for atoi-like conversions please use strToInt()
Definition at line 289 of file mathlib.cpp.
References isBin(), isCharLiteral(), isFloat(), isIntHex(), isOct(), isValidIntegerSuffix(), and toDoubleNumber().
Referenced by Tokenizer::arraySize(), CheckString::checkIncorrectStringCompare(), SymbolDatabase::setValueTypeInTokenList(), and valueFlowSetConstantValue().
|
static |
for conversion of numeric literals
Definition at line 487 of file mathlib.cpp.
References floatHexToDoubleNumber(), isCharLiteral(), isDecimalFloat(), isFloat(), isFloatHex(), isIntHex(), isValidIntegerSuffix(), and toBigNumber().
Referenced by add(), CheckCondition::checkIncorrectLogicOperator(), CheckFunctions::checkMathFunctions(), cos(), divide(), isEqual(), Library::isFloatArgValid(), isGreater(), isGreaterEqual(), isLess(), isLessEqual(), isNumberOneOf(), mod(), multiply(), sin(), subtract(), tan(), toBigNumber(), toBigUNumber(), MathLib::value::value(), and valueFlowSetConstantValue().
|
static |
Definition at line 522 of file mathlib.cpp.
References MathLib::value::str().
|
staticdelete |
Referenced by add(), cos(), divide(), ValueFlow::Value::infoString(), isEqual(), Library::isFloatArgValid(), isNumberOneOf(), mod(), multiply(), sin(), subtract(), tan(), and valueFlowSafeFunctions().
|
static |
Definition at line 70 of file mathlib.h.
Referenced by castValue(), CheckType::checkIntegerOverflow(), MathLib::value::shiftLeft(), MathLib::value::shiftRight(), valueFlowBitAnd(), and valueFlowRightShift().