@@ -1036,33 +1036,41 @@ namespace {
10361036 }
10371037 PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
10381038 }
1039+
1040+ void printASTNodes (const ArrayRef<ASTNode> &Elements, StringRef Name) {
1041+ OS.indent (Indent);
1042+ PrintWithColorRAII (OS, ParenthesisColor) << " (" ;
1043+ PrintWithColorRAII (OS, ASTNodeColor) << Name;
1044+ for (auto Elt : Elements) {
1045+ OS << ' \n ' ;
1046+ if (auto *SubExpr = Elt.dyn_cast <Expr*>())
1047+ printRec (SubExpr);
1048+ else if (auto *SubStmt = Elt.dyn_cast <Stmt*>())
1049+ printRec (SubStmt);
1050+ else
1051+ printRec (Elt.get <Decl*>());
1052+ }
1053+ PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1054+ }
10391055
10401056 void visitIfConfigDecl (IfConfigDecl *ICD) {
1041- OS.indent (Indent);
1042- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1043- OS << " #if_decl\n " ;
1057+ printCommon (ICD, " if_config_decl" );
10441058 Indent += 2 ;
10451059 for (auto &Clause : ICD->getClauses ()) {
1060+ OS << ' \n ' ;
1061+ OS.indent (Indent);
1062+ PrintWithColorRAII (OS, StmtColor) << (Clause.Cond ? " #if:" : " #else:" );
1063+ if (Clause.isActive )
1064+ PrintWithColorRAII (OS, DeclModifierColor) << " active" ;
10461065 if (Clause.Cond ) {
1047- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1048- OS << " #if:" ;
1049- if (Clause.isActive ) OS << " active" ;
10501066 OS << " \n " ;
10511067 printRec (Clause.Cond );
1052- } else {
1053- OS << ' \n ' ;
1054- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1055- OS << " #else:" ;
1056- if (Clause.isActive ) OS << " active" ;
1057- OS << " \n " ;
10581068 }
10591069
1060- for (auto D : Clause.Elements ) {
1061- OS << ' \n ' ;
1062- printRec (D);
1063- }
1064-
1065- PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1070+ OS << ' \n ' ;
1071+ Indent += 2 ;
1072+ printASTNodes (Clause.Elements , " elements" );
1073+ Indent -= 2 ;
10661074 }
10671075
10681076 Indent -= 2 ;
@@ -1422,35 +1430,6 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
14221430 PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
14231431 }
14241432
1425- void visitIfConfigStmt (IfConfigStmt *S) {
1426- printCommon (S, " #if_stmt" );
1427- Indent += 2 ;
1428- for (auto &Clause : S->getClauses ()) {
1429- OS << ' \n ' ;
1430- OS.indent (Indent);
1431- if (Clause.Cond ) {
1432- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1433- PrintWithColorRAII (OS, StmtColor) << " #if:" ;
1434- if (Clause.isActive )
1435- PrintWithColorRAII (OS, DeclModifierColor) << " active" ;
1436- OS << ' \n ' ;
1437- printRec (Clause.Cond );
1438- } else {
1439- PrintWithColorRAII (OS, StmtColor) << " #else" ;
1440- if (Clause.isActive )
1441- PrintWithColorRAII (OS, DeclModifierColor) << " active" ;
1442- }
1443-
1444- OS << ' \n ' ;
1445- Indent += 2 ;
1446- printASTNodes (Clause.Elements , " elements" );
1447- Indent -= 2 ;
1448- }
1449-
1450- Indent -= 2 ;
1451- PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1452- }
1453-
14541433 void visitDoStmt (DoStmt *S) {
14551434 printCommon (S, " do_stmt" ) << ' \n ' ;
14561435 printRec (S->getBody ());
0 commit comments