Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13009: Add valueType-originalTypeName #6686

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading