1 //===--- CommentDumper.cpp - Dumping implementation for Comment ASTs ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/AST/CommentVisitor.h"
11 #include "llvm/Support/raw_ostream.h"
17 class CommentDumper: public comments::ConstCommentVisitor<CommentDumper> {
23 CommentDumper(raw_ostream &OS, SourceManager *SM) :
24 OS(OS), SM(SM), IndentLevel(0)
27 void dumpIndent() const {
28 for (unsigned i = 1, e = IndentLevel; i < e; ++i)
32 void dumpLocation(SourceLocation Loc) {
37 void dumpSourceRange(const Comment *C);
39 void dumpComment(const Comment *C);
41 void dumpSubtree(const Comment *C);
44 void visitTextComment(const TextComment *C);
45 void visitInlineCommandComment(const InlineCommandComment *C);
46 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
47 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
50 void visitParagraphComment(const ParagraphComment *C);
51 void visitBlockCommandComment(const BlockCommandComment *C);
52 void visitParamCommandComment(const ParamCommandComment *C);
53 void visitTParamCommandComment(const TParamCommandComment *C);
54 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
55 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
56 void visitVerbatimLineComment(const VerbatimLineComment *C);
58 void visitFullComment(const FullComment *C);
61 void CommentDumper::dumpSourceRange(const Comment *C) {
65 SourceRange SR = C->getSourceRange();
68 dumpLocation(SR.getBegin());
69 if (SR.getBegin() != SR.getEnd()) {
71 dumpLocation(SR.getEnd());
76 void CommentDumper::dumpComment(const Comment *C) {
78 OS << "(" << C->getCommentKindName()
79 << " " << (const void *) C;
83 void CommentDumper::dumpSubtree(const Comment *C) {
87 for (Comment::child_iterator I = C->child_begin(),
101 void CommentDumper::visitTextComment(const TextComment *C) {
104 OS << " Text=\"" << C->getText() << "\"";
107 void CommentDumper::visitInlineCommandComment(const InlineCommandComment *C) {
110 OS << " Name=\"" << C->getCommandName() << "\"";
111 switch (C->getRenderKind()) {
112 case InlineCommandComment::RenderNormal:
113 OS << " RenderNormal";
115 case InlineCommandComment::RenderBold:
118 case InlineCommandComment::RenderMonospaced:
119 OS << " RenderMonospaced";
121 case InlineCommandComment::RenderEmphasized:
122 OS << " RenderEmphasized";
126 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
127 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
130 void CommentDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
133 OS << " Name=\"" << C->getTagName() << "\"";
134 if (C->getNumAttrs() != 0) {
136 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
137 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
138 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
141 if (C->isSelfClosing())
142 OS << " SelfClosing";
145 void CommentDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
148 OS << " Name=\"" << C->getTagName() << "\"";
151 void CommentDumper::visitParagraphComment(const ParagraphComment *C) {
155 void CommentDumper::visitBlockCommandComment(const BlockCommandComment *C) {
158 OS << " Name=\"" << C->getCommandName() << "\"";
159 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
160 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
163 void CommentDumper::visitParamCommandComment(const ParamCommandComment *C) {
166 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
168 if (C->isDirectionExplicit())
173 if (C->hasParamName())
174 OS << " Param=\"" << C->getParamName() << "\"";
176 if (C->isParamIndexValid())
177 OS << " ParamIndex=" << C->getParamIndex();
180 void CommentDumper::visitTParamCommandComment(const TParamCommandComment *C) {
183 if (C->hasParamName()) {
184 OS << " Param=\"" << C->getParamName() << "\"";
187 if (C->isPositionValid()) {
189 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
190 OS << C->getIndex(i);
198 void CommentDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
201 OS << " Name=\"" << C->getCommandName() << "\""
202 " CloseName=\"" << C->getCloseName() << "\"";
205 void CommentDumper::visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C) {
208 OS << " Text=\"" << C->getText() << "\"";
211 void CommentDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
214 OS << " Text=\"" << C->getText() << "\"";
217 void CommentDumper::visitFullComment(const FullComment *C) {
221 } // unnamed namespace
223 void Comment::dump(llvm::raw_ostream &OS, SourceManager *SM) const {
224 CommentDumper D(llvm::errs(), SM);
226 llvm::errs() << '\n';
229 } // end namespace comments
230 } // end namespace clang