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