steveire created this revision. steveire added a reviewer: aaron.ballman. Herald added a subscriber: cfe-commits.
Repository: rC Clang https://reviews.llvm.org/D55070 Files: lib/AST/ASTDumper.cpp
Index: lib/AST/ASTDumper.cpp =================================================================== --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -109,8 +109,16 @@ }; class ASTDumper - : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>, - public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> { + : public ConstDeclVisitor<ASTDumper>, + public ConstStmtVisitor<ASTDumper>, + public CommentVisitorBase<comments::make_const_ptr, ASTDumper, void, + const FullComment *>, + public TypeVisitor<ASTDumper> { + + using CommentVisitorType = + CommentVisitorBase<comments::make_const_ptr, ASTDumper, void, + const FullComment *>; + raw_ostream &OS; const CommandTraits *Traits; const SourceManager *SM; @@ -139,9 +147,6 @@ const char *LastLocFilename = ""; unsigned LastLocLine = ~0U; - /// The \c FullComment parent of the comment being dumped. - const FullComment *FC = nullptr; - const bool ShowColors; /// Dump a child of the current node. @@ -161,8 +166,7 @@ return; } - const FullComment *OrigFC = FC; - auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) { + auto dumpWithIndent = [this, doDumpChild](bool isLastChild) { // Print out the appropriate tree structure and work out the prefix for // children of this node. For instance: // @@ -186,7 +190,6 @@ FirstChild = true; unsigned Depth = Pending.size(); - FC = OrigFC; doDumpChild(); // If any children are left, they're the last at their nesting level. @@ -586,21 +589,30 @@ // Comments. const char *getCommandName(unsigned CommandID); - void dumpComment(const Comment *C); + void dumpComment(const Comment *C, const FullComment *FC); // Inline comments. - void VisitTextComment(const TextComment *C); - void VisitInlineCommandComment(const InlineCommandComment *C); - void VisitHTMLStartTagComment(const HTMLStartTagComment *C); - void VisitHTMLEndTagComment(const HTMLEndTagComment *C); + 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); - void VisitParamCommandComment(const ParamCommandComment *C); - void VisitTParamCommandComment(const TParamCommandComment *C); - void VisitVerbatimBlockComment(const VerbatimBlockComment *C); - void VisitVerbatimBlockLineComment(const VerbatimBlockLineComment *C); - void VisitVerbatimLineComment(const VerbatimLineComment *C); + 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); }; } @@ -2645,13 +2657,10 @@ void ASTDumper::dumpFullComment(const FullComment *C) { if (!C) return; - - FC = C; - dumpComment(C); - FC = nullptr; + dumpComment(C, C); } -void ASTDumper::dumpComment(const Comment *C) { +void ASTDumper::dumpComment(const Comment *C, const FullComment *FC) { dumpChild([=] { if (!C) { ColorScope Color(OS, ShowColors, NullColor); @@ -2665,18 +2674,19 @@ } dumpPointer(C); dumpSourceRange(C->getSourceRange()); - ConstCommentVisitor<ASTDumper>::Visit(C); + CommentVisitorType::Visit(C, FC); for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); I != E; ++I) - dumpComment(*I); + dumpComment(*I, FC); }); } -void ASTDumper::VisitTextComment(const TextComment *C) { +void ASTDumper::VisitTextComment(const TextComment *C, const FullComment *FC) { OS << " Text=\"" << C->getText() << "\""; } -void ASTDumper::VisitInlineCommandComment(const InlineCommandComment *C) { +void ASTDumper::VisitInlineCommandComment(const InlineCommandComment *C, + const FullComment *FC) { OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""; switch (C->getRenderKind()) { case InlineCommandComment::RenderNormal: @@ -2697,7 +2707,8 @@ OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\""; } -void ASTDumper::VisitHTMLStartTagComment(const HTMLStartTagComment *C) { +void ASTDumper::VisitHTMLStartTagComment(const HTMLStartTagComment *C, + const FullComment *FC) { OS << " Name=\"" << C->getTagName() << "\""; if (C->getNumAttrs() != 0) { OS << " Attrs: "; @@ -2710,17 +2721,20 @@ OS << " SelfClosing"; } -void ASTDumper::VisitHTMLEndTagComment(const HTMLEndTagComment *C) { +void ASTDumper::VisitHTMLEndTagComment(const HTMLEndTagComment *C, + const FullComment *FC) { OS << " Name=\"" << C->getTagName() << "\""; } -void ASTDumper::VisitBlockCommandComment(const BlockCommandComment *C) { +void ASTDumper::VisitBlockCommandComment(const BlockCommandComment *C, + const FullComment *FC) { 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) { +void ASTDumper::VisitParamCommandComment(const ParamCommandComment *C, + const FullComment *FC) { OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection()); if (C->isDirectionExplicit()) @@ -2739,7 +2753,8 @@ OS << " ParamIndex=" << C->getParamIndex(); } -void ASTDumper::VisitTParamCommandComment(const TParamCommandComment *C) { +void ASTDumper::VisitTParamCommandComment(const TParamCommandComment *C, + const FullComment *FC) { if (C->hasParamName()) { if (C->isPositionValid()) OS << " Param=\"" << C->getParamName(FC) << "\""; @@ -2758,17 +2773,19 @@ } } -void ASTDumper::VisitVerbatimBlockComment(const VerbatimBlockComment *C) { +void ASTDumper::VisitVerbatimBlockComment(const VerbatimBlockComment *C, + const FullComment *FC) { OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"" " CloseName=\"" << C->getCloseName() << "\""; } -void ASTDumper::VisitVerbatimBlockLineComment( - const VerbatimBlockLineComment *C) { +void ASTDumper::VisitVerbatimBlockLineComment(const VerbatimBlockLineComment *C, + const FullComment *FC) { OS << " Text=\"" << C->getText() << "\""; } -void ASTDumper::VisitVerbatimLineComment(const VerbatimLineComment *C) { +void ASTDumper::VisitVerbatimLineComment(const VerbatimLineComment *C, + const FullComment *FC) { OS << " Text=\"" << C->getText() << "\""; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits