From f0c353abcb7d5a433545b3ba92675b51ad73dd87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 4 Mar 2017 08:47:53 +0100 Subject: [PATCH] TokenList: append 'U' if needed on hexvalues --- lib/tokenlist.cpp | 8 +++++++- test/testtokenlist.cpp | 13 +++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 20955eee6..6873c1129 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -129,7 +129,13 @@ void TokenList::addtoken(std::string str, const unsigned int lineno, const unsig // Replace hexadecimal value with decimal 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) { str = "bool"; } diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index ac0a2296a..a332cdcf3 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -36,12 +36,13 @@ private: void run() { TEST_CASE(line1); // Ticket #4408 TEST_CASE(line2); // Ticket #5423 - TEST_CASE(testaddtoken); + TEST_CASE(testaddtoken1); + TEST_CASE(testaddtoken2); TEST_CASE(inc); } // inspired by #5895 - void testaddtoken() { + void testaddtoken1() { const std::string code = "0x89504e470d0a1a0a"; TokenList tokenlist(&settings); tokenlist.addtoken(code, 1, 1, false); @@ -55,6 +56,14 @@ private: 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 { // Test for Ticket #4408 const char code[] = "#file \"c:\\a.h\"\n"