Skip to content

Commit 1f3365c

Browse files
committed
Add Valuetype type and sign for stdint macros
1 parent c0b4c73 commit 1f3365c

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7531,6 +7531,15 @@ static const Function* getFunction(const Token* tok) {
75317531
return nullptr;
75327532
}
75337533

7534+
static int getIntegerConstantMacroWidth(const std::string &name) {
7535+
int intnum = 0;
7536+
for (const char c : name) {
7537+
if (std::isdigit(c))
7538+
intnum = (intnum * 10) + std::atoi(&c);
7539+
}
7540+
return intnum;
7541+
}
7542+
75347543
void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *tokens)
75357544
{
75367545
if (!tokens)
@@ -7672,6 +7681,27 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
76727681
}
76737682
}
76747683

7684+
// functions from stdint.h
7685+
else if (Token::Match(tok->previous(), "INT16_C|INT32_C|INT64_C|INT8_C|UINT16_C|UINT32_C|UINT64_C|UINT8_C (")) {
7686+
ValueType valuetype;
7687+
const int macroWidth = getIntegerConstantMacroWidth(tok->previous()->str());
7688+
if (macroWidth == 8)
7689+
valuetype.type = ValueType::Type::CHAR;
7690+
else if (macroWidth == 16)
7691+
valuetype.type = ValueType::Type::SHORT;
7692+
else if (macroWidth == 32)
7693+
valuetype.type = ValueType::Type::INT;
7694+
else if (macroWidth == 64)
7695+
valuetype.type = ValueType::Type::LONGLONG;
7696+
else
7697+
valuetype.type = ValueType::Type::INT;
7698+
if (tok->previous()->str()[0] == 'U')
7699+
valuetype.sign = ValueType::Sign::UNSIGNED;
7700+
else
7701+
valuetype.sign = ValueType::Sign::SIGNED;
7702+
setValueType(tok, valuetype);
7703+
}
7704+
76757705
// function style cast
76767706
else if (tok->previous() && tok->previous()->isStandardType()) {
76777707
ValueType valuetype;

test/testsymboldatabase.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ class TestSymbolDatabase : public TestFixture {
622622
TEST_CASE(dumpFriend); // Check if isFriend added to dump file
623623

624624
TEST_CASE(smartPointerLookupCtor); // #13719);
625+
626+
TEST_CASE(stdintFunction);
625627
}
626628

627629
void array() {
@@ -11317,6 +11319,16 @@ class TestSymbolDatabase : public TestFixture {
1131711319

1131811320
ASSERT(db);
1131911321
}
11322+
11323+
void stdintFunction() {
11324+
GET_SYMBOL_DB("static void example1(void){\n"
11325+
" uint32_t val = 1000;\n"
11326+
" uint8_t a = (uint8_t)(val / UINT32_C(60));\n"
11327+
"}\n");
11328+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "UINT32_C (");
11329+
ASSERT_EQUALS(tok->next()->valueType()->sign, ValueType::Sign::UNSIGNED);
11330+
ASSERT_EQUALS(tok->next()->valueType()->type, ValueType::Type::INT);
11331+
}
1132011332
};
1132111333

1132211334
REGISTER_TEST(TestSymbolDatabase)

0 commit comments

Comments
 (0)