r347900 - NFC: Move ColorScope to global scope
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 29 11:30:38 PST 2018
Author: steveire
Date: Thu Nov 29 11:30:37 2018
New Revision: 347900
URL: http://llvm.org/viewvc/llvm-project?rev=347900&view=rev
Log:
NFC: Move ColorScope to global scope
Modified:
cfe/trunk/lib/AST/ASTDumper.cpp
Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=347900&r1=347899&r2=347900&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Thu Nov 29 11:30:37 2018
@@ -92,6 +92,22 @@ namespace {
// 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> {
@@ -161,7 +177,7 @@ namespace {
// 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(' ');
@@ -193,20 +209,6 @@ namespace {
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)
@@ -607,7 +609,7 @@ namespace {
//===----------------------------------------------------------------------===//
void ASTDumper::dumpPointer(const void *Ptr) {
- ColorScope Color(*this, AddressColor);
+ ColorScope Color(OS, ShowColors, AddressColor);
OS << ' ' << Ptr;
}
@@ -615,7 +617,7 @@ void ASTDumper::dumpLocation(SourceLocat
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
@@ -659,7 +661,7 @@ void ASTDumper::dumpSourceRange(SourceRa
}
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) << "'";
@@ -695,13 +697,13 @@ void ASTDumper::dumpTypeAsChild(QualType
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);
@@ -710,7 +712,7 @@ void ASTDumper::dumpTypeAsChild(const Ty
}
{
- ColorScope Color(*this, TypeColor);
+ ColorScope Color(OS, ShowColors, TypeColor);
OS << T->getTypeClassName() << "Type";
}
dumpPointer(T);
@@ -741,19 +743,19 @@ void ASTDumper::dumpTypeAsChild(const Ty
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() << '\'';
}
@@ -774,7 +776,7 @@ void ASTDumper::dumpDeclRef(const Decl *
void ASTDumper::dumpName(const NamedDecl *ND) {
if (ND->getDeclName()) {
- ColorScope Color(*this, DeclNameColor);
+ ColorScope Color(OS, ShowColors, DeclNameColor);
OS << ' ' << ND->getNameAsString();
}
}
@@ -796,8 +798,8 @@ void ASTDumper::dumpDeclContext(const De
dumpDecl(D);
if (DC->hasExternalLexicalStorage()) {
- dumpChild([=]{
- ColorScope Color(*this, UndeserializedColor);
+ dumpChild([=] {
+ ColorScope Color(OS, ShowColors, UndeserializedColor);
OS << "<undeserialized declarations>";
});
}
@@ -826,7 +828,7 @@ void ASTDumper::dumpLookups(const DeclCo
dumpChild([=] {
OS << "DeclarationName ";
{
- ColorScope Color(*this, DeclNameColor);
+ ColorScope Color(OS, ShowColors, DeclNameColor);
OS << '\'' << Name << '\'';
}
@@ -855,7 +857,7 @@ void ASTDumper::dumpLookups(const DeclCo
if (HasUndeserializedLookups) {
dumpChild([=] {
- ColorScope Color(*this, UndeserializedColor);
+ ColorScope Color(OS, ShowColors, UndeserializedColor);
OS << "<undeserialized lookups>";
});
}
@@ -865,7 +867,7 @@ void ASTDumper::dumpLookups(const DeclCo
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;
@@ -1038,13 +1040,13 @@ void ASTDumper::dumpObjCTypeParamList(co
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);
@@ -1349,12 +1351,12 @@ void ASTDumper::VisitOMPRequiresDecl(con
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";
@@ -1412,7 +1414,7 @@ void ASTDumper::VisitCXXRecordDecl(const
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "DefinitionData";
}
#define FLAG(fn, name) if (D->fn()) OS << " " #name;
@@ -1440,7 +1442,7 @@ void ASTDumper::VisitCXXRecordDecl(const
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "DefaultConstructor";
}
FLAG(hasDefaultConstructor, exists);
@@ -1454,7 +1456,7 @@ void ASTDumper::VisitCXXRecordDecl(const
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "CopyConstructor";
}
FLAG(hasSimpleCopyConstructor, simple);
@@ -1472,7 +1474,7 @@ void ASTDumper::VisitCXXRecordDecl(const
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "MoveConstructor";
}
FLAG(hasMoveConstructor, exists);
@@ -1489,7 +1491,7 @@ void ASTDumper::VisitCXXRecordDecl(const
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "CopyAssignment";
}
FLAG(hasTrivialCopyAssignment, trivial);
@@ -1503,7 +1505,7 @@ void ASTDumper::VisitCXXRecordDecl(const
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "MoveAssignment";
}
FLAG(hasMoveAssignment, exists);
@@ -1517,7 +1519,7 @@ void ASTDumper::VisitCXXRecordDecl(const
dumpChild([=] {
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << "Destructor";
}
FLAG(hasSimpleDestructor, simple);
@@ -1977,7 +1979,7 @@ void ASTDumper::VisitBlockDecl(const Blo
void ASTDumper::dumpStmt(const Stmt *S) {
dumpChild([=] {
if (!S) {
- ColorScope Color(*this, NullColor);
+ ColorScope Color(OS, ShowColors, NullColor);
OS << "<<<NULL>>>";
return;
}
@@ -2001,7 +2003,7 @@ void ASTDumper::dumpStmt(const Stmt *S)
void ASTDumper::VisitStmt(const Stmt *Node) {
{
- ColorScope Color(*this, StmtColor);
+ ColorScope Color(OS, ShowColors, StmtColor);
OS << Node->getStmtClassName();
}
dumpPointer(Node);
@@ -2085,12 +2087,12 @@ void ASTDumper::VisitOMPExecutableDirect
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";
@@ -2114,7 +2116,7 @@ void ASTDumper::VisitExpr(const Expr *No
dumpType(Node->getType());
{
- ColorScope Color(*this, ValueKindColor);
+ ColorScope Color(OS, ShowColors, ValueKindColor);
switch (Node->getValueKind()) {
case VK_RValue:
break;
@@ -2128,7 +2130,7 @@ void ASTDumper::VisitExpr(const Expr *No
}
{
- ColorScope Color(*this, ObjectKindColor);
+ ColorScope Color(OS, ShowColors, ObjectKindColor);
switch (Node->getObjectKind()) {
case OK_Ordinary:
break;
@@ -2177,7 +2179,7 @@ void ASTDumper::VisitCastExpr(const Cast
VisitExpr(Node);
OS << " <";
{
- ColorScope Color(*this, CastColor);
+ ColorScope Color(OS, ShowColors, CastColor);
OS << Node->getCastKindName();
}
dumpBasePath(OS, Node);
@@ -2221,7 +2223,7 @@ void ASTDumper::VisitObjCIvarRefExpr(con
VisitExpr(Node);
{
- ColorScope Color(*this, DeclKindNameColor);
+ ColorScope Color(OS, ShowColors, DeclKindNameColor);
OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
}
OS << "='" << *Node->getDecl() << "'";
@@ -2237,7 +2239,7 @@ void ASTDumper::VisitPredefinedExpr(cons
void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
VisitExpr(Node);
- ColorScope Color(*this, ValueColor);
+ ColorScope Color(OS, ShowColors, ValueColor);
OS << " " << Node->getValue();
}
@@ -2245,26 +2247,26 @@ void ASTDumper::VisitIntegerLiteral(cons
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);
}
@@ -2657,13 +2659,13 @@ void ASTDumper::dumpFullComment(const Fu
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);
More information about the cfe-commits
mailing list