Alexander Kornienko | 40b66a00 | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 1 | //===--- ASTDumper.cpp - Dumping implementation for ASTs ------------------===// |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Alexander Kornienko | 40b66a00 | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 10 | // This file implements the AST dump methods, which dump out the |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 11 | // AST in a form that exposes type details and other fields. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Alexander Kornienko | c3cd2b0 | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 16 | #include "clang/AST/Attr.h" |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 17 | #include "clang/AST/CommentVisitor.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclCXX.h" |
Richard Smith | 6e322c0 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclLookups.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclObjC.h" |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclVisitor.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtVisitor.h" |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 23 | #include "clang/Basic/Module.h" |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 24 | #include "clang/Basic/SourceManager.h" |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 26 | using namespace clang; |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 27 | using namespace clang::comments; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 28 | |
| 29 | //===----------------------------------------------------------------------===// |
Alexander Kornienko | 40b66a00 | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 30 | // ASTDumper Visitor |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 31 | //===----------------------------------------------------------------------===// |
| 32 | |
| 33 | namespace { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 34 | // Colors used for various parts of the AST dump |
| 35 | |
| 36 | struct TerminalColor { |
| 37 | raw_ostream::Colors Color; |
| 38 | bool Bold; |
| 39 | }; |
| 40 | |
| 41 | // Decl kind names (VarDecl, FunctionDecl, etc) |
| 42 | static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true }; |
| 43 | // Attr names (CleanupAttr, GuardedByAttr, etc) |
| 44 | static const TerminalColor AttrColor = { raw_ostream::BLUE, true }; |
| 45 | // Statement names (DeclStmt, ImplicitCastExpr, etc) |
| 46 | static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true }; |
| 47 | // Comment names (FullComment, ParagraphComment, TextComment, etc) |
| 48 | static const TerminalColor CommentColor = { raw_ostream::YELLOW, true }; |
| 49 | |
| 50 | // Type names (int, float, etc, plus user defined types) |
| 51 | static const TerminalColor TypeColor = { raw_ostream::GREEN, false }; |
| 52 | |
| 53 | // Pointer address |
| 54 | static const TerminalColor AddressColor = { raw_ostream::YELLOW, false }; |
| 55 | // Source locations |
| 56 | static const TerminalColor LocationColor = { raw_ostream::YELLOW, false }; |
| 57 | |
| 58 | // lvalue/xvalue |
| 59 | static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false }; |
| 60 | // bitfield/objcproperty/objcsubscript/vectorcomponent |
| 61 | static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false }; |
| 62 | |
| 63 | // Null statements |
| 64 | static const TerminalColor NullColor = { raw_ostream::BLUE, false }; |
| 65 | |
Richard Smith | e565bfa | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 66 | // Undeserialized entities |
| 67 | static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true }; |
| 68 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 69 | // CastKind from CastExpr's |
| 70 | static const TerminalColor CastColor = { raw_ostream::RED, false }; |
| 71 | |
| 72 | // Value of the statement |
| 73 | static const TerminalColor ValueColor = { raw_ostream::CYAN, true }; |
| 74 | // Decl names |
| 75 | static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true }; |
| 76 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 77 | // Indents ( `, -. | ) |
| 78 | static const TerminalColor IndentColor = { raw_ostream::BLUE, false }; |
| 79 | |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 80 | class ASTDumper |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 81 | : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>, |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 82 | public ConstCommentVisitor<ASTDumper> { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 83 | raw_ostream &OS; |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 84 | const CommandTraits *Traits; |
| 85 | const SourceManager *SM; |
Manuel Klimek | cb7b45e | 2012-11-07 00:33:12 +0000 | [diff] [blame] | 86 | bool IsFirstLine; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 87 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 88 | // Indicates whether more child are expected at the current tree depth |
| 89 | enum IndentType { IT_Child, IT_LastChild }; |
| 90 | |
| 91 | /// Indents[i] indicates if another child exists at level i. |
| 92 | /// Used by Indent() to print the tree structure. |
| 93 | llvm::SmallVector<IndentType, 32> Indents; |
| 94 | |
| 95 | /// Indicates that more children will be needed at this indent level. |
| 96 | /// If true, prevents lastChild() from marking the node as the last child. |
| 97 | /// This is used when there are multiple collections of children to be |
| 98 | /// dumped as well as during conditional node dumping. |
| 99 | bool MoreChildren; |
| 100 | |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 101 | /// Keep track of the last location we print out so that we can |
| 102 | /// print out deltas from then on out. |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 103 | const char *LastLocFilename; |
| 104 | unsigned LastLocLine; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 105 | |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 106 | /// The \c FullComment parent of the comment being dumped. |
| 107 | const FullComment *FC; |
| 108 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 109 | bool ShowColors; |
| 110 | |
Manuel Klimek | cb7b45e | 2012-11-07 00:33:12 +0000 | [diff] [blame] | 111 | class IndentScope { |
Alexander Kornienko | 40b66a00 | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 112 | ASTDumper &Dumper; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 113 | // Preserve the Dumper's MoreChildren value from the previous IndentScope |
| 114 | bool MoreChildren; |
Manuel Klimek | cb7b45e | 2012-11-07 00:33:12 +0000 | [diff] [blame] | 115 | public: |
Alexander Kornienko | 40b66a00 | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 116 | IndentScope(ASTDumper &Dumper) : Dumper(Dumper) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 117 | MoreChildren = Dumper.hasMoreChildren(); |
| 118 | Dumper.setMoreChildren(false); |
Manuel Klimek | cb7b45e | 2012-11-07 00:33:12 +0000 | [diff] [blame] | 119 | Dumper.indent(); |
| 120 | } |
| 121 | ~IndentScope() { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 122 | Dumper.setMoreChildren(MoreChildren); |
Manuel Klimek | cb7b45e | 2012-11-07 00:33:12 +0000 | [diff] [blame] | 123 | Dumper.unindent(); |
| 124 | } |
| 125 | }; |
| 126 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 127 | class ColorScope { |
| 128 | ASTDumper &Dumper; |
| 129 | public: |
| 130 | ColorScope(ASTDumper &Dumper, TerminalColor Color) |
| 131 | : Dumper(Dumper) { |
| 132 | if (Dumper.ShowColors) |
| 133 | Dumper.OS.changeColor(Color.Color, Color.Bold); |
| 134 | } |
| 135 | ~ColorScope() { |
| 136 | if (Dumper.ShowColors) |
| 137 | Dumper.OS.resetColor(); |
| 138 | } |
| 139 | }; |
| 140 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 141 | public: |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 142 | ASTDumper(raw_ostream &OS, const CommandTraits *Traits, |
| 143 | const SourceManager *SM) |
Richard Smith | 95f97bf | 2013-01-31 02:04:38 +0000 | [diff] [blame] | 144 | : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false), |
| 145 | LastLocFilename(""), LastLocLine(~0U), FC(0), |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 146 | ShowColors(SM && SM->getDiagnostics().getShowColors()) { } |
| 147 | |
| 148 | ASTDumper(raw_ostream &OS, const CommandTraits *Traits, |
| 149 | const SourceManager *SM, bool ShowColors) |
Richard Smith | 95f97bf | 2013-01-31 02:04:38 +0000 | [diff] [blame] | 150 | : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false), |
| 151 | LastLocFilename(""), LastLocLine(~0U), |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 152 | ShowColors(ShowColors) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | |
Alexander Kornienko | 40b66a00 | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 154 | ~ASTDumper() { |
Manuel Klimek | cb7b45e | 2012-11-07 00:33:12 +0000 | [diff] [blame] | 155 | OS << "\n"; |
| 156 | } |
| 157 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 158 | void dumpDecl(const Decl *D); |
| 159 | void dumpStmt(const Stmt *S); |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 160 | void dumpFullComment(const FullComment *C); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 161 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 162 | // Formatting |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 163 | void indent(); |
| 164 | void unindent(); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 165 | void lastChild(); |
| 166 | bool hasMoreChildren(); |
| 167 | void setMoreChildren(bool Value); |
| 168 | |
| 169 | // Utilities |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 170 | void dumpPointer(const void *Ptr); |
| 171 | void dumpSourceRange(SourceRange R); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 172 | void dumpLocation(SourceLocation Loc); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 173 | void dumpBareType(QualType T); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 174 | void dumpType(QualType T); |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 175 | void dumpBareDeclRef(const Decl *Node); |
Alexander Kornienko | c939453 | 2012-12-20 12:23:54 +0000 | [diff] [blame] | 176 | void dumpDeclRef(const Decl *Node, const char *Label = 0); |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 177 | void dumpName(const NamedDecl *D); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 178 | bool hasNodes(const DeclContext *DC); |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 179 | void dumpDeclContext(const DeclContext *DC); |
Richard Smith | 6e322c0 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 180 | void dumpLookups(const DeclContext *DC); |
Alexander Kornienko | c3cd2b0 | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 181 | void dumpAttr(const Attr *A); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 182 | |
| 183 | // C++ Utilities |
| 184 | void dumpAccessSpecifier(AccessSpecifier AS); |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 185 | void dumpCXXCtorInitializer(const CXXCtorInitializer *Init); |
| 186 | void dumpTemplateParameters(const TemplateParameterList *TPL); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 187 | void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI); |
| 188 | void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A); |
| 189 | void dumpTemplateArgumentList(const TemplateArgumentList &TAL); |
| 190 | void dumpTemplateArgument(const TemplateArgument &A, |
| 191 | SourceRange R = SourceRange()); |
| 192 | |
| 193 | // Decls |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 194 | void VisitLabelDecl(const LabelDecl *D); |
| 195 | void VisitTypedefDecl(const TypedefDecl *D); |
| 196 | void VisitEnumDecl(const EnumDecl *D); |
| 197 | void VisitRecordDecl(const RecordDecl *D); |
| 198 | void VisitEnumConstantDecl(const EnumConstantDecl *D); |
| 199 | void VisitIndirectFieldDecl(const IndirectFieldDecl *D); |
| 200 | void VisitFunctionDecl(const FunctionDecl *D); |
| 201 | void VisitFieldDecl(const FieldDecl *D); |
| 202 | void VisitVarDecl(const VarDecl *D); |
| 203 | void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D); |
| 204 | void VisitImportDecl(const ImportDecl *D); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 205 | |
| 206 | // C++ Decls |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 207 | void VisitNamespaceDecl(const NamespaceDecl *D); |
| 208 | void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D); |
| 209 | void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D); |
| 210 | void VisitTypeAliasDecl(const TypeAliasDecl *D); |
| 211 | void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D); |
| 212 | void VisitCXXRecordDecl(const CXXRecordDecl *D); |
| 213 | void VisitStaticAssertDecl(const StaticAssertDecl *D); |
| 214 | void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D); |
| 215 | void VisitClassTemplateDecl(const ClassTemplateDecl *D); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 216 | void VisitClassTemplateSpecializationDecl( |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 217 | const ClassTemplateSpecializationDecl *D); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 218 | void VisitClassTemplatePartialSpecializationDecl( |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 219 | const ClassTemplatePartialSpecializationDecl *D); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 220 | void VisitClassScopeFunctionSpecializationDecl( |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 221 | const ClassScopeFunctionSpecializationDecl *D); |
| 222 | void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D); |
| 223 | void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D); |
| 224 | void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D); |
| 225 | void VisitUsingDecl(const UsingDecl *D); |
| 226 | void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D); |
| 227 | void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D); |
| 228 | void VisitUsingShadowDecl(const UsingShadowDecl *D); |
| 229 | void VisitLinkageSpecDecl(const LinkageSpecDecl *D); |
| 230 | void VisitAccessSpecDecl(const AccessSpecDecl *D); |
| 231 | void VisitFriendDecl(const FriendDecl *D); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 232 | |
| 233 | // ObjC Decls |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 234 | void VisitObjCIvarDecl(const ObjCIvarDecl *D); |
| 235 | void VisitObjCMethodDecl(const ObjCMethodDecl *D); |
| 236 | void VisitObjCCategoryDecl(const ObjCCategoryDecl *D); |
| 237 | void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D); |
| 238 | void VisitObjCProtocolDecl(const ObjCProtocolDecl *D); |
| 239 | void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D); |
| 240 | void VisitObjCImplementationDecl(const ObjCImplementationDecl *D); |
| 241 | void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D); |
| 242 | void VisitObjCPropertyDecl(const ObjCPropertyDecl *D); |
| 243 | void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D); |
| 244 | void VisitBlockDecl(const BlockDecl *D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 245 | |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 246 | // Stmts. |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 247 | void VisitStmt(const Stmt *Node); |
| 248 | void VisitDeclStmt(const DeclStmt *Node); |
| 249 | void VisitAttributedStmt(const AttributedStmt *Node); |
| 250 | void VisitLabelStmt(const LabelStmt *Node); |
| 251 | void VisitGotoStmt(const GotoStmt *Node); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 252 | |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 253 | // Exprs |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 254 | void VisitExpr(const Expr *Node); |
| 255 | void VisitCastExpr(const CastExpr *Node); |
| 256 | void VisitDeclRefExpr(const DeclRefExpr *Node); |
| 257 | void VisitPredefinedExpr(const PredefinedExpr *Node); |
| 258 | void VisitCharacterLiteral(const CharacterLiteral *Node); |
| 259 | void VisitIntegerLiteral(const IntegerLiteral *Node); |
| 260 | void VisitFloatingLiteral(const FloatingLiteral *Node); |
| 261 | void VisitStringLiteral(const StringLiteral *Str); |
| 262 | void VisitUnaryOperator(const UnaryOperator *Node); |
| 263 | void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node); |
| 264 | void VisitMemberExpr(const MemberExpr *Node); |
| 265 | void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node); |
| 266 | void VisitBinaryOperator(const BinaryOperator *Node); |
| 267 | void VisitCompoundAssignOperator(const CompoundAssignOperator *Node); |
| 268 | void VisitAddrLabelExpr(const AddrLabelExpr *Node); |
| 269 | void VisitBlockExpr(const BlockExpr *Node); |
| 270 | void VisitOpaqueValueExpr(const OpaqueValueExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 271 | |
| 272 | // C++ |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 273 | void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node); |
| 274 | void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node); |
| 275 | void VisitCXXThisExpr(const CXXThisExpr *Node); |
| 276 | void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node); |
| 277 | void VisitCXXConstructExpr(const CXXConstructExpr *Node); |
| 278 | void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node); |
Richard Smith | 211c8dd | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 279 | void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 280 | void VisitExprWithCleanups(const ExprWithCleanups *Node); |
| 281 | void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node); |
| 282 | void dumpCXXTemporary(const CXXTemporary *Temporary); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 283 | |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 284 | // ObjC |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 285 | void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node); |
| 286 | void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node); |
| 287 | void VisitObjCMessageExpr(const ObjCMessageExpr *Node); |
| 288 | void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node); |
| 289 | void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node); |
| 290 | void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node); |
| 291 | void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node); |
| 292 | void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node); |
| 293 | void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node); |
| 294 | void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node); |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 295 | |
| 296 | // Comments. |
| 297 | const char *getCommandName(unsigned CommandID); |
| 298 | void dumpComment(const Comment *C); |
| 299 | |
| 300 | // Inline comments. |
| 301 | void visitTextComment(const TextComment *C); |
| 302 | void visitInlineCommandComment(const InlineCommandComment *C); |
| 303 | void visitHTMLStartTagComment(const HTMLStartTagComment *C); |
| 304 | void visitHTMLEndTagComment(const HTMLEndTagComment *C); |
| 305 | |
| 306 | // Block comments. |
| 307 | void visitBlockCommandComment(const BlockCommandComment *C); |
| 308 | void visitParamCommandComment(const ParamCommandComment *C); |
| 309 | void visitTParamCommandComment(const TParamCommandComment *C); |
| 310 | void visitVerbatimBlockComment(const VerbatimBlockComment *C); |
| 311 | void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C); |
| 312 | void visitVerbatimLineComment(const VerbatimLineComment *C); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 313 | }; |
| 314 | } |
| 315 | |
| 316 | //===----------------------------------------------------------------------===// |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 317 | // Utilities |
| 318 | //===----------------------------------------------------------------------===// |
| 319 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 320 | // Print out the appropriate tree structure using the Indents vector. |
| 321 | // Example of tree and the Indents vector at each level. |
| 322 | // A { } |
| 323 | // |-B { IT_Child } |
| 324 | // | `-C { IT_Child, IT_LastChild } |
| 325 | // `-D { IT_LastChild } |
| 326 | // |-E { IT_LastChild, IT_Child } |
| 327 | // `-F { IT_LastChild, IT_LastChild } |
| 328 | // Type non-last element, last element |
| 329 | // IT_Child "| " "|-" |
| 330 | // IT_LastChild " " "`-" |
Alexander Kornienko | 40b66a00 | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 331 | void ASTDumper::indent() { |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 332 | if (IsFirstLine) |
| 333 | IsFirstLine = false; |
| 334 | else |
| 335 | OS << "\n"; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 336 | |
| 337 | ColorScope Color(*this, IndentColor); |
Craig Topper | 09d19ef | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 338 | for (SmallVectorImpl<IndentType>::const_iterator I = Indents.begin(), |
| 339 | E = Indents.end(); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 340 | I != E; ++I) { |
| 341 | switch (*I) { |
Richard Smith | 95f97bf | 2013-01-31 02:04:38 +0000 | [diff] [blame] | 342 | case IT_Child: |
| 343 | if (I == E - 1) |
| 344 | OS << "|-"; |
| 345 | else |
| 346 | OS << "| "; |
| 347 | continue; |
| 348 | case IT_LastChild: |
| 349 | if (I == E - 1) |
| 350 | OS << "`-"; |
| 351 | else |
| 352 | OS << " "; |
| 353 | continue; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 354 | } |
Richard Smith | 95f97bf | 2013-01-31 02:04:38 +0000 | [diff] [blame] | 355 | llvm_unreachable("Invalid IndentType"); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 356 | } |
| 357 | Indents.push_back(IT_Child); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Alexander Kornienko | 40b66a00 | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 360 | void ASTDumper::unindent() { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 361 | Indents.pop_back(); |
| 362 | } |
| 363 | |
| 364 | // Call before each potential last child node is to be dumped. If MoreChildren |
| 365 | // is false, then this is the last child, otherwise treat as a regular node. |
| 366 | void ASTDumper::lastChild() { |
| 367 | if (!hasMoreChildren()) |
| 368 | Indents.back() = IT_LastChild; |
| 369 | } |
| 370 | |
| 371 | // MoreChildren should be set before calling another function that may print |
| 372 | // additional nodes to prevent conflicting final child nodes. |
| 373 | bool ASTDumper::hasMoreChildren() { |
| 374 | return MoreChildren; |
| 375 | } |
| 376 | |
| 377 | void ASTDumper::setMoreChildren(bool Value) { |
| 378 | MoreChildren = Value; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 381 | void ASTDumper::dumpPointer(const void *Ptr) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 382 | ColorScope Color(*this, AddressColor); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 383 | OS << ' ' << Ptr; |
| 384 | } |
| 385 | |
Alexander Kornienko | 40b66a00 | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 386 | void ASTDumper::dumpLocation(SourceLocation Loc) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 387 | ColorScope Color(*this, LocationColor); |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 388 | SourceLocation SpellingLoc = SM->getSpellingLoc(Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 390 | // The general format we print out is filename:line:col, but we drop pieces |
| 391 | // that haven't changed since the last loc printed. |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 392 | PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc); |
| 393 | |
Douglas Gregor | cb7b1e1 | 2010-11-12 07:15:47 +0000 | [diff] [blame] | 394 | if (PLoc.isInvalid()) { |
| 395 | OS << "<invalid sloc>"; |
| 396 | return; |
| 397 | } |
| 398 | |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 399 | if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 400 | OS << PLoc.getFilename() << ':' << PLoc.getLine() |
| 401 | << ':' << PLoc.getColumn(); |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 402 | LastLocFilename = PLoc.getFilename(); |
| 403 | LastLocLine = PLoc.getLine(); |
| 404 | } else if (PLoc.getLine() != LastLocLine) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 405 | OS << "line" << ':' << PLoc.getLine() |
| 406 | << ':' << PLoc.getColumn(); |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 407 | LastLocLine = PLoc.getLine(); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 408 | } else { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 409 | OS << "col" << ':' << PLoc.getColumn(); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 413 | void ASTDumper::dumpSourceRange(SourceRange R) { |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 414 | // Can't translate locations if a SourceManager isn't available. |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 415 | if (!SM) |
| 416 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 418 | OS << " <"; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 419 | dumpLocation(R.getBegin()); |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 420 | if (R.getBegin() != R.getEnd()) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 421 | OS << ", "; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 422 | dumpLocation(R.getEnd()); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 423 | } |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 424 | OS << ">"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 425 | |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 426 | // <t2.c:123:421[blah], t2.c:412:321> |
| 427 | |
| 428 | } |
| 429 | |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 430 | void ASTDumper::dumpBareType(QualType T) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 431 | ColorScope Color(*this, TypeColor); |
| 432 | |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 433 | SplitQualType T_split = T.split(); |
| 434 | OS << "'" << QualType::getAsString(T_split) << "'"; |
| 435 | |
| 436 | if (!T.isNull()) { |
| 437 | // If the type is sugared, also dump a (shallow) desugared type. |
| 438 | SplitQualType D_split = T.getSplitDesugaredType(); |
| 439 | if (T_split != D_split) |
| 440 | OS << ":'" << QualType::getAsString(D_split) << "'"; |
| 441 | } |
| 442 | } |
| 443 | |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 444 | void ASTDumper::dumpType(QualType T) { |
| 445 | OS << ' '; |
| 446 | dumpBareType(T); |
| 447 | } |
| 448 | |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 449 | void ASTDumper::dumpBareDeclRef(const Decl *D) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 450 | { |
| 451 | ColorScope Color(*this, DeclKindNameColor); |
| 452 | OS << D->getDeclKindName(); |
| 453 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 454 | dumpPointer(D); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 455 | |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 456 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 457 | ColorScope Color(*this, DeclNameColor); |
David Blaikie | 17828ca | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 458 | OS << " '" << ND->getDeclName() << '\''; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 461 | if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 462 | dumpType(VD->getType()); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 465 | void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 466 | if (!D) |
| 467 | return; |
| 468 | |
| 469 | IndentScope Indent(*this); |
| 470 | if (Label) |
| 471 | OS << Label << ' '; |
| 472 | dumpBareDeclRef(D); |
| 473 | } |
| 474 | |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 475 | void ASTDumper::dumpName(const NamedDecl *ND) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 476 | if (ND->getDeclName()) { |
| 477 | ColorScope Color(*this, DeclNameColor); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 478 | OS << ' ' << ND->getNameAsString(); |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 479 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 482 | bool ASTDumper::hasNodes(const DeclContext *DC) { |
| 483 | if (!DC) |
| 484 | return false; |
| 485 | |
Richard Smith | e565bfa | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 486 | return DC->hasExternalLexicalStorage() || |
| 487 | DC->noload_decls_begin() != DC->noload_decls_end(); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 490 | void ASTDumper::dumpDeclContext(const DeclContext *DC) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 491 | if (!DC) |
| 492 | return; |
Richard Smith | e565bfa | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 493 | bool HasUndeserializedDecls = DC->hasExternalLexicalStorage(); |
| 494 | for (DeclContext::decl_iterator I = DC->noload_decls_begin(), E = DC->noload_decls_end(); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 495 | I != E; ++I) { |
| 496 | DeclContext::decl_iterator Next = I; |
| 497 | ++Next; |
Richard Smith | e565bfa | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 498 | if (Next == E && !HasUndeserializedDecls) |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 499 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 500 | dumpDecl(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 501 | } |
Richard Smith | e565bfa | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 502 | if (HasUndeserializedDecls) { |
| 503 | lastChild(); |
| 504 | IndentScope Indent(*this); |
| 505 | ColorScope Color(*this, UndeserializedColor); |
| 506 | OS << "<undeserialized declarations>"; |
| 507 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Richard Smith | 6e322c0 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 510 | void ASTDumper::dumpLookups(const DeclContext *DC) { |
| 511 | IndentScope Indent(*this); |
| 512 | |
| 513 | OS << "StoredDeclsMap "; |
| 514 | dumpBareDeclRef(cast<Decl>(DC)); |
| 515 | |
| 516 | const DeclContext *Primary = DC->getPrimaryContext(); |
| 517 | if (Primary != DC) { |
| 518 | OS << " primary"; |
| 519 | dumpPointer(cast<Decl>(Primary)); |
| 520 | } |
| 521 | |
| 522 | bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage(); |
| 523 | |
| 524 | DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(), |
| 525 | E = Primary->noload_lookups_end(); |
| 526 | while (I != E) { |
| 527 | DeclarationName Name = I.getLookupName(); |
| 528 | DeclContextLookupResult R = *I++; |
| 529 | if (I == E && !HasUndeserializedLookups) |
| 530 | lastChild(); |
| 531 | |
| 532 | IndentScope Indent(*this); |
| 533 | OS << "DeclarationName "; |
| 534 | { |
| 535 | ColorScope Color(*this, DeclNameColor); |
| 536 | OS << '\'' << Name << '\''; |
| 537 | } |
| 538 | |
| 539 | for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end(); |
| 540 | RI != RE; ++RI) { |
| 541 | if (RI + 1 == RE) |
| 542 | lastChild(); |
| 543 | dumpDeclRef(*RI); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | if (HasUndeserializedLookups) { |
| 548 | lastChild(); |
| 549 | IndentScope Indent(*this); |
| 550 | ColorScope Color(*this, UndeserializedColor); |
| 551 | OS << "<undeserialized lookups>"; |
| 552 | } |
| 553 | } |
| 554 | |
Alexander Kornienko | c3cd2b0 | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 555 | void ASTDumper::dumpAttr(const Attr *A) { |
| 556 | IndentScope Indent(*this); |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 557 | { |
| 558 | ColorScope Color(*this, AttrColor); |
| 559 | switch (A->getKind()) { |
Alexander Kornienko | c3cd2b0 | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 560 | #define ATTR(X) case attr::X: OS << #X; break; |
| 561 | #include "clang/Basic/AttrList.inc" |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 562 | default: llvm_unreachable("unexpected attribute kind"); |
| 563 | } |
| 564 | OS << "Attr"; |
Alexander Kornienko | c3cd2b0 | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 565 | } |
Alexander Kornienko | c3cd2b0 | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 566 | dumpPointer(A); |
| 567 | dumpSourceRange(A->getRange()); |
| 568 | #include "clang/AST/AttrDump.inc" |
| 569 | } |
| 570 | |
Richard Smith | 4a19052 | 2013-02-07 01:35:44 +0000 | [diff] [blame] | 571 | static Decl *getPreviousDeclImpl(...) { |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | template<typename T> |
| 576 | static const Decl *getPreviousDeclImpl(const Redeclarable<T> *D) { |
| 577 | return D->getPreviousDecl(); |
| 578 | } |
| 579 | |
| 580 | /// Get the previous declaration in the redeclaration chain for a declaration. |
| 581 | static const Decl *getPreviousDecl(const Decl *D) { |
| 582 | switch (D->getKind()) { |
| 583 | #define DECL(DERIVED, BASE) \ |
| 584 | case Decl::DERIVED: \ |
| 585 | return getPreviousDeclImpl(cast<DERIVED##Decl>(D)); |
| 586 | #define ABSTRACT_DECL(DECL) |
| 587 | #include "clang/AST/DeclNodes.inc" |
| 588 | } |
| 589 | llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); |
| 590 | } |
| 591 | |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 592 | //===----------------------------------------------------------------------===// |
| 593 | // C++ Utilities |
| 594 | //===----------------------------------------------------------------------===// |
| 595 | |
| 596 | void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) { |
| 597 | switch (AS) { |
| 598 | case AS_none: |
| 599 | break; |
| 600 | case AS_public: |
| 601 | OS << "public"; |
| 602 | break; |
| 603 | case AS_protected: |
| 604 | OS << "protected"; |
| 605 | break; |
| 606 | case AS_private: |
| 607 | OS << "private"; |
| 608 | break; |
| 609 | } |
| 610 | } |
| 611 | |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 612 | void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 613 | IndentScope Indent(*this); |
| 614 | OS << "CXXCtorInitializer"; |
| 615 | if (Init->isAnyMemberInitializer()) { |
| 616 | OS << ' '; |
| 617 | dumpBareDeclRef(Init->getAnyMember()); |
| 618 | } else { |
| 619 | dumpType(QualType(Init->getBaseClass(), 0)); |
| 620 | } |
| 621 | dumpStmt(Init->getInit()); |
| 622 | } |
| 623 | |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 624 | void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 625 | if (!TPL) |
| 626 | return; |
| 627 | |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 628 | for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 629 | I != E; ++I) |
| 630 | dumpDecl(*I); |
| 631 | } |
| 632 | |
| 633 | void ASTDumper::dumpTemplateArgumentListInfo( |
| 634 | const TemplateArgumentListInfo &TALI) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 635 | for (unsigned i = 0, e = TALI.size(); i < e; ++i) { |
| 636 | if (i + 1 == e) |
| 637 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 638 | dumpTemplateArgumentLoc(TALI[i]); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 639 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) { |
| 643 | dumpTemplateArgument(A.getArgument(), A.getSourceRange()); |
| 644 | } |
| 645 | |
| 646 | void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) { |
| 647 | for (unsigned i = 0, e = TAL.size(); i < e; ++i) |
| 648 | dumpTemplateArgument(TAL[i]); |
| 649 | } |
| 650 | |
| 651 | void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) { |
| 652 | IndentScope Indent(*this); |
| 653 | OS << "TemplateArgument"; |
| 654 | if (R.isValid()) |
| 655 | dumpSourceRange(R); |
| 656 | |
| 657 | switch (A.getKind()) { |
| 658 | case TemplateArgument::Null: |
| 659 | OS << " null"; |
| 660 | break; |
| 661 | case TemplateArgument::Type: |
| 662 | OS << " type"; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 663 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 664 | dumpType(A.getAsType()); |
| 665 | break; |
| 666 | case TemplateArgument::Declaration: |
| 667 | OS << " decl"; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 668 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 669 | dumpDeclRef(A.getAsDecl()); |
| 670 | break; |
| 671 | case TemplateArgument::NullPtr: |
| 672 | OS << " nullptr"; |
| 673 | break; |
| 674 | case TemplateArgument::Integral: |
Alexander Kornienko | ad7bb36 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 675 | OS << " integral " << A.getAsIntegral(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 676 | break; |
| 677 | case TemplateArgument::Template: |
| 678 | OS << " template "; |
| 679 | A.getAsTemplate().dump(OS); |
| 680 | break; |
| 681 | case TemplateArgument::TemplateExpansion: |
| 682 | OS << " template expansion"; |
| 683 | A.getAsTemplateOrTemplatePattern().dump(OS); |
| 684 | break; |
| 685 | case TemplateArgument::Expression: |
| 686 | OS << " expr"; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 687 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 688 | dumpStmt(A.getAsExpr()); |
| 689 | break; |
| 690 | case TemplateArgument::Pack: |
| 691 | OS << " pack"; |
| 692 | for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end(); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 693 | I != E; ++I) { |
| 694 | if (I + 1 == E) |
| 695 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 696 | dumpTemplateArgument(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 697 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 698 | break; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 702 | //===----------------------------------------------------------------------===// |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 703 | // Decl dumping methods. |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 704 | //===----------------------------------------------------------------------===// |
| 705 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 706 | void ASTDumper::dumpDecl(const Decl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 707 | IndentScope Indent(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 709 | if (!D) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 710 | ColorScope Color(*this, NullColor); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 711 | OS << "<<<NULL>>>"; |
| 712 | return; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 713 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 714 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 715 | { |
| 716 | ColorScope Color(*this, DeclKindNameColor); |
| 717 | OS << D->getDeclKindName() << "Decl"; |
| 718 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 719 | dumpPointer(D); |
Richard Smith | 4a19052 | 2013-02-07 01:35:44 +0000 | [diff] [blame] | 720 | if (D->getLexicalDeclContext() != D->getDeclContext()) |
| 721 | OS << " parent " << cast<Decl>(D->getDeclContext()); |
| 722 | if (const Decl *Prev = getPreviousDecl(D)) |
| 723 | OS << " prev " << Prev; |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 724 | dumpSourceRange(D->getSourceRange()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 725 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 726 | bool HasAttrs = D->attr_begin() != D->attr_end(); |
Richard Smith | 0a74a4c | 2013-05-21 05:24:00 +0000 | [diff] [blame] | 727 | const FullComment *Comment = |
| 728 | D->getASTContext().getLocalCommentForDeclUncached(D); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 729 | // Decls within functions are visited by the body |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 730 | bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) && |
| 731 | hasNodes(dyn_cast<DeclContext>(D)); |
| 732 | |
Richard Smith | 0a74a4c | 2013-05-21 05:24:00 +0000 | [diff] [blame] | 733 | setMoreChildren(HasAttrs || Comment || HasDeclContext); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 734 | ConstDeclVisitor<ASTDumper>::Visit(D); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 735 | |
Richard Smith | 0a74a4c | 2013-05-21 05:24:00 +0000 | [diff] [blame] | 736 | setMoreChildren(Comment || HasDeclContext); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 737 | for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); |
| 738 | I != E; ++I) { |
| 739 | if (I + 1 == E) |
| 740 | lastChild(); |
| 741 | dumpAttr(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | setMoreChildren(HasDeclContext); |
| 745 | lastChild(); |
Richard Smith | 0a74a4c | 2013-05-21 05:24:00 +0000 | [diff] [blame] | 746 | dumpFullComment(Comment); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 747 | |
Nick Lewycky | ad82222 | 2013-08-27 03:15:56 +0000 | [diff] [blame^] | 748 | if (D->isInvalidDecl()) |
| 749 | OS << " invalid"; |
| 750 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 751 | setMoreChildren(false); |
| 752 | if (HasDeclContext) |
Richard Smith | 4a19052 | 2013-02-07 01:35:44 +0000 | [diff] [blame] | 753 | dumpDeclContext(cast<DeclContext>(D)); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 756 | void ASTDumper::VisitLabelDecl(const LabelDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 757 | dumpName(D); |
| 758 | } |
| 759 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 760 | void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 761 | dumpName(D); |
| 762 | dumpType(D->getUnderlyingType()); |
| 763 | if (D->isModulePrivate()) |
| 764 | OS << " __module_private__"; |
| 765 | } |
| 766 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 767 | void ASTDumper::VisitEnumDecl(const EnumDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 768 | if (D->isScoped()) { |
| 769 | if (D->isScopedUsingClassTag()) |
| 770 | OS << " class"; |
| 771 | else |
| 772 | OS << " struct"; |
| 773 | } |
| 774 | dumpName(D); |
| 775 | if (D->isModulePrivate()) |
| 776 | OS << " __module_private__"; |
| 777 | if (D->isFixed()) |
| 778 | dumpType(D->getIntegerType()); |
| 779 | } |
| 780 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 781 | void ASTDumper::VisitRecordDecl(const RecordDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 782 | OS << ' ' << D->getKindName(); |
| 783 | dumpName(D); |
| 784 | if (D->isModulePrivate()) |
| 785 | OS << " __module_private__"; |
| 786 | } |
| 787 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 788 | void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 789 | dumpName(D); |
| 790 | dumpType(D->getType()); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 791 | if (const Expr *Init = D->getInitExpr()) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 792 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 793 | dumpStmt(Init); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 794 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 795 | } |
| 796 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 797 | void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 798 | dumpName(D); |
| 799 | dumpType(D->getType()); |
| 800 | for (IndirectFieldDecl::chain_iterator I = D->chain_begin(), |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 801 | E = D->chain_end(); |
| 802 | I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 803 | if (I + 1 == E) |
| 804 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 805 | dumpDeclRef(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 806 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 809 | void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 810 | dumpName(D); |
| 811 | dumpType(D->getType()); |
| 812 | |
Rafael Espindola | d2615cc | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 813 | StorageClass SC = D->getStorageClass(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 814 | if (SC != SC_None) |
| 815 | OS << ' ' << VarDecl::getStorageClassSpecifierString(SC); |
| 816 | if (D->isInlineSpecified()) |
| 817 | OS << " inline"; |
| 818 | if (D->isVirtualAsWritten()) |
| 819 | OS << " virtual"; |
| 820 | if (D->isModulePrivate()) |
| 821 | OS << " __module_private__"; |
| 822 | |
| 823 | if (D->isPure()) |
| 824 | OS << " pure"; |
| 825 | else if (D->isDeletedAsWritten()) |
| 826 | OS << " delete"; |
| 827 | |
Richard Smith | c077dbe | 2013-05-17 02:09:46 +0000 | [diff] [blame] | 828 | if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) { |
| 829 | FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); |
| 830 | switch (EPI.ExceptionSpecType) { |
| 831 | default: break; |
| 832 | case EST_Unevaluated: |
| 833 | OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl; |
| 834 | break; |
| 835 | case EST_Uninstantiated: |
| 836 | OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate; |
| 837 | break; |
| 838 | } |
| 839 | } |
| 840 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 841 | bool OldMoreChildren = hasMoreChildren(); |
| 842 | const FunctionTemplateSpecializationInfo *FTSI = |
| 843 | D->getTemplateSpecializationInfo(); |
| 844 | bool HasTemplateSpecialization = FTSI; |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 845 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 846 | bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() != |
| 847 | D->getDeclsInPrototypeScope().end(); |
| 848 | |
| 849 | bool HasFunctionDecls = D->param_begin() != D->param_end(); |
| 850 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 851 | const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 852 | bool HasCtorInitializers = C && C->init_begin() != C->init_end(); |
| 853 | |
| 854 | bool HasDeclarationBody = D->doesThisDeclarationHaveABody(); |
| 855 | |
| 856 | setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls || |
| 857 | HasCtorInitializers || HasDeclarationBody); |
| 858 | if (HasTemplateSpecialization) { |
| 859 | lastChild(); |
| 860 | dumpTemplateArgumentList(*FTSI->TemplateArguments); |
| 861 | } |
| 862 | |
| 863 | setMoreChildren(OldMoreChildren || HasFunctionDecls || |
| 864 | HasCtorInitializers || HasDeclarationBody); |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 865 | for (ArrayRef<NamedDecl *>::iterator |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 866 | I = D->getDeclsInPrototypeScope().begin(), |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 867 | E = D->getDeclsInPrototypeScope().end(); I != E; ++I) { |
| 868 | if (I + 1 == E) |
| 869 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 870 | dumpDecl(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 871 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 872 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 873 | setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 874 | for (FunctionDecl::param_const_iterator I = D->param_begin(), |
| 875 | E = D->param_end(); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 876 | I != E; ++I) { |
| 877 | if (I + 1 == E) |
| 878 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 879 | dumpDecl(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | setMoreChildren(OldMoreChildren || HasDeclarationBody); |
| 883 | if (HasCtorInitializers) |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 884 | for (CXXConstructorDecl::init_const_iterator I = C->init_begin(), |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 885 | E = C->init_end(); |
| 886 | I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 887 | if (I + 1 == E) |
| 888 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 889 | dumpCXXCtorInitializer(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 890 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 891 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 892 | setMoreChildren(OldMoreChildren); |
| 893 | if (HasDeclarationBody) { |
| 894 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 895 | dumpStmt(D->getBody()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 896 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 897 | } |
| 898 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 899 | void ASTDumper::VisitFieldDecl(const FieldDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 900 | dumpName(D); |
| 901 | dumpType(D->getType()); |
| 902 | if (D->isMutable()) |
| 903 | OS << " mutable"; |
| 904 | if (D->isModulePrivate()) |
| 905 | OS << " __module_private__"; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 906 | |
| 907 | bool OldMoreChildren = hasMoreChildren(); |
| 908 | bool IsBitField = D->isBitField(); |
| 909 | Expr *Init = D->getInClassInitializer(); |
| 910 | bool HasInit = Init; |
| 911 | |
| 912 | setMoreChildren(OldMoreChildren || HasInit); |
| 913 | if (IsBitField) { |
| 914 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 915 | dumpStmt(D->getBitWidth()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 916 | } |
| 917 | setMoreChildren(OldMoreChildren); |
| 918 | if (HasInit) { |
| 919 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 920 | dumpStmt(Init); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 921 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 924 | void ASTDumper::VisitVarDecl(const VarDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 925 | dumpName(D); |
| 926 | dumpType(D->getType()); |
Rafael Espindola | d2615cc | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 927 | StorageClass SC = D->getStorageClass(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 928 | if (SC != SC_None) |
| 929 | OS << ' ' << VarDecl::getStorageClassSpecifierString(SC); |
Richard Smith | 38afbc7 | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 930 | switch (D->getTLSKind()) { |
| 931 | case VarDecl::TLS_None: break; |
| 932 | case VarDecl::TLS_Static: OS << " tls"; break; |
| 933 | case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break; |
| 934 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 935 | if (D->isModulePrivate()) |
| 936 | OS << " __module_private__"; |
| 937 | if (D->isNRVOVariable()) |
| 938 | OS << " nrvo"; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 939 | if (D->hasInit()) { |
| 940 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 941 | dumpStmt(D->getInit()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 942 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 943 | } |
| 944 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 945 | void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 946 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 947 | dumpStmt(D->getAsmString()); |
| 948 | } |
| 949 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 950 | void ASTDumper::VisitImportDecl(const ImportDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 951 | OS << ' ' << D->getImportedModule()->getFullModuleName(); |
| 952 | } |
| 953 | |
| 954 | //===----------------------------------------------------------------------===// |
| 955 | // C++ Declarations |
| 956 | //===----------------------------------------------------------------------===// |
| 957 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 958 | void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 959 | dumpName(D); |
| 960 | if (D->isInline()) |
| 961 | OS << " inline"; |
| 962 | if (!D->isOriginalNamespace()) |
| 963 | dumpDeclRef(D->getOriginalNamespace(), "original"); |
| 964 | } |
| 965 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 966 | void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 967 | OS << ' '; |
| 968 | dumpBareDeclRef(D->getNominatedNamespace()); |
| 969 | } |
| 970 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 971 | void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 972 | dumpName(D); |
| 973 | dumpDeclRef(D->getAliasedNamespace()); |
| 974 | } |
| 975 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 976 | void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 977 | dumpName(D); |
| 978 | dumpType(D->getUnderlyingType()); |
| 979 | } |
| 980 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 981 | void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 982 | dumpName(D); |
| 983 | dumpTemplateParameters(D->getTemplateParameters()); |
| 984 | dumpDecl(D->getTemplatedDecl()); |
| 985 | } |
| 986 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 987 | void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 988 | VisitRecordDecl(D); |
| 989 | if (!D->isCompleteDefinition()) |
| 990 | return; |
| 991 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 992 | for (CXXRecordDecl::base_class_const_iterator I = D->bases_begin(), |
| 993 | E = D->bases_end(); |
| 994 | I != E; ++I) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 995 | IndentScope Indent(*this); |
| 996 | if (I->isVirtual()) |
| 997 | OS << "virtual "; |
| 998 | dumpAccessSpecifier(I->getAccessSpecifier()); |
| 999 | dumpType(I->getType()); |
| 1000 | if (I->isPackExpansion()) |
| 1001 | OS << "..."; |
| 1002 | } |
| 1003 | } |
| 1004 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1005 | void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1006 | dumpStmt(D->getAssertExpr()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1007 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1008 | dumpStmt(D->getMessage()); |
| 1009 | } |
| 1010 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1011 | void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1012 | dumpName(D); |
| 1013 | dumpTemplateParameters(D->getTemplateParameters()); |
| 1014 | dumpDecl(D->getTemplatedDecl()); |
Dmitri Gribenko | e252a89 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 1015 | for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(), |
| 1016 | E = D->spec_end(); |
| 1017 | I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1018 | FunctionTemplateDecl::spec_iterator Next = I; |
| 1019 | ++Next; |
| 1020 | if (Next == E) |
| 1021 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1022 | switch (I->getTemplateSpecializationKind()) { |
| 1023 | case TSK_Undeclared: |
| 1024 | case TSK_ImplicitInstantiation: |
| 1025 | case TSK_ExplicitInstantiationDeclaration: |
| 1026 | case TSK_ExplicitInstantiationDefinition: |
Dmitri Gribenko | 4216ee1 | 2013-02-21 22:01:10 +0000 | [diff] [blame] | 1027 | if (D == D->getCanonicalDecl()) |
| 1028 | dumpDecl(*I); |
| 1029 | else |
| 1030 | dumpDeclRef(*I); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1031 | break; |
| 1032 | case TSK_ExplicitSpecialization: |
| 1033 | dumpDeclRef(*I); |
| 1034 | break; |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1039 | void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1040 | dumpName(D); |
| 1041 | dumpTemplateParameters(D->getTemplateParameters()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1042 | |
Dmitri Gribenko | e252a89 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 1043 | ClassTemplateDecl::spec_iterator I = D->spec_begin(); |
| 1044 | ClassTemplateDecl::spec_iterator E = D->spec_end(); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1045 | if (I == E) |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1046 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1047 | dumpDecl(D->getTemplatedDecl()); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1048 | for (; I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1049 | ClassTemplateDecl::spec_iterator Next = I; |
| 1050 | ++Next; |
| 1051 | if (Next == E) |
| 1052 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1053 | switch (I->getTemplateSpecializationKind()) { |
| 1054 | case TSK_Undeclared: |
| 1055 | case TSK_ImplicitInstantiation: |
Dmitri Gribenko | 4216ee1 | 2013-02-21 22:01:10 +0000 | [diff] [blame] | 1056 | if (D == D->getCanonicalDecl()) |
| 1057 | dumpDecl(*I); |
| 1058 | else |
| 1059 | dumpDeclRef(*I); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1060 | break; |
| 1061 | case TSK_ExplicitSpecialization: |
| 1062 | case TSK_ExplicitInstantiationDeclaration: |
| 1063 | case TSK_ExplicitInstantiationDefinition: |
| 1064 | dumpDeclRef(*I); |
| 1065 | break; |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | void ASTDumper::VisitClassTemplateSpecializationDecl( |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1071 | const ClassTemplateSpecializationDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1072 | VisitCXXRecordDecl(D); |
| 1073 | dumpTemplateArgumentList(D->getTemplateArgs()); |
| 1074 | } |
| 1075 | |
| 1076 | void ASTDumper::VisitClassTemplatePartialSpecializationDecl( |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1077 | const ClassTemplatePartialSpecializationDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1078 | VisitClassTemplateSpecializationDecl(D); |
| 1079 | dumpTemplateParameters(D->getTemplateParameters()); |
| 1080 | } |
| 1081 | |
| 1082 | void ASTDumper::VisitClassScopeFunctionSpecializationDecl( |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1083 | const ClassScopeFunctionSpecializationDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1084 | dumpDeclRef(D->getSpecialization()); |
| 1085 | if (D->hasExplicitTemplateArgs()) |
| 1086 | dumpTemplateArgumentListInfo(D->templateArgs()); |
| 1087 | } |
| 1088 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1089 | void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1090 | if (D->wasDeclaredWithTypename()) |
| 1091 | OS << " typename"; |
| 1092 | else |
| 1093 | OS << " class"; |
| 1094 | if (D->isParameterPack()) |
| 1095 | OS << " ..."; |
| 1096 | dumpName(D); |
| 1097 | if (D->hasDefaultArgument()) |
| 1098 | dumpType(D->getDefaultArgument()); |
| 1099 | } |
| 1100 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1101 | void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1102 | dumpType(D->getType()); |
| 1103 | if (D->isParameterPack()) |
| 1104 | OS << " ..."; |
| 1105 | dumpName(D); |
| 1106 | if (D->hasDefaultArgument()) |
| 1107 | dumpStmt(D->getDefaultArgument()); |
| 1108 | } |
| 1109 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1110 | void ASTDumper::VisitTemplateTemplateParmDecl( |
| 1111 | const TemplateTemplateParmDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1112 | if (D->isParameterPack()) |
| 1113 | OS << " ..."; |
| 1114 | dumpName(D); |
| 1115 | dumpTemplateParameters(D->getTemplateParameters()); |
| 1116 | if (D->hasDefaultArgument()) |
| 1117 | dumpTemplateArgumentLoc(D->getDefaultArgument()); |
| 1118 | } |
| 1119 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1120 | void ASTDumper::VisitUsingDecl(const UsingDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1121 | OS << ' '; |
| 1122 | D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); |
| 1123 | OS << D->getNameAsString(); |
| 1124 | } |
| 1125 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1126 | void ASTDumper::VisitUnresolvedUsingTypenameDecl( |
| 1127 | const UnresolvedUsingTypenameDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1128 | OS << ' '; |
| 1129 | D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); |
| 1130 | OS << D->getNameAsString(); |
| 1131 | } |
| 1132 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1133 | void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1134 | OS << ' '; |
| 1135 | D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); |
| 1136 | OS << D->getNameAsString(); |
| 1137 | dumpType(D->getType()); |
| 1138 | } |
| 1139 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1140 | void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1141 | OS << ' '; |
| 1142 | dumpBareDeclRef(D->getTargetDecl()); |
| 1143 | } |
| 1144 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1145 | void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1146 | switch (D->getLanguage()) { |
| 1147 | case LinkageSpecDecl::lang_c: OS << " C"; break; |
| 1148 | case LinkageSpecDecl::lang_cxx: OS << " C++"; break; |
| 1149 | } |
| 1150 | } |
| 1151 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1152 | void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1153 | OS << ' '; |
| 1154 | dumpAccessSpecifier(D->getAccess()); |
| 1155 | } |
| 1156 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1157 | void ASTDumper::VisitFriendDecl(const FriendDecl *D) { |
Richard Smith | 4a19052 | 2013-02-07 01:35:44 +0000 | [diff] [blame] | 1158 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1159 | if (TypeSourceInfo *T = D->getFriendType()) |
| 1160 | dumpType(T->getType()); |
| 1161 | else |
| 1162 | dumpDecl(D->getFriendDecl()); |
| 1163 | } |
| 1164 | |
| 1165 | //===----------------------------------------------------------------------===// |
| 1166 | // Obj-C Declarations |
| 1167 | //===----------------------------------------------------------------------===// |
| 1168 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1169 | void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1170 | dumpName(D); |
| 1171 | dumpType(D->getType()); |
| 1172 | if (D->getSynthesize()) |
| 1173 | OS << " synthesize"; |
| 1174 | |
| 1175 | switch (D->getAccessControl()) { |
| 1176 | case ObjCIvarDecl::None: |
| 1177 | OS << " none"; |
| 1178 | break; |
| 1179 | case ObjCIvarDecl::Private: |
| 1180 | OS << " private"; |
| 1181 | break; |
| 1182 | case ObjCIvarDecl::Protected: |
| 1183 | OS << " protected"; |
| 1184 | break; |
| 1185 | case ObjCIvarDecl::Public: |
| 1186 | OS << " public"; |
| 1187 | break; |
| 1188 | case ObjCIvarDecl::Package: |
| 1189 | OS << " package"; |
| 1190 | break; |
| 1191 | } |
| 1192 | } |
| 1193 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1194 | void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1195 | if (D->isInstanceMethod()) |
| 1196 | OS << " -"; |
| 1197 | else |
| 1198 | OS << " +"; |
| 1199 | dumpName(D); |
| 1200 | dumpType(D->getResultType()); |
| 1201 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1202 | bool OldMoreChildren = hasMoreChildren(); |
| 1203 | bool IsVariadic = D->isVariadic(); |
| 1204 | bool HasBody = D->hasBody(); |
| 1205 | |
| 1206 | setMoreChildren(OldMoreChildren || IsVariadic || HasBody); |
| 1207 | if (D->isThisDeclarationADefinition()) { |
| 1208 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1209 | dumpDeclContext(D); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1210 | } else { |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1211 | for (ObjCMethodDecl::param_const_iterator I = D->param_begin(), |
| 1212 | E = D->param_end(); |
| 1213 | I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1214 | if (I + 1 == E) |
| 1215 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1216 | dumpDecl(*I); |
| 1217 | } |
| 1218 | } |
| 1219 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1220 | setMoreChildren(OldMoreChildren || HasBody); |
| 1221 | if (IsVariadic) { |
| 1222 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1223 | IndentScope Indent(*this); |
| 1224 | OS << "..."; |
| 1225 | } |
| 1226 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1227 | setMoreChildren(OldMoreChildren); |
| 1228 | if (HasBody) { |
| 1229 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1230 | dumpStmt(D->getBody()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1231 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1234 | void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1235 | dumpName(D); |
| 1236 | dumpDeclRef(D->getClassInterface()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1237 | if (D->protocol_begin() == D->protocol_end()) |
| 1238 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1239 | dumpDeclRef(D->getImplementation()); |
| 1240 | for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(), |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1241 | E = D->protocol_end(); |
| 1242 | I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1243 | if (I + 1 == E) |
| 1244 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1245 | dumpDeclRef(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1246 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1249 | void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1250 | dumpName(D); |
| 1251 | dumpDeclRef(D->getClassInterface()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1252 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1253 | dumpDeclRef(D->getCategoryDecl()); |
| 1254 | } |
| 1255 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1256 | void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1257 | dumpName(D); |
| 1258 | for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(), |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1259 | E = D->protocol_end(); |
| 1260 | I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1261 | if (I + 1 == E) |
| 1262 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1263 | dumpDeclRef(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1264 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1267 | void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1268 | dumpName(D); |
| 1269 | dumpDeclRef(D->getSuperClass(), "super"); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1270 | if (D->protocol_begin() == D->protocol_end()) |
| 1271 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1272 | dumpDeclRef(D->getImplementation()); |
| 1273 | for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(), |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1274 | E = D->protocol_end(); |
| 1275 | I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1276 | if (I + 1 == E) |
| 1277 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1278 | dumpDeclRef(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1279 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1282 | void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1283 | dumpName(D); |
| 1284 | dumpDeclRef(D->getSuperClass(), "super"); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1285 | if (D->init_begin() == D->init_end()) |
| 1286 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1287 | dumpDeclRef(D->getClassInterface()); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1288 | for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(), |
| 1289 | E = D->init_end(); |
| 1290 | I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1291 | if (I + 1 == E) |
| 1292 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1293 | dumpCXXCtorInitializer(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1294 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1297 | void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1298 | dumpName(D); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1299 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1300 | dumpDeclRef(D->getClassInterface()); |
| 1301 | } |
| 1302 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1303 | void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1304 | dumpName(D); |
| 1305 | dumpType(D->getType()); |
| 1306 | |
| 1307 | if (D->getPropertyImplementation() == ObjCPropertyDecl::Required) |
| 1308 | OS << " required"; |
| 1309 | else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional) |
| 1310 | OS << " optional"; |
| 1311 | |
| 1312 | ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes(); |
| 1313 | if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) { |
| 1314 | if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly) |
| 1315 | OS << " readonly"; |
| 1316 | if (Attrs & ObjCPropertyDecl::OBJC_PR_assign) |
| 1317 | OS << " assign"; |
| 1318 | if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite) |
| 1319 | OS << " readwrite"; |
| 1320 | if (Attrs & ObjCPropertyDecl::OBJC_PR_retain) |
| 1321 | OS << " retain"; |
| 1322 | if (Attrs & ObjCPropertyDecl::OBJC_PR_copy) |
| 1323 | OS << " copy"; |
| 1324 | if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic) |
| 1325 | OS << " nonatomic"; |
| 1326 | if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic) |
| 1327 | OS << " atomic"; |
| 1328 | if (Attrs & ObjCPropertyDecl::OBJC_PR_weak) |
| 1329 | OS << " weak"; |
| 1330 | if (Attrs & ObjCPropertyDecl::OBJC_PR_strong) |
| 1331 | OS << " strong"; |
| 1332 | if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained) |
| 1333 | OS << " unsafe_unretained"; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1334 | if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) { |
| 1335 | if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter)) |
| 1336 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1337 | dumpDeclRef(D->getGetterMethodDecl(), "getter"); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1338 | } |
| 1339 | if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) { |
| 1340 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1341 | dumpDeclRef(D->getSetterMethodDecl(), "setter"); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1342 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1346 | void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1347 | dumpName(D->getPropertyDecl()); |
| 1348 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) |
| 1349 | OS << " synthesize"; |
| 1350 | else |
| 1351 | OS << " dynamic"; |
| 1352 | dumpDeclRef(D->getPropertyDecl()); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1353 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1354 | dumpDeclRef(D->getPropertyIvarDecl()); |
| 1355 | } |
| 1356 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1357 | void ASTDumper::VisitBlockDecl(const BlockDecl *D) { |
| 1358 | for (BlockDecl::param_const_iterator I = D->param_begin(), E = D->param_end(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1359 | I != E; ++I) |
| 1360 | dumpDecl(*I); |
| 1361 | |
| 1362 | if (D->isVariadic()) { |
| 1363 | IndentScope Indent(*this); |
| 1364 | OS << "..."; |
| 1365 | } |
| 1366 | |
| 1367 | if (D->capturesCXXThis()) { |
| 1368 | IndentScope Indent(*this); |
| 1369 | OS << "capture this"; |
| 1370 | } |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1371 | for (BlockDecl::capture_iterator I = D->capture_begin(), E = D->capture_end(); |
| 1372 | I != E; ++I) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1373 | IndentScope Indent(*this); |
| 1374 | OS << "capture"; |
| 1375 | if (I->isByRef()) |
| 1376 | OS << " byref"; |
| 1377 | if (I->isNested()) |
| 1378 | OS << " nested"; |
| 1379 | if (I->getVariable()) { |
| 1380 | OS << ' '; |
| 1381 | dumpBareDeclRef(I->getVariable()); |
| 1382 | } |
| 1383 | if (I->hasCopyExpr()) |
| 1384 | dumpStmt(I->getCopyExpr()); |
| 1385 | } |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1386 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1387 | dumpStmt(D->getBody()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1390 | //===----------------------------------------------------------------------===// |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1391 | // Stmt dumping methods. |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1392 | //===----------------------------------------------------------------------===// |
| 1393 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1394 | void ASTDumper::dumpStmt(const Stmt *S) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1395 | IndentScope Indent(*this); |
| 1396 | |
| 1397 | if (!S) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1398 | ColorScope Color(*this, NullColor); |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1399 | OS << "<<<NULL>>>"; |
| 1400 | return; |
| 1401 | } |
| 1402 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1403 | if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1404 | VisitDeclStmt(DS); |
| 1405 | return; |
| 1406 | } |
| 1407 | |
David Blaikie | 7247c88 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 1408 | setMoreChildren(!S->children().empty()); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1409 | ConstStmtVisitor<ASTDumper>::Visit(S); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1410 | setMoreChildren(false); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1411 | for (Stmt::const_child_range CI = S->children(); CI; ++CI) { |
| 1412 | Stmt::const_child_range Next = CI; |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1413 | ++Next; |
| 1414 | if (!Next) |
| 1415 | lastChild(); |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1416 | dumpStmt(*CI); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1417 | } |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1420 | void ASTDumper::VisitStmt(const Stmt *Node) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1421 | { |
| 1422 | ColorScope Color(*this, StmtColor); |
| 1423 | OS << Node->getStmtClassName(); |
| 1424 | } |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1425 | dumpPointer(Node); |
| 1426 | dumpSourceRange(Node->getSourceRange()); |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1429 | void ASTDumper::VisitDeclStmt(const DeclStmt *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1430 | VisitStmt(Node); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1431 | for (DeclStmt::const_decl_iterator I = Node->decl_begin(), |
| 1432 | E = Node->decl_end(); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1433 | I != E; ++I) { |
| 1434 | if (I + 1 == E) |
| 1435 | lastChild(); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1436 | dumpDecl(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1437 | } |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1440 | void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) { |
Alexander Kornienko | c3cd2b0 | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 1441 | VisitStmt(Node); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1442 | for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(), |
| 1443 | E = Node->getAttrs().end(); |
| 1444 | I != E; ++I) { |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1445 | if (I + 1 == E) |
| 1446 | lastChild(); |
Alexander Kornienko | c3cd2b0 | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 1447 | dumpAttr(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1448 | } |
Alexander Kornienko | c3cd2b0 | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1451 | void ASTDumper::VisitLabelStmt(const LabelStmt *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1452 | VisitStmt(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1453 | OS << " '" << Node->getName() << "'"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1456 | void ASTDumper::VisitGotoStmt(const GotoStmt *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1457 | VisitStmt(Node); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1458 | OS << " '" << Node->getLabel()->getName() << "'"; |
| 1459 | dumpPointer(Node->getLabel()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1462 | //===----------------------------------------------------------------------===// |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1463 | // Expr dumping methods. |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1464 | //===----------------------------------------------------------------------===// |
| 1465 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1466 | void ASTDumper::VisitExpr(const Expr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1467 | VisitStmt(Node); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1468 | dumpType(Node->getType()); |
| 1469 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1470 | { |
| 1471 | ColorScope Color(*this, ValueKindColor); |
| 1472 | switch (Node->getValueKind()) { |
| 1473 | case VK_RValue: |
| 1474 | break; |
| 1475 | case VK_LValue: |
| 1476 | OS << " lvalue"; |
| 1477 | break; |
| 1478 | case VK_XValue: |
| 1479 | OS << " xvalue"; |
| 1480 | break; |
| 1481 | } |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1484 | { |
| 1485 | ColorScope Color(*this, ObjectKindColor); |
| 1486 | switch (Node->getObjectKind()) { |
| 1487 | case OK_Ordinary: |
| 1488 | break; |
| 1489 | case OK_BitField: |
| 1490 | OS << " bitfield"; |
| 1491 | break; |
| 1492 | case OK_ObjCProperty: |
| 1493 | OS << " objcproperty"; |
| 1494 | break; |
| 1495 | case OK_ObjCSubscript: |
| 1496 | OS << " objcsubscript"; |
| 1497 | break; |
| 1498 | case OK_VectorComponent: |
| 1499 | OS << " vectorcomponent"; |
| 1500 | break; |
| 1501 | } |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1502 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1505 | static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) { |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1506 | if (Node->path_empty()) |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 1507 | return; |
| 1508 | |
| 1509 | OS << " ("; |
| 1510 | bool First = true; |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1511 | for (CastExpr::path_const_iterator I = Node->path_begin(), |
| 1512 | E = Node->path_end(); |
| 1513 | I != E; ++I) { |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 1514 | const CXXBaseSpecifier *Base = *I; |
| 1515 | if (!First) |
| 1516 | OS << " -> "; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1517 | |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 1518 | const CXXRecordDecl *RD = |
| 1519 | cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1520 | |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 1521 | if (Base->isVirtual()) |
| 1522 | OS << "virtual "; |
| 1523 | OS << RD->getName(); |
| 1524 | First = false; |
| 1525 | } |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1526 | |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 1527 | OS << ')'; |
| 1528 | } |
| 1529 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1530 | void ASTDumper::VisitCastExpr(const CastExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1531 | VisitExpr(Node); |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1532 | OS << " <"; |
| 1533 | { |
| 1534 | ColorScope Color(*this, CastColor); |
| 1535 | OS << Node->getCastKindName(); |
| 1536 | } |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1537 | dumpBasePath(OS, Node); |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 1538 | OS << ">"; |
Anders Carlsson | 27a5b9b | 2009-08-22 23:33:40 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1541 | void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1542 | VisitExpr(Node); |
Ted Kremenek | eb641f9 | 2007-09-10 17:32:55 +0000 | [diff] [blame] | 1543 | |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1544 | OS << " "; |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1545 | dumpBareDeclRef(Node->getDecl()); |
Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 1546 | if (Node->getDecl() != Node->getFoundDecl()) { |
| 1547 | OS << " ("; |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1548 | dumpBareDeclRef(Node->getFoundDecl()); |
Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 1549 | OS << ")"; |
| 1550 | } |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1553 | void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1554 | VisitExpr(Node); |
John McCall | 9d5f35e | 2009-12-11 21:50:11 +0000 | [diff] [blame] | 1555 | OS << " ("; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1556 | if (!Node->requiresADL()) |
| 1557 | OS << "no "; |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1558 | OS << "ADL) = '" << Node->getName() << '\''; |
John McCall | 9d5f35e | 2009-12-11 21:50:11 +0000 | [diff] [blame] | 1559 | |
| 1560 | UnresolvedLookupExpr::decls_iterator |
| 1561 | I = Node->decls_begin(), E = Node->decls_end(); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1562 | if (I == E) |
| 1563 | OS << " empty"; |
John McCall | 9d5f35e | 2009-12-11 21:50:11 +0000 | [diff] [blame] | 1564 | for (; I != E; ++I) |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1565 | dumpPointer(*I); |
John McCall | 9d5f35e | 2009-12-11 21:50:11 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1568 | void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1569 | VisitExpr(Node); |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 1570 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1571 | { |
| 1572 | ColorScope Color(*this, DeclKindNameColor); |
| 1573 | OS << " " << Node->getDecl()->getDeclKindName() << "Decl"; |
| 1574 | } |
| 1575 | OS << "='" << *Node->getDecl() << "'"; |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1576 | dumpPointer(Node->getDecl()); |
Steve Naroff | 218543b | 2008-05-23 22:01:24 +0000 | [diff] [blame] | 1577 | if (Node->isFreeIvar()) |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1578 | OS << " isFreeIvar"; |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1581 | void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1582 | VisitExpr(Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1583 | switch (Node->getIdentType()) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1584 | default: llvm_unreachable("unknown case"); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1585 | case PredefinedExpr::Func: OS << " __func__"; break; |
| 1586 | case PredefinedExpr::Function: OS << " __FUNCTION__"; break; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1587 | case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break; |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1588 | case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1589 | } |
| 1590 | } |
| 1591 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1592 | void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1593 | VisitExpr(Node); |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1594 | ColorScope Color(*this, ValueColor); |
Richard Trieu | 49cf884 | 2011-11-03 23:56:23 +0000 | [diff] [blame] | 1595 | OS << " " << Node->getValue(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1598 | void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1599 | VisitExpr(Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1600 | |
| 1601 | bool isSigned = Node->getType()->isSignedIntegerType(); |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1602 | ColorScope Color(*this, ValueColor); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1603 | OS << " " << Node->getValue().toString(10, isSigned); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1604 | } |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1605 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1606 | void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1607 | VisitExpr(Node); |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1608 | ColorScope Color(*this, ValueColor); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1609 | OS << " " << Node->getValueAsApproximateDouble(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1610 | } |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1611 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1612 | void ASTDumper::VisitStringLiteral(const StringLiteral *Str) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1613 | VisitExpr(Str); |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1614 | ColorScope Color(*this, ValueColor); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1615 | OS << " "; |
Richard Trieu | 8ab09da | 2012-06-13 20:25:24 +0000 | [diff] [blame] | 1616 | Str->outputString(OS); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1617 | } |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 1618 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1619 | void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1620 | VisitExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1621 | OS << " " << (Node->isPostfix() ? "postfix" : "prefix") |
| 1622 | << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1623 | } |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1624 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1625 | void ASTDumper::VisitUnaryExprOrTypeTraitExpr( |
| 1626 | const UnaryExprOrTypeTraitExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1627 | VisitExpr(Node); |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1628 | switch(Node->getKind()) { |
| 1629 | case UETT_SizeOf: |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1630 | OS << " sizeof"; |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1631 | break; |
| 1632 | case UETT_AlignOf: |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1633 | OS << " alignof"; |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1634 | break; |
| 1635 | case UETT_VecStep: |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1636 | OS << " vec_step"; |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1637 | break; |
| 1638 | } |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 1639 | if (Node->isArgumentType()) |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1640 | dumpType(Node->getArgumentType()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1641 | } |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 1642 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1643 | void ASTDumper::VisitMemberExpr(const MemberExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1644 | VisitExpr(Node); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1645 | OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl(); |
| 1646 | dumpPointer(Node->getMemberDecl()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1647 | } |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1648 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1649 | void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1650 | VisitExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1651 | OS << " " << Node->getAccessor().getNameStart(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1652 | } |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1653 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1654 | void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1655 | VisitExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1656 | OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'"; |
Chris Lattner | eb14fe8 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 1657 | } |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1658 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1659 | void ASTDumper::VisitCompoundAssignOperator( |
| 1660 | const CompoundAssignOperator *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1661 | VisitExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1662 | OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) |
| 1663 | << "' ComputeLHSTy="; |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1664 | dumpBareType(Node->getComputationLHSType()); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1665 | OS << " ComputeResultTy="; |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1666 | dumpBareType(Node->getComputationResultType()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1667 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1668 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1669 | void ASTDumper::VisitBlockExpr(const BlockExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1670 | VisitExpr(Node); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1671 | dumpDecl(Node->getBlockDecl()); |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1674 | void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1675 | VisitExpr(Node); |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1676 | |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1677 | if (Expr *Source = Node->getSourceExpr()) { |
| 1678 | lastChild(); |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1679 | dumpStmt(Source); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1680 | } |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1683 | // GNU extensions. |
| 1684 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1685 | void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1686 | VisitExpr(Node); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1687 | OS << " " << Node->getLabel()->getName(); |
| 1688 | dumpPointer(Node->getLabel()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 1691 | //===----------------------------------------------------------------------===// |
| 1692 | // C++ Expressions |
| 1693 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1694 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1695 | void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1696 | VisitExpr(Node); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1697 | OS << " " << Node->getCastName() |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1698 | << "<" << Node->getTypeAsWritten().getAsString() << ">" |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 1699 | << " <" << Node->getCastKindName(); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1700 | dumpBasePath(OS, Node); |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 1701 | OS << ">"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1704 | void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1705 | VisitExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1706 | OS << " " << (Node->getValue() ? "true" : "false"); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1709 | void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1710 | VisitExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1711 | OS << " this"; |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1714 | void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1715 | VisitExpr(Node); |
Eli Friedman | cc2fca2 | 2011-09-02 17:38:59 +0000 | [diff] [blame] | 1716 | OS << " functional cast to " << Node->getTypeAsWritten().getAsString() |
| 1717 | << " <" << Node->getCastKindName() << ">"; |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1720 | void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1721 | VisitExpr(Node); |
John McCall | d4bbdfe | 2010-02-02 19:03:45 +0000 | [diff] [blame] | 1722 | CXXConstructorDecl *Ctor = Node->getConstructor(); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1723 | dumpType(Ctor->getType()); |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 1724 | if (Node->isElidable()) |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1725 | OS << " elidable"; |
John McCall | f8cf0b0 | 2010-08-07 06:38:55 +0000 | [diff] [blame] | 1726 | if (Node->requiresZeroInitialization()) |
| 1727 | OS << " zeroing"; |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 1728 | } |
| 1729 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1730 | void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1731 | VisitExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1732 | OS << " "; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1733 | dumpCXXTemporary(Node->getTemporary()); |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
Richard Smith | 211c8dd | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 1736 | void |
| 1737 | ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) { |
| 1738 | VisitExpr(Node); |
| 1739 | if (const ValueDecl *VD = Node->getExtendingDecl()) { |
| 1740 | OS << " extended by "; |
| 1741 | dumpBareDeclRef(VD); |
| 1742 | } |
| 1743 | } |
| 1744 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1745 | void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1746 | VisitExpr(Node); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1747 | for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) |
| 1748 | dumpDeclRef(Node->getObject(i), "cleanup"); |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1751 | void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) { |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1752 | OS << "(CXXTemporary"; |
| 1753 | dumpPointer(Temporary); |
| 1754 | OS << ")"; |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1757 | //===----------------------------------------------------------------------===// |
| 1758 | // Obj-C Expressions |
| 1759 | //===----------------------------------------------------------------------===// |
| 1760 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1761 | void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1762 | VisitExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1763 | OS << " selector=" << Node->getSelector().getAsString(); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1764 | switch (Node->getReceiverKind()) { |
| 1765 | case ObjCMessageExpr::Instance: |
| 1766 | break; |
| 1767 | |
| 1768 | case ObjCMessageExpr::Class: |
| 1769 | OS << " class="; |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1770 | dumpBareType(Node->getClassReceiver()); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1771 | break; |
| 1772 | |
| 1773 | case ObjCMessageExpr::SuperInstance: |
| 1774 | OS << " super (instance)"; |
| 1775 | break; |
| 1776 | |
| 1777 | case ObjCMessageExpr::SuperClass: |
| 1778 | OS << " super (class)"; |
| 1779 | break; |
| 1780 | } |
Ted Kremenek | b3d914b | 2008-02-29 22:04:05 +0000 | [diff] [blame] | 1781 | } |
| 1782 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1783 | void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1784 | VisitExpr(Node); |
Argyrios Kyrtzidis | 36faadd | 2012-05-10 20:02:31 +0000 | [diff] [blame] | 1785 | OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString(); |
| 1786 | } |
| 1787 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1788 | void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1789 | VisitStmt(Node); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1790 | if (const VarDecl *CatchParam = Node->getCatchParamDecl()) |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1791 | dumpDecl(CatchParam); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 1792 | else |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1793 | OS << " catch all"; |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1796 | void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1797 | VisitExpr(Node); |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1798 | dumpType(Node->getEncodedType()); |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1801 | void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1802 | VisitExpr(Node); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1803 | |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 1804 | OS << " " << Node->getSelector().getAsString(); |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1807 | void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1808 | VisitExpr(Node); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1809 | |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1810 | OS << ' ' << *Node->getProtocol(); |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1811 | } |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 1812 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1813 | void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1814 | VisitExpr(Node); |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 1815 | if (Node->isImplicitProperty()) { |
Fariborz Jahanian | 99130e5 | 2010-12-22 19:46:35 +0000 | [diff] [blame] | 1816 | OS << " Kind=MethodRef Getter=\""; |
| 1817 | if (Node->getImplicitPropertyGetter()) |
| 1818 | OS << Node->getImplicitPropertyGetter()->getSelector().getAsString(); |
| 1819 | else |
| 1820 | OS << "(null)"; |
| 1821 | |
| 1822 | OS << "\" Setter=\""; |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 1823 | if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter()) |
| 1824 | OS << Setter->getSelector().getAsString(); |
| 1825 | else |
| 1826 | OS << "(null)"; |
| 1827 | OS << "\""; |
| 1828 | } else { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1829 | OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"'; |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 1830 | } |
Fariborz Jahanian | 5daf570 | 2008-11-22 18:39:36 +0000 | [diff] [blame] | 1831 | |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 1832 | if (Node->isSuperReceiver()) |
| 1833 | OS << " super"; |
Argyrios Kyrtzidis | b085d89 | 2012-03-30 00:19:18 +0000 | [diff] [blame] | 1834 | |
| 1835 | OS << " Messaging="; |
| 1836 | if (Node->isMessagingGetter() && Node->isMessagingSetter()) |
| 1837 | OS << "Getter&Setter"; |
| 1838 | else if (Node->isMessagingGetter()) |
| 1839 | OS << "Getter"; |
| 1840 | else if (Node->isMessagingSetter()) |
| 1841 | OS << "Setter"; |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1844 | void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1845 | VisitExpr(Node); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1846 | if (Node->isArraySubscriptRefExpr()) |
| 1847 | OS << " Kind=ArraySubscript GetterForArray=\""; |
| 1848 | else |
| 1849 | OS << " Kind=DictionarySubscript GetterForDictionary=\""; |
| 1850 | if (Node->getAtIndexMethodDecl()) |
| 1851 | OS << Node->getAtIndexMethodDecl()->getSelector().getAsString(); |
| 1852 | else |
| 1853 | OS << "(null)"; |
Alexander Kornienko | 21c8b19 | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 1854 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1855 | if (Node->isArraySubscriptRefExpr()) |
| 1856 | OS << "\" SetterForArray=\""; |
| 1857 | else |
| 1858 | OS << "\" SetterForDictionary=\""; |
| 1859 | if (Node->setAtIndexMethodDecl()) |
| 1860 | OS << Node->setAtIndexMethodDecl()->getSelector().getAsString(); |
| 1861 | else |
| 1862 | OS << "(null)"; |
| 1863 | } |
| 1864 | |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 1865 | void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) { |
Alexander Kornienko | d5bc359 | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 1866 | VisitExpr(Node); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1867 | OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no"); |
| 1868 | } |
| 1869 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1870 | //===----------------------------------------------------------------------===// |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 1871 | // Comments |
| 1872 | //===----------------------------------------------------------------------===// |
| 1873 | |
| 1874 | const char *ASTDumper::getCommandName(unsigned CommandID) { |
| 1875 | if (Traits) |
| 1876 | return Traits->getCommandInfo(CommandID)->Name; |
| 1877 | const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID); |
| 1878 | if (Info) |
| 1879 | return Info->Name; |
| 1880 | return "<not a builtin command>"; |
| 1881 | } |
| 1882 | |
| 1883 | void ASTDumper::dumpFullComment(const FullComment *C) { |
| 1884 | if (!C) |
| 1885 | return; |
| 1886 | |
| 1887 | FC = C; |
| 1888 | dumpComment(C); |
| 1889 | FC = 0; |
| 1890 | } |
| 1891 | |
| 1892 | void ASTDumper::dumpComment(const Comment *C) { |
| 1893 | IndentScope Indent(*this); |
| 1894 | |
| 1895 | if (!C) { |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1896 | ColorScope Color(*this, NullColor); |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 1897 | OS << "<<<NULL>>>"; |
| 1898 | return; |
| 1899 | } |
| 1900 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1901 | { |
| 1902 | ColorScope Color(*this, CommentColor); |
| 1903 | OS << C->getCommentKindName(); |
| 1904 | } |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 1905 | dumpPointer(C); |
| 1906 | dumpSourceRange(C->getSourceRange()); |
| 1907 | ConstCommentVisitor<ASTDumper>::visit(C); |
| 1908 | for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1909 | I != E; ++I) { |
| 1910 | if (I + 1 == E) |
| 1911 | lastChild(); |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 1912 | dumpComment(*I); |
Richard Trieu | e8d4119 | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 1913 | } |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | void ASTDumper::visitTextComment(const TextComment *C) { |
| 1917 | OS << " Text=\"" << C->getText() << "\""; |
| 1918 | } |
| 1919 | |
| 1920 | void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) { |
| 1921 | OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""; |
| 1922 | switch (C->getRenderKind()) { |
| 1923 | case InlineCommandComment::RenderNormal: |
| 1924 | OS << " RenderNormal"; |
| 1925 | break; |
| 1926 | case InlineCommandComment::RenderBold: |
| 1927 | OS << " RenderBold"; |
| 1928 | break; |
| 1929 | case InlineCommandComment::RenderMonospaced: |
| 1930 | OS << " RenderMonospaced"; |
| 1931 | break; |
| 1932 | case InlineCommandComment::RenderEmphasized: |
| 1933 | OS << " RenderEmphasized"; |
| 1934 | break; |
| 1935 | } |
| 1936 | |
| 1937 | for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) |
| 1938 | OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\""; |
| 1939 | } |
| 1940 | |
| 1941 | void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) { |
| 1942 | OS << " Name=\"" << C->getTagName() << "\""; |
| 1943 | if (C->getNumAttrs() != 0) { |
| 1944 | OS << " Attrs: "; |
| 1945 | for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) { |
| 1946 | const HTMLStartTagComment::Attribute &Attr = C->getAttr(i); |
| 1947 | OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\""; |
| 1948 | } |
| 1949 | } |
| 1950 | if (C->isSelfClosing()) |
| 1951 | OS << " SelfClosing"; |
| 1952 | } |
| 1953 | |
| 1954 | void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) { |
| 1955 | OS << " Name=\"" << C->getTagName() << "\""; |
| 1956 | } |
| 1957 | |
| 1958 | void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) { |
| 1959 | OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""; |
| 1960 | for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) |
| 1961 | OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\""; |
| 1962 | } |
| 1963 | |
| 1964 | void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) { |
| 1965 | OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection()); |
| 1966 | |
| 1967 | if (C->isDirectionExplicit()) |
| 1968 | OS << " explicitly"; |
| 1969 | else |
| 1970 | OS << " implicitly"; |
| 1971 | |
| 1972 | if (C->hasParamName()) { |
| 1973 | if (C->isParamIndexValid()) |
| 1974 | OS << " Param=\"" << C->getParamName(FC) << "\""; |
| 1975 | else |
| 1976 | OS << " Param=\"" << C->getParamNameAsWritten() << "\""; |
| 1977 | } |
| 1978 | |
| 1979 | if (C->isParamIndexValid()) |
| 1980 | OS << " ParamIndex=" << C->getParamIndex(); |
| 1981 | } |
| 1982 | |
| 1983 | void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) { |
| 1984 | if (C->hasParamName()) { |
| 1985 | if (C->isPositionValid()) |
| 1986 | OS << " Param=\"" << C->getParamName(FC) << "\""; |
| 1987 | else |
| 1988 | OS << " Param=\"" << C->getParamNameAsWritten() << "\""; |
| 1989 | } |
| 1990 | |
| 1991 | if (C->isPositionValid()) { |
| 1992 | OS << " Position=<"; |
| 1993 | for (unsigned i = 0, e = C->getDepth(); i != e; ++i) { |
| 1994 | OS << C->getIndex(i); |
| 1995 | if (i != e - 1) |
| 1996 | OS << ", "; |
| 1997 | } |
| 1998 | OS << ">"; |
| 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) { |
| 2003 | OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"" |
| 2004 | " CloseName=\"" << C->getCloseName() << "\""; |
| 2005 | } |
| 2006 | |
| 2007 | void ASTDumper::visitVerbatimBlockLineComment( |
| 2008 | const VerbatimBlockLineComment *C) { |
| 2009 | OS << " Text=\"" << C->getText() << "\""; |
| 2010 | } |
| 2011 | |
| 2012 | void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) { |
| 2013 | OS << " Text=\"" << C->getText() << "\""; |
| 2014 | } |
| 2015 | |
| 2016 | //===----------------------------------------------------------------------===// |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 2017 | // Decl method implementations |
| 2018 | //===----------------------------------------------------------------------===// |
| 2019 | |
| 2020 | void Decl::dump() const { |
| 2021 | dump(llvm::errs()); |
| 2022 | } |
| 2023 | |
| 2024 | void Decl::dump(raw_ostream &OS) const { |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 2025 | ASTDumper P(OS, &getASTContext().getCommentCommandTraits(), |
| 2026 | &getASTContext().getSourceManager()); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 2027 | P.dumpDecl(this); |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 2028 | } |
| 2029 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 2030 | void Decl::dumpColor() const { |
| 2031 | ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(), |
| 2032 | &getASTContext().getSourceManager(), /*ShowColors*/true); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 2033 | P.dumpDecl(this); |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 2034 | } |
Richard Smith | 6e322c0 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 2035 | |
| 2036 | void DeclContext::dumpLookups() const { |
Richard Smith | ab297cc | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 2037 | dumpLookups(llvm::errs()); |
| 2038 | } |
| 2039 | |
| 2040 | void DeclContext::dumpLookups(raw_ostream &OS) const { |
Richard Smith | 6e322c0 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 2041 | const DeclContext *DC = this; |
| 2042 | while (!DC->isTranslationUnit()) |
| 2043 | DC = DC->getParent(); |
| 2044 | ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext(); |
Richard Smith | ab297cc | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 2045 | ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager()); |
Richard Smith | 6e322c0 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 2046 | P.dumpLookups(this); |
| 2047 | } |
| 2048 | |
Alexander Kornienko | d538ed9 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 2049 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 2050 | // Stmt method implementations |
| 2051 | //===----------------------------------------------------------------------===// |
| 2052 | |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 2053 | void Stmt::dump(SourceManager &SM) const { |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 2054 | dump(llvm::errs(), SM); |
| 2055 | } |
| 2056 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2057 | void Stmt::dump(raw_ostream &OS, SourceManager &SM) const { |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 2058 | ASTDumper P(OS, 0, &SM); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 2059 | P.dumpStmt(this); |
Chris Lattner | 0c727a3 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 2062 | void Stmt::dump() const { |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 2063 | ASTDumper P(llvm::errs(), 0, 0); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 2064 | P.dumpStmt(this); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 2065 | } |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 2066 | |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 2067 | void Stmt::dumpColor() const { |
| 2068 | ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true); |
Alexander Kornienko | ae54121 | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 2069 | P.dumpStmt(this); |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 2072 | //===----------------------------------------------------------------------===// |
| 2073 | // Comment method implementations |
| 2074 | //===----------------------------------------------------------------------===// |
| 2075 | |
| 2076 | void Comment::dump() const { |
| 2077 | dump(llvm::errs(), 0, 0); |
| 2078 | } |
| 2079 | |
| 2080 | void Comment::dump(const ASTContext &Context) const { |
| 2081 | dump(llvm::errs(), &Context.getCommentCommandTraits(), |
| 2082 | &Context.getSourceManager()); |
| 2083 | } |
| 2084 | |
Alexander Kornienko | 51ccafd | 2013-01-15 12:20:21 +0000 | [diff] [blame] | 2085 | void Comment::dump(raw_ostream &OS, const CommandTraits *Traits, |
Alexander Kornienko | acd356e | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 2086 | const SourceManager *SM) const { |
| 2087 | const FullComment *FC = dyn_cast<FullComment>(this); |
| 2088 | ASTDumper D(OS, Traits, SM); |
| 2089 | D.dumpFullComment(FC); |
| 2090 | } |
Richard Trieu | 7ba443a | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 2091 | |
| 2092 | void Comment::dumpColor() const { |
| 2093 | const FullComment *FC = dyn_cast<FullComment>(this); |
| 2094 | ASTDumper D(llvm::errs(), 0, 0, /*ShowColors*/true); |
| 2095 | D.dumpFullComment(FC); |
| 2096 | } |