| Alexander Kornienko | 18ec81b | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 1 | //===--- ASTDumper.cpp - Dumping implementation for ASTs ------------------===// |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| Alexander Kornienko | 18ec81b | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 9 | // This file implements the AST dump methods, which dump out the |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 10 | // AST in a form that exposes type details and other fields. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
| Stephen Kelly | 0da68ba | 2018-12-05 20:53:14 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTDumperUtils.h" |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 16 | #include "clang/AST/Attr.h" |
| Stephen Kelly | db8fac1 | 2019-01-11 19:16:01 +0000 | [diff] [blame] | 17 | #include "clang/AST/AttrVisitor.h" |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 18 | #include "clang/AST/CommentVisitor.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclLookups.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclObjC.h" |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclOpenMP.h" |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclVisitor.h" |
| Benjamin Kramer | 31b382e | 2016-02-01 17:42:01 +0000 | [diff] [blame] | 24 | #include "clang/AST/LocInfoType.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 25 | #include "clang/AST/StmtVisitor.h" |
| Stephen Kelly | 63a6f3a | 2019-01-12 16:35:37 +0000 | [diff] [blame] | 26 | #include "clang/AST/TemplateArgumentVisitor.h" |
| Stephen Kelly | d8744a7 | 2018-12-05 21:12:39 +0000 | [diff] [blame] | 27 | #include "clang/AST/TextNodeDumper.h" |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 28 | #include "clang/AST/TypeVisitor.h" |
| David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 29 | #include "clang/Basic/Builtins.h" |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 30 | #include "clang/Basic/Module.h" |
| Chris Lattner | 11e30d3 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 31 | #include "clang/Basic/SourceManager.h" |
| Daniel Dunbar | 34a96c8 | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 32 | #include "llvm/Support/raw_ostream.h" |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 33 | using namespace clang; |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 34 | using namespace clang::comments; |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 35 | |
| 36 | //===----------------------------------------------------------------------===// |
| Alexander Kornienko | 18ec81b | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 37 | // ASTDumper Visitor |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 38 | //===----------------------------------------------------------------------===// |
| 39 | |
| 40 | namespace { |
| Stephen Kelly | 27e948c | 2018-11-29 19:30:37 +0000 | [diff] [blame] | 41 | |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 42 | class ASTDumper |
| Stephen Kelly | cdbfb30 | 2018-12-02 17:30:40 +0000 | [diff] [blame] | 43 | : public ConstDeclVisitor<ASTDumper>, |
| 44 | public ConstStmtVisitor<ASTDumper>, |
| 45 | public ConstCommentVisitor<ASTDumper, void, const FullComment *>, |
| Stephen Kelly | db8fac1 | 2019-01-11 19:16:01 +0000 | [diff] [blame] | 46 | public TypeVisitor<ASTDumper>, |
| Stephen Kelly | 63a6f3a | 2019-01-12 16:35:37 +0000 | [diff] [blame] | 47 | public ConstAttrVisitor<ASTDumper>, |
| 48 | public ConstTemplateArgumentVisitor<ASTDumper> { |
| Stephen Kelly | cdbfb30 | 2018-12-02 17:30:40 +0000 | [diff] [blame] | 49 | |
| Stephen Kelly | d8744a7 | 2018-12-05 21:12:39 +0000 | [diff] [blame] | 50 | TextNodeDumper NodeDumper; |
| Stephen Kelly | 0da68ba | 2018-12-05 20:53:14 +0000 | [diff] [blame] | 51 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 52 | raw_ostream &OS; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 54 | /// Indicates whether we should trigger deserialization of nodes that had |
| 55 | /// not already been loaded. |
| 56 | bool Deserialize = false; |
| 57 | |
| Stephen Kelly | e66308b | 2018-11-29 19:30:08 +0000 | [diff] [blame] | 58 | const bool ShowColors; |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 59 | |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 60 | public: |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 61 | ASTDumper(raw_ostream &OS, const CommandTraits *Traits, |
| 62 | const SourceManager *SM) |
| Aaron Ballman | 8c20828 | 2017-12-21 21:42:42 +0000 | [diff] [blame] | 63 | : ASTDumper(OS, Traits, SM, |
| 64 | SM && SM->getDiagnostics().getShowColors()) {} |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 65 | |
| 66 | ASTDumper(raw_ostream &OS, const CommandTraits *Traits, |
| 67 | const SourceManager *SM, bool ShowColors) |
| Aaron Ballman | 8c20828 | 2017-12-21 21:42:42 +0000 | [diff] [blame] | 68 | : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {} |
| 69 | ASTDumper(raw_ostream &OS, const CommandTraits *Traits, |
| 70 | const SourceManager *SM, bool ShowColors, |
| 71 | const PrintingPolicy &PrintPolicy) |
| Stephen Kelly | b6d674f | 2019-01-08 22:32:48 +0000 | [diff] [blame] | 72 | : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS), |
| Stephen Kelly | b6318c9 | 2019-01-30 19:32:48 +0000 | [diff] [blame] | 73 | ShowColors(ShowColors) {} |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 74 | |
| 75 | void setDeserialize(bool D) { Deserialize = D; } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 76 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 77 | void dumpDecl(const Decl *D); |
| Stephen Kelly | 0df805d | 2019-01-11 19:11:17 +0000 | [diff] [blame] | 78 | void dumpStmt(const Stmt *S, StringRef Label = {}); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 79 | |
| Richard Trieu | de5cc7d | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 80 | // Utilities |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 81 | void dumpTypeAsChild(QualType T); |
| 82 | void dumpTypeAsChild(const Type *T); |
| Alexander Kornienko | 787f4c3 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 83 | void dumpDeclContext(const DeclContext *DC); |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 84 | void dumpLookups(const DeclContext *DC, bool DumpDecls); |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 85 | void dumpAttr(const Attr *A); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 86 | |
| 87 | // C++ Utilities |
| Alexander Kornienko | 787f4c3 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 88 | void dumpCXXCtorInitializer(const CXXCtorInitializer *Init); |
| 89 | void dumpTemplateParameters(const TemplateParameterList *TPL); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 90 | void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI); |
| Stephen Kelly | 4383595 | 2018-12-10 21:03:00 +0000 | [diff] [blame] | 91 | void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A, |
| 92 | const Decl *From = nullptr, |
| Stephen Kelly | 1be0bea | 2018-12-10 21:04:04 +0000 | [diff] [blame] | 93 | const char *Label = nullptr); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 94 | void dumpTemplateArgumentList(const TemplateArgumentList &TAL); |
| 95 | void dumpTemplateArgument(const TemplateArgument &A, |
| Stephen Kelly | 4383595 | 2018-12-10 21:03:00 +0000 | [diff] [blame] | 96 | SourceRange R = SourceRange(), |
| 97 | const Decl *From = nullptr, |
| Stephen Kelly | 1be0bea | 2018-12-10 21:04:04 +0000 | [diff] [blame] | 98 | const char *Label = nullptr); |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 99 | template <typename SpecializationDecl> |
| 100 | void dumpTemplateDeclSpecialization(const SpecializationDecl *D, |
| 101 | bool DumpExplicitInst, |
| 102 | bool DumpRefOnly); |
| 103 | template <typename TemplateDecl> |
| 104 | void dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 105 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 106 | // Objective-C utilities. |
| 107 | void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams); |
| 108 | |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 109 | // Types |
| 110 | void VisitComplexType(const ComplexType *T) { |
| 111 | dumpTypeAsChild(T->getElementType()); |
| 112 | } |
| Stephen Kelly | bc2438d | 2019-01-14 20:13:09 +0000 | [diff] [blame] | 113 | void VisitLocInfoType(const LocInfoType *T) { |
| 114 | dumpTypeAsChild(T->getTypeSourceInfo()->getType()); |
| 115 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 116 | void VisitPointerType(const PointerType *T) { |
| 117 | dumpTypeAsChild(T->getPointeeType()); |
| 118 | } |
| 119 | void VisitBlockPointerType(const BlockPointerType *T) { |
| 120 | dumpTypeAsChild(T->getPointeeType()); |
| 121 | } |
| 122 | void VisitReferenceType(const ReferenceType *T) { |
| 123 | dumpTypeAsChild(T->getPointeeType()); |
| 124 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 125 | void VisitMemberPointerType(const MemberPointerType *T) { |
| 126 | dumpTypeAsChild(T->getClass()); |
| 127 | dumpTypeAsChild(T->getPointeeType()); |
| 128 | } |
| 129 | void VisitArrayType(const ArrayType *T) { |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 130 | dumpTypeAsChild(T->getElementType()); |
| 131 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 132 | void VisitVariableArrayType(const VariableArrayType *T) { |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 133 | VisitArrayType(T); |
| 134 | dumpStmt(T->getSizeExpr()); |
| 135 | } |
| 136 | void VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
| Stephen Kelly | ec42aa0 | 2018-12-05 20:34:07 +0000 | [diff] [blame] | 137 | dumpTypeAsChild(T->getElementType()); |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 138 | dumpStmt(T->getSizeExpr()); |
| 139 | } |
| 140 | void VisitDependentSizedExtVectorType( |
| 141 | const DependentSizedExtVectorType *T) { |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 142 | dumpTypeAsChild(T->getElementType()); |
| 143 | dumpStmt(T->getSizeExpr()); |
| 144 | } |
| 145 | void VisitVectorType(const VectorType *T) { |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 146 | dumpTypeAsChild(T->getElementType()); |
| 147 | } |
| 148 | void VisitFunctionType(const FunctionType *T) { |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 149 | dumpTypeAsChild(T->getReturnType()); |
| 150 | } |
| 151 | void VisitFunctionProtoType(const FunctionProtoType *T) { |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 152 | VisitFunctionType(T); |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 153 | for (const QualType &PT : T->getParamTypes()) |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 154 | dumpTypeAsChild(PT); |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 155 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 156 | void VisitTypeOfExprType(const TypeOfExprType *T) { |
| 157 | dumpStmt(T->getUnderlyingExpr()); |
| 158 | } |
| 159 | void VisitDecltypeType(const DecltypeType *T) { |
| 160 | dumpStmt(T->getUnderlyingExpr()); |
| 161 | } |
| 162 | void VisitUnaryTransformType(const UnaryTransformType *T) { |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 163 | dumpTypeAsChild(T->getBaseType()); |
| 164 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 165 | void VisitAttributedType(const AttributedType *T) { |
| 166 | // FIXME: AttrKind |
| 167 | dumpTypeAsChild(T->getModifiedType()); |
| 168 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 169 | void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) { |
| 170 | dumpTypeAsChild(T->getReplacedParameter()); |
| 171 | } |
| 172 | void VisitSubstTemplateTypeParmPackType( |
| 173 | const SubstTemplateTypeParmPackType *T) { |
| 174 | dumpTypeAsChild(T->getReplacedParameter()); |
| 175 | dumpTemplateArgument(T->getArgumentPack()); |
| 176 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 177 | void VisitTemplateSpecializationType(const TemplateSpecializationType *T) { |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 178 | for (const auto &Arg : *T) |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 179 | dumpTemplateArgument(Arg); |
| 180 | if (T->isTypeAlias()) |
| 181 | dumpTypeAsChild(T->getAliasedType()); |
| 182 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 183 | void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
| 184 | dumpTypeAsChild(T->getPointeeType()); |
| 185 | } |
| 186 | void VisitAtomicType(const AtomicType *T) { |
| 187 | dumpTypeAsChild(T->getValueType()); |
| 188 | } |
| Xiuli Pan | 2d12e65 | 2016-05-03 05:37:07 +0000 | [diff] [blame] | 189 | void VisitPipeType(const PipeType *T) { |
| 190 | dumpTypeAsChild(T->getElementType()); |
| 191 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 192 | void VisitAdjustedType(const AdjustedType *T) { |
| 193 | dumpTypeAsChild(T->getOriginalType()); |
| 194 | } |
| 195 | void VisitPackExpansionType(const PackExpansionType *T) { |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 196 | if (!T->isSugared()) |
| 197 | dumpTypeAsChild(T->getPattern()); |
| 198 | } |
| 199 | // FIXME: ElaboratedType, DependentNameType, |
| 200 | // DependentTemplateSpecializationType, ObjCObjectType |
| 201 | |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 202 | // Decls |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 203 | void VisitTypedefDecl(const TypedefDecl *D); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 204 | void VisitEnumConstantDecl(const EnumConstantDecl *D); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 205 | void VisitFunctionDecl(const FunctionDecl *D); |
| 206 | void VisitFieldDecl(const FieldDecl *D); |
| 207 | void VisitVarDecl(const VarDecl *D); |
| Richard Smith | bdb84f3 | 2016-07-22 23:36:59 +0000 | [diff] [blame] | 208 | void VisitDecompositionDecl(const DecompositionDecl *D); |
| Richard Smith | 7873de0 | 2016-08-11 22:25:46 +0000 | [diff] [blame] | 209 | void VisitBindingDecl(const BindingDecl *D); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 210 | void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D); |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 211 | void VisitCapturedDecl(const CapturedDecl *D); |
| 212 | |
| 213 | // OpenMP decls |
| 214 | void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D); |
| 215 | void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D); |
| 216 | void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 217 | |
| 218 | // C++ Decls |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 219 | void VisitTypeAliasDecl(const TypeAliasDecl *D); |
| 220 | void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 221 | void VisitStaticAssertDecl(const StaticAssertDecl *D); |
| 222 | void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D); |
| 223 | void VisitClassTemplateDecl(const ClassTemplateDecl *D); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 224 | void VisitClassTemplateSpecializationDecl( |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 225 | const ClassTemplateSpecializationDecl *D); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 226 | void VisitClassTemplatePartialSpecializationDecl( |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 227 | const ClassTemplatePartialSpecializationDecl *D); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 228 | void VisitClassScopeFunctionSpecializationDecl( |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 229 | const ClassScopeFunctionSpecializationDecl *D); |
| David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 230 | void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D); |
| Richard Smith | d25789a | 2013-09-18 01:36:02 +0000 | [diff] [blame] | 231 | void VisitVarTemplateDecl(const VarTemplateDecl *D); |
| 232 | void VisitVarTemplateSpecializationDecl( |
| 233 | const VarTemplateSpecializationDecl *D); |
| 234 | void VisitVarTemplatePartialSpecializationDecl( |
| 235 | const VarTemplatePartialSpecializationDecl *D); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 236 | void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D); |
| 237 | void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D); |
| 238 | void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 239 | void VisitUsingShadowDecl(const UsingShadowDecl *D); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 240 | void VisitFriendDecl(const FriendDecl *D); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 241 | |
| 242 | // ObjC Decls |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 243 | void VisitObjCMethodDecl(const ObjCMethodDecl *D); |
| 244 | void VisitObjCCategoryDecl(const ObjCCategoryDecl *D); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 245 | void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D); |
| 246 | void VisitObjCImplementationDecl(const ObjCImplementationDecl *D); |
| Stephen Kelly | fbf424e | 2019-01-15 20:41:37 +0000 | [diff] [blame] | 247 | void Visit(const BlockDecl::Capture &C); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 248 | void VisitBlockDecl(const BlockDecl *D); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
| Chris Lattner | 84ca376 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 250 | // Stmts. |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 251 | void VisitDeclStmt(const DeclStmt *Node); |
| 252 | void VisitAttributedStmt(const AttributedStmt *Node); |
| Pavel Labath | 1ef8342 | 2013-09-04 14:35:00 +0000 | [diff] [blame] | 253 | void VisitCXXCatchStmt(const CXXCatchStmt *Node); |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 254 | void VisitCapturedStmt(const CapturedStmt *Node); |
| 255 | |
| 256 | // OpenMP |
| Stephen Kelly | 3cdd1a7 | 2019-01-15 20:31:31 +0000 | [diff] [blame] | 257 | void Visit(const OMPClause *C); |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 258 | void VisitOMPExecutableDirective(const OMPExecutableDirective *Node); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 259 | |
| Chris Lattner | 84ca376 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 260 | // Exprs |
| Richard Smith | f051496 | 2014-06-03 08:24:28 +0000 | [diff] [blame] | 261 | void VisitInitListExpr(const InitListExpr *ILE); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 262 | void VisitBlockExpr(const BlockExpr *Node); |
| 263 | void VisitOpaqueValueExpr(const OpaqueValueExpr *Node); |
| Stephen Kelly | fbf40f4 | 2019-01-29 22:22:55 +0000 | [diff] [blame] | 264 | void Visit(const GenericSelectionExpr::ConstAssociation &A); |
| Richard Smith | 01ccebf | 2018-01-05 21:31:07 +0000 | [diff] [blame] | 265 | void VisitGenericSelectionExpr(const GenericSelectionExpr *E); |
| Chris Lattner | 84ca376 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 266 | |
| 267 | // C++ |
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 268 | void VisitLambdaExpr(const LambdaExpr *Node) { |
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 269 | dumpDecl(Node->getLambdaClass()); |
| 270 | } |
| Serge Pavlov | 6b92603 | 2015-02-16 19:58:41 +0000 | [diff] [blame] | 271 | void VisitSizeOfPackExpr(const SizeOfPackExpr *Node); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
| Chris Lattner | 84ca376 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 273 | // ObjC |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 274 | void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node); |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 275 | |
| 276 | // Comments. |
| Stephen Kelly | cdbfb30 | 2018-12-02 17:30:40 +0000 | [diff] [blame] | 277 | void dumpComment(const Comment *C, const FullComment *FC); |
| Stephen Kelly | db8fac1 | 2019-01-11 19:16:01 +0000 | [diff] [blame] | 278 | |
| Stephen Kelly | 63a6f3a | 2019-01-12 16:35:37 +0000 | [diff] [blame] | 279 | void VisitExpressionTemplateArgument(const TemplateArgument &TA) { |
| 280 | dumpStmt(TA.getAsExpr()); |
| 281 | } |
| 282 | void VisitPackTemplateArgument(const TemplateArgument &TA) { |
| Stephen Kelly | 4b5e7cd | 2019-01-14 19:50:34 +0000 | [diff] [blame] | 283 | for (const auto &TArg : TA.pack_elements()) |
| Stephen Kelly | 63a6f3a | 2019-01-12 16:35:37 +0000 | [diff] [blame] | 284 | dumpTemplateArgument(TArg); |
| 285 | } |
| 286 | |
| Stephen Kelly | db8fac1 | 2019-01-11 19:16:01 +0000 | [diff] [blame] | 287 | // Implements Visit methods for Attrs. |
| 288 | #include "clang/AST/AttrNodeTraverse.inc" |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 289 | }; |
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 290 | } |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 291 | |
| 292 | //===----------------------------------------------------------------------===// |
| Chris Lattner | 11e30d3 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 293 | // Utilities |
| 294 | //===----------------------------------------------------------------------===// |
| 295 | |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 296 | void ASTDumper::dumpTypeAsChild(QualType T) { |
| 297 | SplitQualType SQT = T.split(); |
| 298 | if (!SQT.Quals.hasQualifiers()) |
| 299 | return dumpTypeAsChild(SQT.Ty); |
| 300 | |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 301 | NodeDumper.AddChild([=] { |
| Stephen Kelly | 58c6504 | 2019-01-14 20:15:29 +0000 | [diff] [blame] | 302 | NodeDumper.Visit(T); |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 303 | dumpTypeAsChild(T.split().Ty); |
| 304 | }); |
| 305 | } |
| 306 | |
| 307 | void ASTDumper::dumpTypeAsChild(const Type *T) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 308 | NodeDumper.AddChild([=] { |
| Stephen Kelly | 449fa76 | 2019-01-14 20:11:02 +0000 | [diff] [blame] | 309 | NodeDumper.Visit(T); |
| 310 | if (!T) |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 311 | return; |
| Stephen Kelly | 449fa76 | 2019-01-14 20:11:02 +0000 | [diff] [blame] | 312 | TypeVisitor<ASTDumper>::Visit(T); |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 313 | |
| 314 | QualType SingleStepDesugar = |
| 315 | T->getLocallyUnqualifiedSingleStepDesugaredType(); |
| 316 | if (SingleStepDesugar != QualType(T, 0)) |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 317 | dumpTypeAsChild(SingleStepDesugar); |
| 318 | }); |
| 319 | } |
| 320 | |
| Alexander Kornienko | 787f4c3 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 321 | void ASTDumper::dumpDeclContext(const DeclContext *DC) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 322 | if (!DC) |
| 323 | return; |
| Richard Smith | dcc2c45 | 2014-03-17 23:00:06 +0000 | [diff] [blame] | 324 | |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 325 | for (const auto *D : (Deserialize ? DC->decls() : DC->noload_decls())) |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 326 | dumpDecl(D); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 329 | void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 330 | NodeDumper.AddChild([=] { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 331 | OS << "StoredDeclsMap "; |
| Stephen Kelly | d8744a7 | 2018-12-05 21:12:39 +0000 | [diff] [blame] | 332 | NodeDumper.dumpBareDeclRef(cast<Decl>(DC)); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 333 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 334 | const DeclContext *Primary = DC->getPrimaryContext(); |
| 335 | if (Primary != DC) { |
| 336 | OS << " primary"; |
| Stephen Kelly | d8744a7 | 2018-12-05 21:12:39 +0000 | [diff] [blame] | 337 | NodeDumper.dumpPointer(cast<Decl>(Primary)); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 340 | bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage(); |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 341 | |
| Sam McCall | 091b1ef | 2018-01-16 12:33:46 +0000 | [diff] [blame] | 342 | auto Range = Deserialize |
| 343 | ? Primary->lookups() |
| 344 | : Primary->noload_lookups(/*PreserveInternalState=*/true); |
| 345 | for (auto I = Range.begin(), E = Range.end(); I != E; ++I) { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 346 | DeclarationName Name = I.getLookupName(); |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 347 | DeclContextLookupResult R = *I; |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 348 | |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 349 | NodeDumper.AddChild([=] { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 350 | OS << "DeclarationName "; |
| 351 | { |
| Stephen Kelly | 27e948c | 2018-11-29 19:30:37 +0000 | [diff] [blame] | 352 | ColorScope Color(OS, ShowColors, DeclNameColor); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 353 | OS << '\'' << Name << '\''; |
| 354 | } |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 355 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 356 | for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end(); |
| 357 | RI != RE; ++RI) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 358 | NodeDumper.AddChild([=] { |
| Stephen Kelly | d8744a7 | 2018-12-05 21:12:39 +0000 | [diff] [blame] | 359 | NodeDumper.dumpBareDeclRef(*RI); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 360 | |
| 361 | if ((*RI)->isHidden()) |
| 362 | OS << " hidden"; |
| 363 | |
| 364 | // If requested, dump the redecl chain for this lookup. |
| 365 | if (DumpDecls) { |
| 366 | // Dump earliest decl first. |
| 367 | std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) { |
| 368 | if (Decl *Prev = D->getPreviousDecl()) |
| 369 | DumpWithPrev(Prev); |
| 370 | dumpDecl(D); |
| 371 | }; |
| 372 | DumpWithPrev(*RI); |
| 373 | } |
| 374 | }); |
| 375 | } |
| 376 | }); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 377 | } |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 378 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 379 | if (HasUndeserializedLookups) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 380 | NodeDumper.AddChild([=] { |
| Stephen Kelly | 27e948c | 2018-11-29 19:30:37 +0000 | [diff] [blame] | 381 | ColorScope Color(OS, ShowColors, UndeserializedColor); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 382 | OS << "<undeserialized lookups>"; |
| 383 | }); |
| 384 | } |
| 385 | }); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 388 | void ASTDumper::dumpAttr(const Attr *A) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 389 | NodeDumper.AddChild([=] { |
| Stephen Kelly | db8fac1 | 2019-01-11 19:16:01 +0000 | [diff] [blame] | 390 | NodeDumper.Visit(A); |
| 391 | ConstAttrVisitor<ASTDumper>::Visit(A); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 392 | }); |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 395 | //===----------------------------------------------------------------------===// |
| 396 | // C++ Utilities |
| 397 | //===----------------------------------------------------------------------===// |
| 398 | |
| Alexander Kornienko | 787f4c3 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 399 | void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 400 | NodeDumper.AddChild([=] { |
| Stephen Kelly | 0e050fa | 2019-01-15 20:17:33 +0000 | [diff] [blame] | 401 | NodeDumper.Visit(Init); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 402 | dumpStmt(Init->getInit()); |
| 403 | }); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| Alexander Kornienko | 787f4c3 | 2012-12-20 11:08:38 +0000 | [diff] [blame] | 406 | void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 407 | if (!TPL) |
| 408 | return; |
| 409 | |
| Stephen Kelly | 8805f67 | 2019-01-19 09:57:59 +0000 | [diff] [blame] | 410 | for (const auto &TP : *TPL) |
| 411 | dumpDecl(TP); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | void ASTDumper::dumpTemplateArgumentListInfo( |
| 415 | const TemplateArgumentListInfo &TALI) { |
| Stephen Kelly | 8805f67 | 2019-01-19 09:57:59 +0000 | [diff] [blame] | 416 | for (const auto &TA : TALI.arguments()) |
| 417 | dumpTemplateArgumentLoc(TA); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| Stephen Kelly | 4383595 | 2018-12-10 21:03:00 +0000 | [diff] [blame] | 420 | void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A, |
| Stephen Kelly | 1be0bea | 2018-12-10 21:04:04 +0000 | [diff] [blame] | 421 | const Decl *From, const char *Label) { |
| 422 | dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, Label); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) { |
| 426 | for (unsigned i = 0, e = TAL.size(); i < e; ++i) |
| 427 | dumpTemplateArgument(TAL[i]); |
| 428 | } |
| 429 | |
| Stephen Kelly | 4383595 | 2018-12-10 21:03:00 +0000 | [diff] [blame] | 430 | void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R, |
| Stephen Kelly | 1be0bea | 2018-12-10 21:04:04 +0000 | [diff] [blame] | 431 | const Decl *From, const char *Label) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 432 | NodeDumper.AddChild([=] { |
| Stephen Kelly | 63a6f3a | 2019-01-12 16:35:37 +0000 | [diff] [blame] | 433 | NodeDumper.Visit(A, R, From, Label); |
| 434 | ConstTemplateArgumentVisitor<ASTDumper>::Visit(A); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 435 | }); |
| Alexander Kornienko | 61c93bd | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| Chris Lattner | 11e30d3 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 438 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 439 | // Objective-C Utilities |
| 440 | //===----------------------------------------------------------------------===// |
| 441 | void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) { |
| 442 | if (!typeParams) |
| 443 | return; |
| 444 | |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 445 | for (const auto &typeParam : *typeParams) { |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 446 | dumpDecl(typeParam); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | //===----------------------------------------------------------------------===// |
| Alexander Kornienko | 61c93bd | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 451 | // Decl dumping methods. |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 452 | //===----------------------------------------------------------------------===// |
| 453 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 454 | void ASTDumper::dumpDecl(const Decl *D) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 455 | NodeDumper.AddChild([=] { |
| Stephen Kelly | d83fe89 | 2019-01-15 09:35:52 +0000 | [diff] [blame] | 456 | NodeDumper.Visit(D); |
| 457 | if (!D) |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 458 | return; |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 459 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 460 | ConstDeclVisitor<ASTDumper>::Visit(D); |
| Richard Trieu | de5cc7d | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 461 | |
| Stephen Kelly | 8805f67 | 2019-01-19 09:57:59 +0000 | [diff] [blame] | 462 | for (const auto &A : D->attrs()) |
| 463 | dumpAttr(A); |
| Richard Trieu | de5cc7d | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 464 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 465 | if (const FullComment *Comment = |
| 466 | D->getASTContext().getLocalCommentForDeclUncached(D)) |
| Stephen Kelly | 570b297 | 2018-12-09 13:18:55 +0000 | [diff] [blame] | 467 | dumpComment(Comment, Comment); |
| Richard Trieu | de5cc7d | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 468 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 469 | // Decls within functions are visited by the body. |
| Stephen Kelly | 39271a1 | 2018-12-09 13:20:43 +0000 | [diff] [blame] | 470 | if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D)) { |
| Stephen Kelly | 1e07f4e | 2019-01-18 22:15:09 +0000 | [diff] [blame] | 471 | if (const auto *DC = dyn_cast<DeclContext>(D)) |
| Stephen Kelly | 39271a1 | 2018-12-09 13:20:43 +0000 | [diff] [blame] | 472 | dumpDeclContext(DC); |
| 473 | } |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 474 | }); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 477 | void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) { |
| Richard Smith | ba3a4f9 | 2016-01-12 21:59:26 +0000 | [diff] [blame] | 478 | dumpTypeAsChild(D->getUnderlyingType()); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 481 | void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 482 | if (const Expr *Init = D->getInitExpr()) |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 483 | dumpStmt(Init); |
| 484 | } |
| 485 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 486 | void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) { |
| Stephen Kelly | e80e4cb | 2019-01-15 23:05:11 +0000 | [diff] [blame] | 487 | if (const auto *FTSI = D->getTemplateSpecializationInfo()) |
| Stephen Kelly | 42d9950 | 2019-01-15 22:50:37 +0000 | [diff] [blame] | 488 | dumpTemplateArgumentList(*FTSI->TemplateArguments); |
| 489 | |
| Stephen Kelly | bbd08cc | 2019-01-18 22:00:16 +0000 | [diff] [blame] | 490 | if (D->param_begin()) |
| 491 | for (const auto *Parameter : D->parameters()) |
| Stephen Kelly | 42d9950 | 2019-01-15 22:50:37 +0000 | [diff] [blame] | 492 | dumpDecl(Parameter); |
| 493 | |
| Stephen Kelly | e80e4cb | 2019-01-15 23:05:11 +0000 | [diff] [blame] | 494 | if (const auto *C = dyn_cast<CXXConstructorDecl>(D)) |
| 495 | for (const auto *I : C->inits()) |
| 496 | dumpCXXCtorInitializer(I); |
| Stephen Kelly | 42d9950 | 2019-01-15 22:50:37 +0000 | [diff] [blame] | 497 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 498 | if (D->doesThisDeclarationHaveABody()) |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 499 | dumpStmt(D->getBody()); |
| 500 | } |
| 501 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 502 | void ASTDumper::VisitFieldDecl(const FieldDecl *D) { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 503 | if (D->isBitField()) |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 504 | dumpStmt(D->getBitWidth()); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 505 | if (Expr *Init = D->getInClassInitializer()) |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 506 | dumpStmt(Init); |
| 507 | } |
| 508 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 509 | void ASTDumper::VisitVarDecl(const VarDecl *D) { |
| Stephen Kelly | b6318c9 | 2019-01-30 19:32:48 +0000 | [diff] [blame] | 510 | if (D->hasInit()) |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 511 | dumpStmt(D->getInit()); |
| 512 | } |
| 513 | |
| Richard Smith | bdb84f3 | 2016-07-22 23:36:59 +0000 | [diff] [blame] | 514 | void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) { |
| 515 | VisitVarDecl(D); |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 516 | for (const auto *B : D->bindings()) |
| Richard Smith | bdb84f3 | 2016-07-22 23:36:59 +0000 | [diff] [blame] | 517 | dumpDecl(B); |
| 518 | } |
| 519 | |
| Richard Smith | 7873de0 | 2016-08-11 22:25:46 +0000 | [diff] [blame] | 520 | void ASTDumper::VisitBindingDecl(const BindingDecl *D) { |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 521 | if (const auto *E = D->getBinding()) |
| Richard Smith | 7873de0 | 2016-08-11 22:25:46 +0000 | [diff] [blame] | 522 | dumpStmt(E); |
| 523 | } |
| 524 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 525 | void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 526 | dumpStmt(D->getAsmString()); |
| 527 | } |
| 528 | |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 529 | void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) { |
| 530 | dumpStmt(D->getBody()); |
| 531 | } |
| 532 | |
| 533 | //===----------------------------------------------------------------------===// |
| 534 | // OpenMP Declarations |
| 535 | //===----------------------------------------------------------------------===// |
| 536 | |
| 537 | void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) { |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 538 | for (const auto *E : D->varlists()) |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 539 | dumpStmt(E); |
| 540 | } |
| 541 | |
| 542 | void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) { |
| Stephen Kelly | 266dc19 | 2018-12-10 20:53:39 +0000 | [diff] [blame] | 543 | dumpStmt(D->getCombiner()); |
| 544 | if (const auto *Initializer = D->getInitializer()) |
| 545 | dumpStmt(Initializer); |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) { |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 549 | dumpStmt(D->getInit()); |
| 550 | } |
| Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 551 | |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 552 | //===----------------------------------------------------------------------===// |
| 553 | // C++ Declarations |
| 554 | //===----------------------------------------------------------------------===// |
| 555 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 556 | void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) { |
| Richard Smith | ba3a4f9 | 2016-01-12 21:59:26 +0000 | [diff] [blame] | 557 | dumpTypeAsChild(D->getUnderlyingType()); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 560 | void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 561 | dumpTemplateParameters(D->getTemplateParameters()); |
| 562 | dumpDecl(D->getTemplatedDecl()); |
| 563 | } |
| 564 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 565 | void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 566 | dumpStmt(D->getAssertExpr()); |
| 567 | dumpStmt(D->getMessage()); |
| 568 | } |
| 569 | |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 570 | template <typename SpecializationDecl> |
| 571 | void ASTDumper::dumpTemplateDeclSpecialization(const SpecializationDecl *D, |
| 572 | bool DumpExplicitInst, |
| 573 | bool DumpRefOnly) { |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 574 | bool DumpedAny = false; |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 575 | for (const auto *RedeclWithBadType : D->redecls()) { |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 576 | // FIXME: The redecls() range sometimes has elements of a less-specific |
| 577 | // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives |
| 578 | // us TagDecls, and should give CXXRecordDecls). |
| 579 | auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType); |
| 580 | if (!Redecl) { |
| 581 | // Found the injected-class-name for a class template. This will be dumped |
| 582 | // as part of its surrounding class so we don't need to dump it here. |
| 583 | assert(isa<CXXRecordDecl>(RedeclWithBadType) && |
| 584 | "expected an injected-class-name"); |
| 585 | continue; |
| 586 | } |
| 587 | |
| 588 | switch (Redecl->getTemplateSpecializationKind()) { |
| 589 | case TSK_ExplicitInstantiationDeclaration: |
| 590 | case TSK_ExplicitInstantiationDefinition: |
| 591 | if (!DumpExplicitInst) |
| 592 | break; |
| Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 593 | LLVM_FALLTHROUGH; |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 594 | case TSK_Undeclared: |
| 595 | case TSK_ImplicitInstantiation: |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 596 | if (DumpRefOnly) |
| Stephen Kelly | d186dbc | 2019-01-08 23:11:24 +0000 | [diff] [blame] | 597 | NodeDumper.dumpDeclRef(Redecl); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 598 | else |
| 599 | dumpDecl(Redecl); |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 600 | DumpedAny = true; |
| 601 | break; |
| 602 | case TSK_ExplicitSpecialization: |
| 603 | break; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | // Ensure we dump at least one decl for each specialization. |
| 608 | if (!DumpedAny) |
| Stephen Kelly | d186dbc | 2019-01-08 23:11:24 +0000 | [diff] [blame] | 609 | NodeDumper.dumpDeclRef(D); |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 612 | template <typename TemplateDecl> |
| 613 | void ASTDumper::dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 614 | dumpTemplateParameters(D->getTemplateParameters()); |
| Richard Smith | dcc2c45 | 2014-03-17 23:00:06 +0000 | [diff] [blame] | 615 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 616 | dumpDecl(D->getTemplatedDecl()); |
| Richard Smith | dcc2c45 | 2014-03-17 23:00:06 +0000 | [diff] [blame] | 617 | |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 618 | for (const auto *Child : D->specializations()) |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 619 | dumpTemplateDeclSpecialization(Child, DumpExplicitInst, |
| 620 | !D->isCanonicalDecl()); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| Richard Smith | 20ade55 | 2014-03-17 23:34:53 +0000 | [diff] [blame] | 623 | void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { |
| 624 | // FIXME: We don't add a declaration of a function template specialization |
| 625 | // to its context when it's explicitly instantiated, so dump explicit |
| 626 | // instantiations when we dump the template itself. |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 627 | dumpTemplateDecl(D, true); |
| Richard Smith | 20ade55 | 2014-03-17 23:34:53 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 630 | void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) { |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 631 | dumpTemplateDecl(D, false); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | void ASTDumper::VisitClassTemplateSpecializationDecl( |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 635 | const ClassTemplateSpecializationDecl *D) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 636 | dumpTemplateArgumentList(D->getTemplateArgs()); |
| 637 | } |
| 638 | |
| 639 | void ASTDumper::VisitClassTemplatePartialSpecializationDecl( |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 640 | const ClassTemplatePartialSpecializationDecl *D) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 641 | VisitClassTemplateSpecializationDecl(D); |
| 642 | dumpTemplateParameters(D->getTemplateParameters()); |
| 643 | } |
| 644 | |
| 645 | void ASTDumper::VisitClassScopeFunctionSpecializationDecl( |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 646 | const ClassScopeFunctionSpecializationDecl *D) { |
| Richard Smith | c660c8f | 2018-03-16 13:36:56 +0000 | [diff] [blame] | 647 | dumpDecl(D->getSpecialization()); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 648 | if (D->hasExplicitTemplateArgs()) |
| 649 | dumpTemplateArgumentListInfo(D->templateArgs()); |
| 650 | } |
| 651 | |
| Richard Smith | d25789a | 2013-09-18 01:36:02 +0000 | [diff] [blame] | 652 | void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) { |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 653 | dumpTemplateDecl(D, false); |
| Richard Smith | d25789a | 2013-09-18 01:36:02 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 656 | void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) { |
| David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 657 | dumpTemplateParameters(D->getTemplateParameters()); |
| 658 | } |
| 659 | |
| Richard Smith | d25789a | 2013-09-18 01:36:02 +0000 | [diff] [blame] | 660 | void ASTDumper::VisitVarTemplateSpecializationDecl( |
| 661 | const VarTemplateSpecializationDecl *D) { |
| 662 | dumpTemplateArgumentList(D->getTemplateArgs()); |
| 663 | VisitVarDecl(D); |
| 664 | } |
| 665 | |
| 666 | void ASTDumper::VisitVarTemplatePartialSpecializationDecl( |
| 667 | const VarTemplatePartialSpecializationDecl *D) { |
| 668 | dumpTemplateParameters(D->getTemplateParameters()); |
| 669 | VisitVarTemplateSpecializationDecl(D); |
| 670 | } |
| 671 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 672 | void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 673 | if (D->hasDefaultArgument()) |
| Stephen Kelly | 4383595 | 2018-12-10 21:03:00 +0000 | [diff] [blame] | 674 | dumpTemplateArgument(D->getDefaultArgument(), SourceRange(), |
| 675 | D->getDefaultArgStorage().getInheritedFrom(), |
| 676 | D->defaultArgumentWasInherited() ? "inherited from" |
| 677 | : "previous"); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 680 | void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 681 | if (D->hasDefaultArgument()) |
| Stephen Kelly | 4383595 | 2018-12-10 21:03:00 +0000 | [diff] [blame] | 682 | dumpTemplateArgument(D->getDefaultArgument(), SourceRange(), |
| 683 | D->getDefaultArgStorage().getInheritedFrom(), |
| 684 | D->defaultArgumentWasInherited() ? "inherited from" |
| 685 | : "previous"); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 688 | void ASTDumper::VisitTemplateTemplateParmDecl( |
| 689 | const TemplateTemplateParmDecl *D) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 690 | dumpTemplateParameters(D->getTemplateParameters()); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 691 | if (D->hasDefaultArgument()) |
| Stephen Kelly | 4383595 | 2018-12-10 21:03:00 +0000 | [diff] [blame] | 692 | dumpTemplateArgumentLoc( |
| 693 | D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(), |
| 694 | D->defaultArgumentWasInherited() ? "inherited from" : "previous"); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 697 | void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) { |
| Richard Smith | ba3a4f9 | 2016-01-12 21:59:26 +0000 | [diff] [blame] | 698 | if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl())) |
| 699 | dumpTypeAsChild(TD->getTypeForDecl()); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 702 | void ASTDumper::VisitFriendDecl(const FriendDecl *D) { |
| Stephen Kelly | b6318c9 | 2019-01-30 19:32:48 +0000 | [diff] [blame] | 703 | if (!D->getFriendType()) |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 704 | dumpDecl(D->getFriendDecl()); |
| 705 | } |
| 706 | |
| 707 | //===----------------------------------------------------------------------===// |
| 708 | // Obj-C Declarations |
| 709 | //===----------------------------------------------------------------------===// |
| 710 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 711 | void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) { |
| Stephen Kelly | f4129fd | 2019-01-18 22:14:59 +0000 | [diff] [blame] | 712 | if (D->isThisDeclarationADefinition()) |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 713 | dumpDeclContext(D); |
| Stephen Kelly | f4129fd | 2019-01-18 22:14:59 +0000 | [diff] [blame] | 714 | else |
| David Majnemer | a3debed | 2016-06-24 05:33:44 +0000 | [diff] [blame] | 715 | for (const ParmVarDecl *Parameter : D->parameters()) |
| 716 | dumpDecl(Parameter); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 717 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 718 | if (D->hasBody()) |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 719 | dumpStmt(D->getBody()); |
| 720 | } |
| 721 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 722 | void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { |
| Stephen Kelly | a4fd381 | 2019-01-15 23:07:30 +0000 | [diff] [blame] | 723 | dumpObjCTypeParamList(D->getTypeParamList()); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 724 | } |
| 725 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 726 | void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { |
| Stephen Kelly | a4fd381 | 2019-01-15 23:07:30 +0000 | [diff] [blame] | 727 | dumpObjCTypeParamList(D->getTypeParamListAsWritten()); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 730 | void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { |
| Stephen Kelly | 8805f67 | 2019-01-19 09:57:59 +0000 | [diff] [blame] | 731 | for (const auto &I : D->inits()) |
| 732 | dumpCXXCtorInitializer(I); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| Stephen Kelly | fbf424e | 2019-01-15 20:41:37 +0000 | [diff] [blame] | 735 | void ASTDumper::Visit(const BlockDecl::Capture &C) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 736 | NodeDumper.AddChild([=] { |
| Stephen Kelly | fbf424e | 2019-01-15 20:41:37 +0000 | [diff] [blame] | 737 | NodeDumper.Visit(C); |
| 738 | if (C.hasCopyExpr()) |
| 739 | dumpStmt(C.getCopyExpr()); |
| 740 | }); |
| 741 | } |
| 742 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 743 | void ASTDumper::VisitBlockDecl(const BlockDecl *D) { |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 744 | for (const auto &I : D->parameters()) |
| Aaron Ballman | b2b8b1d | 2014-03-07 16:09:59 +0000 | [diff] [blame] | 745 | dumpDecl(I); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 746 | |
| Stephen Kelly | fbf424e | 2019-01-15 20:41:37 +0000 | [diff] [blame] | 747 | for (const auto &I : D->captures()) |
| 748 | Visit(I); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 749 | dumpStmt(D->getBody()); |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| Alexander Kornienko | 7bd0f9b | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 752 | //===----------------------------------------------------------------------===// |
| Alexander Kornienko | 61c93bd | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 753 | // Stmt dumping methods. |
| Alexander Kornienko | 7bd0f9b | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 754 | //===----------------------------------------------------------------------===// |
| 755 | |
| Stephen Kelly | 0df805d | 2019-01-11 19:11:17 +0000 | [diff] [blame] | 756 | void ASTDumper::dumpStmt(const Stmt *S, StringRef Label) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 757 | NodeDumper.AddChild(Label, [=] { |
| Stephen Kelly | 07b76d2 | 2019-01-12 16:53:27 +0000 | [diff] [blame] | 758 | NodeDumper.Visit(S); |
| 759 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 760 | if (!S) { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 761 | return; |
| 762 | } |
| Stephen Kelly | 50e8287 | 2018-12-06 23:33:33 +0000 | [diff] [blame] | 763 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 764 | ConstStmtVisitor<ASTDumper>::Visit(S); |
| Alexander Kornienko | 7bd0f9b | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 765 | |
| Stephen Kelly | 91f9c9c | 2018-12-03 21:05:52 +0000 | [diff] [blame] | 766 | // Some statements have custom mechanisms for dumping their children. |
| 767 | if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S)) { |
| 768 | return; |
| 769 | } |
| 770 | |
| Benjamin Kramer | 642f173 | 2015-07-02 21:03:14 +0000 | [diff] [blame] | 771 | for (const Stmt *SubStmt : S->children()) |
| 772 | dumpStmt(SubStmt); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 773 | }); |
| Alexander Kornienko | 7bd0f9b | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 776 | void ASTDumper::VisitDeclStmt(const DeclStmt *Node) { |
| Stephen Kelly | 8805f67 | 2019-01-19 09:57:59 +0000 | [diff] [blame] | 777 | for (const auto &D : Node->decls()) |
| 778 | dumpDecl(D); |
| Ted Kremenek | 433a492 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 781 | void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) { |
| Stephen Kelly | 8805f67 | 2019-01-19 09:57:59 +0000 | [diff] [blame] | 782 | for (const auto *A : Node->getAttrs()) |
| 783 | dumpAttr(A); |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| Pavel Labath | 1ef8342 | 2013-09-04 14:35:00 +0000 | [diff] [blame] | 786 | void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) { |
| Pavel Labath | 1ef8342 | 2013-09-04 14:35:00 +0000 | [diff] [blame] | 787 | dumpDecl(Node->getExceptionDecl()); |
| 788 | } |
| 789 | |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 790 | void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) { |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 791 | dumpDecl(Node->getCapturedDecl()); |
| 792 | } |
| 793 | |
| 794 | //===----------------------------------------------------------------------===// |
| 795 | // OpenMP dumping methods. |
| 796 | //===----------------------------------------------------------------------===// |
| 797 | |
| Stephen Kelly | 3cdd1a7 | 2019-01-15 20:31:31 +0000 | [diff] [blame] | 798 | void ASTDumper::Visit(const OMPClause *C) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 799 | NodeDumper.AddChild([=] { |
| Stephen Kelly | 3cdd1a7 | 2019-01-15 20:31:31 +0000 | [diff] [blame] | 800 | NodeDumper.Visit(C); |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 801 | for (const auto *S : C->children()) |
| Stephen Kelly | 3cdd1a7 | 2019-01-15 20:31:31 +0000 | [diff] [blame] | 802 | dumpStmt(S); |
| 803 | }); |
| 804 | } |
| 805 | |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 806 | void ASTDumper::VisitOMPExecutableDirective( |
| 807 | const OMPExecutableDirective *Node) { |
| Stephen Kelly | 3cdd1a7 | 2019-01-15 20:31:31 +0000 | [diff] [blame] | 808 | for (const auto *C : Node->clauses()) |
| 809 | Visit(C); |
| Alexey Bataev | 958b9e7 | 2016-03-31 09:30:50 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 812 | //===----------------------------------------------------------------------===// |
| Alexander Kornienko | 61c93bd | 2012-12-11 15:28:09 +0000 | [diff] [blame] | 813 | // Expr dumping methods. |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 814 | //===----------------------------------------------------------------------===// |
| 815 | |
| Chris Lattner | 84ca376 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 816 | |
| Richard Smith | f051496 | 2014-06-03 08:24:28 +0000 | [diff] [blame] | 817 | void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) { |
| Richard Smith | f051496 | 2014-06-03 08:24:28 +0000 | [diff] [blame] | 818 | if (auto *Filler = ILE->getArrayFiller()) { |
| Stephen Kelly | 0df805d | 2019-01-11 19:11:17 +0000 | [diff] [blame] | 819 | dumpStmt(Filler, "array_filler"); |
| Richard Smith | f051496 | 2014-06-03 08:24:28 +0000 | [diff] [blame] | 820 | } |
| Richard Smith | f051496 | 2014-06-03 08:24:28 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 823 | void ASTDumper::VisitBlockExpr(const BlockExpr *Node) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 824 | dumpDecl(Node->getBlockDecl()); |
| John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 827 | void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 828 | if (Expr *Source = Node->getSourceExpr()) |
| Alexander Kornienko | 7bd0f9b | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 829 | dumpStmt(Source); |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| Stephen Kelly | fbf40f4 | 2019-01-29 22:22:55 +0000 | [diff] [blame] | 832 | void ASTDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 833 | NodeDumper.AddChild([=] { |
| Stephen Kelly | fbf40f4 | 2019-01-29 22:22:55 +0000 | [diff] [blame] | 834 | NodeDumper.Visit(A); |
| 835 | if (const TypeSourceInfo *TSI = A.getTypeSourceInfo()) |
| 836 | dumpTypeAsChild(TSI->getType()); |
| 837 | dumpStmt(A.getAssociationExpr()); |
| 838 | }); |
| 839 | } |
| 840 | |
| Richard Smith | 01ccebf | 2018-01-05 21:31:07 +0000 | [diff] [blame] | 841 | void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) { |
| Richard Smith | 01ccebf | 2018-01-05 21:31:07 +0000 | [diff] [blame] | 842 | dumpStmt(E->getControllingExpr()); |
| 843 | dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove |
| 844 | |
| Bruno Ricci | 1ec7fd3 | 2019-01-29 12:57:11 +0000 | [diff] [blame] | 845 | for (const auto &Assoc : E->associations()) { |
| Stephen Kelly | fbf40f4 | 2019-01-29 22:22:55 +0000 | [diff] [blame] | 846 | Visit(Assoc); |
| Richard Smith | 01ccebf | 2018-01-05 21:31:07 +0000 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
| Chris Lattner | 8f184b1 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 850 | //===----------------------------------------------------------------------===// |
| 851 | // C++ Expressions |
| 852 | //===----------------------------------------------------------------------===// |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 853 | |
| Serge Pavlov | 6b92603 | 2015-02-16 19:58:41 +0000 | [diff] [blame] | 854 | void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) { |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 855 | if (Node->isPartiallySubstituted()) |
| 856 | for (const auto &A : Node->getPartialArguments()) |
| 857 | dumpTemplateArgument(A); |
| Serge Pavlov | 6b92603 | 2015-02-16 19:58:41 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 860 | //===----------------------------------------------------------------------===// |
| 861 | // Obj-C Expressions |
| 862 | //===----------------------------------------------------------------------===// |
| 863 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 864 | void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) { |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 865 | if (const VarDecl *CatchParam = Node->getCatchParamDecl()) |
| Alexander Kornienko | 7bd0f9b | 2012-12-11 15:20:44 +0000 | [diff] [blame] | 866 | dumpDecl(CatchParam); |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 869 | //===----------------------------------------------------------------------===// |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 870 | // Comments |
| 871 | //===----------------------------------------------------------------------===// |
| 872 | |
| Stephen Kelly | cdbfb30 | 2018-12-02 17:30:40 +0000 | [diff] [blame] | 873 | void ASTDumper::dumpComment(const Comment *C, const FullComment *FC) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame^] | 874 | NodeDumper.AddChild([=] { |
| Stephen Kelly | e26a88a | 2018-12-09 13:30:17 +0000 | [diff] [blame] | 875 | NodeDumper.Visit(C, FC); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 876 | if (!C) { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 877 | return; |
| 878 | } |
| Stephen Kelly | cdbfb30 | 2018-12-02 17:30:40 +0000 | [diff] [blame] | 879 | ConstCommentVisitor<ASTDumper, void, const FullComment *>::visit(C, FC); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 880 | for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); |
| 881 | I != E; ++I) |
| Stephen Kelly | cdbfb30 | 2018-12-02 17:30:40 +0000 | [diff] [blame] | 882 | dumpComment(*I, FC); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 883 | }); |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 886 | //===----------------------------------------------------------------------===// |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 887 | // Type method implementations |
| 888 | //===----------------------------------------------------------------------===// |
| 889 | |
| 890 | void QualType::dump(const char *msg) const { |
| 891 | if (msg) |
| 892 | llvm::errs() << msg << ": "; |
| 893 | dump(); |
| 894 | } |
| 895 | |
| Richard Smith | 14d0484 | 2016-11-02 23:57:18 +0000 | [diff] [blame] | 896 | LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); } |
| 897 | |
| 898 | LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const { |
| 899 | ASTDumper Dumper(OS, nullptr, nullptr); |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 900 | Dumper.dumpTypeAsChild(*this); |
| 901 | } |
| 902 | |
| Richard Smith | 14d0484 | 2016-11-02 23:57:18 +0000 | [diff] [blame] | 903 | LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); } |
| 904 | |
| 905 | LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const { |
| 906 | QualType(this, 0).dump(OS); |
| 907 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 908 | |
| 909 | //===----------------------------------------------------------------------===// |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 910 | // Decl method implementations |
| 911 | //===----------------------------------------------------------------------===// |
| 912 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 913 | LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); } |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 914 | |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 915 | LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const { |
| Aaron Ballman | 8c20828 | 2017-12-21 21:42:42 +0000 | [diff] [blame] | 916 | const ASTContext &Ctx = getASTContext(); |
| 917 | const SourceManager &SM = Ctx.getSourceManager(); |
| 918 | ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM, |
| 919 | SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy()); |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 920 | P.setDeserialize(Deserialize); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 921 | P.dumpDecl(this); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 922 | } |
| 923 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 924 | LLVM_DUMP_METHOD void Decl::dumpColor() const { |
| Aaron Ballman | 8c20828 | 2017-12-21 21:42:42 +0000 | [diff] [blame] | 925 | const ASTContext &Ctx = getASTContext(); |
| 926 | ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(), |
| 927 | &Ctx.getSourceManager(), /*ShowColors*/ true, |
| 928 | Ctx.getPrintingPolicy()); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 929 | P.dumpDecl(this); |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 930 | } |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 931 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 932 | LLVM_DUMP_METHOD void DeclContext::dumpLookups() const { |
| Richard Smith | 6ea0582 | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 933 | dumpLookups(llvm::errs()); |
| 934 | } |
| 935 | |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 936 | LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS, |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 937 | bool DumpDecls, |
| 938 | bool Deserialize) const { |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 939 | const DeclContext *DC = this; |
| 940 | while (!DC->isTranslationUnit()) |
| 941 | DC = DC->getParent(); |
| 942 | ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext(); |
| Aaron Ballman | 8c20828 | 2017-12-21 21:42:42 +0000 | [diff] [blame] | 943 | const SourceManager &SM = Ctx.getSourceManager(); |
| 944 | ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(), |
| 945 | SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy()); |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 946 | P.setDeserialize(Deserialize); |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 947 | P.dumpLookups(this, DumpDecls); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 950 | //===----------------------------------------------------------------------===// |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 951 | // Stmt method implementations |
| 952 | //===----------------------------------------------------------------------===// |
| 953 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 954 | LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const { |
| Argyrios Kyrtzidis | c049f75 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 955 | dump(llvm::errs(), SM); |
| 956 | } |
| 957 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 958 | LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const { |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 959 | ASTDumper P(OS, nullptr, &SM); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 960 | P.dumpStmt(this); |
| Chris Lattner | 779d5d9 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| Faisal Vali | 2da8ed9 | 2015-03-22 13:35:56 +0000 | [diff] [blame] | 963 | LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const { |
| 964 | ASTDumper P(OS, nullptr, nullptr); |
| 965 | P.dumpStmt(this); |
| 966 | } |
| 967 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 968 | LLVM_DUMP_METHOD void Stmt::dump() const { |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 969 | ASTDumper P(llvm::errs(), nullptr, nullptr); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 970 | P.dumpStmt(this); |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 971 | } |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 972 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 973 | LLVM_DUMP_METHOD void Stmt::dumpColor() const { |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 974 | ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true); |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 975 | P.dumpStmt(this); |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 978 | //===----------------------------------------------------------------------===// |
| 979 | // Comment method implementations |
| 980 | //===----------------------------------------------------------------------===// |
| 981 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 982 | LLVM_DUMP_METHOD void Comment::dump() const { |
| 983 | dump(llvm::errs(), nullptr, nullptr); |
| 984 | } |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 985 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 986 | LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const { |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 987 | dump(llvm::errs(), &Context.getCommentCommandTraits(), |
| 988 | &Context.getSourceManager()); |
| 989 | } |
| 990 | |
| Alexander Kornienko | 00911f1 | 2013-01-15 12:20:21 +0000 | [diff] [blame] | 991 | void Comment::dump(raw_ostream &OS, const CommandTraits *Traits, |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 992 | const SourceManager *SM) const { |
| 993 | const FullComment *FC = dyn_cast<FullComment>(this); |
| Stephen Kelly | 570b297 | 2018-12-09 13:18:55 +0000 | [diff] [blame] | 994 | if (!FC) |
| 995 | return; |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 996 | ASTDumper D(OS, Traits, SM); |
| Stephen Kelly | 570b297 | 2018-12-09 13:18:55 +0000 | [diff] [blame] | 997 | D.dumpComment(FC, FC); |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 998 | } |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 999 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 1000 | LLVM_DUMP_METHOD void Comment::dumpColor() const { |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1001 | const FullComment *FC = dyn_cast<FullComment>(this); |
| Stephen Kelly | 570b297 | 2018-12-09 13:18:55 +0000 | [diff] [blame] | 1002 | if (!FC) |
| 1003 | return; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1004 | ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true); |
| Stephen Kelly | 570b297 | 2018-12-09 13:18:55 +0000 | [diff] [blame] | 1005 | D.dumpComment(FC, FC); |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 1006 | } |