r348719 - NFC: Move dump of individual comment nodes to NodeDumper

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 9 05:30:17 PST 2018


Author: steveire
Date: Sun Dec  9 05:30:17 2018
New Revision: 348719

URL: http://llvm.org/viewvc/llvm-project?rev=348719&view=rev
Log:
NFC: Move dump of individual comment nodes to NodeDumper

Reviewers: aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55190

Modified:
    cfe/trunk/include/clang/AST/TextNodeDumper.h
    cfe/trunk/lib/AST/ASTDumper.cpp
    cfe/trunk/lib/AST/TextNodeDumper.cpp

Modified: cfe/trunk/include/clang/AST/TextNodeDumper.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TextNodeDumper.h?rev=348719&r1=348718&r2=348719&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TextNodeDumper.h (original)
+++ cfe/trunk/include/clang/AST/TextNodeDumper.h Sun Dec  9 05:30:17 2018
@@ -16,11 +16,15 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTDumperUtils.h"
+#include "clang/AST/CommentCommandTraits.h"
+#include "clang/AST/CommentVisitor.h"
 #include "clang/AST/ExprCXX.h"
 
 namespace clang {
 
-class TextNodeDumper {
+class TextNodeDumper
+    : public comments::ConstCommentVisitor<TextNodeDumper, void,
+                                           const comments::FullComment *> {
   raw_ostream &OS;
   const bool ShowColors;
 
@@ -34,9 +38,16 @@ class TextNodeDumper {
   /// The policy to use for printing; can be defaulted.
   PrintingPolicy PrintPolicy;
 
+  const comments::CommandTraits *Traits;
+
+  const char *getCommandName(unsigned CommandID);
+
 public:
   TextNodeDumper(raw_ostream &OS, bool ShowColors, const SourceManager *SM,
-                 const PrintingPolicy &PrintPolicy);
+                 const PrintingPolicy &PrintPolicy,
+                 const comments::CommandTraits *Traits);
+
+  void Visit(const comments::Comment *C, const comments::FullComment *FC);
 
   void dumpPointer(const void *Ptr);
   void dumpLocation(SourceLocation Loc);
@@ -47,6 +58,28 @@ public:
   void dumpName(const NamedDecl *ND);
   void dumpAccessSpecifier(AccessSpecifier AS);
   void dumpCXXTemporary(const CXXTemporary *Temporary);
+
+  void visitTextComment(const comments::TextComment *C,
+                        const comments::FullComment *);
+  void visitInlineCommandComment(const comments::InlineCommandComment *C,
+                                 const comments::FullComment *);
+  void visitHTMLStartTagComment(const comments::HTMLStartTagComment *C,
+                                const comments::FullComment *);
+  void visitHTMLEndTagComment(const comments::HTMLEndTagComment *C,
+                              const comments::FullComment *);
+  void visitBlockCommandComment(const comments::BlockCommandComment *C,
+                                const comments::FullComment *);
+  void visitParamCommandComment(const comments::ParamCommandComment *C,
+                                const comments::FullComment *FC);
+  void visitTParamCommandComment(const comments::TParamCommandComment *C,
+                                 const comments::FullComment *FC);
+  void visitVerbatimBlockComment(const comments::VerbatimBlockComment *C,
+                                 const comments::FullComment *);
+  void
+  visitVerbatimBlockLineComment(const comments::VerbatimBlockLineComment *C,
+                                const comments::FullComment *);
+  void visitVerbatimLineComment(const comments::VerbatimLineComment *C,
+                                const comments::FullComment *);
 };
 
 } // namespace clang

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348719&r1=348718&r2=348719&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Sun Dec  9 05:30:17 2018
@@ -48,7 +48,6 @@ namespace  {
     TextNodeDumper NodeDumper;
 
     raw_ostream &OS;
-    const CommandTraits *Traits;
 
     /// The policy to use for printing; can be defaulted.
     PrintingPolicy PrintPolicy;
@@ -77,7 +76,7 @@ namespace  {
               const SourceManager *SM, bool ShowColors,
               const PrintingPolicy &PrintPolicy)
         : TreeStructure(OS, ShowColors),
-          NodeDumper(OS, ShowColors, SM, PrintPolicy), OS(OS), Traits(Traits),
+          NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
           PrintPolicy(PrintPolicy), ShowColors(ShowColors) {}
 
     void setDeserialize(bool D) { Deserialize = D; }
@@ -433,31 +432,7 @@ namespace  {
     void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
 
     // Comments.
-    const char *getCommandName(unsigned CommandID);
     void dumpComment(const Comment *C, const FullComment *FC);
-
-    // Inline comments.
-    void visitTextComment(const TextComment *C, const FullComment *FC);
-    void visitInlineCommandComment(const InlineCommandComment *C,
-                                   const FullComment *FC);
-    void visitHTMLStartTagComment(const HTMLStartTagComment *C,
-                                  const FullComment *FC);
-    void visitHTMLEndTagComment(const HTMLEndTagComment *C,
-                                const FullComment *FC);
-
-    // Block comments.
-    void visitBlockCommandComment(const BlockCommandComment *C,
-                                  const FullComment *FC);
-    void visitParamCommandComment(const ParamCommandComment *C,
-                                  const FullComment *FC);
-    void visitTParamCommandComment(const TParamCommandComment *C,
-                                   const FullComment *FC);
-    void visitVerbatimBlockComment(const VerbatimBlockComment *C,
-                                   const FullComment *FC);
-    void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C,
-                                       const FullComment *FC);
-    void visitVerbatimLineComment(const VerbatimLineComment *C,
-                                  const FullComment *FC);
   };
 }
 
