TokenList: append 'U' if needed on hexvalues
This commit is contained in:
parent
1c6c209353
commit
f0c353abcb
|
@ -129,7 +129,13 @@ void TokenList::addtoken(std::string str, const unsigned int lineno, const unsig
|
||||||
|
|
||||||
// Replace hexadecimal value with decimal
|
// Replace hexadecimal value with decimal
|
||||||
if (MathLib::isIntHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) {
|
if (MathLib::isIntHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) {
|
||||||
str = MathLib::value(str).str();
|
// TODO: It would be better if TokenList didn't simplify hexadecimal numbers
|
||||||
|
std::string suffix;
|
||||||
|
if (str.compare(0,2,"0x") == 0 &&
|
||||||
|
str.size() == (2 + _settings->int_bit / 4) &&
|
||||||
|
(str[2] >= '8')) // includes A-F and a-f
|
||||||
|
suffix = "U";
|
||||||
|
str = MathLib::value(str).str() + suffix;
|
||||||
} else if (str.compare(0, 5, "_Bool") == 0) {
|
} else if (str.compare(0, 5, "_Bool") == 0) {
|
||||||
str = "bool";
|
str = "bool";
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,12 +36,13 @@ private:
|
||||||
void run() {
|
void run() {
|
||||||
TEST_CASE(line1); // Ticket #4408
|
TEST_CASE(line1); // Ticket #4408
|
||||||
TEST_CASE(line2); // Ticket #5423
|
TEST_CASE(line2); // Ticket #5423
|
||||||
TEST_CASE(testaddtoken);
|
TEST_CASE(testaddtoken1);
|
||||||
|
TEST_CASE(testaddtoken2);
|
||||||
TEST_CASE(inc);
|
TEST_CASE(inc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// inspired by #5895
|
// inspired by #5895
|
||||||
void testaddtoken() {
|
void testaddtoken1() {
|
||||||
const std::string code = "0x89504e470d0a1a0a";
|
const std::string code = "0x89504e470d0a1a0a";
|
||||||
TokenList tokenlist(&settings);
|
TokenList tokenlist(&settings);
|
||||||
tokenlist.addtoken(code, 1, 1, false);
|
tokenlist.addtoken(code, 1, 1, false);
|
||||||
|
@ -55,6 +56,14 @@ private:
|
||||||
ASSERT_EQUALS(9894494448401390090U, numberULL);
|
ASSERT_EQUALS(9894494448401390090U, numberULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testaddtoken2() {
|
||||||
|
const std::string code = "0xF0000000";
|
||||||
|
settings.int_bit = 32;
|
||||||
|
TokenList tokenlist(&settings);
|
||||||
|
tokenlist.addtoken(code, 1, 1, false);
|
||||||
|
ASSERT_EQUALS("4026531840U", tokenlist.front()->str());
|
||||||
|
}
|
||||||
|
|
||||||
void line1() const {
|
void line1() const {
|
||||||
// Test for Ticket #4408
|
// Test for Ticket #4408
|
||||||
const char code[] = "#file \"c:\\a.h\"\n"
|
const char code[] = "#file \"c:\\a.h\"\n"
|
||||||
|
|
Loading…
Reference in New Issue