mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-28 16:26:05 +00:00
Add dumping support for DeclContext's StoredDeclsMap.
llvm-svn: 184648
This commit is contained in:
parent
80de0a28f1
commit
33937e76fd
@ -1469,10 +1469,16 @@ public:
|
||||
/// of looking up every possible name.
|
||||
class all_lookups_iterator;
|
||||
|
||||
/// \brief Iterators over all possible lookups within this context.
|
||||
all_lookups_iterator lookups_begin() const;
|
||||
|
||||
all_lookups_iterator lookups_end() const;
|
||||
|
||||
/// \brief Iterators over all possible lookups within this context that are
|
||||
/// currently loaded; don't attempt to retrieve anything from an external
|
||||
/// source.
|
||||
all_lookups_iterator noload_lookups_begin() const;
|
||||
all_lookups_iterator noload_lookups_end() const;
|
||||
|
||||
/// udir_iterator - Iterates through the using-directives stored
|
||||
/// within this context.
|
||||
typedef UsingDirectiveDecl * const * udir_iterator;
|
||||
@ -1543,6 +1549,7 @@ public:
|
||||
static bool classof(const DeclContext *D) { return true; }
|
||||
|
||||
LLVM_ATTRIBUTE_USED void dumpDeclContext() const;
|
||||
LLVM_ATTRIBUTE_USED void dumpLookups() const;
|
||||
|
||||
private:
|
||||
void reconcileExternalVisibleStorage();
|
||||
|
@ -37,6 +37,8 @@ public:
|
||||
StoredDeclsMap::iterator End)
|
||||
: It(It), End(End) {}
|
||||
|
||||
DeclarationName getLookupName() const { return It->first; }
|
||||
|
||||
reference operator*() const { return It->second.getLookupResult(); }
|
||||
pointer operator->() const { return It->second.getLookupResult(); }
|
||||
|
||||
@ -66,7 +68,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
DeclContext::all_lookups_iterator DeclContext::lookups_begin() const {
|
||||
inline DeclContext::all_lookups_iterator DeclContext::lookups_begin() const {
|
||||
DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
|
||||
if (Primary->hasExternalVisibleStorage())
|
||||
getParentASTContext().getExternalSource()->completeVisibleDeclsMap(Primary);
|
||||
@ -75,7 +77,7 @@ DeclContext::all_lookups_iterator DeclContext::lookups_begin() const {
|
||||
return all_lookups_iterator();
|
||||
}
|
||||
|
||||
DeclContext::all_lookups_iterator DeclContext::lookups_end() const {
|
||||
inline DeclContext::all_lookups_iterator DeclContext::lookups_end() const {
|
||||
DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
|
||||
if (Primary->hasExternalVisibleStorage())
|
||||
getParentASTContext().getExternalSource()->completeVisibleDeclsMap(Primary);
|
||||
@ -84,6 +86,22 @@ DeclContext::all_lookups_iterator DeclContext::lookups_end() const {
|
||||
return all_lookups_iterator();
|
||||
}
|
||||
|
||||
inline
|
||||
DeclContext::all_lookups_iterator DeclContext::noload_lookups_begin() const {
|
||||
DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
|
||||
if (StoredDeclsMap *Map = Primary->getLookupPtr())
|
||||
return all_lookups_iterator(Map->begin(), Map->end());
|
||||
return all_lookups_iterator();
|
||||
}
|
||||
|
||||
inline
|
||||
DeclContext::all_lookups_iterator DeclContext::noload_lookups_end() const {
|
||||
DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
|
||||
if (StoredDeclsMap *Map = Primary->getLookupPtr())
|
||||
return all_lookups_iterator(Map->end(), Map->end());
|
||||
return all_lookups_iterator();
|
||||
}
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
#endif
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "clang/AST/Attr.h"
|
||||
#include "clang/AST/CommentVisitor.h"
|
||||
#include "clang/AST/DeclCXX.h"
|
||||
#include "clang/AST/DeclLookups.h"
|
||||
#include "clang/AST/DeclObjC.h"
|
||||
#include "clang/AST/DeclVisitor.h"
|
||||
#include "clang/AST/StmtVisitor.h"
|
||||
@ -176,6 +177,7 @@ namespace {
|
||||
void dumpName(const NamedDecl *D);
|
||||
bool hasNodes(const DeclContext *DC);
|
||||
void dumpDeclContext(const DeclContext *DC);
|
||||
void dumpLookups(const DeclContext *DC);
|
||||
void dumpAttr(const Attr *A);
|
||||
|
||||
// C++ Utilities
|
||||
@ -505,6 +507,51 @@ void ASTDumper::dumpDeclContext(const DeclContext *DC) {
|
||||
}
|
||||
}
|
||||
|
||||
void ASTDumper::dumpLookups(const DeclContext *DC) {
|
||||
IndentScope Indent(*this);
|
||||
|
||||
OS << "StoredDeclsMap ";
|
||||
dumpBareDeclRef(cast<Decl>(DC));
|
||||
|
||||
const DeclContext *Primary = DC->getPrimaryContext();
|
||||
if (Primary != DC) {
|
||||
OS << " primary";
|
||||
dumpPointer(cast<Decl>(Primary));
|
||||
}
|
||||
|
||||
bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
|
||||
|
||||
DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
|
||||
E = Primary->noload_lookups_end();
|
||||
while (I != E) {
|
||||
DeclarationName Name = I.getLookupName();
|
||||
DeclContextLookupResult R = *I++;
|
||||
if (I == E && !HasUndeserializedLookups)
|
||||
lastChild();
|
||||
|
||||
IndentScope Indent(*this);
|
||||
OS << "DeclarationName ";
|
||||
{
|
||||
ColorScope Color(*this, DeclNameColor);
|
||||
OS << '\'' << Name << '\'';
|
||||
}
|
||||
|
||||
for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
|
||||
RI != RE; ++RI) {
|
||||
if (RI + 1 == RE)
|
||||
lastChild();
|
||||
dumpDeclRef(*RI);
|
||||
}
|
||||
}
|
||||
|
||||
if (HasUndeserializedLookups) {
|
||||
lastChild();
|
||||
IndentScope Indent(*this);
|
||||
ColorScope Color(*this, UndeserializedColor);
|
||||
OS << "<undeserialized lookups>";
|
||||
}
|
||||
}
|
||||
|
||||
void ASTDumper::dumpAttr(const Attr *A) {
|
||||
IndentScope Indent(*this);
|
||||
{
|
||||
@ -1982,6 +2029,18 @@ void Decl::dumpColor() const {
|
||||
&getASTContext().getSourceManager(), /*ShowColors*/true);
|
||||
P.dumpDecl(this);
|
||||
}
|
||||
|
||||
void DeclContext::dumpLookups() const {
|
||||
const DeclContext *DC = this;
|
||||
while (!DC->isTranslationUnit())
|
||||
DC = DC->getParent();
|
||||
ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
|
||||
|
||||
ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
|
||||
&Ctx.getSourceManager());
|
||||
P.dumpLookups(this);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Stmt method implementations
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
Loading…
x
Reference in New Issue
Block a user