@@ -2289,29 +2264,12 @@ void ASTDumper::VisitObjCBoolLiteralExpr
 // Comments
 //===----------------------------------------------------------------------===//
 
-const char *ASTDumper::getCommandName(unsigned CommandID) {
-  if (Traits)
-    return Traits->getCommandInfo(CommandID)->Name;
-  const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
-  if (Info)
-    return Info->Name;
-  return "<not a builtin command>";
-}
-
 void ASTDumper::dumpComment(const Comment *C, const FullComment *FC) {
   dumpChild([=] {
+    NodeDumper.Visit(C, FC);
     if (!C) {
-      ColorScope Color(OS, ShowColors, NullColor);
-      OS << "<<<NULL>>>";
       return;
     }
-
-    {
-      ColorScope Color(OS, ShowColors, CommentColor);
-      OS << C->getCommentKindName();
-    }
-    NodeDumper.dumpPointer(C);
-    NodeDumper.dumpSourceRange(C->getSourceRange());
     ConstCommentVisitor<ASTDumper, void, const FullComment *>::visit(C, FC);
     for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
          I != E; ++I)
@@ -2319,114 +2277,6 @@ void ASTDumper::dumpComment(const Commen
   });
 }
 
-void ASTDumper::visitTextComment(const TextComment *C, const FullComment *) {
-  OS << " Text=\"" << C->getText() << "\"";
-}
-
-void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C,
-                                          const FullComment *) {
-  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
-  switch (C->getRenderKind()) {
-  case InlineCommandComment::RenderNormal:
-    OS << " RenderNormal";
-    break;
-  case InlineCommandComment::RenderBold:
-    OS << " RenderBold";
-    break;
-  case InlineCommandComment::RenderMonospaced:
-    OS << " RenderMonospaced";
-    break;
-  case InlineCommandComment::RenderEmphasized:
-    OS << " RenderEmphasized";
-    break;
-  }
-
-  for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
-    OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
-}
-
-void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C,
-                                         const FullComment *) {
-  OS << " Name=\"" << C->getTagName() << "\"";
-  if (C->getNumAttrs() != 0) {
-    OS << " Attrs: ";
-    for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
-      const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
-      OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
-    }
-  }
-  if (C->isSelfClosing())
-    OS << " SelfClosing";
-}
-
-void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C,
-                                       const FullComment *) {
-  OS << " Name=\"" << C->getTagName() << "\"";
-}
-
-void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C,
-                                         const FullComment *) {
-  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
-  for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
-    OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
-}
-
-void ASTDumper::visitParamCommandComment(const ParamCommandComment *C,
-                                         const FullComment *FC) {
-  OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
-
-  if (C->isDirectionExplicit())
-    OS << " explicitly";
-  else
-    OS << " implicitly";
-
-  if (C->hasParamName()) {
-    if (C->isParamIndexValid())
-      OS << " Param=\"" << C->getParamName(FC) << "\"";
-    else
-      OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
-  }
-
-  if (C->isParamIndexValid() && !C->isVarArgParam())
-    OS << " ParamIndex=" << C->getParamIndex();
-}
-
-void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C,
-                                          const FullComment *FC) {
-  if (C->hasParamName()) {
-    if (C->isPositionValid())
-      OS << " Param=\"" << C->getParamName(FC) << "\"";
-    else
-      OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
-  }
-
-  if (C->isPositionValid()) {
-    OS << " Position=<";
-    for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
-      OS << C->getIndex(i);
-      if (i != e - 1)
-        OS << ", ";
-    }
-    OS << ">";
-  }
-}
-
-void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C,
-                                          const FullComment *) {
-  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
-        " CloseName=\"" << C->getCloseName() << "\"";
-}
-
-void ASTDumper::visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C,
-                                              const FullComment *) {
-  OS << " Text=\"" << C->getText() << "\"";
-}
-
-void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C,
-                                         const FullComment *) {
-  OS << " Text=\"" << C->getText() << "\"";
-}
-
 //===----------------------------------------------------------------------===//
 // Type method implementations
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/AST/TextNodeDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TextNodeDumper.cpp?rev=348719&r1=348718&r2=348719&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TextNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/TextNodeDumper.cpp Sun Dec  9 05:30:17 2018
@@ -17,8 +17,29 @@ using namespace clang;
 
 TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors,
                                const SourceManager *SM,
