| 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 | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTNodeTraverser.h" |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclLookups.h" |
| Aaron Ballman | 2ce598a | 2019-05-13 21:39:55 +0000 | [diff] [blame^] | 17 | #include "clang/AST/JSONNodeDumper.h" |
| Stephen Kelly | d8744a7 | 2018-12-05 21:12:39 +0000 | [diff] [blame] | 18 | #include "clang/AST/TextNodeDumper.h" |
| David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Builtins.h" |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 20 | #include "clang/Basic/Module.h" |
| Chris Lattner | 11e30d3 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 21 | #include "clang/Basic/SourceManager.h" |
| Daniel Dunbar | 34a96c8 | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 23 | using namespace clang; |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 24 | using namespace clang::comments; |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 25 | |
| 26 | //===----------------------------------------------------------------------===// |
| Alexander Kornienko | 18ec81b | 2012-12-13 13:59:55 +0000 | [diff] [blame] | 27 | // ASTDumper Visitor |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
| 29 | |
| 30 | namespace { |
| Stephen Kelly | 27e948c | 2018-11-29 19:30:37 +0000 | [diff] [blame] | 31 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 32 | class ASTDumper : public ASTNodeTraverser<ASTDumper, TextNodeDumper> { |
| Stephen Kelly | cdbfb30 | 2018-12-02 17:30:40 +0000 | [diff] [blame] | 33 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 34 | TextNodeDumper NodeDumper; |
| Stephen Kelly | 0da68ba | 2018-12-05 20:53:14 +0000 | [diff] [blame] | 35 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 36 | raw_ostream &OS; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 37 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 38 | const bool ShowColors; |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 39 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 40 | public: |
| 41 | ASTDumper(raw_ostream &OS, const CommandTraits *Traits, |
| 42 | const SourceManager *SM) |
| 43 | : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) {} |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 44 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 45 | ASTDumper(raw_ostream &OS, const CommandTraits *Traits, |
| 46 | const SourceManager *SM, bool ShowColors) |
| 47 | : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {} |
| 48 | ASTDumper(raw_ostream &OS, const CommandTraits *Traits, |
| 49 | const SourceManager *SM, bool ShowColors, |
| 50 | const PrintingPolicy &PrintPolicy) |
| 51 | : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS), |
| 52 | ShowColors(ShowColors) {} |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 53 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 54 | TextNodeDumper &doGetNodeDelegate() { return NodeDumper; } |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 55 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 56 | void dumpLookups(const DeclContext *DC, bool DumpDecls); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 57 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 58 | template <typename SpecializationDecl> |
| 59 | void dumpTemplateDeclSpecialization(const SpecializationDecl *D, |
| 60 | bool DumpExplicitInst, bool DumpRefOnly); |
| 61 | template <typename TemplateDecl> |
| 62 | void dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 63 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 64 | void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D); |
| 65 | void VisitClassTemplateDecl(const ClassTemplateDecl *D); |
| 66 | void VisitVarTemplateDecl(const VarTemplateDecl *D); |
| 67 | }; |
| Stephen Kelly | ee7e4cf | 2019-01-30 21:48:32 +0000 | [diff] [blame] | 68 | } // namespace |
| Stephen Kelly | 0808a25 | 2019-01-30 20:03:47 +0000 | [diff] [blame] | 69 | |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 70 | void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame] | 71 | NodeDumper.AddChild([=] { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 72 | OS << "StoredDeclsMap "; |
| Stephen Kelly | d8744a7 | 2018-12-05 21:12:39 +0000 | [diff] [blame] | 73 | NodeDumper.dumpBareDeclRef(cast<Decl>(DC)); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 74 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 75 | const DeclContext *Primary = DC->getPrimaryContext(); |
| 76 | if (Primary != DC) { |
| 77 | OS << " primary"; |
| Stephen Kelly | d8744a7 | 2018-12-05 21:12:39 +0000 | [diff] [blame] | 78 | NodeDumper.dumpPointer(cast<Decl>(Primary)); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 81 | bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage(); |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 82 | |
| Stephen Kelly | c493301 | 2019-02-03 14:06:54 +0000 | [diff] [blame] | 83 | auto Range = getDeserialize() |
| Sam McCall | 091b1ef | 2018-01-16 12:33:46 +0000 | [diff] [blame] | 84 | ? Primary->lookups() |
| 85 | : Primary->noload_lookups(/*PreserveInternalState=*/true); |
| 86 | for (auto I = Range.begin(), E = Range.end(); I != E; ++I) { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 87 | DeclarationName Name = I.getLookupName(); |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 88 | DeclContextLookupResult R = *I; |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 89 | |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame] | 90 | NodeDumper.AddChild([=] { |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 91 | OS << "DeclarationName "; |
| 92 | { |
| Stephen Kelly | 27e948c | 2018-11-29 19:30:37 +0000 | [diff] [blame] | 93 | ColorScope Color(OS, ShowColors, DeclNameColor); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 94 | OS << '\'' << Name << '\''; |
| 95 | } |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 96 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 97 | for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end(); |
| 98 | RI != RE; ++RI) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame] | 99 | NodeDumper.AddChild([=] { |
| Stephen Kelly | d8744a7 | 2018-12-05 21:12:39 +0000 | [diff] [blame] | 100 | NodeDumper.dumpBareDeclRef(*RI); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 101 | |
| 102 | if ((*RI)->isHidden()) |
| 103 | OS << " hidden"; |
| 104 | |
| 105 | // If requested, dump the redecl chain for this lookup. |
| 106 | if (DumpDecls) { |
| 107 | // Dump earliest decl first. |
| 108 | std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) { |
| 109 | if (Decl *Prev = D->getPreviousDecl()) |
| 110 | DumpWithPrev(Prev); |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 111 | Visit(D); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 112 | }; |
| 113 | DumpWithPrev(*RI); |
| 114 | } |
| 115 | }); |
| 116 | } |
| 117 | }); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 118 | } |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 119 | |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 120 | if (HasUndeserializedLookups) { |
| Stephen Kelly | d8aeb55 | 2019-01-30 19:41:04 +0000 | [diff] [blame] | 121 | NodeDumper.AddChild([=] { |
| Stephen Kelly | 27e948c | 2018-11-29 19:30:37 +0000 | [diff] [blame] | 122 | ColorScope Color(OS, ShowColors, UndeserializedColor); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 123 | OS << "<undeserialized lookups>"; |
| 124 | }); |
| 125 | } |
| 126 | }); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 129 | template <typename SpecializationDecl> |
| 130 | void ASTDumper::dumpTemplateDeclSpecialization(const SpecializationDecl *D, |
| 131 | bool DumpExplicitInst, |
| 132 | bool DumpRefOnly) { |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 133 | bool DumpedAny = false; |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 134 | for (const auto *RedeclWithBadType : D->redecls()) { |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 135 | // FIXME: The redecls() range sometimes has elements of a less-specific |
| 136 | // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives |
| 137 | // us TagDecls, and should give CXXRecordDecls). |
| 138 | auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType); |
| 139 | if (!Redecl) { |
| 140 | // Found the injected-class-name for a class template. This will be dumped |
| 141 | // as part of its surrounding class so we don't need to dump it here. |
| 142 | assert(isa<CXXRecordDecl>(RedeclWithBadType) && |
| 143 | "expected an injected-class-name"); |
| 144 | continue; |
| 145 | } |
| 146 | |
| 147 | switch (Redecl->getTemplateSpecializationKind()) { |
| 148 | case TSK_ExplicitInstantiationDeclaration: |
| 149 | case TSK_ExplicitInstantiationDefinition: |
| 150 | if (!DumpExplicitInst) |
| 151 | break; |
| Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 152 | LLVM_FALLTHROUGH; |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 153 | case TSK_Undeclared: |
| 154 | case TSK_ImplicitInstantiation: |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 155 | if (DumpRefOnly) |
| Stephen Kelly | d186dbc | 2019-01-08 23:11:24 +0000 | [diff] [blame] | 156 | NodeDumper.dumpDeclRef(Redecl); |
| Richard Smith | f751445 | 2014-10-30 21:02:37 +0000 | [diff] [blame] | 157 | else |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 158 | Visit(Redecl); |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 159 | DumpedAny = true; |
| 160 | break; |
| 161 | case TSK_ExplicitSpecialization: |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // Ensure we dump at least one decl for each specialization. |
| 167 | if (!DumpedAny) |
| Stephen Kelly | d186dbc | 2019-01-08 23:11:24 +0000 | [diff] [blame] | 168 | NodeDumper.dumpDeclRef(D); |
| Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 171 | template <typename TemplateDecl> |
| 172 | void ASTDumper::dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst) { |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 173 | dumpTemplateParameters(D->getTemplateParameters()); |
| Richard Smith | dcc2c45 | 2014-03-17 23:00:06 +0000 | [diff] [blame] | 174 | |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 175 | Visit(D->getTemplatedDecl()); |
| Richard Smith | dcc2c45 | 2014-03-17 23:00:06 +0000 | [diff] [blame] | 176 | |
| Stephen Kelly | aaebc5f | 2019-01-19 09:57:51 +0000 | [diff] [blame] | 177 | for (const auto *Child : D->specializations()) |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 178 | dumpTemplateDeclSpecialization(Child, DumpExplicitInst, |
| 179 | !D->isCanonicalDecl()); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| Richard Smith | 20ade55 | 2014-03-17 23:34:53 +0000 | [diff] [blame] | 182 | void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { |
| 183 | // FIXME: We don't add a declaration of a function template specialization |
| 184 | // to its context when it's explicitly instantiated, so dump explicit |
| 185 | // instantiations when we dump the template itself. |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 186 | dumpTemplateDecl(D, true); |
| Richard Smith | 20ade55 | 2014-03-17 23:34:53 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| Alexander Kornienko | 540bacb | 2013-02-01 12:35:51 +0000 | [diff] [blame] | 189 | void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) { |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 190 | dumpTemplateDecl(D, false); |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| Richard Smith | d25789a | 2013-09-18 01:36:02 +0000 | [diff] [blame] | 193 | void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) { |
| Stephen Kelly | 2413638 | 2018-12-09 13:33:30 +0000 | [diff] [blame] | 194 | dumpTemplateDecl(D, false); |
| Richard Smith | d25789a | 2013-09-18 01:36:02 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 197 | //===----------------------------------------------------------------------===// |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 198 | // Type method implementations |
| 199 | //===----------------------------------------------------------------------===// |
| 200 | |
| 201 | void QualType::dump(const char *msg) const { |
| 202 | if (msg) |
| 203 | llvm::errs() << msg << ": "; |
| 204 | dump(); |
| 205 | } |
| 206 | |
| Richard Smith | 14d0484 | 2016-11-02 23:57:18 +0000 | [diff] [blame] | 207 | LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); } |
| 208 | |
| 209 | LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const { |
| 210 | ASTDumper Dumper(OS, nullptr, nullptr); |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 211 | Dumper.Visit(*this); |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| Richard Smith | 14d0484 | 2016-11-02 23:57:18 +0000 | [diff] [blame] | 214 | LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); } |
| 215 | |
| 216 | LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const { |
| 217 | QualType(this, 0).dump(OS); |
| 218 | } |
| Richard Smith | d5e7ff8 | 2014-10-31 01:17:45 +0000 | [diff] [blame] | 219 | |
| 220 | //===----------------------------------------------------------------------===// |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 221 | // Decl method implementations |
| 222 | //===----------------------------------------------------------------------===// |
| 223 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 224 | LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); } |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 225 | |
| Aaron Ballman | 2ce598a | 2019-05-13 21:39:55 +0000 | [diff] [blame^] | 226 | LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize, |
| 227 | ASTDumpOutputFormat Format) const { |
| Aaron Ballman | 8c20828 | 2017-12-21 21:42:42 +0000 | [diff] [blame] | 228 | const ASTContext &Ctx = getASTContext(); |
| 229 | const SourceManager &SM = Ctx.getSourceManager(); |
| Aaron Ballman | 2ce598a | 2019-05-13 21:39:55 +0000 | [diff] [blame^] | 230 | |
| 231 | if (ADOF_JSON == Format) { |
| 232 | JSONDumper P(OS, SM, Ctx.getPrintingPolicy()); |
| 233 | (void)Deserialize; // FIXME? |
| 234 | P.Visit(this); |
| 235 | } else { |
| 236 | ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM, |
| 237 | SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy()); |
| 238 | P.setDeserialize(Deserialize); |
| 239 | P.Visit(this); |
| 240 | } |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 243 | LLVM_DUMP_METHOD void Decl::dumpColor() const { |
| Aaron Ballman | 8c20828 | 2017-12-21 21:42:42 +0000 | [diff] [blame] | 244 | const ASTContext &Ctx = getASTContext(); |
| 245 | ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(), |
| 246 | &Ctx.getSourceManager(), /*ShowColors*/ true, |
| 247 | Ctx.getPrintingPolicy()); |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 248 | P.Visit(this); |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 249 | } |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 250 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 251 | LLVM_DUMP_METHOD void DeclContext::dumpLookups() const { |
| Richard Smith | 6ea0582 | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 252 | dumpLookups(llvm::errs()); |
| 253 | } |
| 254 | |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 255 | LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS, |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 256 | bool DumpDecls, |
| 257 | bool Deserialize) const { |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 258 | const DeclContext *DC = this; |
| 259 | while (!DC->isTranslationUnit()) |
| 260 | DC = DC->getParent(); |
| 261 | ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext(); |
| Aaron Ballman | 8c20828 | 2017-12-21 21:42:42 +0000 | [diff] [blame] | 262 | const SourceManager &SM = Ctx.getSourceManager(); |
| 263 | ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(), |
| 264 | SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy()); |
| Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 265 | P.setDeserialize(Deserialize); |
| Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 266 | P.dumpLookups(this, DumpDecls); |
| Richard Smith | 33937e7 | 2013-06-22 21:49:40 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 269 | //===----------------------------------------------------------------------===// |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 270 | // Stmt method implementations |
| 271 | //===----------------------------------------------------------------------===// |
| 272 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 273 | LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const { |
| Argyrios Kyrtzidis | c049f75 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 274 | dump(llvm::errs(), SM); |
| 275 | } |
| 276 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 277 | LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const { |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 278 | ASTDumper P(OS, nullptr, &SM); |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 279 | P.Visit(this); |
| Chris Lattner | 779d5d9 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| Faisal Vali | 2da8ed9 | 2015-03-22 13:35:56 +0000 | [diff] [blame] | 282 | LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const { |
| 283 | ASTDumper P(OS, nullptr, nullptr); |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 284 | P.Visit(this); |
| Faisal Vali | 2da8ed9 | 2015-03-22 13:35:56 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 287 | LLVM_DUMP_METHOD void Stmt::dump() const { |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 288 | ASTDumper P(llvm::errs(), nullptr, nullptr); |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 289 | P.Visit(this); |
| Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 290 | } |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 291 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 292 | LLVM_DUMP_METHOD void Stmt::dumpColor() const { |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 293 | ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true); |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 294 | P.Visit(this); |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 297 | //===----------------------------------------------------------------------===// |
| 298 | // Comment method implementations |
| 299 | //===----------------------------------------------------------------------===// |
| 300 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 301 | LLVM_DUMP_METHOD void Comment::dump() const { |
| 302 | dump(llvm::errs(), nullptr, nullptr); |
| 303 | } |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 304 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 305 | LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const { |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 306 | dump(llvm::errs(), &Context.getCommentCommandTraits(), |
| 307 | &Context.getSourceManager()); |
| 308 | } |
| 309 | |
| Alexander Kornienko | 00911f1 | 2013-01-15 12:20:21 +0000 | [diff] [blame] | 310 | void Comment::dump(raw_ostream &OS, const CommandTraits *Traits, |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 311 | const SourceManager *SM) const { |
| 312 | const FullComment *FC = dyn_cast<FullComment>(this); |
| Stephen Kelly | 570b297 | 2018-12-09 13:18:55 +0000 | [diff] [blame] | 313 | if (!FC) |
| 314 | return; |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 315 | ASTDumper D(OS, Traits, SM); |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 316 | D.Visit(FC, FC); |
| Alexander Kornienko | ebc17b5 | 2013-01-14 14:07:11 +0000 | [diff] [blame] | 317 | } |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 318 | |
| Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 319 | LLVM_DUMP_METHOD void Comment::dumpColor() const { |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 320 | const FullComment *FC = dyn_cast<FullComment>(this); |
| Stephen Kelly | 570b297 | 2018-12-09 13:18:55 +0000 | [diff] [blame] | 321 | if (!FC) |
| 322 | return; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 323 | ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true); |
| Stephen Kelly | 6d110d6 | 2019-01-30 19:49:49 +0000 | [diff] [blame] | 324 | D.Visit(FC, FC); |
| Richard Trieu | d215b8d | 2013-01-26 01:31:20 +0000 | [diff] [blame] | 325 | } |