From fe9a03383433e0b1c7be89dbcaa4bf06b08f45cf Mon Sep 17 00:00:00 2001 From: swasti16 Date: Mon, 12 Aug 2024 16:03:58 +0530 Subject: [PATCH] Fix 13009: Add valueType-originalTypeName for isCast Tok --- lib/tokenize.cpp | 7 ++++--- test/testsymboldatabase.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d9f1131f519..f4bcf957477 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -781,7 +781,8 @@ namespace { const bool isFunctionPointer = Token::Match(mNameToken, "%name% )"); if (isFunctionPointer && isCast(tok->previous())) { tok->insertToken("*"); - insertTokens(tok, std::pair(mRangeType.first, mNameToken->linkAt(1))); + Token* const tok_1 = insertTokens(tok, std::pair(mRangeType.first, mNameToken->linkAt(1))); + tok_1->originalName(tok->str()); tok->deleteThis(); return; } @@ -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; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 7a4af16df6e..ffb640daf9b 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -596,6 +596,7 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(incomplete_type); // #9255 (infinite recursion) TEST_CASE(exprIds); + TEST_CASE(testValuetypeOriginalName); } void array() { @@ -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)