-                               const PrintingPolicy &PrintPolicy)
-    : OS(OS), ShowColors(ShowColors), SM(SM), PrintPolicy(PrintPolicy) {}
+                               const PrintingPolicy &PrintPolicy,
+                               const comments::CommandTraits *Traits)
+    : OS(OS), ShowColors(ShowColors), SM(SM), PrintPolicy(PrintPolicy),
+      Traits(Traits) {}
+
+void TextNodeDumper::Visit(const comments::Comment *C,
+                           const comments::FullComment *FC) {
+  if (!C) {
+    ColorScope Color(OS, ShowColors, NullColor);
+    OS << "<<<NULL>>>";
+    return;
+  }
+
+  {
+    ColorScope Color(OS, ShowColors, CommentColor);
+    OS << C->getCommentKindName();
+  }
+  dumpPointer(C);
+  dumpSourceRange(C->getSourceRange());
+
+  ConstCommentVisitor<TextNodeDumper, void,
+                      const comments::FullComment *>::visit(C, FC);
+}
 
 void TextNodeDumper::dumpPointer(const void *Ptr) {
   ColorScope Color(OS, ShowColors, AddressColor);
@@ -139,3 +160,126 @@ void TextNodeDumper::dumpCXXTemporary(co
   dumpPointer(Temporary);
   OS << ")";
 }
+
+const char *TextNodeDumper::getCommandName(unsigned CommandID) {
+  if (Traits)
+    return Traits->getCommandInfo(CommandID)->Name;
+  const comments::CommandInfo *Info =
+      comments::CommandTraits::getBuiltinCommandInfo(CommandID);
+  if (Info)
+    return Info->Name;
+  return "<not a builtin command>";
+}
+
+void TextNodeDumper::visitTextComment(const comments::TextComment *C,
+                                      const comments::FullComment *) {
+  OS << " Text=\"" << C->getText() << "\"";
+}
+
+void TextNodeDumper::visitInlineCommandComment(
+    const comments::InlineCommandComment *C, const comments::FullComment *) {
+  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
+  switch (C->getRenderKind()) {
+  case comments::InlineCommandComment::RenderNormal:
+    OS << " RenderNormal";
+    break;
+  case comments::InlineCommandComment::RenderBold:
+    OS << " RenderBold";
+    break;
+  case comments::InlineCommandComment::RenderMonospaced:
+    OS << " RenderMonospaced";
+    break;
+  case comments::InlineCommandComment::RenderEmphasized:
+    OS << " RenderEmphasized";
+    break;
+  }
+
+  for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
+    OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
+}
+
+void TextNodeDumper::visitHTMLStartTagComment(
+    const comments::HTMLStartTagComment *C, const comments::FullComment *) {
+  OS << " Name=\"" << C->getTagName() << "\"";
+  if (C->getNumAttrs() != 0) {
+    OS << " Attrs: ";
+    for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
+      const comments::HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
+      OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
+    }
+  }
+  if (C->isSelfClosing())
+    OS << " SelfClosing";
+}
+
+void TextNodeDumper::visitHTMLEndTagComment(
+    const comments::HTMLEndTagComment *C, const comments::FullComment *) {
+  OS << " Name=\"" << C->getTagName() << "\"";
+}
+
+void TextNodeDumper::visitBlockCommandComment(
+    const comments::BlockCommandComment *C, const comments::FullComment *) {
+  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
+  for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
+    OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
+}
+
+void TextNodeDumper::visitParamCommandComment(
+    const comments::ParamCommandComment *C, const comments::FullComment *FC) {
+  OS << " "
+     << comments::ParamCommandComment::getDirectionAsString(C->getDirection());
+
+  if (C->isDirectionExplicit())
+    OS << " explicitly";
+  else
+    OS << " implicitly";
+
+  if (C->hasParamName()) {
+    if (C->isParamIndexValid())
+      OS << " Param=\"" << C->getParamName(FC) << "\"";
+    else
+      OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
+  }
+
+  if (C->isParamIndexValid() && !C->isVarArgParam())
+    OS << " ParamIndex=" << C->getParamIndex();
+}
+
+void TextNodeDumper::visitTParamCommandComment(
+    const comments::TParamCommandComment *C, const comments::FullComment *FC) {
+  if (C->hasParamName()) {
+    if (C->isPositionValid())
+      OS << " Param=\"" << C->getParamName(FC) << "\"";
+    else
+      OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
+  }
+
+  if (C->isPositionValid()) {
+    OS << " Position=<";
+    for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
+      OS << C->getIndex(i);
+      if (i != e - 1)
+        OS << ", ";
+    }
+    OS << ">";
+  }
+}
+
+void TextNodeDumper::visitVerbatimBlockComment(
+    const comments::VerbatimBlockComment *C, const comments::FullComment *) {
+  OS << " Name=\"" << getCommandName(C->getCommandID())
+     << "\""
+        " CloseName=\""
+     << C->getCloseName() << "\"";
+}
+
+void TextNodeDumper::visitVerbatimBlockLineComment(
+    const comments::VerbatimBlockLineComment *C,
+    const comments::FullComment *) {
+  OS << " Text=\"" << C->getText() << "\"";
+}
+
+void TextNodeDumper::visitVerbatimLineComment(
+    const comments::VerbatimLineComment *C, const comments::FullComment *) {
+  OS << " Text=\"" << C->getText() << "\"";
+}




More information about the cfe-commits mailing list