// Indents ( `, -. | )
static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
+ class ColorScope {
+ raw_ostream &OS;
+ const bool ShowColors;
+
+ public:
+ ColorScope(raw_ostream &OS, bool ShowColors, TerminalColor Color)
+ : OS(OS), ShowColors(ShowColors) {
+ if (ShowColors)
+ OS.changeColor(Color.Color, Color.Bold);
+ }
+ ~ColorScope() {
+ if (ShowColors)
+ OS.resetColor();
+ }
+ };
+
class ASTDumper
: public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
// Note that the first level gets no prefix.
{
OS << '\n';
- ColorScope Color(*this, IndentColor);
+ ColorScope Color(OS, ShowColors, IndentColor);
OS << Prefix << (isLastChild ? '`' : '|') << '-';
this->Prefix.push_back(isLastChild ? ' ' : '|');
this->Prefix.push_back(' ');
FirstChild = false;
}
- class ColorScope {
- ASTDumper &Dumper;
- public:
- ColorScope(ASTDumper &Dumper, TerminalColor Color)
- : Dumper(Dumper) {
- if (Dumper.ShowColors)
- Dumper.OS.changeColor(Color.Color, Color.Bold);
- }
- ~ColorScope() {
- if (Dumper.ShowColors)
- Dumper.OS.resetColor();
- }
- };
-
public:
ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
const SourceManager *SM)
//===----------------------------------------------------------------------===//
void ASTDumper::dumpPointer(const void *Ptr) {
- ColorScope Color(*this, AddressColor);
+ ColorScope Color(OS, ShowColors, AddressColor);
OS << ' ' << Ptr;
}
if (!SM)
return;
- ColorScope Color(*this, LocationColor);
+ ColorScope Color(OS, ShowColors, LocationColor);
SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
// The general format we print out is filename:line:col, but we drop pieces
}
void ASTDumper::dumpBareType(QualType T, bool Desugar) {
- ColorScope Color(*this, TypeColor);
+ ColorScope Color(OS, ShowColors, TypeColor);
SplitQualType T_split = T.split();
OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'";
void ASTDumper::dumpTypeAsChild(const Type *T) {
dumpChild([=] {
if (!T) {
- ColorScope Color(*this, NullColor);
+ ColorScope Color(OS, ShowColors, NullColor);
OS << "<<<NULL>>>";
return;
}
if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
{
- ColorScope Color(*this, TypeColor);
+ ColorScope Color(OS, ShowColors, TypeColor);
OS << "LocInfo Type";
}
dumpPointer(T);
}
{
- ColorScope Color(*this, TypeColor);
+ ColorScope Color(OS, ShowColors, TypeColor);
OS << T->getTypeClassName() << "Type";
}
dumpPointer(T);
void ASTDumper::dumpBareDeclRef(const Decl *D) {
if (!D) {
- ColorScope Color(*this, NullColor);
+ ColorScope Color(OS, ShowColors, NullColor);
OS << "<<<NULL>>>";
return;
}
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << D->getDeclKindName();
}
dumpPointer(D);
if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
- ColorScope Color(*this, DeclNameColor);
+ ColorScope Color(OS, ShowColors, DeclNameColor);
OS << " '" << ND->getDeclName() << '\'';
}
void ASTDumper::dumpName(const NamedDecl *ND) {
if (ND->getDeclName()) {
- ColorScope Color(*this, DeclNameColor);
+ ColorScope Color(OS, ShowColors, DeclNameColor);
OS << ' ' << ND->getNameAsString();
}
}
dumpDecl(D);
if (DC->hasExternalLexicalStorage()) {
- dumpChild([=]{
- ColorScope Color(*this, UndeserializedColor);
+ dumpChild([=] {
+ ColorScope Color(OS, ShowColors, UndeserializedColor);
OS << "<undeserialized declarations>";
});
}
dumpChild([=] {
OS << "DeclarationName ";
{
- ColorScope Color(*this, DeclNameColor);
+ ColorScope Color(OS, ShowColors, DeclNameColor);
OS << '\'' << Name << '\'';
}
if (HasUndeserializedLookups) {
dumpChild([=] {
- ColorScope Color(*this, UndeserializedColor);
+ ColorScope Color(OS, ShowColors, UndeserializedColor);
OS << "<undeserialized lookups>";
});
}
void ASTDumper::dumpAttr(const Attr *A) {
dumpChild([=] {
{
- ColorScope Color(*this, AttrColor);
+ ColorScope Color(OS, ShowColors, AttrColor);
switch (A->getKind()) {
#define ATTR(X) case attr::X: OS << #X; break;
void ASTDumper::dumpDecl(const Decl *D) {
dumpChild([=] {
if (!D) {
- ColorScope Color(*this, NullColor);
+ ColorScope Color(OS, ShowColors, NullColor);
OS << "<<<NULL>>>";
return;
}
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << D->getDeclKindName() << "Decl";
}
dumpPointer(D);
for (auto *C : D->clauselists()) {
dumpChild([=] {
if (!C) {
- ColorScope Color(*this, NullColor);
+ ColorScope Color(OS, ShowColors, NullColor);
OS << "<<<NULL>>> OMPClause";
return;
}
{
- ColorScope Color(*this, AttrColor);
+ ColorScope Color(OS, ShowColors, AttrColor);
StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
<< ClauseName.drop_front() << "Clause";
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "DefinitionData";
}
#define FLAG(fn, name) if (D->fn()) OS << " " #name;
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "DefaultConstructor";
}
FLAG(hasDefaultConstructor, exists);
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "CopyConstructor";
}
FLAG(hasSimpleCopyConstructor, simple);
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "MoveConstructor";
}
FLAG(hasMoveConstructor, exists);
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "CopyAssignment";
}
FLAG(hasTrivialCopyAssignment, trivial);
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "MoveAssignment";
}
FLAG(hasMoveAssignment, exists);
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "Destructor";
}
FLAG(hasSimpleDestructor, simple);
void ASTDumper::dumpStmt(const Stmt *S) {
dumpChild([=] {
if (!S) {
- ColorScope Color(*this, NullColor);
+ ColorScope Color(OS, ShowColors, NullColor);
OS << "<<<NULL>>>";
return;
}
void ASTDumper::VisitStmt(const Stmt *Node) {
{
- ColorScope Color(*this, StmtColor);
+ ColorScope Color(OS, ShowColors, StmtColor);
OS << Node->getStmtClassName();
}
dumpPointer(Node);
for (auto *C : Node->clauses()) {
dumpChild([=] {
if (!C) {
- ColorScope Color(*this, NullColor);
+ ColorScope Color(OS, ShowColors, NullColor);
OS << "<<<NULL>>> OMPClause";
return;
}
{
- ColorScope Color(*this, AttrColor);
+ ColorScope Color(OS, ShowColors, AttrColor);
StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
<< ClauseName.drop_front() << "Clause";
dumpType(Node->getType());
{
- ColorScope Color(*this, ValueKindColor);
+ ColorScope Color(OS, ShowColors, ValueKindColor);
switch (Node->getValueKind()) {
case VK_RValue:
break;
}
{
- ColorScope Color(*this, ObjectKindColor);
+ ColorScope Color(OS, ShowColors, ObjectKindColor);
switch (Node->getObjectKind()) {
case OK_Ordinary:
break;
VisitExpr(Node);
OS << " <";
{
- ColorScope Color(*this, CastColor);
+ ColorScope Color(OS, ShowColors, CastColor);
OS << Node->getCastKindName();
}
dumpBasePath(OS, Node);
VisitExpr(Node);
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
}
OS << "='" << *Node->getDecl() << "'";
void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
VisitExpr(Node);
- ColorScope Color(*this, ValueColor);
+ ColorScope Color(OS, ShowColors, ValueColor);
OS << " " << Node->getValue();
}
VisitExpr(Node);
bool isSigned = Node->getType()->isSignedIntegerType();
- ColorScope Color(*this, ValueColor);
+ ColorScope Color(OS, ShowColors, ValueColor);
OS << " " << Node->getValue().toString(10, isSigned);
}
void ASTDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
VisitExpr(Node);
- ColorScope Color(*this, ValueColor);
+ ColorScope Color(OS, ShowColors, ValueColor);
OS << " " << Node->getValueAsString(/*Radix=*/10);
}
void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
VisitExpr(Node);
- ColorScope Color(*this, ValueColor);
+ ColorScope Color(OS, ShowColors, ValueColor);
OS << " " << Node->getValueAsApproximateDouble();
}
void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
VisitExpr(Str);
- ColorScope Color(*this, ValueColor);
+ ColorScope Color(OS, ShowColors, ValueColor);
OS << " ";
Str->outputString(OS);
}
void ASTDumper::dumpComment(const Comment *C) {
dumpChild([=] {
if (!C) {
- ColorScope Color(*this, NullColor);
+ ColorScope Color(OS, ShowColors, NullColor);
OS << "<<<NULL>>>";
return;
}
{
- ColorScope Color(*this, CommentColor);
+ ColorScope Color(OS, ShowColors, CommentColor);
OS << C->getCommentKindName();
}
dumpPointer(C);