Skip to content

Commit 36a55d2

Browse files
committed
casts
1 parent b7074e6 commit 36a55d2

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,23 @@ namespace {
16011601
ExprIdKey key;
16021602
key.parentOp = tok->astParent()->str();
16031603

1604+
if (tok->astParent()->isCast() && tok->astParent()->str() == "(") {
1605+
const Token* typeStartToken;
1606+
const Token* typeEndToken;
1607+
if (tok->astParent()->astOperand2()) {
1608+
typeStartToken = tok->astParent()->astOperand1();
1609+
typeEndToken = tok;
1610+
} else {
1611+
typeStartToken = tok->astParent()->next();
1612+
typeEndToken = tok->astParent()->link();
1613+
}
1614+
std::string type;
1615+
for (const Token* t = typeStartToken; t != typeEndToken; t = t->next()) {
1616+
type += " " + t->str();
1617+
}
1618+
key.parentOp += type;
1619+
}
1620+
16041621
const auto& refs1 = followAllReferences(op1);
16051622
const auto& refs2 = followAllReferences(op2);
16061623

test/testvarid.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ class TestVarID : public TestFixture {
241241
TEST_CASE(exprid4);
242242
TEST_CASE(exprid5);
243243
TEST_CASE(exprid6);
244+
TEST_CASE(exprid7);
244245

245246
TEST_CASE(structuredBindings);
246247
}
@@ -3943,6 +3944,19 @@ class TestVarID : public TestFixture {
39433944
ASSERT_EQUALS(expected, tokenizeExpr(code));
39443945
}
39453946

3947+
void exprid7() {
3948+
// different casts
3949+
const char code[] = "void foo(int a) {\n"
3950+
" if ((char)a == (short)a) {}\n"
3951+
" if ((char)a == (short)a) {}\n"
3952+
"}\n";
3953+
const char expected[] = "1: void foo ( int a ) {\n"
3954+
"2: if ( (@2 char ) a@1 ==@4 (@3 short ) a@1 ) { }\n"
3955+
"3: if ( (@2 char ) a@1 ==@4 (@3 short ) a@1 ) { }\n"
3956+
"4: }\n";
3957+
ASSERT_EQUALS(expected, tokenizeExpr(code));
3958+
}
3959+
39463960
void structuredBindings() {
39473961
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
39483962
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",

0 commit comments

Comments
 (0)