Some initial support for platforms that doesn't have 8-bit char

This commit is contained in:
Daniel Marjamäki 2016-01-05 13:16:00 +01:00
parent b73090c351
commit 125d2f7a36
4 changed files with 41 additions and 5 deletions

View File

@ -60,11 +60,11 @@ void CheckType::checkTooBigBitwiseShift()
continue;
int lhsbits = 0;
if (lhstype->type <= ValueType::Type::INT)
lhsbits = 8 * _settings->sizeof_int;
lhsbits = _settings->int_bit;
else if (lhstype->type == ValueType::Type::LONG)
lhsbits = 8 * _settings->sizeof_long;
lhsbits = _settings->long_bit;
else if (lhstype->type == ValueType::Type::LONGLONG)
lhsbits = 8 * _settings->sizeof_long_long;
lhsbits = _settings->long_long_bit;
else
continue;
@ -105,7 +105,7 @@ void CheckType::checkIntegerOverflow()
return;
// max int value according to platform settings.
const MathLib::bigint maxint = (1LL << (8 * _settings->sizeof_int - 1)) - 1;
const MathLib::bigint maxint = (1LL << (_settings->int_bit - 1)) - 1;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();

View File

@ -154,6 +154,11 @@ bool Settings::platform(PlatformType type)
sizeof_size_t = sizeof(std::size_t);
sizeof_pointer = sizeof(void *);
defaultSign = '\0';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
return true;
case Native: // same as system this code was compile on
platformType = type;
@ -172,6 +177,11 @@ bool Settings::platform(PlatformType type)
int x = 2;
defaultSign = (-10 / x == -5) ? 's' : 'u';
}
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
return true;
case Win32W:
case Win32A:
@ -188,6 +198,11 @@ bool Settings::platform(PlatformType type)
sizeof_size_t = 4;
sizeof_pointer = 4;
defaultSign = '\0';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
return true;
case Win64:
platformType = type;
@ -203,6 +218,11 @@ bool Settings::platform(PlatformType type)
sizeof_size_t = 8;
sizeof_pointer = 8;
defaultSign = '\0';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
return true;
case Unix32:
platformType = type;
@ -218,6 +238,11 @@ bool Settings::platform(PlatformType type)
sizeof_size_t = 4;
sizeof_pointer = 4;
defaultSign = '\0';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
return true;
case Unix64:
platformType = type;
@ -233,6 +258,11 @@ bool Settings::platform(PlatformType type)
sizeof_size_t = 8;
sizeof_pointer = 8;
defaultSign = '\0';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
return true;
}

View File

@ -243,6 +243,12 @@ public:
/** Struct contains standards settings */
Standards standards;
unsigned int char_bit; /// bits in char
unsigned int short_bit; /// bits in short
unsigned int int_bit; /// bits in int
unsigned int long_bit; /// bits in long
unsigned int long_long_bit; /// bits in long long
/** size of standard types */
unsigned int sizeof_bool;
unsigned int sizeof_short;

View File

@ -4909,7 +4909,7 @@ void Tokenizer::simplifyCasts()
// #4164 : ((unsigned char)1) => (1)
if (Token::Match(tok->next(), "( %type% ) %num%") && tok->next()->link()->previous()->isStandardType()) {
const MathLib::bigint value = MathLib::toLongNumber(tok->next()->link()->next()->str());
unsigned int bits = 8 * _typeSize[tok->next()->link()->previous()->str()];
unsigned int bits = _settings->char_bit * _typeSize[tok->next()->link()->previous()->str()];
if (!tok->tokAt(2)->isUnsigned() && bits > 0)
bits--;
if (bits < 31 && value >= 0 && value < (1LL << bits)) {