[clang] [APINotes] Support nested tags (PR #99655)
Egor Zhdan via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 19 08:19:44 PDT 2024
================
@@ -783,51 +783,76 @@ static void ProcessVersionedAPINotes(
}
}
+static std::optional<api_notes::Context>
+UnwindNamespaceContext(DeclContext *DC, api_notes::APINotesManager &APINotes) {
+ if (auto NamespaceContext = dyn_cast<NamespaceDecl>(DC)) {
+ for (auto Reader : APINotes.findAPINotes(NamespaceContext->getLocation())) {
+ // Retrieve the context ID for the parent namespace of the decl.
+ std::stack<NamespaceDecl *> NamespaceStack;
+ {
+ for (auto CurrentNamespace = NamespaceContext; CurrentNamespace;
+ CurrentNamespace =
+ dyn_cast<NamespaceDecl>(CurrentNamespace->getParent())) {
+ if (!CurrentNamespace->isInlineNamespace())
+ NamespaceStack.push(CurrentNamespace);
+ }
+ }
+ std::optional<api_notes::ContextID> NamespaceID;
+ while (!NamespaceStack.empty()) {
+ auto CurrentNamespace = NamespaceStack.top();
+ NamespaceStack.pop();
+ NamespaceID =
+ Reader->lookupNamespaceID(CurrentNamespace->getName(), NamespaceID);
+ if (!NamespaceID)
+ return std::nullopt;
+ }
+ if (NamespaceID)
+ return api_notes::Context(*NamespaceID,
+ api_notes::ContextKind::Namespace);
+ }
+ }
+ return std::nullopt;
+}
+
+static std::optional<api_notes::Context>
+UnwindTagContext(TagDecl *DC, api_notes::APINotesManager &APINotes) {
+ for (auto Reader : APINotes.findAPINotes(DC->getLocation())) {
+ // Retrieve the context ID for the parent tag of the decl.
+ std::stack<TagDecl *> TagStack;
+ {
+ for (auto CurrentTag = DC; CurrentTag;
+ CurrentTag = dyn_cast<TagDecl>(CurrentTag->getParent()))
+ TagStack.push(CurrentTag);
+ }
+ assert(!TagStack.empty());
----------------
egorzhdan wrote:
Not sure I follow: a tag might be a top-level entity, if its context is the translation unit. It isn't necessarily nested in a C++ namespace.
https://github.com/llvm/llvm-project/pull/99655
More information about the cfe-commits
mailing list