xref: /minix3/external/bsd/llvm/dist/clang/lib/AST/ASTDumper.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===--- ASTDumper.cpp - Dumping implementation for ASTs ------------------===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This file implements the AST dump methods, which dump out the
11f4a2713aSLionel Sambuc // AST in a form that exposes type details and other fields.
12f4a2713aSLionel Sambuc //
13f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc #include "clang/AST/ASTContext.h"
16f4a2713aSLionel Sambuc #include "clang/AST/Attr.h"
17f4a2713aSLionel Sambuc #include "clang/AST/CommentVisitor.h"
18f4a2713aSLionel Sambuc #include "clang/AST/DeclCXX.h"
19f4a2713aSLionel Sambuc #include "clang/AST/DeclLookups.h"
20f4a2713aSLionel Sambuc #include "clang/AST/DeclObjC.h"
21f4a2713aSLionel Sambuc #include "clang/AST/DeclVisitor.h"
22f4a2713aSLionel Sambuc #include "clang/AST/StmtVisitor.h"
23*0a6a1f1dSLionel Sambuc #include "clang/AST/TypeVisitor.h"
24f4a2713aSLionel Sambuc #include "clang/Basic/Module.h"
25f4a2713aSLionel Sambuc #include "clang/Basic/SourceManager.h"
26f4a2713aSLionel Sambuc #include "llvm/Support/raw_ostream.h"
27f4a2713aSLionel Sambuc using namespace clang;
28f4a2713aSLionel Sambuc using namespace clang::comments;
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
31f4a2713aSLionel Sambuc // ASTDumper Visitor
32f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc namespace  {
35f4a2713aSLionel Sambuc   // Colors used for various parts of the AST dump
36*0a6a1f1dSLionel Sambuc   // Do not use bold yellow for any text.  It is hard to read on white screens.
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc   struct TerminalColor {
39f4a2713aSLionel Sambuc     raw_ostream::Colors Color;
40f4a2713aSLionel Sambuc     bool Bold;
41f4a2713aSLionel Sambuc   };
42f4a2713aSLionel Sambuc 
43*0a6a1f1dSLionel Sambuc   // Red           - CastColor
44*0a6a1f1dSLionel Sambuc   // Green         - TypeColor
45*0a6a1f1dSLionel Sambuc   // Bold Green    - DeclKindNameColor, UndeserializedColor
46*0a6a1f1dSLionel Sambuc   // Yellow        - AddressColor, LocationColor
47*0a6a1f1dSLionel Sambuc   // Blue          - CommentColor, NullColor, IndentColor
48*0a6a1f1dSLionel Sambuc   // Bold Blue     - AttrColor
49*0a6a1f1dSLionel Sambuc   // Bold Magenta  - StmtColor
50*0a6a1f1dSLionel Sambuc   // Cyan          - ValueKindColor, ObjectKindColor
51*0a6a1f1dSLionel Sambuc   // Bold Cyan     - ValueColor, DeclNameColor
52*0a6a1f1dSLionel Sambuc 
53f4a2713aSLionel Sambuc   // Decl kind names (VarDecl, FunctionDecl, etc)
54f4a2713aSLionel Sambuc   static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
55f4a2713aSLionel Sambuc   // Attr names (CleanupAttr, GuardedByAttr, etc)
56f4a2713aSLionel Sambuc   static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
57f4a2713aSLionel Sambuc   // Statement names (DeclStmt, ImplicitCastExpr, etc)
58f4a2713aSLionel Sambuc   static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
59f4a2713aSLionel Sambuc   // Comment names (FullComment, ParagraphComment, TextComment, etc)
60*0a6a1f1dSLionel Sambuc   static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
61f4a2713aSLionel Sambuc 
62f4a2713aSLionel Sambuc   // Type names (int, float, etc, plus user defined types)
63f4a2713aSLionel Sambuc   static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
64f4a2713aSLionel Sambuc 
65f4a2713aSLionel Sambuc   // Pointer address
66f4a2713aSLionel Sambuc   static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
67f4a2713aSLionel Sambuc   // Source locations
68f4a2713aSLionel Sambuc   static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
69f4a2713aSLionel Sambuc 
70f4a2713aSLionel Sambuc   // lvalue/xvalue
71f4a2713aSLionel Sambuc   static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
72f4a2713aSLionel Sambuc   // bitfield/objcproperty/objcsubscript/vectorcomponent
73f4a2713aSLionel Sambuc   static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
74f4a2713aSLionel Sambuc 
75f4a2713aSLionel Sambuc   // Null statements
76f4a2713aSLionel Sambuc   static const TerminalColor NullColor = { raw_ostream::BLUE, false };
77f4a2713aSLionel Sambuc 
78f4a2713aSLionel Sambuc   // Undeserialized entities
79f4a2713aSLionel Sambuc   static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
80f4a2713aSLionel Sambuc 
81f4a2713aSLionel Sambuc   // CastKind from CastExpr's
82f4a2713aSLionel Sambuc   static const TerminalColor CastColor = { raw_ostream::RED, false };
83f4a2713aSLionel Sambuc 
84f4a2713aSLionel Sambuc   // Value of the statement
85f4a2713aSLionel Sambuc   static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
86f4a2713aSLionel Sambuc   // Decl names
87f4a2713aSLionel Sambuc   static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
88f4a2713aSLionel Sambuc 
89f4a2713aSLionel Sambuc   // Indents ( `, -. | )
90f4a2713aSLionel Sambuc   static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
91f4a2713aSLionel Sambuc 
92f4a2713aSLionel Sambuc   class ASTDumper
93f4a2713aSLionel Sambuc       : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
94*0a6a1f1dSLionel Sambuc         public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
95f4a2713aSLionel Sambuc     raw_ostream &OS;
96f4a2713aSLionel Sambuc     const CommandTraits *Traits;
97f4a2713aSLionel Sambuc     const SourceManager *SM;
98f4a2713aSLionel Sambuc 
99*0a6a1f1dSLionel Sambuc     /// Pending[i] is an action to dump an entity at level i.
100*0a6a1f1dSLionel Sambuc     llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
101f4a2713aSLionel Sambuc 
102*0a6a1f1dSLionel Sambuc     /// Indicates whether we're at the top level.
103*0a6a1f1dSLionel Sambuc     bool TopLevel;
104f4a2713aSLionel Sambuc 
105*0a6a1f1dSLionel Sambuc     /// Indicates if we're handling the first child after entering a new depth.
106*0a6a1f1dSLionel Sambuc     bool FirstChild;
107*0a6a1f1dSLionel Sambuc 
108*0a6a1f1dSLionel Sambuc     /// Prefix for currently-being-dumped entity.
109*0a6a1f1dSLionel Sambuc     std::string Prefix;
110f4a2713aSLionel Sambuc 
111f4a2713aSLionel Sambuc     /// Keep track of the last location we print out so that we can
112f4a2713aSLionel Sambuc     /// print out deltas from then on out.
113f4a2713aSLionel Sambuc     const char *LastLocFilename;
114f4a2713aSLionel Sambuc     unsigned LastLocLine;
115f4a2713aSLionel Sambuc 
116f4a2713aSLionel Sambuc     /// The \c FullComment parent of the comment being dumped.
117f4a2713aSLionel Sambuc     const FullComment *FC;
118f4a2713aSLionel Sambuc 
119f4a2713aSLionel Sambuc     bool ShowColors;
120f4a2713aSLionel Sambuc 
121*0a6a1f1dSLionel Sambuc     /// Dump a child of the current node.
dumpChild(Fn doDumpChild)122*0a6a1f1dSLionel Sambuc     template<typename Fn> void dumpChild(Fn doDumpChild) {
123*0a6a1f1dSLionel Sambuc       // If we're at the top level, there's nothing interesting to do; just
124*0a6a1f1dSLionel Sambuc       // run the dumper.
125*0a6a1f1dSLionel Sambuc       if (TopLevel) {
126*0a6a1f1dSLionel Sambuc         TopLevel = false;
127*0a6a1f1dSLionel Sambuc         doDumpChild();
128*0a6a1f1dSLionel Sambuc         while (!Pending.empty()) {
129*0a6a1f1dSLionel Sambuc           Pending.back()(true);
130*0a6a1f1dSLionel Sambuc           Pending.pop_back();
131f4a2713aSLionel Sambuc         }
132*0a6a1f1dSLionel Sambuc         Prefix.clear();
133*0a6a1f1dSLionel Sambuc         OS << "\n";
134*0a6a1f1dSLionel Sambuc         TopLevel = true;
135*0a6a1f1dSLionel Sambuc         return;
136f4a2713aSLionel Sambuc       }
137*0a6a1f1dSLionel Sambuc 
138*0a6a1f1dSLionel Sambuc       const FullComment *OrigFC = FC;
139*0a6a1f1dSLionel Sambuc       auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
140*0a6a1f1dSLionel Sambuc         // Print out the appropriate tree structure and work out the prefix for
141*0a6a1f1dSLionel Sambuc         // children of this node. For instance:
142*0a6a1f1dSLionel Sambuc         //
143*0a6a1f1dSLionel Sambuc         //   A        Prefix = ""
144*0a6a1f1dSLionel Sambuc         //   |-B      Prefix = "| "
145*0a6a1f1dSLionel Sambuc         //   | `-C    Prefix = "|   "
146*0a6a1f1dSLionel Sambuc         //   `-D      Prefix = "  "
147*0a6a1f1dSLionel Sambuc         //     |-E    Prefix = "  | "
148*0a6a1f1dSLionel Sambuc         //     `-F    Prefix = "    "
149*0a6a1f1dSLionel Sambuc         //   G        Prefix = ""
150*0a6a1f1dSLionel Sambuc         //
151*0a6a1f1dSLionel Sambuc         // Note that the first level gets no prefix.
152*0a6a1f1dSLionel Sambuc         {
153*0a6a1f1dSLionel Sambuc           OS << '\n';
154*0a6a1f1dSLionel Sambuc           ColorScope Color(*this, IndentColor);
155*0a6a1f1dSLionel Sambuc           OS << Prefix << (isLastChild ? '`' : '|') << '-';
156*0a6a1f1dSLionel Sambuc           this->Prefix.push_back(isLastChild ? ' ' : '|');
157*0a6a1f1dSLionel Sambuc           this->Prefix.push_back(' ');
158*0a6a1f1dSLionel Sambuc         }
159*0a6a1f1dSLionel Sambuc 
160*0a6a1f1dSLionel Sambuc         FirstChild = true;
161*0a6a1f1dSLionel Sambuc         unsigned Depth = Pending.size();
162*0a6a1f1dSLionel Sambuc 
163*0a6a1f1dSLionel Sambuc         FC = OrigFC;
164*0a6a1f1dSLionel Sambuc         doDumpChild();
165*0a6a1f1dSLionel Sambuc 
166*0a6a1f1dSLionel Sambuc         // If any children are left, they're the last at their nesting level.
167*0a6a1f1dSLionel Sambuc         // Dump those ones out now.
168*0a6a1f1dSLionel Sambuc         while (Depth < Pending.size()) {
169*0a6a1f1dSLionel Sambuc           Pending.back()(true);
170*0a6a1f1dSLionel Sambuc           this->Pending.pop_back();
171*0a6a1f1dSLionel Sambuc         }
172*0a6a1f1dSLionel Sambuc 
173*0a6a1f1dSLionel Sambuc         // Restore the old prefix.
174*0a6a1f1dSLionel Sambuc         this->Prefix.resize(Prefix.size() - 2);
175f4a2713aSLionel Sambuc       };
176f4a2713aSLionel Sambuc 
177*0a6a1f1dSLionel Sambuc       if (FirstChild) {
178*0a6a1f1dSLionel Sambuc         Pending.push_back(std::move(dumpWithIndent));
179*0a6a1f1dSLionel Sambuc       } else {
180*0a6a1f1dSLionel Sambuc         Pending.back()(false);
181*0a6a1f1dSLionel Sambuc         Pending.back() = std::move(dumpWithIndent);
182*0a6a1f1dSLionel Sambuc       }
183*0a6a1f1dSLionel Sambuc       FirstChild = false;
184*0a6a1f1dSLionel Sambuc     }
185*0a6a1f1dSLionel Sambuc 
186f4a2713aSLionel Sambuc     class ColorScope {
187f4a2713aSLionel Sambuc       ASTDumper &Dumper;
188f4a2713aSLionel Sambuc     public:
ColorScope(ASTDumper & Dumper,TerminalColor Color)189f4a2713aSLionel Sambuc       ColorScope(ASTDumper &Dumper, TerminalColor Color)
190f4a2713aSLionel Sambuc         : Dumper(Dumper) {
191f4a2713aSLionel Sambuc         if (Dumper.ShowColors)
192f4a2713aSLionel Sambuc           Dumper.OS.changeColor(Color.Color, Color.Bold);
193f4a2713aSLionel Sambuc       }
~ColorScope()194f4a2713aSLionel Sambuc       ~ColorScope() {
195f4a2713aSLionel Sambuc         if (Dumper.ShowColors)
196f4a2713aSLionel Sambuc           Dumper.OS.resetColor();
197f4a2713aSLionel Sambuc       }
198f4a2713aSLionel Sambuc     };
199f4a2713aSLionel Sambuc 
200f4a2713aSLionel Sambuc   public:
ASTDumper(raw_ostream & OS,const CommandTraits * Traits,const SourceManager * SM)201f4a2713aSLionel Sambuc     ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
202f4a2713aSLionel Sambuc               const SourceManager *SM)
203*0a6a1f1dSLionel Sambuc       : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
204*0a6a1f1dSLionel Sambuc         LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
205f4a2713aSLionel Sambuc         ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
206f4a2713aSLionel Sambuc 
ASTDumper(raw_ostream & OS,const CommandTraits * Traits,const SourceManager * SM,bool ShowColors)207f4a2713aSLionel Sambuc     ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
208f4a2713aSLionel Sambuc               const SourceManager *SM, bool ShowColors)
209*0a6a1f1dSLionel Sambuc       : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
210f4a2713aSLionel Sambuc         LastLocFilename(""), LastLocLine(~0U),
211f4a2713aSLionel Sambuc         ShowColors(ShowColors) { }
212f4a2713aSLionel Sambuc 
213f4a2713aSLionel Sambuc     void dumpDecl(const Decl *D);
214f4a2713aSLionel Sambuc     void dumpStmt(const Stmt *S);
215f4a2713aSLionel Sambuc     void dumpFullComment(const FullComment *C);
216f4a2713aSLionel Sambuc 
217f4a2713aSLionel Sambuc     // Utilities
218f4a2713aSLionel Sambuc     void dumpPointer(const void *Ptr);
219f4a2713aSLionel Sambuc     void dumpSourceRange(SourceRange R);
220f4a2713aSLionel Sambuc     void dumpLocation(SourceLocation Loc);
221*0a6a1f1dSLionel Sambuc     void dumpBareType(QualType T, bool Desugar = true);
222f4a2713aSLionel Sambuc     void dumpType(QualType T);
223*0a6a1f1dSLionel Sambuc     void dumpTypeAsChild(QualType T);
224*0a6a1f1dSLionel Sambuc     void dumpTypeAsChild(const Type *T);
225f4a2713aSLionel Sambuc     void dumpBareDeclRef(const Decl *Node);
226*0a6a1f1dSLionel Sambuc     void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
227f4a2713aSLionel Sambuc     void dumpName(const NamedDecl *D);
228f4a2713aSLionel Sambuc     bool hasNodes(const DeclContext *DC);
229f4a2713aSLionel Sambuc     void dumpDeclContext(const DeclContext *DC);
230*0a6a1f1dSLionel Sambuc     void dumpLookups(const DeclContext *DC, bool DumpDecls);
231f4a2713aSLionel Sambuc     void dumpAttr(const Attr *A);
232f4a2713aSLionel Sambuc 
233f4a2713aSLionel Sambuc     // C++ Utilities
234f4a2713aSLionel Sambuc     void dumpAccessSpecifier(AccessSpecifier AS);
235f4a2713aSLionel Sambuc     void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
236f4a2713aSLionel Sambuc     void dumpTemplateParameters(const TemplateParameterList *TPL);
237f4a2713aSLionel Sambuc     void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
238f4a2713aSLionel Sambuc     void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
239f4a2713aSLionel Sambuc     void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
240f4a2713aSLionel Sambuc     void dumpTemplateArgument(const TemplateArgument &A,
241f4a2713aSLionel Sambuc                               SourceRange R = SourceRange());
242f4a2713aSLionel Sambuc 
243*0a6a1f1dSLionel Sambuc     // Types
VisitComplexType(const ComplexType * T)244*0a6a1f1dSLionel Sambuc     void VisitComplexType(const ComplexType *T) {
245*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getElementType());
246*0a6a1f1dSLionel Sambuc     }
VisitPointerType(const PointerType * T)247*0a6a1f1dSLionel Sambuc     void VisitPointerType(const PointerType *T) {
248*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getPointeeType());
249*0a6a1f1dSLionel Sambuc     }
VisitBlockPointerType(const BlockPointerType * T)250*0a6a1f1dSLionel Sambuc     void VisitBlockPointerType(const BlockPointerType *T) {
251*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getPointeeType());
252*0a6a1f1dSLionel Sambuc     }
VisitReferenceType(const ReferenceType * T)253*0a6a1f1dSLionel Sambuc     void VisitReferenceType(const ReferenceType *T) {
254*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getPointeeType());
255*0a6a1f1dSLionel Sambuc     }
VisitRValueReferenceType(const ReferenceType * T)256*0a6a1f1dSLionel Sambuc     void VisitRValueReferenceType(const ReferenceType *T) {
257*0a6a1f1dSLionel Sambuc       if (T->isSpelledAsLValue())
258*0a6a1f1dSLionel Sambuc         OS << " written as lvalue reference";
259*0a6a1f1dSLionel Sambuc       VisitReferenceType(T);
260*0a6a1f1dSLionel Sambuc     }
VisitMemberPointerType(const MemberPointerType * T)261*0a6a1f1dSLionel Sambuc     void VisitMemberPointerType(const MemberPointerType *T) {
262*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getClass());
263*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getPointeeType());
264*0a6a1f1dSLionel Sambuc     }
VisitArrayType(const ArrayType * T)265*0a6a1f1dSLionel Sambuc     void VisitArrayType(const ArrayType *T) {
266*0a6a1f1dSLionel Sambuc       switch (T->getSizeModifier()) {
267*0a6a1f1dSLionel Sambuc         case ArrayType::Normal: break;
268*0a6a1f1dSLionel Sambuc         case ArrayType::Static: OS << " static"; break;
269*0a6a1f1dSLionel Sambuc         case ArrayType::Star: OS << " *"; break;
270*0a6a1f1dSLionel Sambuc       }
271*0a6a1f1dSLionel Sambuc       OS << " " << T->getIndexTypeQualifiers().getAsString();
272*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getElementType());
273*0a6a1f1dSLionel Sambuc     }
VisitConstantArrayType(const ConstantArrayType * T)274*0a6a1f1dSLionel Sambuc     void VisitConstantArrayType(const ConstantArrayType *T) {
275*0a6a1f1dSLionel Sambuc       OS << " " << T->getSize();
276*0a6a1f1dSLionel Sambuc       VisitArrayType(T);
277*0a6a1f1dSLionel Sambuc     }
VisitVariableArrayType(const VariableArrayType * T)278*0a6a1f1dSLionel Sambuc     void VisitVariableArrayType(const VariableArrayType *T) {
279*0a6a1f1dSLionel Sambuc       OS << " ";
280*0a6a1f1dSLionel Sambuc       dumpSourceRange(T->getBracketsRange());
281*0a6a1f1dSLionel Sambuc       VisitArrayType(T);
282*0a6a1f1dSLionel Sambuc       dumpStmt(T->getSizeExpr());
283*0a6a1f1dSLionel Sambuc     }
VisitDependentSizedArrayType(const DependentSizedArrayType * T)284*0a6a1f1dSLionel Sambuc     void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
285*0a6a1f1dSLionel Sambuc       VisitArrayType(T);
286*0a6a1f1dSLionel Sambuc       OS << " ";
287*0a6a1f1dSLionel Sambuc       dumpSourceRange(T->getBracketsRange());
288*0a6a1f1dSLionel Sambuc       dumpStmt(T->getSizeExpr());
289*0a6a1f1dSLionel Sambuc     }
VisitDependentSizedExtVectorType(const DependentSizedExtVectorType * T)290*0a6a1f1dSLionel Sambuc     void VisitDependentSizedExtVectorType(
291*0a6a1f1dSLionel Sambuc         const DependentSizedExtVectorType *T) {
292*0a6a1f1dSLionel Sambuc       OS << " ";
293*0a6a1f1dSLionel Sambuc       dumpLocation(T->getAttributeLoc());
294*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getElementType());
295*0a6a1f1dSLionel Sambuc       dumpStmt(T->getSizeExpr());
296*0a6a1f1dSLionel Sambuc     }
VisitVectorType(const VectorType * T)297*0a6a1f1dSLionel Sambuc     void VisitVectorType(const VectorType *T) {
298*0a6a1f1dSLionel Sambuc       switch (T->getVectorKind()) {
299*0a6a1f1dSLionel Sambuc         case VectorType::GenericVector: break;
300*0a6a1f1dSLionel Sambuc         case VectorType::AltiVecVector: OS << " altivec"; break;
301*0a6a1f1dSLionel Sambuc         case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
302*0a6a1f1dSLionel Sambuc         case VectorType::AltiVecBool: OS << " altivec bool"; break;
303*0a6a1f1dSLionel Sambuc         case VectorType::NeonVector: OS << " neon"; break;
304*0a6a1f1dSLionel Sambuc         case VectorType::NeonPolyVector: OS << " neon poly"; break;
305*0a6a1f1dSLionel Sambuc       }
306*0a6a1f1dSLionel Sambuc       OS << " " << T->getNumElements();
307*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getElementType());
308*0a6a1f1dSLionel Sambuc     }
VisitFunctionType(const FunctionType * T)309*0a6a1f1dSLionel Sambuc     void VisitFunctionType(const FunctionType *T) {
310*0a6a1f1dSLionel Sambuc       auto EI = T->getExtInfo();
311*0a6a1f1dSLionel Sambuc       if (EI.getNoReturn()) OS << " noreturn";
312*0a6a1f1dSLionel Sambuc       if (EI.getProducesResult()) OS << " produces_result";
313*0a6a1f1dSLionel Sambuc       if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
314*0a6a1f1dSLionel Sambuc       OS << " " << FunctionType::getNameForCallConv(EI.getCC());
315*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getReturnType());
316*0a6a1f1dSLionel Sambuc     }
VisitFunctionProtoType(const FunctionProtoType * T)317*0a6a1f1dSLionel Sambuc     void VisitFunctionProtoType(const FunctionProtoType *T) {
318*0a6a1f1dSLionel Sambuc       auto EPI = T->getExtProtoInfo();
319*0a6a1f1dSLionel Sambuc       if (EPI.HasTrailingReturn) OS << " trailing_return";
320*0a6a1f1dSLionel Sambuc       if (T->isConst()) OS << " const";
321*0a6a1f1dSLionel Sambuc       if (T->isVolatile()) OS << " volatile";
322*0a6a1f1dSLionel Sambuc       if (T->isRestrict()) OS << " restrict";
323*0a6a1f1dSLionel Sambuc       switch (EPI.RefQualifier) {
324*0a6a1f1dSLionel Sambuc         case RQ_None: break;
325*0a6a1f1dSLionel Sambuc         case RQ_LValue: OS << " &"; break;
326*0a6a1f1dSLionel Sambuc         case RQ_RValue: OS << " &&"; break;
327*0a6a1f1dSLionel Sambuc       }
328*0a6a1f1dSLionel Sambuc       // FIXME: Exception specification.
329*0a6a1f1dSLionel Sambuc       // FIXME: Consumed parameters.
330*0a6a1f1dSLionel Sambuc       VisitFunctionType(T);
331*0a6a1f1dSLionel Sambuc       for (QualType PT : T->getParamTypes())
332*0a6a1f1dSLionel Sambuc         dumpTypeAsChild(PT);
333*0a6a1f1dSLionel Sambuc       if (EPI.Variadic)
334*0a6a1f1dSLionel Sambuc         dumpChild([=] { OS << "..."; });
335*0a6a1f1dSLionel Sambuc     }
VisitUnresolvedUsingType(const UnresolvedUsingType * T)336*0a6a1f1dSLionel Sambuc     void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
337*0a6a1f1dSLionel Sambuc       dumpDeclRef(T->getDecl());
338*0a6a1f1dSLionel Sambuc     }
VisitTypedefType(const TypedefType * T)339*0a6a1f1dSLionel Sambuc     void VisitTypedefType(const TypedefType *T) {
340*0a6a1f1dSLionel Sambuc       dumpDeclRef(T->getDecl());
341*0a6a1f1dSLionel Sambuc     }
VisitTypeOfExprType(const TypeOfExprType * T)342*0a6a1f1dSLionel Sambuc     void VisitTypeOfExprType(const TypeOfExprType *T) {
343*0a6a1f1dSLionel Sambuc       dumpStmt(T->getUnderlyingExpr());
344*0a6a1f1dSLionel Sambuc     }
VisitDecltypeType(const DecltypeType * T)345*0a6a1f1dSLionel Sambuc     void VisitDecltypeType(const DecltypeType *T) {
346*0a6a1f1dSLionel Sambuc       dumpStmt(T->getUnderlyingExpr());
347*0a6a1f1dSLionel Sambuc     }
VisitUnaryTransformType(const UnaryTransformType * T)348*0a6a1f1dSLionel Sambuc     void VisitUnaryTransformType(const UnaryTransformType *T) {
349*0a6a1f1dSLionel Sambuc       switch (T->getUTTKind()) {
350*0a6a1f1dSLionel Sambuc       case UnaryTransformType::EnumUnderlyingType:
351*0a6a1f1dSLionel Sambuc         OS << " underlying_type";
352*0a6a1f1dSLionel Sambuc         break;
353*0a6a1f1dSLionel Sambuc       }
354*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getBaseType());
355*0a6a1f1dSLionel Sambuc     }
VisitTagType(const TagType * T)356*0a6a1f1dSLionel Sambuc     void VisitTagType(const TagType *T) {
357*0a6a1f1dSLionel Sambuc       dumpDeclRef(T->getDecl());
358*0a6a1f1dSLionel Sambuc     }
VisitAttributedType(const AttributedType * T)359*0a6a1f1dSLionel Sambuc     void VisitAttributedType(const AttributedType *T) {
360*0a6a1f1dSLionel Sambuc       // FIXME: AttrKind
361*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getModifiedType());
362*0a6a1f1dSLionel Sambuc     }
VisitTemplateTypeParmType(const TemplateTypeParmType * T)363*0a6a1f1dSLionel Sambuc     void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
364*0a6a1f1dSLionel Sambuc       OS << " depth " << T->getDepth() << " index " << T->getIndex();
365*0a6a1f1dSLionel Sambuc       if (T->isParameterPack()) OS << " pack";
366*0a6a1f1dSLionel Sambuc       dumpDeclRef(T->getDecl());
367*0a6a1f1dSLionel Sambuc     }
VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType * T)368*0a6a1f1dSLionel Sambuc     void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
369*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getReplacedParameter());
370*0a6a1f1dSLionel Sambuc     }
VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType * T)371*0a6a1f1dSLionel Sambuc     void VisitSubstTemplateTypeParmPackType(
372*0a6a1f1dSLionel Sambuc         const SubstTemplateTypeParmPackType *T) {
373*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getReplacedParameter());
374*0a6a1f1dSLionel Sambuc       dumpTemplateArgument(T->getArgumentPack());
375*0a6a1f1dSLionel Sambuc     }
VisitAutoType(const AutoType * T)376*0a6a1f1dSLionel Sambuc     void VisitAutoType(const AutoType *T) {
377*0a6a1f1dSLionel Sambuc       if (T->isDecltypeAuto()) OS << " decltype(auto)";
378*0a6a1f1dSLionel Sambuc       if (!T->isDeduced())
379*0a6a1f1dSLionel Sambuc         OS << " undeduced";
380*0a6a1f1dSLionel Sambuc     }
VisitTemplateSpecializationType(const TemplateSpecializationType * T)381*0a6a1f1dSLionel Sambuc     void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
382*0a6a1f1dSLionel Sambuc       if (T->isTypeAlias()) OS << " alias";
383*0a6a1f1dSLionel Sambuc       OS << " "; T->getTemplateName().dump(OS);
384*0a6a1f1dSLionel Sambuc       for (auto &Arg : *T)
385*0a6a1f1dSLionel Sambuc         dumpTemplateArgument(Arg);
386*0a6a1f1dSLionel Sambuc       if (T->isTypeAlias())
387*0a6a1f1dSLionel Sambuc         dumpTypeAsChild(T->getAliasedType());
388*0a6a1f1dSLionel Sambuc     }
VisitInjectedClassNameType(const InjectedClassNameType * T)389*0a6a1f1dSLionel Sambuc     void VisitInjectedClassNameType(const InjectedClassNameType *T) {
390*0a6a1f1dSLionel Sambuc       dumpDeclRef(T->getDecl());
391*0a6a1f1dSLionel Sambuc     }
VisitObjCInterfaceType(const ObjCInterfaceType * T)392*0a6a1f1dSLionel Sambuc     void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
393*0a6a1f1dSLionel Sambuc       dumpDeclRef(T->getDecl());
394*0a6a1f1dSLionel Sambuc     }
VisitObjCObjectPointerType(const ObjCObjectPointerType * T)395*0a6a1f1dSLionel Sambuc     void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
396*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getPointeeType());
397*0a6a1f1dSLionel Sambuc     }
VisitAtomicType(const AtomicType * T)398*0a6a1f1dSLionel Sambuc     void VisitAtomicType(const AtomicType *T) {
399*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getValueType());
400*0a6a1f1dSLionel Sambuc     }
VisitAdjustedType(const AdjustedType * T)401*0a6a1f1dSLionel Sambuc     void VisitAdjustedType(const AdjustedType *T) {
402*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(T->getOriginalType());
403*0a6a1f1dSLionel Sambuc     }
VisitPackExpansionType(const PackExpansionType * T)404*0a6a1f1dSLionel Sambuc     void VisitPackExpansionType(const PackExpansionType *T) {
405*0a6a1f1dSLionel Sambuc       if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
406*0a6a1f1dSLionel Sambuc       if (!T->isSugared())
407*0a6a1f1dSLionel Sambuc         dumpTypeAsChild(T->getPattern());
408*0a6a1f1dSLionel Sambuc     }
409*0a6a1f1dSLionel Sambuc     // FIXME: ElaboratedType, DependentNameType,
410*0a6a1f1dSLionel Sambuc     // DependentTemplateSpecializationType, ObjCObjectType
411*0a6a1f1dSLionel Sambuc 
412f4a2713aSLionel Sambuc     // Decls
413f4a2713aSLionel Sambuc     void VisitLabelDecl(const LabelDecl *D);
414f4a2713aSLionel Sambuc     void VisitTypedefDecl(const TypedefDecl *D);
415f4a2713aSLionel Sambuc     void VisitEnumDecl(const EnumDecl *D);
416f4a2713aSLionel Sambuc     void VisitRecordDecl(const RecordDecl *D);
417f4a2713aSLionel Sambuc     void VisitEnumConstantDecl(const EnumConstantDecl *D);
418f4a2713aSLionel Sambuc     void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
419f4a2713aSLionel Sambuc     void VisitFunctionDecl(const FunctionDecl *D);
420f4a2713aSLionel Sambuc     void VisitFieldDecl(const FieldDecl *D);
421f4a2713aSLionel Sambuc     void VisitVarDecl(const VarDecl *D);
422f4a2713aSLionel Sambuc     void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
423f4a2713aSLionel Sambuc     void VisitImportDecl(const ImportDecl *D);
424f4a2713aSLionel Sambuc 
425f4a2713aSLionel Sambuc     // C++ Decls
426f4a2713aSLionel Sambuc     void VisitNamespaceDecl(const NamespaceDecl *D);
427f4a2713aSLionel Sambuc     void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
428f4a2713aSLionel Sambuc     void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
429f4a2713aSLionel Sambuc     void VisitTypeAliasDecl(const TypeAliasDecl *D);
430f4a2713aSLionel Sambuc     void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
431f4a2713aSLionel Sambuc     void VisitCXXRecordDecl(const CXXRecordDecl *D);
432f4a2713aSLionel Sambuc     void VisitStaticAssertDecl(const StaticAssertDecl *D);
433*0a6a1f1dSLionel Sambuc     template<typename SpecializationDecl>
434*0a6a1f1dSLionel Sambuc     void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
435*0a6a1f1dSLionel Sambuc                                          bool DumpExplicitInst,
436*0a6a1f1dSLionel Sambuc                                          bool DumpRefOnly);
437*0a6a1f1dSLionel Sambuc     template<typename TemplateDecl>
438*0a6a1f1dSLionel Sambuc     void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
439f4a2713aSLionel Sambuc     void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
440f4a2713aSLionel Sambuc     void VisitClassTemplateDecl(const ClassTemplateDecl *D);
441f4a2713aSLionel Sambuc     void VisitClassTemplateSpecializationDecl(
442f4a2713aSLionel Sambuc         const ClassTemplateSpecializationDecl *D);
443f4a2713aSLionel Sambuc     void VisitClassTemplatePartialSpecializationDecl(
444f4a2713aSLionel Sambuc         const ClassTemplatePartialSpecializationDecl *D);
445f4a2713aSLionel Sambuc     void VisitClassScopeFunctionSpecializationDecl(
446f4a2713aSLionel Sambuc         const ClassScopeFunctionSpecializationDecl *D);
447f4a2713aSLionel Sambuc     void VisitVarTemplateDecl(const VarTemplateDecl *D);
448f4a2713aSLionel Sambuc     void VisitVarTemplateSpecializationDecl(
449f4a2713aSLionel Sambuc         const VarTemplateSpecializationDecl *D);
450f4a2713aSLionel Sambuc     void VisitVarTemplatePartialSpecializationDecl(
451f4a2713aSLionel Sambuc         const VarTemplatePartialSpecializationDecl *D);
452f4a2713aSLionel Sambuc     void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
453f4a2713aSLionel Sambuc     void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
454f4a2713aSLionel Sambuc     void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
455f4a2713aSLionel Sambuc     void VisitUsingDecl(const UsingDecl *D);
456f4a2713aSLionel Sambuc     void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
457f4a2713aSLionel Sambuc     void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
458f4a2713aSLionel Sambuc     void VisitUsingShadowDecl(const UsingShadowDecl *D);
459f4a2713aSLionel Sambuc     void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
460f4a2713aSLionel Sambuc     void VisitAccessSpecDecl(const AccessSpecDecl *D);
461f4a2713aSLionel Sambuc     void VisitFriendDecl(const FriendDecl *D);
462f4a2713aSLionel Sambuc 
463f4a2713aSLionel Sambuc     // ObjC Decls
464f4a2713aSLionel Sambuc     void VisitObjCIvarDecl(const ObjCIvarDecl *D);
465f4a2713aSLionel Sambuc     void VisitObjCMethodDecl(const ObjCMethodDecl *D);
466f4a2713aSLionel Sambuc     void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
467f4a2713aSLionel Sambuc     void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
468f4a2713aSLionel Sambuc     void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
469f4a2713aSLionel Sambuc     void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
470f4a2713aSLionel Sambuc     void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
471f4a2713aSLionel Sambuc     void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
472f4a2713aSLionel Sambuc     void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
473f4a2713aSLionel Sambuc     void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
474f4a2713aSLionel Sambuc     void VisitBlockDecl(const BlockDecl *D);
475f4a2713aSLionel Sambuc 
476f4a2713aSLionel Sambuc     // Stmts.
477f4a2713aSLionel Sambuc     void VisitStmt(const Stmt *Node);
478f4a2713aSLionel Sambuc     void VisitDeclStmt(const DeclStmt *Node);
479f4a2713aSLionel Sambuc     void VisitAttributedStmt(const AttributedStmt *Node);
480f4a2713aSLionel Sambuc     void VisitLabelStmt(const LabelStmt *Node);
481f4a2713aSLionel Sambuc     void VisitGotoStmt(const GotoStmt *Node);
482f4a2713aSLionel Sambuc     void VisitCXXCatchStmt(const CXXCatchStmt *Node);
483f4a2713aSLionel Sambuc 
484f4a2713aSLionel Sambuc     // Exprs
485f4a2713aSLionel Sambuc     void VisitExpr(const Expr *Node);
486f4a2713aSLionel Sambuc     void VisitCastExpr(const CastExpr *Node);
487f4a2713aSLionel Sambuc     void VisitDeclRefExpr(const DeclRefExpr *Node);
488f4a2713aSLionel Sambuc     void VisitPredefinedExpr(const PredefinedExpr *Node);
489f4a2713aSLionel Sambuc     void VisitCharacterLiteral(const CharacterLiteral *Node);
490f4a2713aSLionel Sambuc     void VisitIntegerLiteral(const IntegerLiteral *Node);
491f4a2713aSLionel Sambuc     void VisitFloatingLiteral(const FloatingLiteral *Node);
492f4a2713aSLionel Sambuc     void VisitStringLiteral(const StringLiteral *Str);
493*0a6a1f1dSLionel Sambuc     void VisitInitListExpr(const InitListExpr *ILE);
494f4a2713aSLionel Sambuc     void VisitUnaryOperator(const UnaryOperator *Node);
495f4a2713aSLionel Sambuc     void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
496f4a2713aSLionel Sambuc     void VisitMemberExpr(const MemberExpr *Node);
497f4a2713aSLionel Sambuc     void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
498f4a2713aSLionel Sambuc     void VisitBinaryOperator(const BinaryOperator *Node);
499f4a2713aSLionel Sambuc     void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
500f4a2713aSLionel Sambuc     void VisitAddrLabelExpr(const AddrLabelExpr *Node);
501f4a2713aSLionel Sambuc     void VisitBlockExpr(const BlockExpr *Node);
502f4a2713aSLionel Sambuc     void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
503f4a2713aSLionel Sambuc 
504f4a2713aSLionel Sambuc     // C++
505f4a2713aSLionel Sambuc     void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
506f4a2713aSLionel Sambuc     void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
507f4a2713aSLionel Sambuc     void VisitCXXThisExpr(const CXXThisExpr *Node);
508f4a2713aSLionel Sambuc     void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
509f4a2713aSLionel Sambuc     void VisitCXXConstructExpr(const CXXConstructExpr *Node);
510f4a2713aSLionel Sambuc     void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
511f4a2713aSLionel Sambuc     void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
512f4a2713aSLionel Sambuc     void VisitExprWithCleanups(const ExprWithCleanups *Node);
513f4a2713aSLionel Sambuc     void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
514f4a2713aSLionel Sambuc     void dumpCXXTemporary(const CXXTemporary *Temporary);
VisitLambdaExpr(const LambdaExpr * Node)515f4a2713aSLionel Sambuc     void VisitLambdaExpr(const LambdaExpr *Node) {
516f4a2713aSLionel Sambuc       VisitExpr(Node);
517f4a2713aSLionel Sambuc       dumpDecl(Node->getLambdaClass());
518f4a2713aSLionel Sambuc     }
519f4a2713aSLionel Sambuc 
520f4a2713aSLionel Sambuc     // ObjC
521f4a2713aSLionel Sambuc     void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
522f4a2713aSLionel Sambuc     void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
523f4a2713aSLionel Sambuc     void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
524f4a2713aSLionel Sambuc     void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
525f4a2713aSLionel Sambuc     void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
526f4a2713aSLionel Sambuc     void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
527f4a2713aSLionel Sambuc     void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
528f4a2713aSLionel Sambuc     void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
529f4a2713aSLionel Sambuc     void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
530f4a2713aSLionel Sambuc     void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
531f4a2713aSLionel Sambuc 
532f4a2713aSLionel Sambuc     // Comments.
533f4a2713aSLionel Sambuc     const char *getCommandName(unsigned CommandID);
534f4a2713aSLionel Sambuc     void dumpComment(const Comment *C);
535f4a2713aSLionel Sambuc 
536f4a2713aSLionel Sambuc     // Inline comments.
537f4a2713aSLionel Sambuc     void visitTextComment(const TextComment *C);
538f4a2713aSLionel Sambuc     void visitInlineCommandComment(const InlineCommandComment *C);
539f4a2713aSLionel Sambuc     void visitHTMLStartTagComment(const HTMLStartTagComment *C);
540f4a2713aSLionel Sambuc     void visitHTMLEndTagComment(const HTMLEndTagComment *C);
541f4a2713aSLionel Sambuc 
542f4a2713aSLionel Sambuc     // Block comments.
543f4a2713aSLionel Sambuc     void visitBlockCommandComment(const BlockCommandComment *C);
544f4a2713aSLionel Sambuc     void visitParamCommandComment(const ParamCommandComment *C);
545f4a2713aSLionel Sambuc     void visitTParamCommandComment(const TParamCommandComment *C);
546f4a2713aSLionel Sambuc     void visitVerbatimBlockComment(const VerbatimBlockComment *C);
547f4a2713aSLionel Sambuc     void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
548f4a2713aSLionel Sambuc     void visitVerbatimLineComment(const VerbatimLineComment *C);
549f4a2713aSLionel Sambuc   };
550f4a2713aSLionel Sambuc }
551f4a2713aSLionel Sambuc 
552f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
553f4a2713aSLionel Sambuc //  Utilities
554f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
555f4a2713aSLionel Sambuc 
dumpPointer(const void * Ptr)556f4a2713aSLionel Sambuc void ASTDumper::dumpPointer(const void *Ptr) {
557f4a2713aSLionel Sambuc   ColorScope Color(*this, AddressColor);
558f4a2713aSLionel Sambuc   OS << ' ' << Ptr;
559f4a2713aSLionel Sambuc }
560f4a2713aSLionel Sambuc 
dumpLocation(SourceLocation Loc)561f4a2713aSLionel Sambuc void ASTDumper::dumpLocation(SourceLocation Loc) {
562*0a6a1f1dSLionel Sambuc   if (!SM)
563*0a6a1f1dSLionel Sambuc     return;
564*0a6a1f1dSLionel Sambuc 
565f4a2713aSLionel Sambuc   ColorScope Color(*this, LocationColor);
566f4a2713aSLionel Sambuc   SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
567f4a2713aSLionel Sambuc 
568f4a2713aSLionel Sambuc   // The general format we print out is filename:line:col, but we drop pieces
569f4a2713aSLionel Sambuc   // that haven't changed since the last loc printed.
570f4a2713aSLionel Sambuc   PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
571f4a2713aSLionel Sambuc 
572f4a2713aSLionel Sambuc   if (PLoc.isInvalid()) {
573f4a2713aSLionel Sambuc     OS << "<invalid sloc>";
574f4a2713aSLionel Sambuc     return;
575f4a2713aSLionel Sambuc   }
576f4a2713aSLionel Sambuc 
577f4a2713aSLionel Sambuc   if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
578f4a2713aSLionel Sambuc     OS << PLoc.getFilename() << ':' << PLoc.getLine()
579f4a2713aSLionel Sambuc        << ':' << PLoc.getColumn();
580f4a2713aSLionel Sambuc     LastLocFilename = PLoc.getFilename();
581f4a2713aSLionel Sambuc     LastLocLine = PLoc.getLine();
582f4a2713aSLionel Sambuc   } else if (PLoc.getLine() != LastLocLine) {
583f4a2713aSLionel Sambuc     OS << "line" << ':' << PLoc.getLine()
584f4a2713aSLionel Sambuc        << ':' << PLoc.getColumn();
585f4a2713aSLionel Sambuc     LastLocLine = PLoc.getLine();
586f4a2713aSLionel Sambuc   } else {
587f4a2713aSLionel Sambuc     OS << "col" << ':' << PLoc.getColumn();
588f4a2713aSLionel Sambuc   }
589f4a2713aSLionel Sambuc }
590f4a2713aSLionel Sambuc 
dumpSourceRange(SourceRange R)591f4a2713aSLionel Sambuc void ASTDumper::dumpSourceRange(SourceRange R) {
592f4a2713aSLionel Sambuc   // Can't translate locations if a SourceManager isn't available.
593f4a2713aSLionel Sambuc   if (!SM)
594f4a2713aSLionel Sambuc     return;
595f4a2713aSLionel Sambuc 
596f4a2713aSLionel Sambuc   OS << " <";
597f4a2713aSLionel Sambuc   dumpLocation(R.getBegin());
598f4a2713aSLionel Sambuc   if (R.getBegin() != R.getEnd()) {
599f4a2713aSLionel Sambuc     OS << ", ";
600f4a2713aSLionel Sambuc     dumpLocation(R.getEnd());
601f4a2713aSLionel Sambuc   }
602f4a2713aSLionel Sambuc   OS << ">";
603f4a2713aSLionel Sambuc 
604f4a2713aSLionel Sambuc   // <t2.c:123:421[blah], t2.c:412:321>
605f4a2713aSLionel Sambuc 
606f4a2713aSLionel Sambuc }
607f4a2713aSLionel Sambuc 
dumpBareType(QualType T,bool Desugar)608*0a6a1f1dSLionel Sambuc void ASTDumper::dumpBareType(QualType T, bool Desugar) {
609f4a2713aSLionel Sambuc   ColorScope Color(*this, TypeColor);
610f4a2713aSLionel Sambuc 
611f4a2713aSLionel Sambuc   SplitQualType T_split = T.split();
612f4a2713aSLionel Sambuc   OS << "'" << QualType::getAsString(T_split) << "'";
613f4a2713aSLionel Sambuc 
614*0a6a1f1dSLionel Sambuc   if (Desugar && !T.isNull()) {
615f4a2713aSLionel Sambuc     // If the type is sugared, also dump a (shallow) desugared type.
616f4a2713aSLionel Sambuc     SplitQualType D_split = T.getSplitDesugaredType();
617f4a2713aSLionel Sambuc     if (T_split != D_split)
618f4a2713aSLionel Sambuc       OS << ":'" << QualType::getAsString(D_split) << "'";
619f4a2713aSLionel Sambuc   }
620f4a2713aSLionel Sambuc }
621f4a2713aSLionel Sambuc 
dumpType(QualType T)622f4a2713aSLionel Sambuc void ASTDumper::dumpType(QualType T) {
623f4a2713aSLionel Sambuc   OS << ' ';
624f4a2713aSLionel Sambuc   dumpBareType(T);
625f4a2713aSLionel Sambuc }
626f4a2713aSLionel Sambuc 
dumpTypeAsChild(QualType T)627*0a6a1f1dSLionel Sambuc void ASTDumper::dumpTypeAsChild(QualType T) {
628*0a6a1f1dSLionel Sambuc   SplitQualType SQT = T.split();
629*0a6a1f1dSLionel Sambuc   if (!SQT.Quals.hasQualifiers())
630*0a6a1f1dSLionel Sambuc     return dumpTypeAsChild(SQT.Ty);
631*0a6a1f1dSLionel Sambuc 
632*0a6a1f1dSLionel Sambuc   dumpChild([=] {
633*0a6a1f1dSLionel Sambuc     OS << "QualType";
634*0a6a1f1dSLionel Sambuc     dumpPointer(T.getAsOpaquePtr());
635*0a6a1f1dSLionel Sambuc     OS << " ";
636*0a6a1f1dSLionel Sambuc     dumpBareType(T, false);
637*0a6a1f1dSLionel Sambuc     OS << " " << T.split().Quals.getAsString();
638*0a6a1f1dSLionel Sambuc     dumpTypeAsChild(T.split().Ty);
639*0a6a1f1dSLionel Sambuc   });
640*0a6a1f1dSLionel Sambuc }
641*0a6a1f1dSLionel Sambuc 
dumpTypeAsChild(const Type * T)642*0a6a1f1dSLionel Sambuc void ASTDumper::dumpTypeAsChild(const Type *T) {
643*0a6a1f1dSLionel Sambuc   dumpChild([=] {
644*0a6a1f1dSLionel Sambuc     if (!T) {
645*0a6a1f1dSLionel Sambuc       ColorScope Color(*this, NullColor);
646*0a6a1f1dSLionel Sambuc       OS << "<<<NULL>>>";
647*0a6a1f1dSLionel Sambuc       return;
648*0a6a1f1dSLionel Sambuc     }
649*0a6a1f1dSLionel Sambuc 
650*0a6a1f1dSLionel Sambuc     {
651*0a6a1f1dSLionel Sambuc       ColorScope Color(*this, TypeColor);
652*0a6a1f1dSLionel Sambuc       OS << T->getTypeClassName() << "Type";
653*0a6a1f1dSLionel Sambuc     }
654*0a6a1f1dSLionel Sambuc     dumpPointer(T);
655*0a6a1f1dSLionel Sambuc     OS << " ";
656*0a6a1f1dSLionel Sambuc     dumpBareType(QualType(T, 0), false);
657*0a6a1f1dSLionel Sambuc 
658*0a6a1f1dSLionel Sambuc     QualType SingleStepDesugar =
659*0a6a1f1dSLionel Sambuc         T->getLocallyUnqualifiedSingleStepDesugaredType();
660*0a6a1f1dSLionel Sambuc     if (SingleStepDesugar != QualType(T, 0))
661*0a6a1f1dSLionel Sambuc       OS << " sugar";
662*0a6a1f1dSLionel Sambuc     if (T->isDependentType())
663*0a6a1f1dSLionel Sambuc       OS << " dependent";
664*0a6a1f1dSLionel Sambuc     else if (T->isInstantiationDependentType())
665*0a6a1f1dSLionel Sambuc       OS << " instantiation_dependent";
666*0a6a1f1dSLionel Sambuc     if (T->isVariablyModifiedType())
667*0a6a1f1dSLionel Sambuc       OS << " variably_modified";
668*0a6a1f1dSLionel Sambuc     if (T->containsUnexpandedParameterPack())
669*0a6a1f1dSLionel Sambuc       OS << " contains_unexpanded_pack";
670*0a6a1f1dSLionel Sambuc     if (T->isFromAST())
671*0a6a1f1dSLionel Sambuc       OS << " imported";
672*0a6a1f1dSLionel Sambuc 
673*0a6a1f1dSLionel Sambuc     TypeVisitor<ASTDumper>::Visit(T);
674*0a6a1f1dSLionel Sambuc 
675*0a6a1f1dSLionel Sambuc     if (SingleStepDesugar != QualType(T, 0))
676*0a6a1f1dSLionel Sambuc       dumpTypeAsChild(SingleStepDesugar);
677*0a6a1f1dSLionel Sambuc   });
678*0a6a1f1dSLionel Sambuc }
679*0a6a1f1dSLionel Sambuc 
dumpBareDeclRef(const Decl * D)680f4a2713aSLionel Sambuc void ASTDumper::dumpBareDeclRef(const Decl *D) {
681f4a2713aSLionel Sambuc   {
682f4a2713aSLionel Sambuc     ColorScope Color(*this, DeclKindNameColor);
683f4a2713aSLionel Sambuc     OS << D->getDeclKindName();
684f4a2713aSLionel Sambuc   }
685f4a2713aSLionel Sambuc   dumpPointer(D);
686f4a2713aSLionel Sambuc 
687f4a2713aSLionel Sambuc   if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
688f4a2713aSLionel Sambuc     ColorScope Color(*this, DeclNameColor);
689f4a2713aSLionel Sambuc     OS << " '" << ND->getDeclName() << '\'';
690f4a2713aSLionel Sambuc   }
691f4a2713aSLionel Sambuc 
692f4a2713aSLionel Sambuc   if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
693f4a2713aSLionel Sambuc     dumpType(VD->getType());
694f4a2713aSLionel Sambuc }
695f4a2713aSLionel Sambuc 
dumpDeclRef(const Decl * D,const char * Label)696f4a2713aSLionel Sambuc void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
697f4a2713aSLionel Sambuc   if (!D)
698f4a2713aSLionel Sambuc     return;
699f4a2713aSLionel Sambuc 
700*0a6a1f1dSLionel Sambuc   dumpChild([=]{
701f4a2713aSLionel Sambuc     if (Label)
702f4a2713aSLionel Sambuc       OS << Label << ' ';
703f4a2713aSLionel Sambuc     dumpBareDeclRef(D);
704*0a6a1f1dSLionel Sambuc   });
705f4a2713aSLionel Sambuc }
706f4a2713aSLionel Sambuc 
dumpName(const NamedDecl * ND)707f4a2713aSLionel Sambuc void ASTDumper::dumpName(const NamedDecl *ND) {
708f4a2713aSLionel Sambuc   if (ND->getDeclName()) {
709f4a2713aSLionel Sambuc     ColorScope Color(*this, DeclNameColor);
710f4a2713aSLionel Sambuc     OS << ' ' << ND->getNameAsString();
711f4a2713aSLionel Sambuc   }
712f4a2713aSLionel Sambuc }
713f4a2713aSLionel Sambuc 
hasNodes(const DeclContext * DC)714f4a2713aSLionel Sambuc bool ASTDumper::hasNodes(const DeclContext *DC) {
715f4a2713aSLionel Sambuc   if (!DC)
716f4a2713aSLionel Sambuc     return false;
717f4a2713aSLionel Sambuc 
718f4a2713aSLionel Sambuc   return DC->hasExternalLexicalStorage() ||
719f4a2713aSLionel Sambuc          DC->noload_decls_begin() != DC->noload_decls_end();
720f4a2713aSLionel Sambuc }
721f4a2713aSLionel Sambuc 
dumpDeclContext(const DeclContext * DC)722f4a2713aSLionel Sambuc void ASTDumper::dumpDeclContext(const DeclContext *DC) {
723f4a2713aSLionel Sambuc   if (!DC)
724f4a2713aSLionel Sambuc     return;
725*0a6a1f1dSLionel Sambuc 
726*0a6a1f1dSLionel Sambuc   for (auto *D : DC->noload_decls())
727*0a6a1f1dSLionel Sambuc     dumpDecl(D);
728*0a6a1f1dSLionel Sambuc 
729*0a6a1f1dSLionel Sambuc   if (DC->hasExternalLexicalStorage()) {
730*0a6a1f1dSLionel Sambuc     dumpChild([=]{
731f4a2713aSLionel Sambuc       ColorScope Color(*this, UndeserializedColor);
732f4a2713aSLionel Sambuc       OS << "<undeserialized declarations>";
733*0a6a1f1dSLionel Sambuc     });
734f4a2713aSLionel Sambuc   }
735f4a2713aSLionel Sambuc }
736f4a2713aSLionel Sambuc 
dumpLookups(const DeclContext * DC,bool DumpDecls)737*0a6a1f1dSLionel Sambuc void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
738*0a6a1f1dSLionel Sambuc   dumpChild([=] {
739f4a2713aSLionel Sambuc     OS << "StoredDeclsMap ";
740f4a2713aSLionel Sambuc     dumpBareDeclRef(cast<Decl>(DC));
741f4a2713aSLionel Sambuc 
742f4a2713aSLionel Sambuc     const DeclContext *Primary = DC->getPrimaryContext();
743f4a2713aSLionel Sambuc     if (Primary != DC) {
744f4a2713aSLionel Sambuc       OS << " primary";
745f4a2713aSLionel Sambuc       dumpPointer(cast<Decl>(Primary));
746f4a2713aSLionel Sambuc     }
747f4a2713aSLionel Sambuc 
748f4a2713aSLionel Sambuc     bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
749f4a2713aSLionel Sambuc 
750f4a2713aSLionel Sambuc     DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
751f4a2713aSLionel Sambuc                                       E = Primary->noload_lookups_end();
752f4a2713aSLionel Sambuc     while (I != E) {
753f4a2713aSLionel Sambuc       DeclarationName Name = I.getLookupName();
754f4a2713aSLionel Sambuc       DeclContextLookupResult R = *I++;
755f4a2713aSLionel Sambuc 
756*0a6a1f1dSLionel Sambuc       dumpChild([=] {
757f4a2713aSLionel Sambuc         OS << "DeclarationName ";
758f4a2713aSLionel Sambuc         {
759f4a2713aSLionel Sambuc           ColorScope Color(*this, DeclNameColor);
760f4a2713aSLionel Sambuc           OS << '\'' << Name << '\'';
761f4a2713aSLionel Sambuc         }
762f4a2713aSLionel Sambuc 
763f4a2713aSLionel Sambuc         for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
764f4a2713aSLionel Sambuc              RI != RE; ++RI) {
765*0a6a1f1dSLionel Sambuc           dumpChild([=] {
766*0a6a1f1dSLionel Sambuc             dumpBareDeclRef(*RI);
767*0a6a1f1dSLionel Sambuc 
768f4a2713aSLionel Sambuc             if ((*RI)->isHidden())
769f4a2713aSLionel Sambuc               OS << " hidden";
770*0a6a1f1dSLionel Sambuc 
771*0a6a1f1dSLionel Sambuc             // If requested, dump the redecl chain for this lookup.
772*0a6a1f1dSLionel Sambuc             if (DumpDecls) {
773*0a6a1f1dSLionel Sambuc               // Dump earliest decl first.
774*0a6a1f1dSLionel Sambuc               std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
775*0a6a1f1dSLionel Sambuc                 if (Decl *Prev = D->getPreviousDecl())
776*0a6a1f1dSLionel Sambuc                   DumpWithPrev(Prev);
777*0a6a1f1dSLionel Sambuc                 dumpDecl(D);
778*0a6a1f1dSLionel Sambuc               };
779*0a6a1f1dSLionel Sambuc               DumpWithPrev(*RI);
780f4a2713aSLionel Sambuc             }
781*0a6a1f1dSLionel Sambuc           });
782*0a6a1f1dSLionel Sambuc         }
783*0a6a1f1dSLionel Sambuc       });
784f4a2713aSLionel Sambuc     }
785f4a2713aSLionel Sambuc 
786f4a2713aSLionel Sambuc     if (HasUndeserializedLookups) {
787*0a6a1f1dSLionel Sambuc       dumpChild([=] {
788f4a2713aSLionel Sambuc         ColorScope Color(*this, UndeserializedColor);
789f4a2713aSLionel Sambuc         OS << "<undeserialized lookups>";
790*0a6a1f1dSLionel Sambuc       });
791f4a2713aSLionel Sambuc     }
792*0a6a1f1dSLionel Sambuc   });
793f4a2713aSLionel Sambuc }
794f4a2713aSLionel Sambuc 
dumpAttr(const Attr * A)795f4a2713aSLionel Sambuc void ASTDumper::dumpAttr(const Attr *A) {
796*0a6a1f1dSLionel Sambuc   dumpChild([=] {
797f4a2713aSLionel Sambuc     {
798f4a2713aSLionel Sambuc       ColorScope Color(*this, AttrColor);
799*0a6a1f1dSLionel Sambuc 
800f4a2713aSLionel Sambuc       switch (A->getKind()) {
801f4a2713aSLionel Sambuc #define ATTR(X) case attr::X: OS << #X; break;
802f4a2713aSLionel Sambuc #include "clang/Basic/AttrList.inc"
803*0a6a1f1dSLionel Sambuc       default:
804*0a6a1f1dSLionel Sambuc         llvm_unreachable("unexpected attribute kind");
805f4a2713aSLionel Sambuc       }
806f4a2713aSLionel Sambuc       OS << "Attr";
807f4a2713aSLionel Sambuc     }
808f4a2713aSLionel Sambuc     dumpPointer(A);
809f4a2713aSLionel Sambuc     dumpSourceRange(A->getRange());
810*0a6a1f1dSLionel Sambuc     if (A->isInherited())
811*0a6a1f1dSLionel Sambuc       OS << " Inherited";
812*0a6a1f1dSLionel Sambuc     if (A->isImplicit())
813*0a6a1f1dSLionel Sambuc       OS << " Implicit";
814f4a2713aSLionel Sambuc #include "clang/AST/AttrDump.inc"
815*0a6a1f1dSLionel Sambuc   });
816f4a2713aSLionel Sambuc }
817f4a2713aSLionel Sambuc 
dumpPreviousDeclImpl(raw_ostream & OS,...)818f4a2713aSLionel Sambuc static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
819f4a2713aSLionel Sambuc 
820f4a2713aSLionel Sambuc template<typename T>
dumpPreviousDeclImpl(raw_ostream & OS,const Mergeable<T> * D)821f4a2713aSLionel Sambuc static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
822f4a2713aSLionel Sambuc   const T *First = D->getFirstDecl();
823f4a2713aSLionel Sambuc   if (First != D)
824f4a2713aSLionel Sambuc     OS << " first " << First;
825f4a2713aSLionel Sambuc }
826f4a2713aSLionel Sambuc 
827f4a2713aSLionel Sambuc template<typename T>
dumpPreviousDeclImpl(raw_ostream & OS,const Redeclarable<T> * D)828f4a2713aSLionel Sambuc static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
829f4a2713aSLionel Sambuc   const T *Prev = D->getPreviousDecl();
830f4a2713aSLionel Sambuc   if (Prev)
831f4a2713aSLionel Sambuc     OS << " prev " << Prev;
832f4a2713aSLionel Sambuc }
833f4a2713aSLionel Sambuc 
834f4a2713aSLionel Sambuc /// Dump the previous declaration in the redeclaration chain for a declaration,
835f4a2713aSLionel Sambuc /// if any.
dumpPreviousDecl(raw_ostream & OS,const Decl * D)836f4a2713aSLionel Sambuc static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
837f4a2713aSLionel Sambuc   switch (D->getKind()) {
838f4a2713aSLionel Sambuc #define DECL(DERIVED, BASE) \
839f4a2713aSLionel Sambuc   case Decl::DERIVED: \
840f4a2713aSLionel Sambuc     return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
841f4a2713aSLionel Sambuc #define ABSTRACT_DECL(DECL)
842f4a2713aSLionel Sambuc #include "clang/AST/DeclNodes.inc"
843f4a2713aSLionel Sambuc   }
844f4a2713aSLionel Sambuc   llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
845f4a2713aSLionel Sambuc }
846f4a2713aSLionel Sambuc 
847f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
848f4a2713aSLionel Sambuc //  C++ Utilities
849f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
850f4a2713aSLionel Sambuc 
dumpAccessSpecifier(AccessSpecifier AS)851f4a2713aSLionel Sambuc void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
852f4a2713aSLionel Sambuc   switch (AS) {
853f4a2713aSLionel Sambuc   case AS_none:
854f4a2713aSLionel Sambuc     break;
855f4a2713aSLionel Sambuc   case AS_public:
856f4a2713aSLionel Sambuc     OS << "public";
857f4a2713aSLionel Sambuc     break;
858f4a2713aSLionel Sambuc   case AS_protected:
859f4a2713aSLionel Sambuc     OS << "protected";
860f4a2713aSLionel Sambuc     break;
861f4a2713aSLionel Sambuc   case AS_private:
862f4a2713aSLionel Sambuc     OS << "private";
863f4a2713aSLionel Sambuc     break;
864f4a2713aSLionel Sambuc   }
865f4a2713aSLionel Sambuc }
866f4a2713aSLionel Sambuc 
dumpCXXCtorInitializer(const CXXCtorInitializer * Init)867f4a2713aSLionel Sambuc void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
868*0a6a1f1dSLionel Sambuc   dumpChild([=] {
869f4a2713aSLionel Sambuc     OS << "CXXCtorInitializer";
870f4a2713aSLionel Sambuc     if (Init->isAnyMemberInitializer()) {
871f4a2713aSLionel Sambuc       OS << ' ';
872f4a2713aSLionel Sambuc       dumpBareDeclRef(Init->getAnyMember());
873*0a6a1f1dSLionel Sambuc     } else if (Init->isBaseInitializer()) {
874f4a2713aSLionel Sambuc       dumpType(QualType(Init->getBaseClass(), 0));
875*0a6a1f1dSLionel Sambuc     } else if (Init->isDelegatingInitializer()) {
876*0a6a1f1dSLionel Sambuc       dumpType(Init->getTypeSourceInfo()->getType());
877*0a6a1f1dSLionel Sambuc     } else {
878*0a6a1f1dSLionel Sambuc       llvm_unreachable("Unknown initializer type");
879f4a2713aSLionel Sambuc     }
880f4a2713aSLionel Sambuc     dumpStmt(Init->getInit());
881*0a6a1f1dSLionel Sambuc   });
882f4a2713aSLionel Sambuc }
883f4a2713aSLionel Sambuc 
dumpTemplateParameters(const TemplateParameterList * TPL)884f4a2713aSLionel Sambuc void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
885f4a2713aSLionel Sambuc   if (!TPL)
886f4a2713aSLionel Sambuc     return;
887f4a2713aSLionel Sambuc 
888f4a2713aSLionel Sambuc   for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
889f4a2713aSLionel Sambuc        I != E; ++I)
890f4a2713aSLionel Sambuc     dumpDecl(*I);
891f4a2713aSLionel Sambuc }
892f4a2713aSLionel Sambuc 
dumpTemplateArgumentListInfo(const TemplateArgumentListInfo & TALI)893f4a2713aSLionel Sambuc void ASTDumper::dumpTemplateArgumentListInfo(
894f4a2713aSLionel Sambuc     const TemplateArgumentListInfo &TALI) {
895*0a6a1f1dSLionel Sambuc   for (unsigned i = 0, e = TALI.size(); i < e; ++i)
896f4a2713aSLionel Sambuc     dumpTemplateArgumentLoc(TALI[i]);
897f4a2713aSLionel Sambuc }
898f4a2713aSLionel Sambuc 
dumpTemplateArgumentLoc(const TemplateArgumentLoc & A)899f4a2713aSLionel Sambuc void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
900f4a2713aSLionel Sambuc   dumpTemplateArgument(A.getArgument(), A.getSourceRange());
901f4a2713aSLionel Sambuc }
902f4a2713aSLionel Sambuc 
dumpTemplateArgumentList(const TemplateArgumentList & TAL)903f4a2713aSLionel Sambuc void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
904f4a2713aSLionel Sambuc   for (unsigned i = 0, e = TAL.size(); i < e; ++i)
905f4a2713aSLionel Sambuc     dumpTemplateArgument(TAL[i]);
906f4a2713aSLionel Sambuc }
907f4a2713aSLionel Sambuc 
dumpTemplateArgument(const TemplateArgument & A,SourceRange R)908f4a2713aSLionel Sambuc void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
909*0a6a1f1dSLionel Sambuc   dumpChild([=] {
910f4a2713aSLionel Sambuc     OS << "TemplateArgument";
911f4a2713aSLionel Sambuc     if (R.isValid())
912f4a2713aSLionel Sambuc       dumpSourceRange(R);
913f4a2713aSLionel Sambuc 
914f4a2713aSLionel Sambuc     switch (A.getKind()) {
915f4a2713aSLionel Sambuc     case TemplateArgument::Null:
916f4a2713aSLionel Sambuc       OS << " null";
917f4a2713aSLionel Sambuc       break;
918f4a2713aSLionel Sambuc     case TemplateArgument::Type:
919f4a2713aSLionel Sambuc       OS << " type";
920f4a2713aSLionel Sambuc       dumpType(A.getAsType());
921f4a2713aSLionel Sambuc       break;
922f4a2713aSLionel Sambuc     case TemplateArgument::Declaration:
923f4a2713aSLionel Sambuc       OS << " decl";
924f4a2713aSLionel Sambuc       dumpDeclRef(A.getAsDecl());
925f4a2713aSLionel Sambuc       break;
926f4a2713aSLionel Sambuc     case TemplateArgument::NullPtr:
927f4a2713aSLionel Sambuc       OS << " nullptr";
928f4a2713aSLionel Sambuc       break;
929f4a2713aSLionel Sambuc     case TemplateArgument::Integral:
930f4a2713aSLionel Sambuc       OS << " integral " << A.getAsIntegral();
931f4a2713aSLionel Sambuc       break;
932f4a2713aSLionel Sambuc     case TemplateArgument::Template:
933f4a2713aSLionel Sambuc       OS << " template ";
934f4a2713aSLionel Sambuc       A.getAsTemplate().dump(OS);
935f4a2713aSLionel Sambuc       break;
936f4a2713aSLionel Sambuc     case TemplateArgument::TemplateExpansion:
937f4a2713aSLionel Sambuc       OS << " template expansion";
938f4a2713aSLionel Sambuc       A.getAsTemplateOrTemplatePattern().dump(OS);
939f4a2713aSLionel Sambuc       break;
940f4a2713aSLionel Sambuc     case TemplateArgument::Expression:
941f4a2713aSLionel Sambuc       OS << " expr";
942f4a2713aSLionel Sambuc       dumpStmt(A.getAsExpr());
943f4a2713aSLionel Sambuc       break;
944f4a2713aSLionel Sambuc     case TemplateArgument::Pack:
945f4a2713aSLionel Sambuc       OS << " pack";
946f4a2713aSLionel Sambuc       for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
947*0a6a1f1dSLionel Sambuc            I != E; ++I)
948f4a2713aSLionel Sambuc         dumpTemplateArgument(*I);
949f4a2713aSLionel Sambuc       break;
950f4a2713aSLionel Sambuc     }
951*0a6a1f1dSLionel Sambuc   });
952f4a2713aSLionel Sambuc }
953f4a2713aSLionel Sambuc 
954f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
955f4a2713aSLionel Sambuc //  Decl dumping methods.
956f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
957f4a2713aSLionel Sambuc 
dumpDecl(const Decl * D)958f4a2713aSLionel Sambuc void ASTDumper::dumpDecl(const Decl *D) {
959*0a6a1f1dSLionel Sambuc   dumpChild([=] {
960f4a2713aSLionel Sambuc     if (!D) {
961f4a2713aSLionel Sambuc       ColorScope Color(*this, NullColor);
962f4a2713aSLionel Sambuc       OS << "<<<NULL>>>";
963f4a2713aSLionel Sambuc       return;
964f4a2713aSLionel Sambuc     }
965f4a2713aSLionel Sambuc 
966f4a2713aSLionel Sambuc     {
967f4a2713aSLionel Sambuc       ColorScope Color(*this, DeclKindNameColor);
968f4a2713aSLionel Sambuc       OS << D->getDeclKindName() << "Decl";
969f4a2713aSLionel Sambuc     }
970f4a2713aSLionel Sambuc     dumpPointer(D);
971f4a2713aSLionel Sambuc     if (D->getLexicalDeclContext() != D->getDeclContext())
972f4a2713aSLionel Sambuc       OS << " parent " << cast<Decl>(D->getDeclContext());
973f4a2713aSLionel Sambuc     dumpPreviousDecl(OS, D);
974f4a2713aSLionel Sambuc     dumpSourceRange(D->getSourceRange());
975*0a6a1f1dSLionel Sambuc     OS << ' ';
976*0a6a1f1dSLionel Sambuc     dumpLocation(D->getLocation());
977f4a2713aSLionel Sambuc     if (Module *M = D->getOwningModule())
978f4a2713aSLionel Sambuc       OS << " in " << M->getFullModuleName();
979f4a2713aSLionel Sambuc     if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
980f4a2713aSLionel Sambuc       if (ND->isHidden())
981f4a2713aSLionel Sambuc         OS << " hidden";
982*0a6a1f1dSLionel Sambuc     if (D->isImplicit())
983*0a6a1f1dSLionel Sambuc       OS << " implicit";
984*0a6a1f1dSLionel Sambuc     if (D->isUsed())
985*0a6a1f1dSLionel Sambuc       OS << " used";
986*0a6a1f1dSLionel Sambuc     else if (D->isThisDeclarationReferenced())
987*0a6a1f1dSLionel Sambuc       OS << " referenced";
988f4a2713aSLionel Sambuc     if (D->isInvalidDecl())
989f4a2713aSLionel Sambuc       OS << " invalid";
990*0a6a1f1dSLionel Sambuc     if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
991*0a6a1f1dSLionel Sambuc       if (FD->isConstexpr())
992*0a6a1f1dSLionel Sambuc         OS << " constexpr";
993f4a2713aSLionel Sambuc 
994*0a6a1f1dSLionel Sambuc 
995*0a6a1f1dSLionel Sambuc     ConstDeclVisitor<ASTDumper>::Visit(D);
996*0a6a1f1dSLionel Sambuc 
997*0a6a1f1dSLionel Sambuc     for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
998*0a6a1f1dSLionel Sambuc          ++I)
999*0a6a1f1dSLionel Sambuc       dumpAttr(*I);
1000*0a6a1f1dSLionel Sambuc 
1001*0a6a1f1dSLionel Sambuc     if (const FullComment *Comment =
1002*0a6a1f1dSLionel Sambuc             D->getASTContext().getLocalCommentForDeclUncached(D))
1003*0a6a1f1dSLionel Sambuc       dumpFullComment(Comment);
1004*0a6a1f1dSLionel Sambuc 
1005*0a6a1f1dSLionel Sambuc     // Decls within functions are visited by the body.
1006*0a6a1f1dSLionel Sambuc     if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1007*0a6a1f1dSLionel Sambuc         hasNodes(dyn_cast<DeclContext>(D)))
1008f4a2713aSLionel Sambuc       dumpDeclContext(cast<DeclContext>(D));
1009*0a6a1f1dSLionel Sambuc   });
1010f4a2713aSLionel Sambuc }
1011f4a2713aSLionel Sambuc 
VisitLabelDecl(const LabelDecl * D)1012f4a2713aSLionel Sambuc void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
1013f4a2713aSLionel Sambuc   dumpName(D);
1014f4a2713aSLionel Sambuc }
1015f4a2713aSLionel Sambuc 
VisitTypedefDecl(const TypedefDecl * D)1016f4a2713aSLionel Sambuc void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
1017f4a2713aSLionel Sambuc   dumpName(D);
1018f4a2713aSLionel Sambuc   dumpType(D->getUnderlyingType());
1019f4a2713aSLionel Sambuc   if (D->isModulePrivate())
1020f4a2713aSLionel Sambuc     OS << " __module_private__";
1021f4a2713aSLionel Sambuc }
1022f4a2713aSLionel Sambuc 
VisitEnumDecl(const EnumDecl * D)1023f4a2713aSLionel Sambuc void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
1024f4a2713aSLionel Sambuc   if (D->isScoped()) {
1025f4a2713aSLionel Sambuc     if (D->isScopedUsingClassTag())
1026f4a2713aSLionel Sambuc       OS << " class";
1027f4a2713aSLionel Sambuc     else
1028f4a2713aSLionel Sambuc       OS << " struct";
1029f4a2713aSLionel Sambuc   }
1030f4a2713aSLionel Sambuc   dumpName(D);
1031f4a2713aSLionel Sambuc   if (D->isModulePrivate())
1032f4a2713aSLionel Sambuc     OS << " __module_private__";
1033f4a2713aSLionel Sambuc   if (D->isFixed())
1034f4a2713aSLionel Sambuc     dumpType(D->getIntegerType());
1035f4a2713aSLionel Sambuc }
1036f4a2713aSLionel Sambuc 
VisitRecordDecl(const RecordDecl * D)1037f4a2713aSLionel Sambuc void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
1038f4a2713aSLionel Sambuc   OS << ' ' << D->getKindName();
1039f4a2713aSLionel Sambuc   dumpName(D);
1040f4a2713aSLionel Sambuc   if (D->isModulePrivate())
1041f4a2713aSLionel Sambuc     OS << " __module_private__";
1042f4a2713aSLionel Sambuc   if (D->isCompleteDefinition())
1043f4a2713aSLionel Sambuc     OS << " definition";
1044f4a2713aSLionel Sambuc }
1045f4a2713aSLionel Sambuc 
VisitEnumConstantDecl(const EnumConstantDecl * D)1046f4a2713aSLionel Sambuc void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
1047f4a2713aSLionel Sambuc   dumpName(D);
1048f4a2713aSLionel Sambuc   dumpType(D->getType());
1049*0a6a1f1dSLionel Sambuc   if (const Expr *Init = D->getInitExpr())
1050f4a2713aSLionel Sambuc     dumpStmt(Init);
1051f4a2713aSLionel Sambuc }
1052f4a2713aSLionel Sambuc 
VisitIndirectFieldDecl(const IndirectFieldDecl * D)1053f4a2713aSLionel Sambuc void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
1054f4a2713aSLionel Sambuc   dumpName(D);
1055f4a2713aSLionel Sambuc   dumpType(D->getType());
1056*0a6a1f1dSLionel Sambuc 
1057*0a6a1f1dSLionel Sambuc   for (auto *Child : D->chain())
1058*0a6a1f1dSLionel Sambuc     dumpDeclRef(Child);
1059f4a2713aSLionel Sambuc }
1060f4a2713aSLionel Sambuc 
VisitFunctionDecl(const FunctionDecl * D)1061f4a2713aSLionel Sambuc void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
1062f4a2713aSLionel Sambuc   dumpName(D);
1063f4a2713aSLionel Sambuc   dumpType(D->getType());
1064f4a2713aSLionel Sambuc 
1065f4a2713aSLionel Sambuc   StorageClass SC = D->getStorageClass();
1066f4a2713aSLionel Sambuc   if (SC != SC_None)
1067f4a2713aSLionel Sambuc     OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1068f4a2713aSLionel Sambuc   if (D->isInlineSpecified())
1069f4a2713aSLionel Sambuc     OS << " inline";
1070f4a2713aSLionel Sambuc   if (D->isVirtualAsWritten())
1071f4a2713aSLionel Sambuc     OS << " virtual";
1072f4a2713aSLionel Sambuc   if (D->isModulePrivate())
1073f4a2713aSLionel Sambuc     OS << " __module_private__";
1074f4a2713aSLionel Sambuc 
1075f4a2713aSLionel Sambuc   if (D->isPure())
1076f4a2713aSLionel Sambuc     OS << " pure";
1077f4a2713aSLionel Sambuc   else if (D->isDeletedAsWritten())
1078f4a2713aSLionel Sambuc     OS << " delete";
1079f4a2713aSLionel Sambuc 
1080f4a2713aSLionel Sambuc   if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1081f4a2713aSLionel Sambuc     FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
1082*0a6a1f1dSLionel Sambuc     switch (EPI.ExceptionSpec.Type) {
1083f4a2713aSLionel Sambuc     default: break;
1084f4a2713aSLionel Sambuc     case EST_Unevaluated:
1085*0a6a1f1dSLionel Sambuc       OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
1086f4a2713aSLionel Sambuc       break;
1087f4a2713aSLionel Sambuc     case EST_Uninstantiated:
1088*0a6a1f1dSLionel Sambuc       OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
1089f4a2713aSLionel Sambuc       break;
1090f4a2713aSLionel Sambuc     }
1091f4a2713aSLionel Sambuc   }
1092f4a2713aSLionel Sambuc 
1093*0a6a1f1dSLionel Sambuc   if (const FunctionTemplateSpecializationInfo *FTSI =
1094*0a6a1f1dSLionel Sambuc           D->getTemplateSpecializationInfo())
1095f4a2713aSLionel Sambuc     dumpTemplateArgumentList(*FTSI->TemplateArguments);
1096f4a2713aSLionel Sambuc 
1097f4a2713aSLionel Sambuc   for (ArrayRef<NamedDecl *>::iterator
1098f4a2713aSLionel Sambuc        I = D->getDeclsInPrototypeScope().begin(),
1099*0a6a1f1dSLionel Sambuc        E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
1100f4a2713aSLionel Sambuc     dumpDecl(*I);
1101f4a2713aSLionel Sambuc 
1102f4a2713aSLionel Sambuc   for (FunctionDecl::param_const_iterator I = D->param_begin(),
1103f4a2713aSLionel Sambuc                                           E = D->param_end();
1104*0a6a1f1dSLionel Sambuc        I != E; ++I)
1105f4a2713aSLionel Sambuc     dumpDecl(*I);
1106f4a2713aSLionel Sambuc 
1107*0a6a1f1dSLionel Sambuc   if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
1108f4a2713aSLionel Sambuc     for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
1109f4a2713aSLionel Sambuc                                                  E = C->init_end();
1110*0a6a1f1dSLionel Sambuc          I != E; ++I)
1111f4a2713aSLionel Sambuc       dumpCXXCtorInitializer(*I);
1112f4a2713aSLionel Sambuc 
1113*0a6a1f1dSLionel Sambuc   if (D->doesThisDeclarationHaveABody())
1114f4a2713aSLionel Sambuc     dumpStmt(D->getBody());
1115f4a2713aSLionel Sambuc }
1116f4a2713aSLionel Sambuc 
VisitFieldDecl(const FieldDecl * D)1117f4a2713aSLionel Sambuc void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
1118f4a2713aSLionel Sambuc   dumpName(D);
1119f4a2713aSLionel Sambuc   dumpType(D->getType());
1120f4a2713aSLionel Sambuc   if (D->isMutable())
1121f4a2713aSLionel Sambuc     OS << " mutable";
1122f4a2713aSLionel Sambuc   if (D->isModulePrivate())
1123f4a2713aSLionel Sambuc     OS << " __module_private__";
1124f4a2713aSLionel Sambuc 
1125*0a6a1f1dSLionel Sambuc   if (D->isBitField())
1126f4a2713aSLionel Sambuc     dumpStmt(D->getBitWidth());
1127*0a6a1f1dSLionel Sambuc   if (Expr *Init = D->getInClassInitializer())
1128f4a2713aSLionel Sambuc     dumpStmt(Init);
1129f4a2713aSLionel Sambuc }
1130f4a2713aSLionel Sambuc 
VisitVarDecl(const VarDecl * D)1131f4a2713aSLionel Sambuc void ASTDumper::VisitVarDecl(const VarDecl *D) {
1132f4a2713aSLionel Sambuc   dumpName(D);
1133f4a2713aSLionel Sambuc   dumpType(D->getType());
1134f4a2713aSLionel Sambuc   StorageClass SC = D->getStorageClass();
1135f4a2713aSLionel Sambuc   if (SC != SC_None)
1136f4a2713aSLionel Sambuc     OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1137f4a2713aSLionel Sambuc   switch (D->getTLSKind()) {
1138f4a2713aSLionel Sambuc   case VarDecl::TLS_None: break;
1139f4a2713aSLionel Sambuc   case VarDecl::TLS_Static: OS << " tls"; break;
1140f4a2713aSLionel Sambuc   case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1141f4a2713aSLionel Sambuc   }
1142f4a2713aSLionel Sambuc   if (D->isModulePrivate())
1143f4a2713aSLionel Sambuc     OS << " __module_private__";
1144f4a2713aSLionel Sambuc   if (D->isNRVOVariable())
1145f4a2713aSLionel Sambuc     OS << " nrvo";
1146f4a2713aSLionel Sambuc   if (D->hasInit()) {
1147*0a6a1f1dSLionel Sambuc     switch (D->getInitStyle()) {
1148*0a6a1f1dSLionel Sambuc     case VarDecl::CInit: OS << " cinit"; break;
1149*0a6a1f1dSLionel Sambuc     case VarDecl::CallInit: OS << " callinit"; break;
1150*0a6a1f1dSLionel Sambuc     case VarDecl::ListInit: OS << " listinit"; break;
1151*0a6a1f1dSLionel Sambuc     }
1152f4a2713aSLionel Sambuc     dumpStmt(D->getInit());
1153f4a2713aSLionel Sambuc   }
1154f4a2713aSLionel Sambuc }
1155f4a2713aSLionel Sambuc 
VisitFileScopeAsmDecl(const FileScopeAsmDecl * D)1156f4a2713aSLionel Sambuc void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
1157f4a2713aSLionel Sambuc   dumpStmt(D->getAsmString());
1158f4a2713aSLionel Sambuc }
1159f4a2713aSLionel Sambuc 
VisitImportDecl(const ImportDecl * D)1160f4a2713aSLionel Sambuc void ASTDumper::VisitImportDecl(const ImportDecl *D) {
1161f4a2713aSLionel Sambuc   OS << ' ' << D->getImportedModule()->getFullModuleName();
1162f4a2713aSLionel Sambuc }
1163f4a2713aSLionel Sambuc 
1164f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1165f4a2713aSLionel Sambuc // C++ Declarations
1166f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1167f4a2713aSLionel Sambuc 
VisitNamespaceDecl(const NamespaceDecl * D)1168f4a2713aSLionel Sambuc void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
1169f4a2713aSLionel Sambuc   dumpName(D);
1170f4a2713aSLionel Sambuc   if (D->isInline())
1171f4a2713aSLionel Sambuc     OS << " inline";
1172f4a2713aSLionel Sambuc   if (!D->isOriginalNamespace())
1173f4a2713aSLionel Sambuc     dumpDeclRef(D->getOriginalNamespace(), "original");
1174f4a2713aSLionel Sambuc }
1175f4a2713aSLionel Sambuc 
VisitUsingDirectiveDecl(const UsingDirectiveDecl * D)1176f4a2713aSLionel Sambuc void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
1177f4a2713aSLionel Sambuc   OS << ' ';
1178f4a2713aSLionel Sambuc   dumpBareDeclRef(D->getNominatedNamespace());
1179f4a2713aSLionel Sambuc }
1180f4a2713aSLionel Sambuc 
VisitNamespaceAliasDecl(const NamespaceAliasDecl * D)1181f4a2713aSLionel Sambuc void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
1182f4a2713aSLionel Sambuc   dumpName(D);
1183f4a2713aSLionel Sambuc   dumpDeclRef(D->getAliasedNamespace());
1184f4a2713aSLionel Sambuc }
1185f4a2713aSLionel Sambuc 
VisitTypeAliasDecl(const TypeAliasDecl * D)1186f4a2713aSLionel Sambuc void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
1187f4a2713aSLionel Sambuc   dumpName(D);
1188f4a2713aSLionel Sambuc   dumpType(D->getUnderlyingType());
1189f4a2713aSLionel Sambuc }
1190f4a2713aSLionel Sambuc 
VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl * D)1191f4a2713aSLionel Sambuc void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
1192f4a2713aSLionel Sambuc   dumpName(D);
1193f4a2713aSLionel Sambuc   dumpTemplateParameters(D->getTemplateParameters());
1194f4a2713aSLionel Sambuc   dumpDecl(D->getTemplatedDecl());
1195f4a2713aSLionel Sambuc }
1196f4a2713aSLionel Sambuc 
VisitCXXRecordDecl(const CXXRecordDecl * D)1197f4a2713aSLionel Sambuc void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
1198f4a2713aSLionel Sambuc   VisitRecordDecl(D);
1199f4a2713aSLionel Sambuc   if (!D->isCompleteDefinition())
1200f4a2713aSLionel Sambuc     return;
1201f4a2713aSLionel Sambuc 
1202*0a6a1f1dSLionel Sambuc   for (const auto &I : D->bases()) {
1203*0a6a1f1dSLionel Sambuc     dumpChild([=] {
1204*0a6a1f1dSLionel Sambuc       if (I.isVirtual())
1205f4a2713aSLionel Sambuc         OS << "virtual ";
1206*0a6a1f1dSLionel Sambuc       dumpAccessSpecifier(I.getAccessSpecifier());
1207*0a6a1f1dSLionel Sambuc       dumpType(I.getType());
1208*0a6a1f1dSLionel Sambuc       if (I.isPackExpansion())
1209f4a2713aSLionel Sambuc         OS << "...";
1210*0a6a1f1dSLionel Sambuc     });
1211f4a2713aSLionel Sambuc   }
1212f4a2713aSLionel Sambuc }
1213f4a2713aSLionel Sambuc 
VisitStaticAssertDecl(const StaticAssertDecl * D)1214f4a2713aSLionel Sambuc void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
1215f4a2713aSLionel Sambuc   dumpStmt(D->getAssertExpr());
1216f4a2713aSLionel Sambuc   dumpStmt(D->getMessage());
1217f4a2713aSLionel Sambuc }
1218f4a2713aSLionel Sambuc 
1219*0a6a1f1dSLionel Sambuc template<typename SpecializationDecl>
VisitTemplateDeclSpecialization(const SpecializationDecl * D,bool DumpExplicitInst,bool DumpRefOnly)1220*0a6a1f1dSLionel Sambuc void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
1221*0a6a1f1dSLionel Sambuc                                                 bool DumpExplicitInst,
1222*0a6a1f1dSLionel Sambuc                                                 bool DumpRefOnly) {
1223*0a6a1f1dSLionel Sambuc   bool DumpedAny = false;
1224*0a6a1f1dSLionel Sambuc   for (auto *RedeclWithBadType : D->redecls()) {
1225*0a6a1f1dSLionel Sambuc     // FIXME: The redecls() range sometimes has elements of a less-specific
1226*0a6a1f1dSLionel Sambuc     // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1227*0a6a1f1dSLionel Sambuc     // us TagDecls, and should give CXXRecordDecls).
1228*0a6a1f1dSLionel Sambuc     auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1229*0a6a1f1dSLionel Sambuc     if (!Redecl) {
1230*0a6a1f1dSLionel Sambuc       // Found the injected-class-name for a class template. This will be dumped
1231*0a6a1f1dSLionel Sambuc       // as part of its surrounding class so we don't need to dump it here.
1232*0a6a1f1dSLionel Sambuc       assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1233*0a6a1f1dSLionel Sambuc              "expected an injected-class-name");
1234*0a6a1f1dSLionel Sambuc       continue;
1235*0a6a1f1dSLionel Sambuc     }
1236*0a6a1f1dSLionel Sambuc 
1237*0a6a1f1dSLionel Sambuc     switch (Redecl->getTemplateSpecializationKind()) {
1238f4a2713aSLionel Sambuc     case TSK_ExplicitInstantiationDeclaration:
1239f4a2713aSLionel Sambuc     case TSK_ExplicitInstantiationDefinition:
1240*0a6a1f1dSLionel Sambuc       if (!DumpExplicitInst)
1241*0a6a1f1dSLionel Sambuc         break;
1242*0a6a1f1dSLionel Sambuc       // Fall through.
1243*0a6a1f1dSLionel Sambuc     case TSK_Undeclared:
1244*0a6a1f1dSLionel Sambuc     case TSK_ImplicitInstantiation:
1245*0a6a1f1dSLionel Sambuc       if (DumpRefOnly)
1246*0a6a1f1dSLionel Sambuc         dumpDeclRef(Redecl);
1247f4a2713aSLionel Sambuc       else
1248*0a6a1f1dSLionel Sambuc         dumpDecl(Redecl);
1249*0a6a1f1dSLionel Sambuc       DumpedAny = true;
1250f4a2713aSLionel Sambuc       break;
1251f4a2713aSLionel Sambuc     case TSK_ExplicitSpecialization:
1252f4a2713aSLionel Sambuc       break;
1253f4a2713aSLionel Sambuc     }
1254f4a2713aSLionel Sambuc   }
1255*0a6a1f1dSLionel Sambuc 
1256*0a6a1f1dSLionel Sambuc   // Ensure we dump at least one decl for each specialization.
1257*0a6a1f1dSLionel Sambuc   if (!DumpedAny)
1258*0a6a1f1dSLionel Sambuc     dumpDeclRef(D);
1259*0a6a1f1dSLionel Sambuc }
1260*0a6a1f1dSLionel Sambuc 
1261*0a6a1f1dSLionel Sambuc template<typename TemplateDecl>
VisitTemplateDecl(const TemplateDecl * D,bool DumpExplicitInst)1262*0a6a1f1dSLionel Sambuc void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1263*0a6a1f1dSLionel Sambuc                                   bool DumpExplicitInst) {
1264*0a6a1f1dSLionel Sambuc   dumpName(D);
1265*0a6a1f1dSLionel Sambuc   dumpTemplateParameters(D->getTemplateParameters());
1266*0a6a1f1dSLionel Sambuc 
1267*0a6a1f1dSLionel Sambuc   dumpDecl(D->getTemplatedDecl());
1268*0a6a1f1dSLionel Sambuc 
1269*0a6a1f1dSLionel Sambuc   for (auto *Child : D->specializations())
1270*0a6a1f1dSLionel Sambuc     VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
1271*0a6a1f1dSLionel Sambuc                                     !D->isCanonicalDecl());
1272*0a6a1f1dSLionel Sambuc }
1273*0a6a1f1dSLionel Sambuc 
VisitFunctionTemplateDecl(const FunctionTemplateDecl * D)1274*0a6a1f1dSLionel Sambuc void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1275*0a6a1f1dSLionel Sambuc   // FIXME: We don't add a declaration of a function template specialization
1276*0a6a1f1dSLionel Sambuc   // to its context when it's explicitly instantiated, so dump explicit
1277*0a6a1f1dSLionel Sambuc   // instantiations when we dump the template itself.
1278*0a6a1f1dSLionel Sambuc   VisitTemplateDecl(D, true);
1279f4a2713aSLionel Sambuc }
1280f4a2713aSLionel Sambuc 
VisitClassTemplateDecl(const ClassTemplateDecl * D)1281f4a2713aSLionel Sambuc void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
1282*0a6a1f1dSLionel Sambuc   VisitTemplateDecl(D, false);
1283f4a2713aSLionel Sambuc }
1284f4a2713aSLionel Sambuc 
VisitClassTemplateSpecializationDecl(const ClassTemplateSpecializationDecl * D)1285f4a2713aSLionel Sambuc void ASTDumper::VisitClassTemplateSpecializationDecl(
1286f4a2713aSLionel Sambuc     const ClassTemplateSpecializationDecl *D) {
1287f4a2713aSLionel Sambuc   VisitCXXRecordDecl(D);
1288f4a2713aSLionel Sambuc   dumpTemplateArgumentList(D->getTemplateArgs());
1289f4a2713aSLionel Sambuc }
1290f4a2713aSLionel Sambuc 
VisitClassTemplatePartialSpecializationDecl(const ClassTemplatePartialSpecializationDecl * D)1291f4a2713aSLionel Sambuc void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
1292f4a2713aSLionel Sambuc     const ClassTemplatePartialSpecializationDecl *D) {
1293f4a2713aSLionel Sambuc   VisitClassTemplateSpecializationDecl(D);
1294f4a2713aSLionel Sambuc   dumpTemplateParameters(D->getTemplateParameters());
1295f4a2713aSLionel Sambuc }
1296f4a2713aSLionel Sambuc 
VisitClassScopeFunctionSpecializationDecl(const ClassScopeFunctionSpecializationDecl * D)1297f4a2713aSLionel Sambuc void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
1298f4a2713aSLionel Sambuc     const ClassScopeFunctionSpecializationDecl *D) {
1299f4a2713aSLionel Sambuc   dumpDeclRef(D->getSpecialization());
1300f4a2713aSLionel Sambuc   if (D->hasExplicitTemplateArgs())
1301f4a2713aSLionel Sambuc     dumpTemplateArgumentListInfo(D->templateArgs());
1302f4a2713aSLionel Sambuc }
1303f4a2713aSLionel Sambuc 
VisitVarTemplateDecl(const VarTemplateDecl * D)1304f4a2713aSLionel Sambuc void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1305*0a6a1f1dSLionel Sambuc   VisitTemplateDecl(D, false);
1306f4a2713aSLionel Sambuc }
1307f4a2713aSLionel Sambuc 
VisitVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl * D)1308f4a2713aSLionel Sambuc void ASTDumper::VisitVarTemplateSpecializationDecl(
1309f4a2713aSLionel Sambuc     const VarTemplateSpecializationDecl *D) {
1310f4a2713aSLionel Sambuc   dumpTemplateArgumentList(D->getTemplateArgs());
1311f4a2713aSLionel Sambuc   VisitVarDecl(D);
1312f4a2713aSLionel Sambuc }
1313f4a2713aSLionel Sambuc 
VisitVarTemplatePartialSpecializationDecl(const VarTemplatePartialSpecializationDecl * D)1314f4a2713aSLionel Sambuc void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1315f4a2713aSLionel Sambuc     const VarTemplatePartialSpecializationDecl *D) {
1316f4a2713aSLionel Sambuc   dumpTemplateParameters(D->getTemplateParameters());
1317f4a2713aSLionel Sambuc   VisitVarTemplateSpecializationDecl(D);
1318f4a2713aSLionel Sambuc }
1319f4a2713aSLionel Sambuc 
VisitTemplateTypeParmDecl(const TemplateTypeParmDecl * D)1320f4a2713aSLionel Sambuc void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
1321f4a2713aSLionel Sambuc   if (D->wasDeclaredWithTypename())
1322f4a2713aSLionel Sambuc     OS << " typename";
1323f4a2713aSLionel Sambuc   else
1324f4a2713aSLionel Sambuc     OS << " class";
1325f4a2713aSLionel Sambuc   if (D->isParameterPack())
1326f4a2713aSLionel Sambuc     OS << " ...";
1327f4a2713aSLionel Sambuc   dumpName(D);
1328f4a2713aSLionel Sambuc   if (D->hasDefaultArgument())
1329*0a6a1f1dSLionel Sambuc     dumpTemplateArgument(D->getDefaultArgument());
1330f4a2713aSLionel Sambuc }
1331f4a2713aSLionel Sambuc 
VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl * D)1332f4a2713aSLionel Sambuc void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
1333f4a2713aSLionel Sambuc   dumpType(D->getType());
1334f4a2713aSLionel Sambuc   if (D->isParameterPack())
1335f4a2713aSLionel Sambuc     OS << " ...";
1336f4a2713aSLionel Sambuc   dumpName(D);
1337f4a2713aSLionel Sambuc   if (D->hasDefaultArgument())
1338*0a6a1f1dSLionel Sambuc     dumpTemplateArgument(D->getDefaultArgument());
1339f4a2713aSLionel Sambuc }
1340f4a2713aSLionel Sambuc 
VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl * D)1341f4a2713aSLionel Sambuc void ASTDumper::VisitTemplateTemplateParmDecl(
1342f4a2713aSLionel Sambuc     const TemplateTemplateParmDecl *D) {
1343f4a2713aSLionel Sambuc   if (D->isParameterPack())
1344f4a2713aSLionel Sambuc     OS << " ...";
1345f4a2713aSLionel Sambuc   dumpName(D);
1346f4a2713aSLionel Sambuc   dumpTemplateParameters(D->getTemplateParameters());
1347f4a2713aSLionel Sambuc   if (D->hasDefaultArgument())
1348f4a2713aSLionel Sambuc     dumpTemplateArgumentLoc(D->getDefaultArgument());
1349f4a2713aSLionel Sambuc }
1350f4a2713aSLionel Sambuc 
VisitUsingDecl(const UsingDecl * D)1351f4a2713aSLionel Sambuc void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
1352f4a2713aSLionel Sambuc   OS << ' ';
1353f4a2713aSLionel Sambuc   D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1354f4a2713aSLionel Sambuc   OS << D->getNameAsString();
1355f4a2713aSLionel Sambuc }
1356f4a2713aSLionel Sambuc 
VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl * D)1357f4a2713aSLionel Sambuc void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1358f4a2713aSLionel Sambuc     const UnresolvedUsingTypenameDecl *D) {
1359f4a2713aSLionel Sambuc   OS << ' ';
1360f4a2713aSLionel Sambuc   D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1361f4a2713aSLionel Sambuc   OS << D->getNameAsString();
1362f4a2713aSLionel Sambuc }
1363f4a2713aSLionel Sambuc 
VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl * D)1364f4a2713aSLionel Sambuc void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
1365f4a2713aSLionel Sambuc   OS << ' ';
1366f4a2713aSLionel Sambuc   D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1367f4a2713aSLionel Sambuc   OS << D->getNameAsString();
1368f4a2713aSLionel Sambuc   dumpType(D->getType());
1369f4a2713aSLionel Sambuc }
1370f4a2713aSLionel Sambuc 
VisitUsingShadowDecl(const UsingShadowDecl * D)1371f4a2713aSLionel Sambuc void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
1372f4a2713aSLionel Sambuc   OS << ' ';
1373f4a2713aSLionel Sambuc   dumpBareDeclRef(D->getTargetDecl());
1374f4a2713aSLionel Sambuc }
1375f4a2713aSLionel Sambuc 
VisitLinkageSpecDecl(const LinkageSpecDecl * D)1376f4a2713aSLionel Sambuc void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
1377f4a2713aSLionel Sambuc   switch (D->getLanguage()) {
1378f4a2713aSLionel Sambuc   case LinkageSpecDecl::lang_c: OS << " C"; break;
1379f4a2713aSLionel Sambuc   case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1380f4a2713aSLionel Sambuc   }
1381f4a2713aSLionel Sambuc }
1382f4a2713aSLionel Sambuc 
VisitAccessSpecDecl(const AccessSpecDecl * D)1383f4a2713aSLionel Sambuc void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
1384f4a2713aSLionel Sambuc   OS << ' ';
1385f4a2713aSLionel Sambuc   dumpAccessSpecifier(D->getAccess());
1386f4a2713aSLionel Sambuc }
1387f4a2713aSLionel Sambuc 
VisitFriendDecl(const FriendDecl * D)1388f4a2713aSLionel Sambuc void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
1389f4a2713aSLionel Sambuc   if (TypeSourceInfo *T = D->getFriendType())
1390f4a2713aSLionel Sambuc     dumpType(T->getType());
1391f4a2713aSLionel Sambuc   else
1392f4a2713aSLionel Sambuc     dumpDecl(D->getFriendDecl());
1393f4a2713aSLionel Sambuc }
1394f4a2713aSLionel Sambuc 
1395f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1396f4a2713aSLionel Sambuc // Obj-C Declarations
1397f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1398f4a2713aSLionel Sambuc 
VisitObjCIvarDecl(const ObjCIvarDecl * D)1399f4a2713aSLionel Sambuc void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
1400f4a2713aSLionel Sambuc   dumpName(D);
1401f4a2713aSLionel Sambuc   dumpType(D->getType());
1402f4a2713aSLionel Sambuc   if (D->getSynthesize())
1403f4a2713aSLionel Sambuc     OS << " synthesize";
1404f4a2713aSLionel Sambuc 
1405f4a2713aSLionel Sambuc   switch (D->getAccessControl()) {
1406f4a2713aSLionel Sambuc   case ObjCIvarDecl::None:
1407f4a2713aSLionel Sambuc     OS << " none";
1408f4a2713aSLionel Sambuc     break;
1409f4a2713aSLionel Sambuc   case ObjCIvarDecl::Private:
1410f4a2713aSLionel Sambuc     OS << " private";
1411f4a2713aSLionel Sambuc     break;
1412f4a2713aSLionel Sambuc   case ObjCIvarDecl::Protected:
1413f4a2713aSLionel Sambuc     OS << " protected";
1414f4a2713aSLionel Sambuc     break;
1415f4a2713aSLionel Sambuc   case ObjCIvarDecl::Public:
1416f4a2713aSLionel Sambuc     OS << " public";
1417f4a2713aSLionel Sambuc     break;
1418f4a2713aSLionel Sambuc   case ObjCIvarDecl::Package:
1419f4a2713aSLionel Sambuc     OS << " package";
1420f4a2713aSLionel Sambuc     break;
1421f4a2713aSLionel Sambuc   }
1422f4a2713aSLionel Sambuc }
1423f4a2713aSLionel Sambuc 
VisitObjCMethodDecl(const ObjCMethodDecl * D)1424f4a2713aSLionel Sambuc void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
1425f4a2713aSLionel Sambuc   if (D->isInstanceMethod())
1426f4a2713aSLionel Sambuc     OS << " -";
1427f4a2713aSLionel Sambuc   else
1428f4a2713aSLionel Sambuc     OS << " +";
1429f4a2713aSLionel Sambuc   dumpName(D);
1430*0a6a1f1dSLionel Sambuc   dumpType(D->getReturnType());
1431f4a2713aSLionel Sambuc 
1432f4a2713aSLionel Sambuc   if (D->isThisDeclarationADefinition()) {
1433f4a2713aSLionel Sambuc     dumpDeclContext(D);
1434f4a2713aSLionel Sambuc   } else {
1435f4a2713aSLionel Sambuc     for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1436f4a2713aSLionel Sambuc                                               E = D->param_end();
1437*0a6a1f1dSLionel Sambuc          I != E; ++I)
1438f4a2713aSLionel Sambuc       dumpDecl(*I);
1439f4a2713aSLionel Sambuc   }
1440f4a2713aSLionel Sambuc 
1441*0a6a1f1dSLionel Sambuc   if (D->isVariadic())
1442*0a6a1f1dSLionel Sambuc     dumpChild([=] { OS << "..."; });
1443f4a2713aSLionel Sambuc 
1444*0a6a1f1dSLionel Sambuc   if (D->hasBody())
1445f4a2713aSLionel Sambuc     dumpStmt(D->getBody());
1446f4a2713aSLionel Sambuc }
1447f4a2713aSLionel Sambuc 
VisitObjCCategoryDecl(const ObjCCategoryDecl * D)1448f4a2713aSLionel Sambuc void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
1449f4a2713aSLionel Sambuc   dumpName(D);
1450f4a2713aSLionel Sambuc   dumpDeclRef(D->getClassInterface());
1451f4a2713aSLionel Sambuc   dumpDeclRef(D->getImplementation());
1452f4a2713aSLionel Sambuc   for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
1453f4a2713aSLionel Sambuc                                            E = D->protocol_end();
1454*0a6a1f1dSLionel Sambuc        I != E; ++I)
1455f4a2713aSLionel Sambuc     dumpDeclRef(*I);
1456f4a2713aSLionel Sambuc }
1457f4a2713aSLionel Sambuc 
VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl * D)1458f4a2713aSLionel Sambuc void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
1459f4a2713aSLionel Sambuc   dumpName(D);
1460f4a2713aSLionel Sambuc   dumpDeclRef(D->getClassInterface());
1461f4a2713aSLionel Sambuc   dumpDeclRef(D->getCategoryDecl());
1462f4a2713aSLionel Sambuc }
1463f4a2713aSLionel Sambuc 
VisitObjCProtocolDecl(const ObjCProtocolDecl * D)1464f4a2713aSLionel Sambuc void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
1465f4a2713aSLionel Sambuc   dumpName(D);
1466*0a6a1f1dSLionel Sambuc 
1467*0a6a1f1dSLionel Sambuc   for (auto *Child : D->protocols())
1468*0a6a1f1dSLionel Sambuc     dumpDeclRef(Child);
1469f4a2713aSLionel Sambuc }
1470f4a2713aSLionel Sambuc 
VisitObjCInterfaceDecl(const ObjCInterfaceDecl * D)1471f4a2713aSLionel Sambuc void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
1472f4a2713aSLionel Sambuc   dumpName(D);
1473f4a2713aSLionel Sambuc   dumpDeclRef(D->getSuperClass(), "super");
1474*0a6a1f1dSLionel Sambuc 
1475f4a2713aSLionel Sambuc   dumpDeclRef(D->getImplementation());
1476*0a6a1f1dSLionel Sambuc   for (auto *Child : D->protocols())
1477*0a6a1f1dSLionel Sambuc     dumpDeclRef(Child);
1478f4a2713aSLionel Sambuc }
1479f4a2713aSLionel Sambuc 
VisitObjCImplementationDecl(const ObjCImplementationDecl * D)1480f4a2713aSLionel Sambuc void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
1481f4a2713aSLionel Sambuc   dumpName(D);
1482f4a2713aSLionel Sambuc   dumpDeclRef(D->getSuperClass(), "super");
1483f4a2713aSLionel Sambuc   dumpDeclRef(D->getClassInterface());
1484f4a2713aSLionel Sambuc   for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1485f4a2713aSLionel Sambuc                                                    E = D->init_end();
1486*0a6a1f1dSLionel Sambuc        I != E; ++I)
1487f4a2713aSLionel Sambuc     dumpCXXCtorInitializer(*I);
1488f4a2713aSLionel Sambuc }
1489f4a2713aSLionel Sambuc 
VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl * D)1490f4a2713aSLionel Sambuc void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
1491f4a2713aSLionel Sambuc   dumpName(D);
1492f4a2713aSLionel Sambuc   dumpDeclRef(D->getClassInterface());
1493f4a2713aSLionel Sambuc }
1494f4a2713aSLionel Sambuc 
VisitObjCPropertyDecl(const ObjCPropertyDecl * D)1495f4a2713aSLionel Sambuc void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
1496f4a2713aSLionel Sambuc   dumpName(D);
1497f4a2713aSLionel Sambuc   dumpType(D->getType());
1498f4a2713aSLionel Sambuc 
1499f4a2713aSLionel Sambuc   if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1500f4a2713aSLionel Sambuc     OS << " required";
1501f4a2713aSLionel Sambuc   else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1502f4a2713aSLionel Sambuc     OS << " optional";
1503f4a2713aSLionel Sambuc 
1504f4a2713aSLionel Sambuc   ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1505f4a2713aSLionel Sambuc   if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1506f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1507f4a2713aSLionel Sambuc       OS << " readonly";
1508f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1509f4a2713aSLionel Sambuc       OS << " assign";
1510f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1511f4a2713aSLionel Sambuc       OS << " readwrite";
1512f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1513f4a2713aSLionel Sambuc       OS << " retain";
1514f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1515f4a2713aSLionel Sambuc       OS << " copy";
1516f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1517f4a2713aSLionel Sambuc       OS << " nonatomic";
1518f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1519f4a2713aSLionel Sambuc       OS << " atomic";
1520f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1521f4a2713aSLionel Sambuc       OS << " weak";
1522f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1523f4a2713aSLionel Sambuc       OS << " strong";
1524f4a2713aSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1525f4a2713aSLionel Sambuc       OS << " unsafe_unretained";
1526*0a6a1f1dSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
1527f4a2713aSLionel Sambuc       dumpDeclRef(D->getGetterMethodDecl(), "getter");
1528*0a6a1f1dSLionel Sambuc     if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
1529f4a2713aSLionel Sambuc       dumpDeclRef(D->getSetterMethodDecl(), "setter");
1530f4a2713aSLionel Sambuc   }
1531f4a2713aSLionel Sambuc }
1532f4a2713aSLionel Sambuc 
VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl * D)1533f4a2713aSLionel Sambuc void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
1534f4a2713aSLionel Sambuc   dumpName(D->getPropertyDecl());
1535f4a2713aSLionel Sambuc   if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1536f4a2713aSLionel Sambuc     OS << " synthesize";
1537f4a2713aSLionel Sambuc   else
1538f4a2713aSLionel Sambuc     OS << " dynamic";
1539f4a2713aSLionel Sambuc   dumpDeclRef(D->getPropertyDecl());
1540f4a2713aSLionel Sambuc   dumpDeclRef(D->getPropertyIvarDecl());
1541f4a2713aSLionel Sambuc }
1542f4a2713aSLionel Sambuc 
VisitBlockDecl(const BlockDecl * D)1543f4a2713aSLionel Sambuc void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1544*0a6a1f1dSLionel Sambuc   for (auto I : D->params())
1545*0a6a1f1dSLionel Sambuc     dumpDecl(I);
1546f4a2713aSLionel Sambuc 
1547*0a6a1f1dSLionel Sambuc   if (D->isVariadic())
1548*0a6a1f1dSLionel Sambuc     dumpChild([=]{ OS << "..."; });
1549f4a2713aSLionel Sambuc 
1550*0a6a1f1dSLionel Sambuc   if (D->capturesCXXThis())
1551*0a6a1f1dSLionel Sambuc     dumpChild([=]{ OS << "capture this"; });
1552*0a6a1f1dSLionel Sambuc 
1553*0a6a1f1dSLionel Sambuc   for (const auto &I : D->captures()) {
1554*0a6a1f1dSLionel Sambuc     dumpChild([=] {
1555f4a2713aSLionel Sambuc       OS << "capture";
1556*0a6a1f1dSLionel Sambuc       if (I.isByRef())
1557f4a2713aSLionel Sambuc         OS << " byref";
1558*0a6a1f1dSLionel Sambuc       if (I.isNested())
1559f4a2713aSLionel Sambuc         OS << " nested";
1560*0a6a1f1dSLionel Sambuc       if (I.getVariable()) {
1561f4a2713aSLionel Sambuc         OS << ' ';
1562*0a6a1f1dSLionel Sambuc         dumpBareDeclRef(I.getVariable());
1563f4a2713aSLionel Sambuc       }
1564*0a6a1f1dSLionel Sambuc       if (I.hasCopyExpr())
1565*0a6a1f1dSLionel Sambuc         dumpStmt(I.getCopyExpr());
1566*0a6a1f1dSLionel Sambuc     });
1567f4a2713aSLionel Sambuc   }
1568f4a2713aSLionel Sambuc   dumpStmt(D->getBody());
1569f4a2713aSLionel Sambuc }
1570f4a2713aSLionel Sambuc 
1571f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1572f4a2713aSLionel Sambuc //  Stmt dumping methods.
1573f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1574f4a2713aSLionel Sambuc 
dumpStmt(const Stmt * S)1575f4a2713aSLionel Sambuc void ASTDumper::dumpStmt(const Stmt *S) {
1576*0a6a1f1dSLionel Sambuc   dumpChild([=] {
1577f4a2713aSLionel Sambuc     if (!S) {
1578f4a2713aSLionel Sambuc       ColorScope Color(*this, NullColor);
1579f4a2713aSLionel Sambuc       OS << "<<<NULL>>>";
1580f4a2713aSLionel Sambuc       return;
1581f4a2713aSLionel Sambuc     }
1582f4a2713aSLionel Sambuc 
1583f4a2713aSLionel Sambuc     if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1584f4a2713aSLionel Sambuc       VisitDeclStmt(DS);
1585f4a2713aSLionel Sambuc       return;
1586f4a2713aSLionel Sambuc     }
1587f4a2713aSLionel Sambuc 
1588f4a2713aSLionel Sambuc     ConstStmtVisitor<ASTDumper>::Visit(S);
1589*0a6a1f1dSLionel Sambuc 
1590*0a6a1f1dSLionel Sambuc     for (Stmt::const_child_range CI = S->children(); CI; ++CI)
1591f4a2713aSLionel Sambuc       dumpStmt(*CI);
1592*0a6a1f1dSLionel Sambuc   });
1593f4a2713aSLionel Sambuc }
1594f4a2713aSLionel Sambuc 
VisitStmt(const Stmt * Node)1595f4a2713aSLionel Sambuc void ASTDumper::VisitStmt(const Stmt *Node) {
1596f4a2713aSLionel Sambuc   {
1597f4a2713aSLionel Sambuc     ColorScope Color(*this, StmtColor);
1598f4a2713aSLionel Sambuc     OS << Node->getStmtClassName();
1599f4a2713aSLionel Sambuc   }
1600f4a2713aSLionel Sambuc   dumpPointer(Node);
1601f4a2713aSLionel Sambuc   dumpSourceRange(Node->getSourceRange());
1602f4a2713aSLionel Sambuc }
1603f4a2713aSLionel Sambuc 
VisitDeclStmt(const DeclStmt * Node)1604f4a2713aSLionel Sambuc void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
1605f4a2713aSLionel Sambuc   VisitStmt(Node);
1606f4a2713aSLionel Sambuc   for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1607f4a2713aSLionel Sambuc                                      E = Node->decl_end();
1608*0a6a1f1dSLionel Sambuc        I != E; ++I)
1609f4a2713aSLionel Sambuc     dumpDecl(*I);
1610f4a2713aSLionel Sambuc }
1611f4a2713aSLionel Sambuc 
VisitAttributedStmt(const AttributedStmt * Node)1612f4a2713aSLionel Sambuc void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
1613f4a2713aSLionel Sambuc   VisitStmt(Node);
1614f4a2713aSLionel Sambuc   for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1615f4a2713aSLionel Sambuc                                         E = Node->getAttrs().end();
1616*0a6a1f1dSLionel Sambuc        I != E; ++I)
1617f4a2713aSLionel Sambuc     dumpAttr(*I);
1618f4a2713aSLionel Sambuc }
1619f4a2713aSLionel Sambuc 
VisitLabelStmt(const LabelStmt * Node)1620f4a2713aSLionel Sambuc void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
1621f4a2713aSLionel Sambuc   VisitStmt(Node);
1622f4a2713aSLionel Sambuc   OS << " '" << Node->getName() << "'";
1623f4a2713aSLionel Sambuc }
1624f4a2713aSLionel Sambuc 
VisitGotoStmt(const GotoStmt * Node)1625f4a2713aSLionel Sambuc void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
1626f4a2713aSLionel Sambuc   VisitStmt(Node);
1627f4a2713aSLionel Sambuc   OS << " '" << Node->getLabel()->getName() << "'";
1628f4a2713aSLionel Sambuc   dumpPointer(Node->getLabel());
1629f4a2713aSLionel Sambuc }
1630f4a2713aSLionel Sambuc 
VisitCXXCatchStmt(const CXXCatchStmt * Node)1631f4a2713aSLionel Sambuc void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1632f4a2713aSLionel Sambuc   VisitStmt(Node);
1633f4a2713aSLionel Sambuc   dumpDecl(Node->getExceptionDecl());
1634f4a2713aSLionel Sambuc }
1635f4a2713aSLionel Sambuc 
1636f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1637f4a2713aSLionel Sambuc //  Expr dumping methods.
1638f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1639f4a2713aSLionel Sambuc 
VisitExpr(const Expr * Node)1640f4a2713aSLionel Sambuc void ASTDumper::VisitExpr(const Expr *Node) {
1641f4a2713aSLionel Sambuc   VisitStmt(Node);
1642f4a2713aSLionel Sambuc   dumpType(Node->getType());
1643f4a2713aSLionel Sambuc 
1644f4a2713aSLionel Sambuc   {
1645f4a2713aSLionel Sambuc     ColorScope Color(*this, ValueKindColor);
1646f4a2713aSLionel Sambuc     switch (Node->getValueKind()) {
1647f4a2713aSLionel Sambuc     case VK_RValue:
1648f4a2713aSLionel Sambuc       break;
1649f4a2713aSLionel Sambuc     case VK_LValue:
1650f4a2713aSLionel Sambuc       OS << " lvalue";
1651f4a2713aSLionel Sambuc       break;
1652f4a2713aSLionel Sambuc     case VK_XValue:
1653f4a2713aSLionel Sambuc       OS << " xvalue";
1654f4a2713aSLionel Sambuc       break;
1655f4a2713aSLionel Sambuc     }
1656f4a2713aSLionel Sambuc   }
1657f4a2713aSLionel Sambuc 
1658f4a2713aSLionel Sambuc   {
1659f4a2713aSLionel Sambuc     ColorScope Color(*this, ObjectKindColor);
1660f4a2713aSLionel Sambuc     switch (Node->getObjectKind()) {
1661f4a2713aSLionel Sambuc     case OK_Ordinary:
1662f4a2713aSLionel Sambuc       break;
1663f4a2713aSLionel Sambuc     case OK_BitField:
1664f4a2713aSLionel Sambuc       OS << " bitfield";
1665f4a2713aSLionel Sambuc       break;
1666f4a2713aSLionel Sambuc     case OK_ObjCProperty:
1667f4a2713aSLionel Sambuc       OS << " objcproperty";
1668f4a2713aSLionel Sambuc       break;
1669f4a2713aSLionel Sambuc     case OK_ObjCSubscript:
1670f4a2713aSLionel Sambuc       OS << " objcsubscript";
1671f4a2713aSLionel Sambuc       break;
1672f4a2713aSLionel Sambuc     case OK_VectorComponent:
1673f4a2713aSLionel Sambuc       OS << " vectorcomponent";
1674f4a2713aSLionel Sambuc       break;
1675f4a2713aSLionel Sambuc     }
1676f4a2713aSLionel Sambuc   }
1677f4a2713aSLionel Sambuc }
1678f4a2713aSLionel Sambuc 
dumpBasePath(raw_ostream & OS,const CastExpr * Node)1679f4a2713aSLionel Sambuc static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
1680f4a2713aSLionel Sambuc   if (Node->path_empty())
1681f4a2713aSLionel Sambuc     return;
1682f4a2713aSLionel Sambuc 
1683f4a2713aSLionel Sambuc   OS << " (";
1684f4a2713aSLionel Sambuc   bool First = true;
1685f4a2713aSLionel Sambuc   for (CastExpr::path_const_iterator I = Node->path_begin(),
1686f4a2713aSLionel Sambuc                                      E = Node->path_end();
1687f4a2713aSLionel Sambuc        I != E; ++I) {
1688f4a2713aSLionel Sambuc     const CXXBaseSpecifier *Base = *I;
1689f4a2713aSLionel Sambuc     if (!First)
1690f4a2713aSLionel Sambuc       OS << " -> ";
1691f4a2713aSLionel Sambuc 
1692f4a2713aSLionel Sambuc     const CXXRecordDecl *RD =
1693f4a2713aSLionel Sambuc     cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
1694f4a2713aSLionel Sambuc 
1695f4a2713aSLionel Sambuc     if (Base->isVirtual())
1696f4a2713aSLionel Sambuc       OS << "virtual ";
1697f4a2713aSLionel Sambuc     OS << RD->getName();
1698f4a2713aSLionel Sambuc     First = false;
1699f4a2713aSLionel Sambuc   }
1700f4a2713aSLionel Sambuc 
1701f4a2713aSLionel Sambuc   OS << ')';
1702f4a2713aSLionel Sambuc }
1703f4a2713aSLionel Sambuc 
VisitCastExpr(const CastExpr * Node)1704f4a2713aSLionel Sambuc void ASTDumper::VisitCastExpr(const CastExpr *Node) {
1705f4a2713aSLionel Sambuc   VisitExpr(Node);
1706f4a2713aSLionel Sambuc   OS << " <";
1707f4a2713aSLionel Sambuc   {
1708f4a2713aSLionel Sambuc     ColorScope Color(*this, CastColor);
1709f4a2713aSLionel Sambuc     OS << Node->getCastKindName();
1710f4a2713aSLionel Sambuc   }
1711f4a2713aSLionel Sambuc   dumpBasePath(OS, Node);
1712f4a2713aSLionel Sambuc   OS << ">";
1713f4a2713aSLionel Sambuc }
1714f4a2713aSLionel Sambuc 
VisitDeclRefExpr(const DeclRefExpr * Node)1715f4a2713aSLionel Sambuc void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
1716f4a2713aSLionel Sambuc   VisitExpr(Node);
1717f4a2713aSLionel Sambuc 
1718f4a2713aSLionel Sambuc   OS << " ";
1719f4a2713aSLionel Sambuc   dumpBareDeclRef(Node->getDecl());
1720f4a2713aSLionel Sambuc   if (Node->getDecl() != Node->getFoundDecl()) {
1721f4a2713aSLionel Sambuc     OS << " (";
1722f4a2713aSLionel Sambuc     dumpBareDeclRef(Node->getFoundDecl());
1723f4a2713aSLionel Sambuc     OS << ")";
1724f4a2713aSLionel Sambuc   }
1725f4a2713aSLionel Sambuc }
1726f4a2713aSLionel Sambuc 
VisitUnresolvedLookupExpr(const UnresolvedLookupExpr * Node)1727f4a2713aSLionel Sambuc void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
1728f4a2713aSLionel Sambuc   VisitExpr(Node);
1729f4a2713aSLionel Sambuc   OS << " (";
1730f4a2713aSLionel Sambuc   if (!Node->requiresADL())
1731f4a2713aSLionel Sambuc     OS << "no ";
1732f4a2713aSLionel Sambuc   OS << "ADL) = '" << Node->getName() << '\'';
1733f4a2713aSLionel Sambuc 
1734f4a2713aSLionel Sambuc   UnresolvedLookupExpr::decls_iterator
1735f4a2713aSLionel Sambuc     I = Node->decls_begin(), E = Node->decls_end();
1736f4a2713aSLionel Sambuc   if (I == E)
1737f4a2713aSLionel Sambuc     OS << " empty";
1738f4a2713aSLionel Sambuc   for (; I != E; ++I)
1739f4a2713aSLionel Sambuc     dumpPointer(*I);
1740f4a2713aSLionel Sambuc }
1741f4a2713aSLionel Sambuc 
VisitObjCIvarRefExpr(const ObjCIvarRefExpr * Node)1742f4a2713aSLionel Sambuc void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
1743f4a2713aSLionel Sambuc   VisitExpr(Node);
1744f4a2713aSLionel Sambuc 
1745f4a2713aSLionel Sambuc   {
1746f4a2713aSLionel Sambuc     ColorScope Color(*this, DeclKindNameColor);
1747f4a2713aSLionel Sambuc     OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1748f4a2713aSLionel Sambuc   }
1749f4a2713aSLionel Sambuc   OS << "='" << *Node->getDecl() << "'";
1750f4a2713aSLionel Sambuc   dumpPointer(Node->getDecl());
1751f4a2713aSLionel Sambuc   if (Node->isFreeIvar())
1752f4a2713aSLionel Sambuc     OS << " isFreeIvar";
1753f4a2713aSLionel Sambuc }
1754f4a2713aSLionel Sambuc 
VisitPredefinedExpr(const PredefinedExpr * Node)1755f4a2713aSLionel Sambuc void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
1756f4a2713aSLionel Sambuc   VisitExpr(Node);
1757*0a6a1f1dSLionel Sambuc   OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
1758f4a2713aSLionel Sambuc }
1759f4a2713aSLionel Sambuc 
VisitCharacterLiteral(const CharacterLiteral * Node)1760f4a2713aSLionel Sambuc void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
1761f4a2713aSLionel Sambuc   VisitExpr(Node);
1762f4a2713aSLionel Sambuc   ColorScope Color(*this, ValueColor);
1763f4a2713aSLionel Sambuc   OS << " " << Node->getValue();
1764f4a2713aSLionel Sambuc }
1765f4a2713aSLionel Sambuc 
VisitIntegerLiteral(const IntegerLiteral * Node)1766f4a2713aSLionel Sambuc void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
1767f4a2713aSLionel Sambuc   VisitExpr(Node);
1768f4a2713aSLionel Sambuc 
1769f4a2713aSLionel Sambuc   bool isSigned = Node->getType()->isSignedIntegerType();
1770f4a2713aSLionel Sambuc   ColorScope Color(*this, ValueColor);
1771f4a2713aSLionel Sambuc   OS << " " << Node->getValue().toString(10, isSigned);
1772f4a2713aSLionel Sambuc }
1773f4a2713aSLionel Sambuc 
VisitFloatingLiteral(const FloatingLiteral * Node)1774f4a2713aSLionel Sambuc void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
1775f4a2713aSLionel Sambuc   VisitExpr(Node);
1776f4a2713aSLionel Sambuc   ColorScope Color(*this, ValueColor);
1777f4a2713aSLionel Sambuc   OS << " " << Node->getValueAsApproximateDouble();
1778f4a2713aSLionel Sambuc }
1779f4a2713aSLionel Sambuc 
VisitStringLiteral(const StringLiteral * Str)1780f4a2713aSLionel Sambuc void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
1781f4a2713aSLionel Sambuc   VisitExpr(Str);
1782f4a2713aSLionel Sambuc   ColorScope Color(*this, ValueColor);
1783f4a2713aSLionel Sambuc   OS << " ";
1784f4a2713aSLionel Sambuc   Str->outputString(OS);
1785f4a2713aSLionel Sambuc }
1786f4a2713aSLionel Sambuc 
VisitInitListExpr(const InitListExpr * ILE)1787*0a6a1f1dSLionel Sambuc void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1788*0a6a1f1dSLionel Sambuc   VisitExpr(ILE);
1789*0a6a1f1dSLionel Sambuc   if (auto *Filler = ILE->getArrayFiller()) {
1790*0a6a1f1dSLionel Sambuc     dumpChild([=] {
1791*0a6a1f1dSLionel Sambuc       OS << "array filler";
1792*0a6a1f1dSLionel Sambuc       dumpStmt(Filler);
1793*0a6a1f1dSLionel Sambuc     });
1794*0a6a1f1dSLionel Sambuc   }
1795*0a6a1f1dSLionel Sambuc   if (auto *Field = ILE->getInitializedFieldInUnion()) {
1796*0a6a1f1dSLionel Sambuc     OS << " field ";
1797*0a6a1f1dSLionel Sambuc     dumpBareDeclRef(Field);
1798*0a6a1f1dSLionel Sambuc   }
1799*0a6a1f1dSLionel Sambuc }
1800*0a6a1f1dSLionel Sambuc 
VisitUnaryOperator(const UnaryOperator * Node)1801f4a2713aSLionel Sambuc void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
1802f4a2713aSLionel Sambuc   VisitExpr(Node);
1803f4a2713aSLionel Sambuc   OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1804f4a2713aSLionel Sambuc      << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1805f4a2713aSLionel Sambuc }
1806f4a2713aSLionel Sambuc 
VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr * Node)1807f4a2713aSLionel Sambuc void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1808f4a2713aSLionel Sambuc     const UnaryExprOrTypeTraitExpr *Node) {
1809f4a2713aSLionel Sambuc   VisitExpr(Node);
1810f4a2713aSLionel Sambuc   switch(Node->getKind()) {
1811f4a2713aSLionel Sambuc   case UETT_SizeOf:
1812f4a2713aSLionel Sambuc     OS << " sizeof";
1813f4a2713aSLionel Sambuc     break;
1814f4a2713aSLionel Sambuc   case UETT_AlignOf:
1815f4a2713aSLionel Sambuc     OS << " alignof";
1816f4a2713aSLionel Sambuc     break;
1817f4a2713aSLionel Sambuc   case UETT_VecStep:
1818f4a2713aSLionel Sambuc     OS << " vec_step";
1819f4a2713aSLionel Sambuc     break;
1820f4a2713aSLionel Sambuc   }
1821f4a2713aSLionel Sambuc   if (Node->isArgumentType())
1822f4a2713aSLionel Sambuc     dumpType(Node->getArgumentType());
1823f4a2713aSLionel Sambuc }
1824f4a2713aSLionel Sambuc 
VisitMemberExpr(const MemberExpr * Node)1825f4a2713aSLionel Sambuc void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
1826f4a2713aSLionel Sambuc   VisitExpr(Node);
1827f4a2713aSLionel Sambuc   OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1828f4a2713aSLionel Sambuc   dumpPointer(Node->getMemberDecl());
1829f4a2713aSLionel Sambuc }
1830f4a2713aSLionel Sambuc 
VisitExtVectorElementExpr(const ExtVectorElementExpr * Node)1831f4a2713aSLionel Sambuc void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
1832f4a2713aSLionel Sambuc   VisitExpr(Node);
1833f4a2713aSLionel Sambuc   OS << " " << Node->getAccessor().getNameStart();
1834f4a2713aSLionel Sambuc }
1835f4a2713aSLionel Sambuc 
VisitBinaryOperator(const BinaryOperator * Node)1836f4a2713aSLionel Sambuc void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
1837f4a2713aSLionel Sambuc   VisitExpr(Node);
1838f4a2713aSLionel Sambuc   OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1839f4a2713aSLionel Sambuc }
1840f4a2713aSLionel Sambuc 
VisitCompoundAssignOperator(const CompoundAssignOperator * Node)1841f4a2713aSLionel Sambuc void ASTDumper::VisitCompoundAssignOperator(
1842f4a2713aSLionel Sambuc     const CompoundAssignOperator *Node) {
1843f4a2713aSLionel Sambuc   VisitExpr(Node);
1844f4a2713aSLionel Sambuc   OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1845f4a2713aSLionel Sambuc      << "' ComputeLHSTy=";
1846f4a2713aSLionel Sambuc   dumpBareType(Node->getComputationLHSType());
1847f4a2713aSLionel Sambuc   OS << " ComputeResultTy=";
1848f4a2713aSLionel Sambuc   dumpBareType(Node->getComputationResultType());
1849f4a2713aSLionel Sambuc }
1850f4a2713aSLionel Sambuc 
VisitBlockExpr(const BlockExpr * Node)1851f4a2713aSLionel Sambuc void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
1852f4a2713aSLionel Sambuc   VisitExpr(Node);
1853f4a2713aSLionel Sambuc   dumpDecl(Node->getBlockDecl());
1854f4a2713aSLionel Sambuc }
1855f4a2713aSLionel Sambuc 
VisitOpaqueValueExpr(const OpaqueValueExpr * Node)1856f4a2713aSLionel Sambuc void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
1857f4a2713aSLionel Sambuc   VisitExpr(Node);
1858f4a2713aSLionel Sambuc 
1859*0a6a1f1dSLionel Sambuc   if (Expr *Source = Node->getSourceExpr())
1860f4a2713aSLionel Sambuc     dumpStmt(Source);
1861f4a2713aSLionel Sambuc }
1862f4a2713aSLionel Sambuc 
1863f4a2713aSLionel Sambuc // GNU extensions.
1864f4a2713aSLionel Sambuc 
VisitAddrLabelExpr(const AddrLabelExpr * Node)1865f4a2713aSLionel Sambuc void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
1866f4a2713aSLionel Sambuc   VisitExpr(Node);
1867f4a2713aSLionel Sambuc   OS << " " << Node->getLabel()->getName();
1868f4a2713aSLionel Sambuc   dumpPointer(Node->getLabel());
1869f4a2713aSLionel Sambuc }
1870f4a2713aSLionel Sambuc 
1871f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1872f4a2713aSLionel Sambuc // C++ Expressions
1873f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1874f4a2713aSLionel Sambuc 
VisitCXXNamedCastExpr(const CXXNamedCastExpr * Node)1875f4a2713aSLionel Sambuc void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
1876f4a2713aSLionel Sambuc   VisitExpr(Node);
1877f4a2713aSLionel Sambuc   OS << " " << Node->getCastName()
1878f4a2713aSLionel Sambuc      << "<" << Node->getTypeAsWritten().getAsString() << ">"
1879f4a2713aSLionel Sambuc      << " <" << Node->getCastKindName();
1880f4a2713aSLionel Sambuc   dumpBasePath(OS, Node);
1881f4a2713aSLionel Sambuc   OS << ">";
1882f4a2713aSLionel Sambuc }
1883f4a2713aSLionel Sambuc 
VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr * Node)1884f4a2713aSLionel Sambuc void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
1885f4a2713aSLionel Sambuc   VisitExpr(Node);
1886f4a2713aSLionel Sambuc   OS << " " << (Node->getValue() ? "true" : "false");
1887f4a2713aSLionel Sambuc }
1888f4a2713aSLionel Sambuc 
VisitCXXThisExpr(const CXXThisExpr * Node)1889f4a2713aSLionel Sambuc void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
1890f4a2713aSLionel Sambuc   VisitExpr(Node);
1891f4a2713aSLionel Sambuc   OS << " this";
1892f4a2713aSLionel Sambuc }
1893f4a2713aSLionel Sambuc 
VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr * Node)1894f4a2713aSLionel Sambuc void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
1895f4a2713aSLionel Sambuc   VisitExpr(Node);
1896f4a2713aSLionel Sambuc   OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1897f4a2713aSLionel Sambuc      << " <" << Node->getCastKindName() << ">";
1898f4a2713aSLionel Sambuc }
1899f4a2713aSLionel Sambuc 
VisitCXXConstructExpr(const CXXConstructExpr * Node)1900f4a2713aSLionel Sambuc void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
1901f4a2713aSLionel Sambuc   VisitExpr(Node);
1902f4a2713aSLionel Sambuc   CXXConstructorDecl *Ctor = Node->getConstructor();
1903f4a2713aSLionel Sambuc   dumpType(Ctor->getType());
1904f4a2713aSLionel Sambuc   if (Node->isElidable())
1905f4a2713aSLionel Sambuc     OS << " elidable";
1906f4a2713aSLionel Sambuc   if (Node->requiresZeroInitialization())
1907f4a2713aSLionel Sambuc     OS << " zeroing";
1908f4a2713aSLionel Sambuc }
1909f4a2713aSLionel Sambuc 
VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr * Node)1910f4a2713aSLionel Sambuc void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
1911f4a2713aSLionel Sambuc   VisitExpr(Node);
1912f4a2713aSLionel Sambuc   OS << " ";
1913f4a2713aSLionel Sambuc   dumpCXXTemporary(Node->getTemporary());
1914f4a2713aSLionel Sambuc }
1915f4a2713aSLionel Sambuc 
1916f4a2713aSLionel Sambuc void
VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr * Node)1917f4a2713aSLionel Sambuc ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1918f4a2713aSLionel Sambuc   VisitExpr(Node);
1919f4a2713aSLionel Sambuc   if (const ValueDecl *VD = Node->getExtendingDecl()) {
1920f4a2713aSLionel Sambuc     OS << " extended by ";
1921f4a2713aSLionel Sambuc     dumpBareDeclRef(VD);
1922f4a2713aSLionel Sambuc   }
1923f4a2713aSLionel Sambuc }
1924f4a2713aSLionel Sambuc 
VisitExprWithCleanups(const ExprWithCleanups * Node)1925f4a2713aSLionel Sambuc void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
1926f4a2713aSLionel Sambuc   VisitExpr(Node);
1927f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1928f4a2713aSLionel Sambuc     dumpDeclRef(Node->getObject(i), "cleanup");
1929f4a2713aSLionel Sambuc }
1930f4a2713aSLionel Sambuc 
dumpCXXTemporary(const CXXTemporary * Temporary)1931f4a2713aSLionel Sambuc void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
1932f4a2713aSLionel Sambuc   OS << "(CXXTemporary";
1933f4a2713aSLionel Sambuc   dumpPointer(Temporary);
1934f4a2713aSLionel Sambuc   OS << ")";
1935f4a2713aSLionel Sambuc }
1936f4a2713aSLionel Sambuc 
1937f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1938f4a2713aSLionel Sambuc // Obj-C Expressions
1939f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1940f4a2713aSLionel Sambuc 
VisitObjCMessageExpr(const ObjCMessageExpr * Node)1941f4a2713aSLionel Sambuc void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
1942f4a2713aSLionel Sambuc   VisitExpr(Node);
1943*0a6a1f1dSLionel Sambuc   OS << " selector=";
1944*0a6a1f1dSLionel Sambuc   Node->getSelector().print(OS);
1945f4a2713aSLionel Sambuc   switch (Node->getReceiverKind()) {
1946f4a2713aSLionel Sambuc   case ObjCMessageExpr::Instance:
1947f4a2713aSLionel Sambuc     break;
1948f4a2713aSLionel Sambuc 
1949f4a2713aSLionel Sambuc   case ObjCMessageExpr::Class:
1950f4a2713aSLionel Sambuc     OS << " class=";
1951f4a2713aSLionel Sambuc     dumpBareType(Node->getClassReceiver());
1952f4a2713aSLionel Sambuc     break;
1953f4a2713aSLionel Sambuc 
1954f4a2713aSLionel Sambuc   case ObjCMessageExpr::SuperInstance:
1955f4a2713aSLionel Sambuc     OS << " super (instance)";
1956f4a2713aSLionel Sambuc     break;
1957f4a2713aSLionel Sambuc 
1958f4a2713aSLionel Sambuc   case ObjCMessageExpr::SuperClass:
1959f4a2713aSLionel Sambuc     OS << " super (class)";
1960f4a2713aSLionel Sambuc     break;
1961f4a2713aSLionel Sambuc   }
1962f4a2713aSLionel Sambuc }
1963f4a2713aSLionel Sambuc 
VisitObjCBoxedExpr(const ObjCBoxedExpr * Node)1964f4a2713aSLionel Sambuc void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
1965f4a2713aSLionel Sambuc   VisitExpr(Node);
1966*0a6a1f1dSLionel Sambuc   OS << " selector=";
1967*0a6a1f1dSLionel Sambuc   Node->getBoxingMethod()->getSelector().print(OS);
1968f4a2713aSLionel Sambuc }
1969f4a2713aSLionel Sambuc 
VisitObjCAtCatchStmt(const ObjCAtCatchStmt * Node)1970f4a2713aSLionel Sambuc void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
1971f4a2713aSLionel Sambuc   VisitStmt(Node);
1972f4a2713aSLionel Sambuc   if (const VarDecl *CatchParam = Node->getCatchParamDecl())
1973f4a2713aSLionel Sambuc     dumpDecl(CatchParam);
1974f4a2713aSLionel Sambuc   else
1975f4a2713aSLionel Sambuc     OS << " catch all";
1976f4a2713aSLionel Sambuc }
1977f4a2713aSLionel Sambuc 
VisitObjCEncodeExpr(const ObjCEncodeExpr * Node)1978f4a2713aSLionel Sambuc void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
1979f4a2713aSLionel Sambuc   VisitExpr(Node);
1980f4a2713aSLionel Sambuc   dumpType(Node->getEncodedType());
1981f4a2713aSLionel Sambuc }
1982f4a2713aSLionel Sambuc 
VisitObjCSelectorExpr(const ObjCSelectorExpr * Node)1983f4a2713aSLionel Sambuc void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
1984f4a2713aSLionel Sambuc   VisitExpr(Node);
1985f4a2713aSLionel Sambuc 
1986*0a6a1f1dSLionel Sambuc   OS << " ";
1987*0a6a1f1dSLionel Sambuc   Node->getSelector().print(OS);
1988f4a2713aSLionel Sambuc }
1989f4a2713aSLionel Sambuc 
VisitObjCProtocolExpr(const ObjCProtocolExpr * Node)1990f4a2713aSLionel Sambuc void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
1991f4a2713aSLionel Sambuc   VisitExpr(Node);
1992f4a2713aSLionel Sambuc 
1993f4a2713aSLionel Sambuc   OS << ' ' << *Node->getProtocol();
1994f4a2713aSLionel Sambuc }
1995f4a2713aSLionel Sambuc 
VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr * Node)1996f4a2713aSLionel Sambuc void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
1997f4a2713aSLionel Sambuc   VisitExpr(Node);
1998f4a2713aSLionel Sambuc   if (Node->isImplicitProperty()) {
1999f4a2713aSLionel Sambuc     OS << " Kind=MethodRef Getter=\"";
2000f4a2713aSLionel Sambuc     if (Node->getImplicitPropertyGetter())
2001*0a6a1f1dSLionel Sambuc       Node->getImplicitPropertyGetter()->getSelector().print(OS);
2002f4a2713aSLionel Sambuc     else
2003f4a2713aSLionel Sambuc       OS << "(null)";
2004f4a2713aSLionel Sambuc 
2005f4a2713aSLionel Sambuc     OS << "\" Setter=\"";
2006f4a2713aSLionel Sambuc     if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
2007*0a6a1f1dSLionel Sambuc       Setter->getSelector().print(OS);
2008f4a2713aSLionel Sambuc     else
2009f4a2713aSLionel Sambuc       OS << "(null)";
2010f4a2713aSLionel Sambuc     OS << "\"";
2011f4a2713aSLionel Sambuc   } else {
2012f4a2713aSLionel Sambuc     OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
2013f4a2713aSLionel Sambuc   }
2014f4a2713aSLionel Sambuc 
2015f4a2713aSLionel Sambuc   if (Node->isSuperReceiver())
2016f4a2713aSLionel Sambuc     OS << " super";
2017f4a2713aSLionel Sambuc 
2018f4a2713aSLionel Sambuc   OS << " Messaging=";
2019f4a2713aSLionel Sambuc   if (Node->isMessagingGetter() && Node->isMessagingSetter())
2020f4a2713aSLionel Sambuc     OS << "Getter&Setter";
2021f4a2713aSLionel Sambuc   else if (Node->isMessagingGetter())
2022f4a2713aSLionel Sambuc     OS << "Getter";
2023f4a2713aSLionel Sambuc   else if (Node->isMessagingSetter())
2024f4a2713aSLionel Sambuc     OS << "Setter";
2025f4a2713aSLionel Sambuc }
2026f4a2713aSLionel Sambuc 
VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr * Node)2027f4a2713aSLionel Sambuc void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
2028f4a2713aSLionel Sambuc   VisitExpr(Node);
2029f4a2713aSLionel Sambuc   if (Node->isArraySubscriptRefExpr())
2030f4a2713aSLionel Sambuc     OS << " Kind=ArraySubscript GetterForArray=\"";
2031f4a2713aSLionel Sambuc   else
2032f4a2713aSLionel Sambuc     OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2033f4a2713aSLionel Sambuc   if (Node->getAtIndexMethodDecl())
2034*0a6a1f1dSLionel Sambuc     Node->getAtIndexMethodDecl()->getSelector().print(OS);
2035f4a2713aSLionel Sambuc   else
2036f4a2713aSLionel Sambuc     OS << "(null)";
2037f4a2713aSLionel Sambuc 
2038f4a2713aSLionel Sambuc   if (Node->isArraySubscriptRefExpr())
2039f4a2713aSLionel Sambuc     OS << "\" SetterForArray=\"";
2040f4a2713aSLionel Sambuc   else
2041f4a2713aSLionel Sambuc     OS << "\" SetterForDictionary=\"";
2042f4a2713aSLionel Sambuc   if (Node->setAtIndexMethodDecl())
2043*0a6a1f1dSLionel Sambuc     Node->setAtIndexMethodDecl()->getSelector().print(OS);
2044f4a2713aSLionel Sambuc   else
2045f4a2713aSLionel Sambuc     OS << "(null)";
2046f4a2713aSLionel Sambuc }
2047f4a2713aSLionel Sambuc 
VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr * Node)2048f4a2713aSLionel Sambuc void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
2049f4a2713aSLionel Sambuc   VisitExpr(Node);
2050f4a2713aSLionel Sambuc   OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2051f4a2713aSLionel Sambuc }
2052f4a2713aSLionel Sambuc 
2053f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2054f4a2713aSLionel Sambuc // Comments
2055f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2056f4a2713aSLionel Sambuc 
getCommandName(unsigned CommandID)2057f4a2713aSLionel Sambuc const char *ASTDumper::getCommandName(unsigned CommandID) {
2058f4a2713aSLionel Sambuc   if (Traits)
2059f4a2713aSLionel Sambuc     return Traits->getCommandInfo(CommandID)->Name;
2060f4a2713aSLionel Sambuc   const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2061f4a2713aSLionel Sambuc   if (Info)
2062f4a2713aSLionel Sambuc     return Info->Name;
2063f4a2713aSLionel Sambuc   return "<not a builtin command>";
2064f4a2713aSLionel Sambuc }
2065f4a2713aSLionel Sambuc 
dumpFullComment(const FullComment * C)2066f4a2713aSLionel Sambuc void ASTDumper::dumpFullComment(const FullComment *C) {
2067f4a2713aSLionel Sambuc   if (!C)
2068f4a2713aSLionel Sambuc     return;
2069f4a2713aSLionel Sambuc 
2070f4a2713aSLionel Sambuc   FC = C;
2071f4a2713aSLionel Sambuc   dumpComment(C);
2072*0a6a1f1dSLionel Sambuc   FC = nullptr;
2073f4a2713aSLionel Sambuc }
2074f4a2713aSLionel Sambuc 
dumpComment(const Comment * C)2075f4a2713aSLionel Sambuc void ASTDumper::dumpComment(const Comment *C) {
2076*0a6a1f1dSLionel Sambuc   dumpChild([=] {
2077f4a2713aSLionel Sambuc     if (!C) {
2078f4a2713aSLionel Sambuc       ColorScope Color(*this, NullColor);
2079f4a2713aSLionel Sambuc       OS << "<<<NULL>>>";
2080f4a2713aSLionel Sambuc       return;
2081f4a2713aSLionel Sambuc     }
2082f4a2713aSLionel Sambuc 
2083f4a2713aSLionel Sambuc     {
2084f4a2713aSLionel Sambuc       ColorScope Color(*this, CommentColor);
2085f4a2713aSLionel Sambuc       OS << C->getCommentKindName();
2086f4a2713aSLionel Sambuc     }
2087f4a2713aSLionel Sambuc     dumpPointer(C);
2088f4a2713aSLionel Sambuc     dumpSourceRange(C->getSourceRange());
2089f4a2713aSLionel Sambuc     ConstCommentVisitor<ASTDumper>::visit(C);
2090f4a2713aSLionel Sambuc     for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2091*0a6a1f1dSLionel Sambuc          I != E; ++I)
2092f4a2713aSLionel Sambuc       dumpComment(*I);
2093*0a6a1f1dSLionel Sambuc   });
2094f4a2713aSLionel Sambuc }
2095f4a2713aSLionel Sambuc 
visitTextComment(const TextComment * C)2096f4a2713aSLionel Sambuc void ASTDumper::visitTextComment(const TextComment *C) {
2097f4a2713aSLionel Sambuc   OS << " Text=\"" << C->getText() << "\"";
2098f4a2713aSLionel Sambuc }
2099f4a2713aSLionel Sambuc 
visitInlineCommandComment(const InlineCommandComment * C)2100f4a2713aSLionel Sambuc void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2101f4a2713aSLionel Sambuc   OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2102f4a2713aSLionel Sambuc   switch (C->getRenderKind()) {
2103f4a2713aSLionel Sambuc   case InlineCommandComment::RenderNormal:
2104f4a2713aSLionel Sambuc     OS << " RenderNormal";
2105f4a2713aSLionel Sambuc     break;
2106f4a2713aSLionel Sambuc   case InlineCommandComment::RenderBold:
2107f4a2713aSLionel Sambuc     OS << " RenderBold";
2108f4a2713aSLionel Sambuc     break;
2109f4a2713aSLionel Sambuc   case InlineCommandComment::RenderMonospaced:
2110f4a2713aSLionel Sambuc     OS << " RenderMonospaced";
2111f4a2713aSLionel Sambuc     break;
2112f4a2713aSLionel Sambuc   case InlineCommandComment::RenderEmphasized:
2113f4a2713aSLionel Sambuc     OS << " RenderEmphasized";
2114f4a2713aSLionel Sambuc     break;
2115f4a2713aSLionel Sambuc   }
2116f4a2713aSLionel Sambuc 
2117f4a2713aSLionel Sambuc   for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2118f4a2713aSLionel Sambuc     OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2119f4a2713aSLionel Sambuc }
2120f4a2713aSLionel Sambuc 
visitHTMLStartTagComment(const HTMLStartTagComment * C)2121f4a2713aSLionel Sambuc void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2122f4a2713aSLionel Sambuc   OS << " Name=\"" << C->getTagName() << "\"";
2123f4a2713aSLionel Sambuc   if (C->getNumAttrs() != 0) {
2124f4a2713aSLionel Sambuc     OS << " Attrs: ";
2125f4a2713aSLionel Sambuc     for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2126f4a2713aSLionel Sambuc       const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2127f4a2713aSLionel Sambuc       OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2128f4a2713aSLionel Sambuc     }
2129f4a2713aSLionel Sambuc   }
2130f4a2713aSLionel Sambuc   if (C->isSelfClosing())
2131f4a2713aSLionel Sambuc     OS << " SelfClosing";
2132f4a2713aSLionel Sambuc }
2133f4a2713aSLionel Sambuc 
visitHTMLEndTagComment(const HTMLEndTagComment * C)2134f4a2713aSLionel Sambuc void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2135f4a2713aSLionel Sambuc   OS << " Name=\"" << C->getTagName() << "\"";
2136f4a2713aSLionel Sambuc }
2137f4a2713aSLionel Sambuc 
visitBlockCommandComment(const BlockCommandComment * C)2138f4a2713aSLionel Sambuc void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2139f4a2713aSLionel Sambuc   OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2140f4a2713aSLionel Sambuc   for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2141f4a2713aSLionel Sambuc     OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2142f4a2713aSLionel Sambuc }
2143f4a2713aSLionel Sambuc 
visitParamCommandComment(const ParamCommandComment * C)2144f4a2713aSLionel Sambuc void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2145f4a2713aSLionel Sambuc   OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2146f4a2713aSLionel Sambuc 
2147f4a2713aSLionel Sambuc   if (C->isDirectionExplicit())
2148f4a2713aSLionel Sambuc     OS << " explicitly";
2149f4a2713aSLionel Sambuc   else
2150f4a2713aSLionel Sambuc     OS << " implicitly";
2151f4a2713aSLionel Sambuc 
2152f4a2713aSLionel Sambuc   if (C->hasParamName()) {
2153f4a2713aSLionel Sambuc     if (C->isParamIndexValid())
2154f4a2713aSLionel Sambuc       OS << " Param=\"" << C->getParamName(FC) << "\"";
2155f4a2713aSLionel Sambuc     else
2156f4a2713aSLionel Sambuc       OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2157f4a2713aSLionel Sambuc   }
2158f4a2713aSLionel Sambuc 
2159*0a6a1f1dSLionel Sambuc   if (C->isParamIndexValid() && !C->isVarArgParam())
2160f4a2713aSLionel Sambuc     OS << " ParamIndex=" << C->getParamIndex();
2161f4a2713aSLionel Sambuc }
2162f4a2713aSLionel Sambuc 
visitTParamCommandComment(const TParamCommandComment * C)2163f4a2713aSLionel Sambuc void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2164f4a2713aSLionel Sambuc   if (C->hasParamName()) {
2165f4a2713aSLionel Sambuc     if (C->isPositionValid())
2166f4a2713aSLionel Sambuc       OS << " Param=\"" << C->getParamName(FC) << "\"";
2167f4a2713aSLionel Sambuc     else
2168f4a2713aSLionel Sambuc       OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2169f4a2713aSLionel Sambuc   }
2170f4a2713aSLionel Sambuc 
2171f4a2713aSLionel Sambuc   if (C->isPositionValid()) {
2172f4a2713aSLionel Sambuc     OS << " Position=<";
2173f4a2713aSLionel Sambuc     for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2174f4a2713aSLionel Sambuc       OS << C->getIndex(i);
2175f4a2713aSLionel Sambuc       if (i != e - 1)
2176f4a2713aSLionel Sambuc         OS << ", ";
2177f4a2713aSLionel Sambuc     }
2178f4a2713aSLionel Sambuc     OS << ">";
2179f4a2713aSLionel Sambuc   }
2180f4a2713aSLionel Sambuc }
2181f4a2713aSLionel Sambuc 
visitVerbatimBlockComment(const VerbatimBlockComment * C)2182f4a2713aSLionel Sambuc void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2183f4a2713aSLionel Sambuc   OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2184f4a2713aSLionel Sambuc         " CloseName=\"" << C->getCloseName() << "\"";
2185f4a2713aSLionel Sambuc }
2186f4a2713aSLionel Sambuc 
visitVerbatimBlockLineComment(const VerbatimBlockLineComment * C)2187f4a2713aSLionel Sambuc void ASTDumper::visitVerbatimBlockLineComment(
2188f4a2713aSLionel Sambuc     const VerbatimBlockLineComment *C) {
2189f4a2713aSLionel Sambuc   OS << " Text=\"" << C->getText() << "\"";
2190f4a2713aSLionel Sambuc }
2191f4a2713aSLionel Sambuc 
visitVerbatimLineComment(const VerbatimLineComment * C)2192f4a2713aSLionel Sambuc void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2193f4a2713aSLionel Sambuc   OS << " Text=\"" << C->getText() << "\"";
2194f4a2713aSLionel Sambuc }
2195f4a2713aSLionel Sambuc 
2196f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2197*0a6a1f1dSLionel Sambuc // Type method implementations
2198*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
2199*0a6a1f1dSLionel Sambuc 
dump(const char * msg) const2200*0a6a1f1dSLionel Sambuc void QualType::dump(const char *msg) const {
2201*0a6a1f1dSLionel Sambuc   if (msg)
2202*0a6a1f1dSLionel Sambuc     llvm::errs() << msg << ": ";
2203*0a6a1f1dSLionel Sambuc   dump();
2204*0a6a1f1dSLionel Sambuc }
2205*0a6a1f1dSLionel Sambuc 
dump() const2206*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void QualType::dump() const {
2207*0a6a1f1dSLionel Sambuc   ASTDumper Dumper(llvm::errs(), nullptr, nullptr);
2208*0a6a1f1dSLionel Sambuc   Dumper.dumpTypeAsChild(*this);
2209*0a6a1f1dSLionel Sambuc }
2210*0a6a1f1dSLionel Sambuc 
dump() const2211*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
2212*0a6a1f1dSLionel Sambuc 
2213*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
2214f4a2713aSLionel Sambuc // Decl method implementations
2215f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2216f4a2713aSLionel Sambuc 
dump() const2217*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
2218f4a2713aSLionel Sambuc 
dump(raw_ostream & OS) const2219*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
2220f4a2713aSLionel Sambuc   ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2221f4a2713aSLionel Sambuc               &getASTContext().getSourceManager());
2222f4a2713aSLionel Sambuc   P.dumpDecl(this);
2223f4a2713aSLionel Sambuc }
2224f4a2713aSLionel Sambuc 
dumpColor() const2225*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Decl::dumpColor() const {
2226f4a2713aSLionel Sambuc   ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2227f4a2713aSLionel Sambuc               &getASTContext().getSourceManager(), /*ShowColors*/true);
2228f4a2713aSLionel Sambuc   P.dumpDecl(this);
2229f4a2713aSLionel Sambuc }
2230f4a2713aSLionel Sambuc 
dumpLookups() const2231*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
2232f4a2713aSLionel Sambuc   dumpLookups(llvm::errs());
2233f4a2713aSLionel Sambuc }
2234f4a2713aSLionel Sambuc 
dumpLookups(raw_ostream & OS,bool DumpDecls) const2235*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2236*0a6a1f1dSLionel Sambuc                                                bool DumpDecls) const {
2237f4a2713aSLionel Sambuc   const DeclContext *DC = this;
2238f4a2713aSLionel Sambuc   while (!DC->isTranslationUnit())
2239f4a2713aSLionel Sambuc     DC = DC->getParent();
2240f4a2713aSLionel Sambuc   ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
2241f4a2713aSLionel Sambuc   ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
2242*0a6a1f1dSLionel Sambuc   P.dumpLookups(this, DumpDecls);
2243f4a2713aSLionel Sambuc }
2244f4a2713aSLionel Sambuc 
2245f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2246f4a2713aSLionel Sambuc // Stmt method implementations
2247f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2248f4a2713aSLionel Sambuc 
dump(SourceManager & SM) const2249*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
2250f4a2713aSLionel Sambuc   dump(llvm::errs(), SM);
2251f4a2713aSLionel Sambuc }
2252f4a2713aSLionel Sambuc 
dump(raw_ostream & OS,SourceManager & SM) const2253*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
2254*0a6a1f1dSLionel Sambuc   ASTDumper P(OS, nullptr, &SM);
2255f4a2713aSLionel Sambuc   P.dumpStmt(this);
2256f4a2713aSLionel Sambuc }
2257f4a2713aSLionel Sambuc 
dump() const2258*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Stmt::dump() const {
2259*0a6a1f1dSLionel Sambuc   ASTDumper P(llvm::errs(), nullptr, nullptr);
2260f4a2713aSLionel Sambuc   P.dumpStmt(this);
2261f4a2713aSLionel Sambuc }
2262f4a2713aSLionel Sambuc 
dumpColor() const2263*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Stmt::dumpColor() const {
2264*0a6a1f1dSLionel Sambuc   ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2265f4a2713aSLionel Sambuc   P.dumpStmt(this);
2266f4a2713aSLionel Sambuc }
2267f4a2713aSLionel Sambuc 
2268f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2269f4a2713aSLionel Sambuc // Comment method implementations
2270f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2271f4a2713aSLionel Sambuc 
dump() const2272*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Comment::dump() const {
2273*0a6a1f1dSLionel Sambuc   dump(llvm::errs(), nullptr, nullptr);
2274f4a2713aSLionel Sambuc }
2275f4a2713aSLionel Sambuc 
dump(const ASTContext & Context) const2276*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
2277f4a2713aSLionel Sambuc   dump(llvm::errs(), &Context.getCommentCommandTraits(),
2278f4a2713aSLionel Sambuc        &Context.getSourceManager());
2279f4a2713aSLionel Sambuc }
2280f4a2713aSLionel Sambuc 
dump(raw_ostream & OS,const CommandTraits * Traits,const SourceManager * SM) const2281f4a2713aSLionel Sambuc void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
2282f4a2713aSLionel Sambuc                    const SourceManager *SM) const {
2283f4a2713aSLionel Sambuc   const FullComment *FC = dyn_cast<FullComment>(this);
2284f4a2713aSLionel Sambuc   ASTDumper D(OS, Traits, SM);
2285f4a2713aSLionel Sambuc   D.dumpFullComment(FC);
2286f4a2713aSLionel Sambuc }
2287f4a2713aSLionel Sambuc 
dumpColor() const2288*0a6a1f1dSLionel Sambuc LLVM_DUMP_METHOD void Comment::dumpColor() const {
2289f4a2713aSLionel Sambuc   const FullComment *FC = dyn_cast<FullComment>(this);
2290*0a6a1f1dSLionel Sambuc   ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2291f4a2713aSLionel Sambuc   D.dumpFullComment(FC);
2292f4a2713aSLionel Sambuc }
2293