[clang-tools-extra] Symbol tags in SymbolInformation, WorkspaceSymbol, CallHierarchyItem and TypeHierarchyItem (PR #170103)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 29 05:30:37 PDT 2026
================
@@ -153,10 +192,55 @@ bool isUniqueDefinition(const NamedDecl *Decl) {
isa<TemplateTemplateParmDecl>(Decl) || isa<ObjCCategoryDecl>(Decl) ||
isa<ObjCImplDecl>(Decl);
}
+
+// Filter symbol tags based on the presence of other tags and the kind of
+// symbol. This is needed to avoid redundant tags, e.g. Overrides implies
+// Virtual and Implements implies Overrides/Virtual.
+SymbolTags filterSymbolTags(SymbolTags ST) {
+ const SymbolTags VirtualMask = toSymbolTagBitmask(SymbolTag::Virtual);
+ const SymbolTags OverridesMask = toSymbolTagBitmask(SymbolTag::Overrides);
+ const SymbolTags ImplementsMask = toSymbolTagBitmask(SymbolTag::Implements);
+ const SymbolTags AbstractMask = toSymbolTagBitmask(SymbolTag::Abstract);
+ const SymbolTags FinalMask = toSymbolTagBitmask(SymbolTag::Final);
+
+ const SymbolTags RemoveVirtualAndOverrides = VirtualMask | OverridesMask;
+
+ // Implements implies both Overrides and Virtual.
+ if (ST & ImplementsMask)
+ ST &= ~RemoveVirtualAndOverrides;
+
+ // Final also suppresses both Virtual and Overrides in this model.
+ if (ST & FinalMask)
+ ST &= ~RemoveVirtualAndOverrides;
+
+ // Overrides or Abstract each imply Virtual.
+ if (ST & (OverridesMask | AbstractMask))
+ ST &= ~VirtualMask;
+
+ return ST;
+}
+
+bool isCXXClassMethod(const clang::clangd::Symbol &S) {
+ using clang::index::SymbolKind;
+ using clang::index::SymbolLanguage;
+
+ if (S.SymInfo.Lang != SymbolLanguage::CXX)
+ return false;
+
+ return llvm::is_contained({SymbolKind::InstanceMethod,
+ SymbolKind::StaticMethod, SymbolKind::Constructor,
+ SymbolKind::Destructor,
+ SymbolKind::ConversionFunction},
+ S.SymInfo.Kind);
+}
+
+template <typename E> constexpr E enumIncrement(E Value) {
+ return static_cast<E>(static_cast<std::underlying_type_t<E>>(Value) + 1);
+}
} // namespace
SymbolTags toSymbolTagBitmask(const SymbolTag ST) {
- return (1 << static_cast<unsigned>(ST));
+ return (1 << static_cast<uint32_t>(ST));
----------------
timon-ul wrote:
For consistency purposes you should revert this too.
https://github.com/llvm/llvm-project/pull/170103
More information about the cfe-commits
mailing list