forked from qt-creator/qt-creator
CPlusPlus: Add new usage tag "Template"
For use in follow-up patch. Change-Id: I49c057280be9b09862a89fa385a7396f1b1093bb Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -274,6 +274,10 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto it2 = it; it2 != m_astPath.rend(); ++it2) {
|
||||
if ((*it2)->asTemplateDeclaration())
|
||||
return tags |= Usage::Tag::Template;
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
if (const auto retStmt = (*it)->asReturnStatement()) {
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
WritableRef = 1 << 3,
|
||||
Override = 1 << 4,
|
||||
MocInvokable = 1 << 5,
|
||||
Template = 1 << 6,
|
||||
};
|
||||
using Tags = QFlags<Tag>;
|
||||
|
||||
|
||||
@@ -360,6 +360,22 @@ static Usage::Tags getUsageType(const ClangdAstPath &path, const QString &search
|
||||
if (path.last().role() == "expression" && path.last().kind() == "CXXConstruct")
|
||||
invokedConstructor = path.last().detail().value_or(QString());
|
||||
const auto isPotentialWrite = [&] { return potentialWrite && !isFunction; };
|
||||
const auto isSomeSortOfTemplate = [&](auto declPathIt) {
|
||||
if (declPathIt->kind() == "Function") {
|
||||
const auto children = declPathIt->children().value_or(QList<ClangdAstNode>());
|
||||
for (const ClangdAstNode &child : children) {
|
||||
if (child.role() == "template argument")
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (; declPathIt != path.rend(); ++declPathIt) {
|
||||
if (declPathIt->kind() == "FunctionTemplate" || declPathIt->kind() == "ClassTemplate"
|
||||
|| declPathIt->kind() == "ClassTemplatePartialSpecialization") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
for (auto pathIt = path.rbegin(); pathIt != path.rend(); ++pathIt) {
|
||||
if (pathIt->arcanaContains("non_odr_use_unevaluated"))
|
||||
return {};
|
||||
@@ -414,6 +430,8 @@ static Usage::Tags getUsageType(const ClangdAstPath &path, const QString &search
|
||||
tags |= Usage::Tag::MocInvokable;
|
||||
}
|
||||
}
|
||||
if (isSomeSortOfTemplate(pathIt))
|
||||
tags |= Usage::Tag::Template;
|
||||
return tags;
|
||||
}
|
||||
if (pathIt->kind() == "MemberInitializer")
|
||||
|
||||
@@ -1134,7 +1134,7 @@ void tst_FindUsages::templateClassParameters()
|
||||
findUsages(templArgument);
|
||||
QCOMPARE(findUsages.usages().size(), 5);
|
||||
QCOMPARE(findUsages.usages().at(0).tags, Usage::Tag::Declaration);
|
||||
QCOMPARE(findUsages.usages().at(1).tags, Usage::Tags());
|
||||
QCOMPARE(findUsages.usages().at(1).tags, Usage::Tag::Template);
|
||||
QCOMPARE(findUsages.usages().at(2).tags, Usage::Tags());
|
||||
QCOMPARE(findUsages.usages().at(3).tags, Usage::Tags());
|
||||
QCOMPARE(findUsages.usages().at(4).tags, Usage::Tags());
|
||||
@@ -1221,7 +1221,7 @@ void tst_FindUsages::templateFunctionParameters()
|
||||
QCOMPARE(findUsages.usages().size(), 4);
|
||||
QCOMPARE(findUsages.usages().at(0).tags, Usage::Tag::Declaration);
|
||||
QCOMPARE(findUsages.usages().at(1).tags, Usage::Tags());
|
||||
QCOMPARE(findUsages.usages().at(2).tags, Usage::Tags());
|
||||
QCOMPARE(findUsages.usages().at(2).tags, Usage::Tag::Template);
|
||||
QCOMPARE(findUsages.usages().at(3).tags, Usage::Tags());
|
||||
}
|
||||
|
||||
@@ -1253,7 +1253,8 @@ void tst_FindUsages::templatedFunction_QTCREATORBUG9749()
|
||||
FindUsages findUsages(src, doc, snapshot, true);
|
||||
findUsages(func);
|
||||
QCOMPARE(findUsages.usages().size(), 2);
|
||||
QCOMPARE(findUsages.usages().at(0).tags, Usage::Tag::Declaration);
|
||||
QCOMPARE(findUsages.usages().at(0).tags,
|
||||
(Usage::Tags{Usage::Tag::Declaration, Usage::Tag::Template}));
|
||||
QCOMPARE(findUsages.usages().at(1).tags, Usage::Tags());
|
||||
}
|
||||
|
||||
@@ -1458,7 +1459,8 @@ void tst_FindUsages::memberAccessAsTemplate()
|
||||
FindUsages find(src, doc, snapshot, true);
|
||||
find(f);
|
||||
QCOMPARE(find.usages().size(), 2);
|
||||
QCOMPARE(find.usages()[0].tags, Usage::Tag::Declaration);
|
||||
QCOMPARE(find.usages()[0].tags,
|
||||
(Usage::Tags{Usage::Tag::Declaration, Usage::Tag::Template}));
|
||||
QCOMPARE(find.usages()[0].line, 4);
|
||||
QCOMPARE(find.usages()[0].col, 7);
|
||||
QCOMPARE(find.usages()[1].tags, Usage::Tags());
|
||||
|
||||
Reference in New Issue
Block a user