CPlusPlus: Properly categorize usages in if statements

Change-Id: I5f6e5fa14ea51cd9e61a9e2e96c110ca618be429
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Christian Kandeler
2020-11-04 12:38:40 +01:00
parent 8527cbedcc
commit cf6757406d
2 changed files with 11 additions and 3 deletions

View File

@@ -334,6 +334,8 @@ Usage::Type FindUsages::getType(int line, int column, int tokenIndex)
return Usage::Type::Read; return Usage::Type::Read;
if ((*it)->asCaseStatement()) if ((*it)->asCaseStatement())
return Usage::Type::Read; return Usage::Type::Read;
if ((*it)->asIfStatement())
return Usage::Type::Read;
if ((*it)->asLambdaCapture() || (*it)->asNamedTypeSpecifier() if ((*it)->asLambdaCapture() || (*it)->asNamedTypeSpecifier()
|| (*it)->asElaboratedTypeSpecifier()) { || (*it)->asElaboratedTypeSpecifier()) {
return Usage::Type::Other; return Usage::Type::Other;

View File

@@ -2084,6 +2084,8 @@ int main()
switch (S::value = 5) { switch (S::value = 5) {
default: break; default: break;
} }
if (S::value) {}
if (S::value = 0) {}
} }
)"; )";
@@ -2109,7 +2111,7 @@ int main()
// Access to struct member // Access to struct member
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot);
find(sv); find(sv);
QCOMPARE(find.usages().size(), 21); QCOMPARE(find.usages().size(), 23);
QCOMPARE(find.usages().at(0).type, Usage::Type::Read); QCOMPARE(find.usages().at(0).type, Usage::Type::Read);
QCOMPARE(find.usages().at(1).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(1).type, Usage::Type::Declaration);
QCOMPARE(find.usages().at(2).type, Usage::Type::WritableRef); QCOMPARE(find.usages().at(2).type, Usage::Type::WritableRef);
@@ -2131,6 +2133,8 @@ int main()
QCOMPARE(find.usages().at(18).type, Usage::Type::Read); QCOMPARE(find.usages().at(18).type, Usage::Type::Read);
QCOMPARE(find.usages().at(19).type, Usage::Type::Read); QCOMPARE(find.usages().at(19).type, Usage::Type::Read);
QCOMPARE(find.usages().at(20).type, Usage::Type::Write); QCOMPARE(find.usages().at(20).type, Usage::Type::Write);
QCOMPARE(find.usages().at(21).type, Usage::Type::Read);
QCOMPARE(find.usages().at(22).type, Usage::Type::Write);
Declaration * const sv2 = structS->memberAt(2)->asDeclaration(); Declaration * const sv2 = structS->memberAt(2)->asDeclaration();
QVERIFY(sv2); QVERIFY(sv2);
@@ -2147,7 +2151,7 @@ int main()
QCOMPARE(main->memberCount(), 1); QCOMPARE(main->memberCount(), 1);
Block * const block = main->memberAt(0)->asBlock(); Block * const block = main->memberAt(0)->asBlock();
QVERIFY(block); QVERIFY(block);
QCOMPARE(block->memberCount(), 15); QCOMPARE(block->memberCount(), 17);
// Access to pointer // Access to pointer
Declaration * const p = block->memberAt(1)->asDeclaration(); Declaration * const p = block->memberAt(1)->asDeclaration();
@@ -2213,7 +2217,7 @@ int main()
// Usages of struct type // Usages of struct type
find(structS); find(structS);
QCOMPARE(find.usages().size(), 8); QCOMPARE(find.usages().size(), 10);
QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration);
QCOMPARE(find.usages().at(1).type, Usage::Type::Other); QCOMPARE(find.usages().at(1).type, Usage::Type::Other);
QCOMPARE(find.usages().at(2).type, Usage::Type::Other); QCOMPARE(find.usages().at(2).type, Usage::Type::Other);
@@ -2225,6 +2229,8 @@ int main()
QCOMPARE(find.usages().at(5).type, Usage::Type::Read); QCOMPARE(find.usages().at(5).type, Usage::Type::Read);
QCOMPARE(find.usages().at(6).type, Usage::Type::Read); QCOMPARE(find.usages().at(6).type, Usage::Type::Read);
QCOMPARE(find.usages().at(7).type, Usage::Type::Write); QCOMPARE(find.usages().at(7).type, Usage::Type::Write);
QCOMPARE(find.usages().at(8).type, Usage::Type::Read);
QCOMPARE(find.usages().at(9).type, Usage::Type::Write);
} }
QTEST_APPLESS_MAIN(tst_FindUsages) QTEST_APPLESS_MAIN(tst_FindUsages)