forked from OSchip/llvm-project
[clang][NFC] Store a pointer to the ASTContext in ASTDumper and TextNodeDumper
In general there is no way to get to the ASTContext from most AST nodes (Decls are one of the exception). This will be a problem when implementing the rest of APValue::dump since we need the ASTContext to dump some kinds of APValues. The ASTContext* in ASTDumper and TextNodeDumper is not always non-null. This is because we still want to be able to use the various dump() functions in a debugger. No functional changes intended.
This commit is contained in:
parent
0059f6ffe8
commit
aa7fd905e4
|
@ -157,8 +157,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
|
||||||
OS << "Binding for \"" << BI->first << "\":\n";
|
OS << "Binding for \"" << BI->first << "\":\n";
|
||||||
const ASTContext &Ctx = AST->getASTContext();
|
const ASTContext &Ctx = AST->getASTContext();
|
||||||
const SourceManager &SM = Ctx.getSourceManager();
|
const SourceManager &SM = Ctx.getSourceManager();
|
||||||
ASTDumper Dumper(OS, &Ctx.getCommentCommandTraits(), &SM,
|
ASTDumper Dumper(OS, Ctx, SM.getDiagnostics().getShowColors());
|
||||||
SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
|
|
||||||
Dumper.SetTraversalKind(QS.TK);
|
Dumper.SetTraversalKind(QS.TK);
|
||||||
Dumper.Visit(BI->second);
|
Dumper.Visit(BI->second);
|
||||||
OS << "\n";
|
OS << "\n";
|
||||||
|
|
|
@ -62,7 +62,7 @@ REGISTER_TWEAK(DumpAST)
|
||||||
llvm::Expected<Tweak::Effect> DumpAST::apply(const Selection &Inputs) {
|
llvm::Expected<Tweak::Effect> DumpAST::apply(const Selection &Inputs) {
|
||||||
std::string Str;
|
std::string Str;
|
||||||
llvm::raw_string_ostream OS(Str);
|
llvm::raw_string_ostream OS(Str);
|
||||||
Node->dump(OS, Inputs.AST->getSourceManager());
|
Node->dump(OS, Inputs.AST->getASTContext());
|
||||||
return Effect::showMessage(std::move(OS.str()));
|
return Effect::showMessage(std::move(OS.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -372,7 +372,7 @@ public:
|
||||||
bool isAddrLabelDiff() const { return Kind == AddrLabelDiff; }
|
bool isAddrLabelDiff() const { return Kind == AddrLabelDiff; }
|
||||||
|
|
||||||
void dump() const;
|
void dump() const;
|
||||||
void dump(raw_ostream &OS) const;
|
void dump(raw_ostream &OS, const ASTContext *Context) const;
|
||||||
|
|
||||||
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const;
|
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const;
|
||||||
std::string getAsString(const ASTContext &Ctx, QualType Ty) const;
|
std::string getAsString(const ASTContext &Ctx, QualType Ty) const;
|
||||||
|
|
|
@ -24,18 +24,11 @@ class ASTDumper : public ASTNodeTraverser<ASTDumper, TextNodeDumper> {
|
||||||
const bool ShowColors;
|
const bool ShowColors;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
|
ASTDumper(raw_ostream &OS, const ASTContext &Context, bool ShowColors)
|
||||||
const SourceManager *SM)
|
: NodeDumper(OS, Context, ShowColors), OS(OS), ShowColors(ShowColors) {}
|
||||||
: ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) {}
|
|
||||||
|
|
||||||
ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
|
ASTDumper(raw_ostream &OS, bool ShowColors)
|
||||||
const SourceManager *SM, bool ShowColors)
|
: NodeDumper(OS, ShowColors), OS(OS), ShowColors(ShowColors) {}
|
||||||
: ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
|
|
||||||
ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
|
|
||||||
const SourceManager *SM, bool ShowColors,
|
|
||||||
const PrintingPolicy &PrintPolicy)
|
|
||||||
: NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
|
|
||||||
ShowColors(ShowColors) {}
|
|
||||||
|
|
||||||
TextNodeDumper &doGetNodeDelegate() { return NodeDumper; }
|
TextNodeDumper &doGetNodeDelegate() { return NodeDumper; }
|
||||||
|
|
||||||
|
|
|
@ -278,7 +278,7 @@ public:
|
||||||
void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const;
|
void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const;
|
||||||
|
|
||||||
/// Dumps the node to the given output stream.
|
/// Dumps the node to the given output stream.
|
||||||
void dump(llvm::raw_ostream &OS, SourceManager &SM) const;
|
void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
|
||||||
|
|
||||||
/// For nodes which represent textual entities in the source code,
|
/// For nodes which represent textual entities in the source code,
|
||||||
/// return their SourceRange. For all other nodes, return SourceRange().
|
/// return their SourceRange. For all other nodes, return SourceRange().
|
||||||
|
|
|
@ -209,9 +209,7 @@ public:
|
||||||
|
|
||||||
void dump() const;
|
void dump() const;
|
||||||
void dumpColor() const;
|
void dumpColor() const;
|
||||||
void dump(const ASTContext &Context) const;
|
void dump(raw_ostream &OS, const ASTContext &Context) const;
|
||||||
void dump(raw_ostream &OS, const CommandTraits *Traits,
|
|
||||||
const SourceManager *SM) const;
|
|
||||||
|
|
||||||
SourceRange getSourceRange() const LLVM_READONLY { return Range; }
|
SourceRange getSourceRange() const LLVM_READONLY { return Range; }
|
||||||
|
|
||||||
|
|
|
@ -1166,9 +1166,7 @@ public:
|
||||||
/// Dumps the specified AST fragment and all subtrees to
|
/// Dumps the specified AST fragment and all subtrees to
|
||||||
/// \c llvm::errs().
|
/// \c llvm::errs().
|
||||||
void dump() const;
|
void dump() const;
|
||||||
void dump(SourceManager &SM) const;
|
void dump(raw_ostream &OS, const ASTContext &Context) const;
|
||||||
void dump(raw_ostream &OS, SourceManager &SM) const;
|
|
||||||
void dump(raw_ostream &OS) const;
|
|
||||||
|
|
||||||
/// \return Unique reproducible object identifier
|
/// \return Unique reproducible object identifier
|
||||||
int64_t getID(const ASTContext &Context) const;
|
int64_t getID(const ASTContext &Context) const;
|
||||||
|
|
|
@ -139,19 +139,23 @@ class TextNodeDumper
|
||||||
const char *LastLocFilename = "";
|
const char *LastLocFilename = "";
|
||||||
unsigned LastLocLine = ~0U;
|
unsigned LastLocLine = ~0U;
|
||||||
|
|
||||||
const SourceManager *SM;
|
/// \p Context, \p SM, and \p Traits can be null. This is because we want
|
||||||
|
/// to be able to call \p dump() in a debugger without having to pass the
|
||||||
|
/// \p ASTContext to \p dump. Not all parts of the AST dump output will be
|
||||||
|
/// available without the \p ASTContext.
|
||||||
|
const ASTContext *Context = nullptr;
|
||||||
|
const SourceManager *SM = nullptr;
|
||||||
|
|
||||||
/// The policy to use for printing; can be defaulted.
|
/// The policy to use for printing; can be defaulted.
|
||||||
PrintingPolicy PrintPolicy;
|
PrintingPolicy PrintPolicy = LangOptions();
|
||||||
|
|
||||||
const comments::CommandTraits *Traits;
|
const comments::CommandTraits *Traits = nullptr;
|
||||||
|
|
||||||
const char *getCommandName(unsigned CommandID);
|
const char *getCommandName(unsigned CommandID);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextNodeDumper(raw_ostream &OS, bool ShowColors, const SourceManager *SM,
|
TextNodeDumper(raw_ostream &OS, const ASTContext &Context, bool ShowColors);
|
||||||
const PrintingPolicy &PrintPolicy,
|
TextNodeDumper(raw_ostream &OS, bool ShowColors);
|
||||||
const comments::CommandTraits *Traits);
|
|
||||||
|
|
||||||
void Visit(const comments::Comment *C, const comments::FullComment *FC);
|
void Visit(const comments::Comment *C, const comments::FullComment *FC);
|
||||||
|
|
||||||
|
|
|
@ -1058,7 +1058,7 @@ public:
|
||||||
|
|
||||||
void dump(const char *s) const;
|
void dump(const char *s) const;
|
||||||
void dump() const;
|
void dump() const;
|
||||||
void dump(llvm::raw_ostream &OS) const;
|
void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
|
||||||
|
|
||||||
void Profile(llvm::FoldingSetNodeID &ID) const {
|
void Profile(llvm::FoldingSetNodeID &ID) const {
|
||||||
ID.AddPointer(getAsOpaquePtr());
|
ID.AddPointer(getAsOpaquePtr());
|
||||||
|
@ -2471,7 +2471,7 @@ public:
|
||||||
|
|
||||||
CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
|
CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
|
||||||
void dump() const;
|
void dump() const;
|
||||||
void dump(llvm::raw_ostream &OS) const;
|
void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This will check for a TypedefType by removing any existing sugar
|
/// This will check for a TypedefType by removing any existing sugar
|
||||||
|
|
|
@ -378,11 +378,6 @@ void APValue::swap(APValue &RHS) {
|
||||||
memcpy(RHS.Data.buffer, TmpData, DataSize);
|
memcpy(RHS.Data.buffer, TmpData, DataSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void APValue::dump() const {
|
|
||||||
dump(llvm::errs());
|
|
||||||
llvm::errs() << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
static double GetApproxValue(const llvm::APFloat &F) {
|
static double GetApproxValue(const llvm::APFloat &F) {
|
||||||
llvm::APFloat V = F;
|
llvm::APFloat V = F;
|
||||||
bool ignored;
|
bool ignored;
|
||||||
|
@ -391,7 +386,13 @@ static double GetApproxValue(const llvm::APFloat &F) {
|
||||||
return V.convertToDouble();
|
return V.convertToDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APValue::dump(raw_ostream &OS) const {
|
LLVM_DUMP_METHOD void APValue::dump() const {
|
||||||
|
dump(llvm::errs(), /*Context=*/nullptr);
|
||||||
|
llvm::errs() << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVM_DUMP_METHOD void APValue::dump(raw_ostream &OS,
|
||||||
|
const ASTContext *Context) const {
|
||||||
switch (getKind()) {
|
switch (getKind()) {
|
||||||
case None:
|
case None:
|
||||||
OS << "None";
|
OS << "None";
|
||||||
|
@ -410,10 +411,10 @@ void APValue::dump(raw_ostream &OS) const {
|
||||||
return;
|
return;
|
||||||
case Vector:
|
case Vector:
|
||||||
OS << "Vector: ";
|
OS << "Vector: ";
|
||||||
getVectorElt(0).dump(OS);
|
getVectorElt(0).dump(OS, Context);
|
||||||
for (unsigned i = 1; i != getVectorLength(); ++i) {
|
for (unsigned i = 1; i != getVectorLength(); ++i) {
|
||||||
OS << ", ";
|
OS << ", ";
|
||||||
getVectorElt(i).dump(OS);
|
getVectorElt(i).dump(OS, Context);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case ComplexInt:
|
case ComplexInt:
|
||||||
|
@ -429,36 +430,37 @@ void APValue::dump(raw_ostream &OS) const {
|
||||||
case Array:
|
case Array:
|
||||||
OS << "Array: ";
|
OS << "Array: ";
|
||||||
for (unsigned I = 0, N = getArrayInitializedElts(); I != N; ++I) {
|
for (unsigned I = 0, N = getArrayInitializedElts(); I != N; ++I) {
|
||||||
getArrayInitializedElt(I).dump(OS);
|
getArrayInitializedElt(I).dump(OS, Context);
|
||||||
if (I != getArraySize() - 1) OS << ", ";
|
if (I != getArraySize() - 1)
|
||||||
|
OS << ", ";
|
||||||
}
|
}
|
||||||
if (hasArrayFiller()) {
|
if (hasArrayFiller()) {
|
||||||
OS << getArraySize() - getArrayInitializedElts() << " x ";
|
OS << getArraySize() - getArrayInitializedElts() << " x ";
|
||||||
getArrayFiller().dump(OS);
|
getArrayFiller().dump(OS, Context);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case Struct:
|
case Struct:
|
||||||
OS << "Struct ";
|
OS << "Struct ";
|
||||||
if (unsigned N = getStructNumBases()) {
|
if (unsigned N = getStructNumBases()) {
|
||||||
OS << " bases: ";
|
OS << " bases: ";
|
||||||
getStructBase(0).dump(OS);
|
getStructBase(0).dump(OS, Context);
|
||||||
for (unsigned I = 1; I != N; ++I) {
|
for (unsigned I = 1; I != N; ++I) {
|
||||||
OS << ", ";
|
OS << ", ";
|
||||||
getStructBase(I).dump(OS);
|
getStructBase(I).dump(OS, Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unsigned N = getStructNumFields()) {
|
if (unsigned N = getStructNumFields()) {
|
||||||
OS << " fields: ";
|
OS << " fields: ";
|
||||||
getStructField(0).dump(OS);
|
getStructField(0).dump(OS, Context);
|
||||||
for (unsigned I = 1; I != N; ++I) {
|
for (unsigned I = 1; I != N; ++I) {
|
||||||
OS << ", ";
|
OS << ", ";
|
||||||
getStructField(I).dump(OS);
|
getStructField(I).dump(OS, Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case Union:
|
case Union:
|
||||||
OS << "Union: ";
|
OS << "Union: ";
|
||||||
getUnionValue().dump(OS);
|
getUnionValue().dump(OS, Context);
|
||||||
return;
|
return;
|
||||||
case MemberPointer:
|
case MemberPointer:
|
||||||
OS << "MemberPointer: <todo>";
|
OS << "MemberPointer: <todo>";
|
||||||
|
|
|
@ -159,17 +159,22 @@ void QualType::dump(const char *msg) const {
|
||||||
dump();
|
dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
|
LLVM_DUMP_METHOD void QualType::dump() const {
|
||||||
|
ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
|
||||||
LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
|
|
||||||
ASTDumper Dumper(OS, nullptr, nullptr);
|
|
||||||
Dumper.Visit(*this);
|
Dumper.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
|
LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS,
|
||||||
|
const ASTContext &Context) const {
|
||||||
|
ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
|
||||||
|
Dumper.Visit(*this);
|
||||||
|
}
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
|
LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
|
||||||
QualType(this, 0).dump(OS);
|
|
||||||
|
LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS,
|
||||||
|
const ASTContext &Context) const {
|
||||||
|
QualType(this, 0).dump(OS, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -189,8 +194,7 @@ LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize,
|
||||||
(void)Deserialize; // FIXME?
|
(void)Deserialize; // FIXME?
|
||||||
P.Visit(this);
|
P.Visit(this);
|
||||||
} else {
|
} else {
|
||||||
ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
|
ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors());
|
||||||
SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
|
|
||||||
P.setDeserialize(Deserialize);
|
P.setDeserialize(Deserialize);
|
||||||
P.Visit(this);
|
P.Visit(this);
|
||||||
}
|
}
|
||||||
|
@ -198,9 +202,7 @@ LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize,
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Decl::dumpColor() const {
|
LLVM_DUMP_METHOD void Decl::dumpColor() const {
|
||||||
const ASTContext &Ctx = getASTContext();
|
const ASTContext &Ctx = getASTContext();
|
||||||
ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
|
ASTDumper P(llvm::errs(), Ctx, /*ShowColors=*/true);
|
||||||
&Ctx.getSourceManager(), /*ShowColors*/ true,
|
|
||||||
Ctx.getPrintingPolicy());
|
|
||||||
P.Visit(this);
|
P.Visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,10 +216,8 @@ LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
|
||||||
const DeclContext *DC = this;
|
const DeclContext *DC = this;
|
||||||
while (!DC->isTranslationUnit())
|
while (!DC->isTranslationUnit())
|
||||||
DC = DC->getParent();
|
DC = DC->getParent();
|
||||||
ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
|
const ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
|
||||||
const SourceManager &SM = Ctx.getSourceManager();
|
ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors());
|
||||||
ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
|
|
||||||
SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
|
|
||||||
P.setDeserialize(Deserialize);
|
P.setDeserialize(Deserialize);
|
||||||
P.dumpLookups(this, DumpDecls);
|
P.dumpLookups(this, DumpDecls);
|
||||||
}
|
}
|
||||||
|
@ -226,27 +226,19 @@ LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
|
||||||
// Stmt method implementations
|
// Stmt method implementations
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
|
|
||||||
dump(llvm::errs(), SM);
|
|
||||||
}
|
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
|
|
||||||
ASTDumper P(OS, nullptr, &SM);
|
|
||||||
P.Visit(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
|
|
||||||
ASTDumper P(OS, nullptr, nullptr);
|
|
||||||
P.Visit(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Stmt::dump() const {
|
LLVM_DUMP_METHOD void Stmt::dump() const {
|
||||||
ASTDumper P(llvm::errs(), nullptr, nullptr);
|
ASTDumper P(llvm::errs(), /*ShowColors=*/false);
|
||||||
|
P.Visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS,
|
||||||
|
const ASTContext &Context) const {
|
||||||
|
ASTDumper P(OS, Context, Context.getDiagnostics().getShowColors());
|
||||||
P.Visit(this);
|
P.Visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Stmt::dumpColor() const {
|
LLVM_DUMP_METHOD void Stmt::dumpColor() const {
|
||||||
ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
|
ASTDumper P(llvm::errs(), /*ShowColors=*/true);
|
||||||
P.Visit(this);
|
P.Visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,27 +247,26 @@ LLVM_DUMP_METHOD void Stmt::dumpColor() const {
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Comment::dump() const {
|
LLVM_DUMP_METHOD void Comment::dump() const {
|
||||||
dump(llvm::errs(), nullptr, nullptr);
|
const auto *FC = dyn_cast<FullComment>(this);
|
||||||
}
|
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
|
|
||||||
dump(llvm::errs(), &Context.getCommentCommandTraits(),
|
|
||||||
&Context.getSourceManager());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
|
|
||||||
const SourceManager *SM) const {
|
|
||||||
const FullComment *FC = dyn_cast<FullComment>(this);
|
|
||||||
if (!FC)
|
if (!FC)
|
||||||
return;
|
return;
|
||||||
ASTDumper D(OS, Traits, SM);
|
ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
|
||||||
D.Visit(FC, FC);
|
Dumper.Visit(FC, FC);
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVM_DUMP_METHOD void Comment::dump(raw_ostream &OS,
|
||||||
|
const ASTContext &Context) const {
|
||||||
|
const auto *FC = dyn_cast<FullComment>(this);
|
||||||
|
if (!FC)
|
||||||
|
return;
|
||||||
|
ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
|
||||||
|
Dumper.Visit(FC, FC);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVM_DUMP_METHOD void Comment::dumpColor() const {
|
LLVM_DUMP_METHOD void Comment::dumpColor() const {
|
||||||
const FullComment *FC = dyn_cast<FullComment>(this);
|
const auto *FC = dyn_cast<FullComment>(this);
|
||||||
if (!FC)
|
if (!FC)
|
||||||
return;
|
return;
|
||||||
ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
|
ASTDumper Dumper(llvm::errs(), /*ShowColors=*/true);
|
||||||
D.Visit(FC, FC);
|
Dumper.Visit(FC, FC);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,13 +152,14 @@ void DynTypedNode::print(llvm::raw_ostream &OS,
|
||||||
OS << "Unable to print values of type " << NodeKind.asStringRef() << "\n";
|
OS << "Unable to print values of type " << NodeKind.asStringRef() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynTypedNode::dump(llvm::raw_ostream &OS, SourceManager &SM) const {
|
void DynTypedNode::dump(llvm::raw_ostream &OS,
|
||||||
|
const ASTContext &Context) const {
|
||||||
if (const Decl *D = get<Decl>())
|
if (const Decl *D = get<Decl>())
|
||||||
D->dump(OS);
|
D->dump(OS);
|
||||||
else if (const Stmt *S = get<Stmt>())
|
else if (const Stmt *S = get<Stmt>())
|
||||||
S->dump(OS, SM);
|
S->dump(OS, Context);
|
||||||
else if (const Type *T = get<Type>())
|
else if (const Type *T = get<Type>())
|
||||||
T->dump(OS);
|
T->dump(OS, Context);
|
||||||
else
|
else
|
||||||
OS << "Unable to dump values of type " << NodeKind.asStringRef() << "\n";
|
OS << "Unable to dump values of type " << NodeKind.asStringRef() << "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,12 +51,15 @@ static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
|
||||||
llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
|
llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
|
||||||
}
|
}
|
||||||
|
|
||||||
TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors,
|
TextNodeDumper::TextNodeDumper(raw_ostream &OS, const ASTContext &Context,
|
||||||
const SourceManager *SM,
|
bool ShowColors)
|
||||||
const PrintingPolicy &PrintPolicy,
|
: TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors),
|
||||||
const comments::CommandTraits *Traits)
|
Context(&Context), SM(&Context.getSourceManager()),
|
||||||
: TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors), SM(SM),
|
PrintPolicy(Context.getPrintingPolicy()),
|
||||||
PrintPolicy(PrintPolicy), Traits(Traits) {}
|
Traits(&Context.getCommentCommandTraits()) {}
|
||||||
|
|
||||||
|
TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors)
|
||||||
|
: TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors) {}
|
||||||
|
|
||||||
void TextNodeDumper::Visit(const comments::Comment *C,
|
void TextNodeDumper::Visit(const comments::Comment *C,
|
||||||
const comments::FullComment *FC) {
|
const comments::FullComment *FC) {
|
||||||
|
@ -712,7 +715,7 @@ void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
|
||||||
if (Node->getResultAPValueKind() != APValue::None) {
|
if (Node->getResultAPValueKind() != APValue::None) {
|
||||||
ColorScope Color(OS, ShowColors, ValueColor);
|
ColorScope Color(OS, ShowColors, ValueColor);
|
||||||
OS << " ";
|
OS << " ";
|
||||||
Node->getAPValueResult().dump(OS);
|
Node->getAPValueResult().dump(OS, Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -755,7 +755,7 @@ private:
|
||||||
return D->getKind() == Decl::TranslationUnit;
|
return D->getKind() == Decl::TranslationUnit;
|
||||||
})) {
|
})) {
|
||||||
llvm::errs() << "Tried to match orphan node:\n";
|
llvm::errs() << "Tried to match orphan node:\n";
|
||||||
Node.dump(llvm::errs(), ActiveASTContext->getSourceManager());
|
Node.dump(llvm::errs(), *ActiveASTContext);
|
||||||
llvm_unreachable("Parent map should be complete!");
|
llvm_unreachable("Parent map should be complete!");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -98,7 +98,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
ComplexPairTy VisitStmt(Stmt *S) {
|
ComplexPairTy VisitStmt(Stmt *S) {
|
||||||
S->dump(CGF.getContext().getSourceManager());
|
S->dump(llvm::errs(), CGF.getContext());
|
||||||
llvm_unreachable("Stmt can't have complex result type!");
|
llvm_unreachable("Stmt can't have complex result type!");
|
||||||
}
|
}
|
||||||
ComplexPairTy VisitExpr(Expr *S);
|
ComplexPairTy VisitExpr(Expr *S);
|
||||||
|
|
|
@ -413,7 +413,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VisitStmt(Stmt *S) {
|
Value *VisitStmt(Stmt *S) {
|
||||||
S->dump(CGF.getContext().getSourceManager());
|
S->dump(llvm::errs(), CGF.getContext());
|
||||||
llvm_unreachable("Stmt can't have complex result type!");
|
llvm_unreachable("Stmt can't have complex result type!");
|
||||||
}
|
}
|
||||||
Value *VisitExpr(Expr *S);
|
Value *VisitExpr(Expr *S);
|
||||||
|
|
|
@ -103,9 +103,9 @@ namespace {
|
||||||
// FIXME: Support OutputFormat in type dumping.
|
// FIXME: Support OutputFormat in type dumping.
|
||||||
// FIXME: Support combining -ast-dump-decl-types with -ast-dump-lookups.
|
// FIXME: Support combining -ast-dump-decl-types with -ast-dump-lookups.
|
||||||
if (auto *VD = dyn_cast<ValueDecl>(InnerD))
|
if (auto *VD = dyn_cast<ValueDecl>(InnerD))
|
||||||
VD->getType().dump(Out);
|
VD->getType().dump(Out, VD->getASTContext());
|
||||||
if (auto *TD = dyn_cast<TypeDecl>(InnerD))
|
if (auto *TD = dyn_cast<TypeDecl>(InnerD))
|
||||||
TD->getTypeForDecl()->dump(Out);
|
TD->getTypeForDecl()->dump(Out, TD->getASTContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ FullComment *CommentParserTest::parseString(const char *Source) {
|
||||||
|
|
||||||
if (MY_DEBUG) {
|
if (MY_DEBUG) {
|
||||||
llvm::errs() << "=== Source:\n" << Source << "\n=== AST:\n";
|
llvm::errs() << "=== Source:\n" << Source << "\n=== AST:\n";
|
||||||
FC->dump(llvm::errs(), &Traits, &SourceMgr);
|
FC->dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
Token Tok;
|
Token Tok;
|
||||||
|
|
|
@ -271,7 +271,7 @@ protected:
|
||||||
const DynTypedNode &Node) override {
|
const DynTypedNode &Node) override {
|
||||||
std::string DumpStr;
|
std::string DumpStr;
|
||||||
llvm::raw_string_ostream Dump(DumpStr);
|
llvm::raw_string_ostream Dump(DumpStr);
|
||||||
Node.dump(Dump, *Result.SourceManager);
|
Node.dump(Dump, *Result.Context);
|
||||||
|
|
||||||
if (Dump.str().find(ExpectSubstring) == std::string::npos) {
|
if (Dump.str().find(ExpectSubstring) == std::string::npos) {
|
||||||
std::string MsgStr;
|
std::string MsgStr;
|
||||||
|
|
Loading…
Reference in New Issue