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