Fix some clang warnings about type conversions
This commit is contained in:
parent
9ac83d7624
commit
718e42f5ca
|
@ -205,7 +205,7 @@ static const Signaltype listofsignals[] = {
|
|||
* \return size of array
|
||||
* */
|
||||
template<typename T, int size>
|
||||
int GetArrayLength(const T(&)[size])
|
||||
size_t GetArrayLength(const T(&)[size])
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -21,60 +21,10 @@
|
|||
#include "mathlib.h"
|
||||
#include "errorlogger.h"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <cctype>
|
||||
#include <limits>
|
||||
|
||||
MathLib::bigint MathLib::toLongNumber(const std::string &str)
|
||||
{
|
||||
// hexadecimal numbers:
|
||||
if (isHex(str)) {
|
||||
if (str[0] == '-') {
|
||||
bigint ret = 0;
|
||||
std::istringstream istr(str);
|
||||
istr >> std::hex >> ret;
|
||||
return ret;
|
||||
} else {
|
||||
unsigned long long ret = 0;
|
||||
std::istringstream istr(str);
|
||||
istr >> std::hex >> ret;
|
||||
return (bigint)ret;
|
||||
}
|
||||
}
|
||||
|
||||
// octal numbers:
|
||||
if (isOct(str)) {
|
||||
bigint ret = 0;
|
||||
std::istringstream istr(str);
|
||||
istr >> std::oct >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// binary numbers:
|
||||
if (isBin(str)) {
|
||||
bigint ret = 0;
|
||||
for (std::string::size_type i = str[0] == '0'?2:3; i < str.length(); i++) {
|
||||
ret <<= 1;
|
||||
if (str[i] == '1')
|
||||
ret |= 1;
|
||||
}
|
||||
if (str[0] == '-')
|
||||
ret = -ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (isFloat(str))
|
||||
return static_cast<bigint>(std::atof(str.c_str()));
|
||||
|
||||
bigint ret = 0;
|
||||
std::istringstream istr(str);
|
||||
istr >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
double MathLib::toDoubleNumber(const std::string &str)
|
||||
{
|
||||
if (isHex(str))
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define mathlibH
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "config.h"
|
||||
|
@ -35,7 +36,53 @@ public:
|
|||
typedef long long bigint;
|
||||
typedef unsigned long long biguint;
|
||||
|
||||
static bigint toLongNumber(const std::string & str);
|
||||
template < class T = bigint >
|
||||
static T toLongNumber(const std::string & str) {
|
||||
// hexadecimal numbers:
|
||||
if (isHex(str)) {
|
||||
if (str[0] == '-') {
|
||||
T ret = 0;
|
||||
std::istringstream istr(str);
|
||||
istr >> std::hex >> ret;
|
||||
return ret;
|
||||
} else {
|
||||
unsigned long long ret = 0;
|
||||
std::istringstream istr(str);
|
||||
istr >> std::hex >> ret;
|
||||
return (T)ret;
|
||||
}
|
||||
}
|
||||
|
||||
// octal numbers:
|
||||
if (isOct(str)) {
|
||||
T ret = 0;
|
||||
std::istringstream istr(str);
|
||||
istr >> std::oct >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// binary numbers:
|
||||
if (isBin(str)) {
|
||||
T ret = 0;
|
||||
for (std::string::size_type i = str[0] == '0'?2:3; i < str.length(); i++) {
|
||||
ret <<= 1;
|
||||
if (str[i] == '1')
|
||||
ret |= 1;
|
||||
}
|
||||
if (str[0] == '-')
|
||||
ret = -ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (isFloat(str))
|
||||
return static_cast<T>(std::atof(str.c_str()));
|
||||
|
||||
T ret = 0;
|
||||
std::istringstream istr(str);
|
||||
istr >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T> static std::string toString(T value) {
|
||||
std::ostringstream result;
|
||||
result << value;
|
||||
|
|
|
@ -803,8 +803,8 @@ static bool isLowerEqualThanMulDiv(const Token* lower)
|
|||
template <typename T>
|
||||
std::string typeCorrectShift(const char cop, const Token* left, const Token* right)
|
||||
{
|
||||
const T leftInt=MathLib::toLongNumber(left->str());
|
||||
const T rightInt=MathLib::toLongNumber(right->str());
|
||||
const T leftInt=MathLib::toLongNumber<T>(left->str());
|
||||
const T rightInt=MathLib::toLongNumber<T>(right->str());
|
||||
|
||||
if (cop == '&' || cop == '|' || cop == '^')
|
||||
return MathLib::calculate(left->str(), right->str(), cop);
|
||||
|
|
Loading…
Reference in New Issue