Skip to content

Commit

Permalink
Fix #13009: Add valueType-originalTypeName (#6686)
Browse files Browse the repository at this point in the history
  • Loading branch information
swasti16 authored Aug 13, 2024
1 parent 5fecde1 commit 35a0df1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,8 @@ namespace {
const bool isFunctionPointer = Token::Match(mNameToken, "%name% )");
if (isFunctionPointer && isCast(tok->previous())) {
tok->insertToken("*");
insertTokens(tok, std::pair<Token*, Token*>(mRangeType.first, mNameToken->linkAt(1)));
Token* const tok_1 = insertTokens(tok, std::pair<Token*, Token*>(mRangeType.first, mNameToken->linkAt(1)));
tok_1->originalName(tok->str());
tok->deleteThis();
return;
}
Expand Down Expand Up @@ -1041,8 +1042,8 @@ namespace {

private:
static bool isCast(const Token* tok) {
if (Token::Match(tok, "( %name% ) (|%name%"))
return !tok->tokAt(2)->isKeyword();
if (Token::Match(tok, "( %name% ) (|%name%|%num%"))
return !tok->tokAt(3)->isKeyword();
if (Token::Match(tok, "< %name% > (") && tok->previous() && endsWith(tok->strAt(-1), "_cast", 5))
return true;
return false;
Expand Down
29 changes: 29 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ class TestSymbolDatabase : public TestFixture {

TEST_CASE(incomplete_type); // #9255 (infinite recursion)
TEST_CASE(exprIds);
TEST_CASE(testValuetypeOriginalName);
}

void array() {
Expand Down Expand Up @@ -10821,6 +10822,34 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS(true, testExprIdNotEqual(code, "(", 3U, "(", 4U));
}
}

void testValuetypeOriginalName() {
{
GET_SYMBOL_DB("typedef void ( *fp16 )( int16_t n );\n"
"typedef void ( *fp32 )( int32_t n );\n"
"void R_11_1 ( void ) {\n"
" fp16 fp1 = NULL;\n"
" fp32 fp2 = ( fp32) fp1;\n"
"}\n");
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "( void * ) fp1");
ASSERT_EQUALS(tok->isCast(), true);
ASSERT(tok->valueType());
ASSERT(tok->valueType()->originalTypeName == "fp32");
ASSERT(tok->valueType()->pointer == 1);
ASSERT(tok->valueType()->constness == 0);
}

{
GET_SYMBOL_DB("typedef void ( *fp16 )( int16_t n );\n"
"fp16 fp3 = ( fp16 ) 0x8000;");
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "( void * ) 0x8000");
ASSERT_EQUALS(tok->isCast(), true);
ASSERT(tok->valueType());
ASSERT(tok->valueType()->originalTypeName == "fp16");
ASSERT(tok->valueType()->pointer == 1);
ASSERT(tok->valueType()->constness == 0);
}
}
};

REGISTER_TEST(TestSymbolDatabase)

0 comments on commit 35a0df1

Please sign in to comment.