Chris Lattner | d1cdee7 | 2007-10-07 06:04:32 +0000 | [diff] [blame] | 1 | //===--- ASTConsumers.cpp - ASTConsumer implementations -------------------===// |
Bill Wendling | aec64c3 | 2007-06-23 00:39:57 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Bill Wendling | aec64c3 | 2007-06-23 00:39:57 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | d1cdee7 | 2007-10-07 06:04:32 +0000 | [diff] [blame] | 10 | // AST Consumer Implementations. |
Bill Wendling | aec64c3 | 2007-06-23 00:39:57 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Eli Friedman | 9f30fc3 | 2009-05-18 22:50:54 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/ASTConsumers.h" |
Bill Wendling | aec64c3 | 2007-06-23 00:39:57 +0000 | [diff] [blame] | 15 | #include "clang/AST/AST.h" |
Chris Lattner | 09c39db | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTConsumer.h" |
Chris Lattner | a5adead | 2009-03-28 04:27:18 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 7de5966 | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 18 | #include "clang/AST/PrettyPrinter.h" |
Alexander Kornienko | 3db68ee | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 19 | #include "clang/AST/RecordLayout.h" |
| 20 | #include "clang/AST/RecursiveASTVisitor.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/Basic/Diagnostic.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include "clang/Basic/SourceManager.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Path.h" |
Alexander Kornienko | 3db68ee | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Timer.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 26 | using namespace clang; |
Bill Wendling | aec64c3 | 2007-06-23 00:39:57 +0000 | [diff] [blame] | 27 | |
Ted Kremenek | 7c81bdd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 29 | /// ASTPrinter - Pretty-printer and dumper of ASTs |
Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 30 | |
Ted Kremenek | 7c81bdd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 31 | namespace { |
Alexander Kornienko | 3db68ee | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 32 | class ASTPrinter : public ASTConsumer, |
| 33 | public RecursiveASTVisitor<ASTPrinter> { |
| 34 | typedef RecursiveASTVisitor<ASTPrinter> base; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 35 | |
Ted Kremenek | 7c81bdd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 36 | public: |
Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 37 | enum Kind { DumpFull, Dump, Print, None }; |
| 38 | ASTPrinter(std::unique_ptr<raw_ostream> Out, Kind K, StringRef FilterString, |
| 39 | bool DumpLookups = false) |
| 40 | : Out(Out ? *Out : llvm::outs()), OwnedOut(std::move(Out)), |
| 41 | OutputKind(K), FilterString(FilterString), DumpLookups(DumpLookups) {} |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | |
Craig Topper | afa7cb3 | 2014-03-13 06:07:04 +0000 | [diff] [blame] | 43 | void HandleTranslationUnit(ASTContext &Context) override { |
Alexander Kornienko | 3db68ee | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 44 | TranslationUnitDecl *D = Context.getTranslationUnitDecl(); |
| 45 | |
Richard Smith | 6ea0582 | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 46 | if (FilterString.empty()) |
| 47 | return print(D); |
Alexander Kornienko | 3db68ee | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 48 | |
| 49 | TraverseDecl(D); |
Bill Wendling | aec64c3 | 2007-06-23 00:39:57 +0000 | [diff] [blame] | 50 | } |
Alexander Kornienko | 3db68ee | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 51 | |
| 52 | bool shouldWalkTypesOfTypeLocs() const { return false; } |
| 53 | |
| 54 | bool TraverseDecl(Decl *D) { |
Craig Topper | 49a2790 | 2014-05-22 04:46:25 +0000 | [diff] [blame] | 55 | if (D && filterMatches(D)) { |
Dmitri Gribenko | 3233391 | 2012-11-21 10:54:55 +0000 | [diff] [blame] | 56 | bool ShowColors = Out.has_colors(); |
| 57 | if (ShowColors) |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 58 | Out.changeColor(raw_ostream::BLUE); |
Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 59 | Out << (OutputKind != Print ? "Dumping " : "Printing ") << getName(D) |
Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 60 | << ":\n"; |
Dmitri Gribenko | 3233391 | 2012-11-21 10:54:55 +0000 | [diff] [blame] | 61 | if (ShowColors) |
| 62 | Out.resetColor(); |
Richard Smith | 6ea0582 | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 63 | print(D); |
Alexander Kornienko | 2018618 | 2012-08-17 17:38:39 +0000 | [diff] [blame] | 64 | Out << "\n"; |
Alexander Kornienko | 3db68ee | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 65 | // Don't traverse child nodes to avoid output duplication. |
| 66 | return true; |
| 67 | } |
| 68 | return base::TraverseDecl(D); |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | std::string getName(Decl *D) { |
| 73 | if (isa<NamedDecl>(D)) |
| 74 | return cast<NamedDecl>(D)->getQualifiedNameAsString(); |
| 75 | return ""; |
| 76 | } |
| 77 | bool filterMatches(Decl *D) { |
| 78 | return getName(D).find(FilterString) != std::string::npos; |
| 79 | } |
Richard Smith | 6ea0582 | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 80 | void print(Decl *D) { |
| 81 | if (DumpLookups) { |
Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 82 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { |
| 83 | if (DC == DC->getPrimaryContext()) |
Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 84 | DC->dumpLookups(Out, OutputKind != None, OutputKind == DumpFull); |
Richard Smith | 35f986d | 2014-08-11 22:11:07 +0000 | [diff] [blame] | 85 | else |
| 86 | Out << "Lookup map is in primary DeclContext " |
| 87 | << DC->getPrimaryContext() << "\n"; |
| 88 | } else |
Richard Smith | 6ea0582 | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 89 | Out << "Not a DeclContext\n"; |
Joel E. Denny | 7bcc210 | 2018-05-14 18:41:44 +0000 | [diff] [blame^] | 90 | } else if (OutputKind == Print) { |
| 91 | PrintingPolicy Policy(D->getASTContext().getLangOpts()); |
| 92 | D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true); |
| 93 | } else if (OutputKind != None) |
Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 94 | D->dump(Out, OutputKind == DumpFull); |
Richard Smith | 6ea0582 | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 95 | } |
Alexander Kornienko | 3db68ee | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 96 | |
| 97 | raw_ostream &Out; |
Peter Collingbourne | 03f8907 | 2016-07-15 00:55:40 +0000 | [diff] [blame] | 98 | std::unique_ptr<raw_ostream> OwnedOut; |
Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 99 | |
| 100 | /// How to output individual declarations. |
| 101 | Kind OutputKind; |
| 102 | |
| 103 | /// Which declarations or DeclContexts to display. |
Alexander Kornienko | 3db68ee | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 104 | std::string FilterString; |
Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 105 | |
| 106 | /// Whether the primary output is lookup results or declarations. Individual |
| 107 | /// results will be output with a format determined by OutputKind. This is |
| 108 | /// incompatible with OutputKind == Print. |
Richard Smith | 6ea0582 | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 109 | bool DumpLookups; |
Chris Lattner | 09c39db | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 110 | }; |
Alexander Kornienko | 4de0359 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 111 | |
| 112 | class ASTDeclNodeLister : public ASTConsumer, |
| 113 | public RecursiveASTVisitor<ASTDeclNodeLister> { |
Alexander Kornienko | 4de0359 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 114 | public: |
Craig Topper | 49a2790 | 2014-05-22 04:46:25 +0000 | [diff] [blame] | 115 | ASTDeclNodeLister(raw_ostream *Out = nullptr) |
Alexander Kornienko | 4de0359 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 116 | : Out(Out ? *Out : llvm::outs()) {} |
| 117 | |
Craig Topper | afa7cb3 | 2014-03-13 06:07:04 +0000 | [diff] [blame] | 118 | void HandleTranslationUnit(ASTContext &Context) override { |
Alexander Kornienko | 4de0359 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 119 | TraverseDecl(Context.getTranslationUnitDecl()); |
| 120 | } |
| 121 | |
| 122 | bool shouldWalkTypesOfTypeLocs() const { return false; } |
| 123 | |
Craig Topper | 4567053 | 2014-03-13 07:14:47 +0000 | [diff] [blame] | 124 | bool VisitNamedDecl(NamedDecl *D) { |
Benjamin Kramer | 24ebf7c | 2013-02-23 13:53:57 +0000 | [diff] [blame] | 125 | D->printQualifiedName(Out); |
| 126 | Out << '\n'; |
Alexander Kornienko | 4de0359 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 127 | return true; |
| 128 | } |
| 129 | |
| 130 | private: |
| 131 | raw_ostream &Out; |
| 132 | }; |
Chris Lattner | c0c3dff | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 133 | } // end anonymous namespace |
Chris Lattner | cbe4f77 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 134 | |
Peter Collingbourne | 03f8907 | 2016-07-15 00:55:40 +0000 | [diff] [blame] | 135 | std::unique_ptr<ASTConsumer> |
| 136 | clang::CreateASTPrinter(std::unique_ptr<raw_ostream> Out, |
| 137 | StringRef FilterString) { |
Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 138 | return llvm::make_unique<ASTPrinter>(std::move(Out), ASTPrinter::Print, |
Peter Collingbourne | 03f8907 | 2016-07-15 00:55:40 +0000 | [diff] [blame] | 139 | FilterString); |
Ted Kremenek | 5933768 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 140 | } |
Ted Kremenek | 7c81bdd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 141 | |
Alexander Kornienko | d10d790 | 2018-04-06 13:01:12 +0000 | [diff] [blame] | 142 | std::unique_ptr<ASTConsumer> |
| 143 | clang::CreateASTDumper(std::unique_ptr<raw_ostream> Out, |
| 144 | StringRef FilterString, |
| 145 | bool DumpDecls, |
| 146 | bool Deserialize, |
| 147 | bool DumpLookups) { |
Aaron Ballman | 08d3b39 | 2017-06-15 00:00:08 +0000 | [diff] [blame] | 148 | assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump"); |
Alexander Kornienko | d10d790 | 2018-04-06 13:01:12 +0000 | [diff] [blame] | 149 | return llvm::make_unique<ASTPrinter>(std::move(Out), |
Richard Smith | 3a36ac1 | 2017-03-09 22:00:01 +0000 | [diff] [blame] | 150 | Deserialize ? ASTPrinter::DumpFull : |
| 151 | DumpDecls ? ASTPrinter::Dump : |
| 152 | ASTPrinter::None, |
| 153 | FilterString, DumpLookups); |
Douglas Gregor | 32887f0 | 2009-04-26 02:02:08 +0000 | [diff] [blame] | 154 | } |
Chris Lattner | 09c39db | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 155 | |
David Blaikie | 6beb6aa | 2014-08-10 19:56:51 +0000 | [diff] [blame] | 156 | std::unique_ptr<ASTConsumer> clang::CreateASTDeclNodeLister() { |
| 157 | return llvm::make_unique<ASTDeclNodeLister>(nullptr); |
Alexander Kornienko | 4de0359 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Ted Kremenek | 7c81bdd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 160 | //===----------------------------------------------------------------------===// |
| 161 | /// ASTViewer - AST Visualization |
| 162 | |
Ted Kremenek | 66d130a | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 163 | namespace { |
| 164 | class ASTViewer : public ASTConsumer { |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 165 | ASTContext *Context; |
Ted Kremenek | 66d130a | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 166 | public: |
Craig Topper | afa7cb3 | 2014-03-13 06:07:04 +0000 | [diff] [blame] | 167 | void Initialize(ASTContext &Context) override { |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 168 | this->Context = &Context; |
Ted Kremenek | 66d130a | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 169 | } |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 170 | |
Craig Topper | afa7cb3 | 2014-03-13 06:07:04 +0000 | [diff] [blame] | 171 | bool HandleTopLevelDecl(DeclGroupRef D) override { |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 172 | for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) |
| 173 | HandleTopLevelSingleDecl(*I); |
Argyrios Kyrtzidis | 841dd88 | 2011-11-18 00:26:59 +0000 | [diff] [blame] | 174 | return true; |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 175 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 176 | |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 177 | void HandleTopLevelSingleDecl(Decl *D); |
Ted Kremenek | 66d130a | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 178 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 179 | } |
Ted Kremenek | 66d130a | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 180 | |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 181 | void ASTViewer::HandleTopLevelSingleDecl(Decl *D) { |
Argyrios Kyrtzidis | 46f556d | 2010-07-07 11:31:23 +0000 | [diff] [blame] | 182 | if (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)) { |
| 183 | D->print(llvm::errs()); |
| 184 | |
| 185 | if (Stmt *Body = D->getBody()) { |
Benjamin Kramer | 89b422c | 2009-08-23 12:08:50 +0000 | [diff] [blame] | 186 | llvm::errs() << '\n'; |
Douglas Gregor | e2350a3 | 2009-09-12 00:08:48 +0000 | [diff] [blame] | 187 | Body->viewAST(); |
Benjamin Kramer | 89b422c | 2009-08-23 12:08:50 +0000 | [diff] [blame] | 188 | llvm::errs() << '\n'; |
Chris Lattner | c0c3dff | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 189 | } |
Chris Lattner | c0c3dff | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
David Blaikie | 6beb6aa | 2014-08-10 19:56:51 +0000 | [diff] [blame] | 193 | std::unique_ptr<ASTConsumer> clang::CreateASTViewer() { |
| 194 | return llvm::make_unique<ASTViewer>(); |
| 195 | } |
Ted Kremenek | 66d130a | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 196 | |
Ted Kremenek | 45c9e96 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 197 | //===----------------------------------------------------------------------===// |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 198 | /// DeclContextPrinter - Decl and DeclContext Visualization |
| 199 | |
| 200 | namespace { |
| 201 | |
| 202 | class DeclContextPrinter : public ASTConsumer { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 203 | raw_ostream& Out; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 204 | public: |
| 205 | DeclContextPrinter() : Out(llvm::errs()) {} |
| 206 | |
Craig Topper | afa7cb3 | 2014-03-13 06:07:04 +0000 | [diff] [blame] | 207 | void HandleTranslationUnit(ASTContext &C) override { |
Chris Lattner | cf16983 | 2009-03-28 04:11:33 +0000 | [diff] [blame] | 208 | PrintDeclContext(C.getTranslationUnitDecl(), 4); |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void PrintDeclContext(const DeclContext* DC, unsigned Indentation); |
| 212 | }; |
Chris Lattner | c0c3dff | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 213 | } // end anonymous namespace |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 214 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 215 | void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 216 | unsigned Indentation) { |
| 217 | // Print DeclContext name. |
Argyrios Kyrtzidis | be40b7e | 2009-01-13 13:11:58 +0000 | [diff] [blame] | 218 | switch (DC->getDeclKind()) { |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 219 | case Decl::TranslationUnit: |
| 220 | Out << "[translation unit] " << DC; |
| 221 | break; |
| 222 | case Decl::Namespace: { |
| 223 | Out << "[namespace] "; |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 224 | const NamespaceDecl* ND = cast<NamespaceDecl>(DC); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 225 | Out << *ND; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 226 | break; |
| 227 | } |
Zhongxing Xu | 100f30b | 2009-01-13 02:41:08 +0000 | [diff] [blame] | 228 | case Decl::Enum: { |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 229 | const EnumDecl* ED = cast<EnumDecl>(DC); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 230 | if (ED->isCompleteDefinition()) |
Zhongxing Xu | 100f30b | 2009-01-13 02:41:08 +0000 | [diff] [blame] | 231 | Out << "[enum] "; |
| 232 | else |
| 233 | Out << "<enum> "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 234 | Out << *ED; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 235 | break; |
Zhongxing Xu | 100f30b | 2009-01-13 02:41:08 +0000 | [diff] [blame] | 236 | } |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 237 | case Decl::Record: { |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 238 | const RecordDecl* RD = cast<RecordDecl>(DC); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 239 | if (RD->isCompleteDefinition()) |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 240 | Out << "[struct] "; |
| 241 | else |
| 242 | Out << "<struct> "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 243 | Out << *RD; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 244 | break; |
| 245 | } |
| 246 | case Decl::CXXRecord: { |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 247 | const CXXRecordDecl* RD = cast<CXXRecordDecl>(DC); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 248 | if (RD->isCompleteDefinition()) |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 249 | Out << "[class] "; |
| 250 | else |
| 251 | Out << "<class> "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 252 | Out << *RD << ' ' << DC; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 253 | break; |
| 254 | } |
| 255 | case Decl::ObjCMethod: |
| 256 | Out << "[objc method]"; |
| 257 | break; |
| 258 | case Decl::ObjCInterface: |
| 259 | Out << "[objc interface]"; |
| 260 | break; |
| 261 | case Decl::ObjCCategory: |
| 262 | Out << "[objc category]"; |
| 263 | break; |
| 264 | case Decl::ObjCProtocol: |
| 265 | Out << "[objc protocol]"; |
| 266 | break; |
| 267 | case Decl::ObjCImplementation: |
| 268 | Out << "[objc implementation]"; |
| 269 | break; |
| 270 | case Decl::ObjCCategoryImpl: |
| 271 | Out << "[objc categoryimpl]"; |
| 272 | break; |
| 273 | case Decl::LinkageSpec: |
| 274 | Out << "[linkage spec]"; |
| 275 | break; |
| 276 | case Decl::Block: |
| 277 | Out << "[block]"; |
| 278 | break; |
| 279 | case Decl::Function: { |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 280 | const FunctionDecl* FD = cast<FunctionDecl>(DC); |
Alexis Hunt | 4a8ea10 | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 281 | if (FD->doesThisDeclarationHaveABody()) |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 282 | Out << "[function] "; |
| 283 | else |
| 284 | Out << "<function> "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 285 | Out << *FD; |
Zhongxing Xu | 13e82c0 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 286 | // Print the parameters. |
| 287 | Out << "("; |
| 288 | bool PrintComma = false; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 289 | for (auto I : FD->parameters()) { |
Zhongxing Xu | 13e82c0 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 290 | if (PrintComma) |
| 291 | Out << ", "; |
| 292 | else |
| 293 | PrintComma = true; |
Aaron Ballman | f6bf62e | 2014-03-07 15:12:56 +0000 | [diff] [blame] | 294 | Out << *I; |
Zhongxing Xu | 13e82c0 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 295 | } |
| 296 | Out << ")"; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 297 | break; |
| 298 | } |
| 299 | case Decl::CXXMethod: { |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 300 | const CXXMethodDecl* D = cast<CXXMethodDecl>(DC); |
Argyrios Kyrtzidis | c4b766b | 2009-06-17 22:49:50 +0000 | [diff] [blame] | 301 | if (D->isOutOfLine()) |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 302 | Out << "[c++ method] "; |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 303 | else if (D->isImplicit()) |
| 304 | Out << "(c++ method) "; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 305 | else |
| 306 | Out << "<c++ method> "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 307 | Out << *D; |
Zhongxing Xu | 13e82c0 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 308 | // Print the parameters. |
| 309 | Out << "("; |
| 310 | bool PrintComma = false; |
David Majnemer | a3debed | 2016-06-24 05:33:44 +0000 | [diff] [blame] | 311 | for (ParmVarDecl *Parameter : D->parameters()) { |
Zhongxing Xu | 13e82c0 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 312 | if (PrintComma) |
| 313 | Out << ", "; |
| 314 | else |
| 315 | PrintComma = true; |
David Majnemer | a3debed | 2016-06-24 05:33:44 +0000 | [diff] [blame] | 316 | Out << *Parameter; |
Zhongxing Xu | 13e82c0 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 317 | } |
| 318 | Out << ")"; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 319 | |
| 320 | // Check the semantic DeclContext. |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 321 | const DeclContext* SemaDC = D->getDeclContext(); |
| 322 | const DeclContext* LexicalDC = D->getLexicalDeclContext(); |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 323 | if (SemaDC != LexicalDC) |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 324 | Out << " [[" << SemaDC << "]]"; |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 325 | |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 326 | break; |
| 327 | } |
| 328 | case Decl::CXXConstructor: { |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 329 | const CXXConstructorDecl* D = cast<CXXConstructorDecl>(DC); |
Argyrios Kyrtzidis | c4b766b | 2009-06-17 22:49:50 +0000 | [diff] [blame] | 330 | if (D->isOutOfLine()) |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 331 | Out << "[c++ ctor] "; |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 332 | else if (D->isImplicit()) |
| 333 | Out << "(c++ ctor) "; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 334 | else |
| 335 | Out << "<c++ ctor> "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 336 | Out << *D; |
Zhongxing Xu | 13e82c0 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 337 | // Print the parameters. |
| 338 | Out << "("; |
| 339 | bool PrintComma = false; |
David Majnemer | a3debed | 2016-06-24 05:33:44 +0000 | [diff] [blame] | 340 | for (ParmVarDecl *Parameter : D->parameters()) { |
Zhongxing Xu | 13e82c0 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 341 | if (PrintComma) |
| 342 | Out << ", "; |
| 343 | else |
| 344 | PrintComma = true; |
David Majnemer | a3debed | 2016-06-24 05:33:44 +0000 | [diff] [blame] | 345 | Out << *Parameter; |
Zhongxing Xu | 13e82c0 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 346 | } |
| 347 | Out << ")"; |
| 348 | |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 349 | // Check the semantic DC. |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 350 | const DeclContext* SemaDC = D->getDeclContext(); |
| 351 | const DeclContext* LexicalDC = D->getLexicalDeclContext(); |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 352 | if (SemaDC != LexicalDC) |
| 353 | Out << " [[" << SemaDC << "]]"; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 354 | break; |
| 355 | } |
| 356 | case Decl::CXXDestructor: { |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 357 | const CXXDestructorDecl* D = cast<CXXDestructorDecl>(DC); |
Argyrios Kyrtzidis | c4b766b | 2009-06-17 22:49:50 +0000 | [diff] [blame] | 358 | if (D->isOutOfLine()) |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 359 | Out << "[c++ dtor] "; |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 360 | else if (D->isImplicit()) |
| 361 | Out << "(c++ dtor) "; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 362 | else |
| 363 | Out << "<c++ dtor> "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 364 | Out << *D; |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 365 | // Check the semantic DC. |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 366 | const DeclContext* SemaDC = D->getDeclContext(); |
| 367 | const DeclContext* LexicalDC = D->getLexicalDeclContext(); |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 368 | if (SemaDC != LexicalDC) |
| 369 | Out << " [[" << SemaDC << "]]"; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 370 | break; |
| 371 | } |
| 372 | case Decl::CXXConversion: { |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 373 | const CXXConversionDecl* D = cast<CXXConversionDecl>(DC); |
Argyrios Kyrtzidis | c4b766b | 2009-06-17 22:49:50 +0000 | [diff] [blame] | 374 | if (D->isOutOfLine()) |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 375 | Out << "[c++ conversion] "; |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 376 | else if (D->isImplicit()) |
| 377 | Out << "(c++ conversion) "; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 378 | else |
| 379 | Out << "<c++ conversion> "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 380 | Out << *D; |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 381 | // Check the semantic DC. |
Argyrios Kyrtzidis | 9b7bd9b | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 382 | const DeclContext* SemaDC = D->getDeclContext(); |
| 383 | const DeclContext* LexicalDC = D->getLexicalDeclContext(); |
Zhongxing Xu | d90c6d9 | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 384 | if (SemaDC != LexicalDC) |
| 385 | Out << " [[" << SemaDC << "]]"; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 386 | break; |
| 387 | } |
| 388 | |
Alex Lorenz | eebc494 | 2017-01-03 12:11:17 +0000 | [diff] [blame] | 389 | case Decl::ClassTemplateSpecialization: { |
| 390 | const auto *CTSD = cast<ClassTemplateSpecializationDecl>(DC); |
| 391 | if (CTSD->isCompleteDefinition()) |
| 392 | Out << "[class template specialization] "; |
| 393 | else |
| 394 | Out << "<class template specialization> "; |
| 395 | Out << *CTSD; |
| 396 | break; |
| 397 | } |
| 398 | |
| 399 | case Decl::ClassTemplatePartialSpecialization: { |
| 400 | const auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl>(DC); |
| 401 | if (CTPSD->isCompleteDefinition()) |
| 402 | Out << "[class template partial specialization] "; |
| 403 | else |
| 404 | Out << "<class template partial specialization> "; |
| 405 | Out << *CTPSD; |
| 406 | break; |
| 407 | } |
| 408 | |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 409 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 410 | llvm_unreachable("a decl that inherits DeclContext isn't handled"); |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | Out << "\n"; |
| 414 | |
| 415 | // Print decls in the DeclContext. |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 416 | for (auto *I : DC->decls()) { |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 417 | for (unsigned i = 0; i < Indentation; ++i) |
Mike Stump | 74a7647 | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 418 | Out << " "; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 419 | |
| 420 | Decl::Kind DK = I->getKind(); |
| 421 | switch (DK) { |
| 422 | case Decl::Namespace: |
| 423 | case Decl::Enum: |
| 424 | case Decl::Record: |
| 425 | case Decl::CXXRecord: |
| 426 | case Decl::ObjCMethod: |
| 427 | case Decl::ObjCInterface: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | case Decl::ObjCCategory: |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 429 | case Decl::ObjCProtocol: |
| 430 | case Decl::ObjCImplementation: |
| 431 | case Decl::ObjCCategoryImpl: |
| 432 | case Decl::LinkageSpec: |
| 433 | case Decl::Block: |
| 434 | case Decl::Function: |
| 435 | case Decl::CXXMethod: |
| 436 | case Decl::CXXConstructor: |
| 437 | case Decl::CXXDestructor: |
| 438 | case Decl::CXXConversion: |
Alex Lorenz | eebc494 | 2017-01-03 12:11:17 +0000 | [diff] [blame] | 439 | case Decl::ClassTemplateSpecialization: |
| 440 | case Decl::ClassTemplatePartialSpecialization: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 441 | DeclContext* DC = cast<DeclContext>(I); |
Mike Stump | 74a7647 | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 442 | PrintDeclContext(DC, Indentation+2); |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 443 | break; |
| 444 | } |
Francois Pichet | 48e2d9e | 2010-12-21 03:08:02 +0000 | [diff] [blame] | 445 | case Decl::IndirectField: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 446 | IndirectFieldDecl* IFD = cast<IndirectFieldDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 447 | Out << "<IndirectField> " << *IFD << '\n'; |
Francois Pichet | 48e2d9e | 2010-12-21 03:08:02 +0000 | [diff] [blame] | 448 | break; |
| 449 | } |
Chris Lattner | d12b480 | 2011-02-18 00:52:55 +0000 | [diff] [blame] | 450 | case Decl::Label: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 451 | LabelDecl *LD = cast<LabelDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 452 | Out << "<Label> " << *LD << '\n'; |
Chris Lattner | d12b480 | 2011-02-18 00:52:55 +0000 | [diff] [blame] | 453 | break; |
| 454 | } |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 455 | case Decl::Field: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 456 | FieldDecl *FD = cast<FieldDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 457 | Out << "<field> " << *FD << '\n'; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 458 | break; |
| 459 | } |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 460 | case Decl::Typedef: |
| 461 | case Decl::TypeAlias: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 462 | TypedefNameDecl* TD = cast<TypedefNameDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 463 | Out << "<typedef> " << *TD << '\n'; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 464 | break; |
| 465 | } |
| 466 | case Decl::EnumConstant: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 467 | EnumConstantDecl* ECD = cast<EnumConstantDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 468 | Out << "<enum constant> " << *ECD << '\n'; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 469 | break; |
| 470 | } |
| 471 | case Decl::Var: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 472 | VarDecl* VD = cast<VarDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 473 | Out << "<var> " << *VD << '\n'; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 474 | break; |
| 475 | } |
| 476 | case Decl::ImplicitParam: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 477 | ImplicitParamDecl* IPD = cast<ImplicitParamDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 478 | Out << "<implicit parameter> " << *IPD << '\n'; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 479 | break; |
| 480 | } |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 481 | case Decl::ParmVar: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 482 | ParmVarDecl* PVD = cast<ParmVarDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 483 | Out << "<parameter> " << *PVD << '\n'; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 484 | break; |
| 485 | } |
| 486 | case Decl::ObjCProperty: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 487 | ObjCPropertyDecl* OPD = cast<ObjCPropertyDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 488 | Out << "<objc property> " << *OPD << '\n'; |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 489 | break; |
| 490 | } |
Eli Friedman | 897bc03 | 2009-12-08 06:22:37 +0000 | [diff] [blame] | 491 | case Decl::FunctionTemplate: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 492 | FunctionTemplateDecl* FTD = cast<FunctionTemplateDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 493 | Out << "<function template> " << *FTD << '\n'; |
Eli Friedman | 897bc03 | 2009-12-08 06:22:37 +0000 | [diff] [blame] | 494 | break; |
| 495 | } |
Eli Friedman | c6f59b1 | 2010-01-03 02:01:11 +0000 | [diff] [blame] | 496 | case Decl::FileScopeAsm: { |
| 497 | Out << "<file-scope asm>\n"; |
| 498 | break; |
| 499 | } |
| 500 | case Decl::UsingDirective: { |
| 501 | Out << "<using directive>\n"; |
| 502 | break; |
| 503 | } |
| 504 | case Decl::NamespaceAlias: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 505 | NamespaceAliasDecl* NAD = cast<NamespaceAliasDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 506 | Out << "<namespace alias> " << *NAD << '\n'; |
Eli Friedman | c6f59b1 | 2010-01-03 02:01:11 +0000 | [diff] [blame] | 507 | break; |
| 508 | } |
Zhongxing Xu | 00c6046 | 2010-01-20 03:21:28 +0000 | [diff] [blame] | 509 | case Decl::ClassTemplate: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 510 | ClassTemplateDecl *CTD = cast<ClassTemplateDecl>(I); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 511 | Out << "<class template> " << *CTD << '\n'; |
Zhongxing Xu | 00c6046 | 2010-01-20 03:21:28 +0000 | [diff] [blame] | 512 | break; |
| 513 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 514 | case Decl::OMPThreadPrivate: { |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 515 | Out << "<omp threadprivate> " << '"' << I << "\"\n"; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 516 | break; |
| 517 | } |
Alex Lorenz | 14abc7f | 2017-01-03 12:07:20 +0000 | [diff] [blame] | 518 | case Decl::Friend: { |
| 519 | Out << "<friend>"; |
| 520 | if (const NamedDecl *ND = cast<FriendDecl>(I)->getFriendDecl()) |
| 521 | Out << ' ' << *ND; |
| 522 | Out << "\n"; |
| 523 | break; |
| 524 | } |
Alex Lorenz | 1d86ab4 | 2017-01-03 12:08:40 +0000 | [diff] [blame] | 525 | case Decl::Using: { |
| 526 | Out << "<using> " << *cast<UsingDecl>(I) << "\n"; |
| 527 | break; |
| 528 | } |
| 529 | case Decl::UsingShadow: { |
| 530 | Out << "<using shadow> " << *cast<UsingShadowDecl>(I) << "\n"; |
| 531 | break; |
| 532 | } |
Alex Lorenz | 009978b | 2017-01-03 12:09:39 +0000 | [diff] [blame] | 533 | case Decl::Empty: { |
| 534 | Out << "<empty>\n"; |
| 535 | break; |
| 536 | } |
Alex Lorenz | 21c3293 | 2017-01-03 12:12:36 +0000 | [diff] [blame] | 537 | case Decl::AccessSpec: { |
| 538 | Out << "<access specifier>\n"; |
| 539 | break; |
| 540 | } |
Alex Lorenz | a186417 | 2017-01-03 12:14:59 +0000 | [diff] [blame] | 541 | case Decl::VarTemplate: { |
| 542 | Out << "<var template> " << *cast<VarTemplateDecl>(I) << "\n"; |
| 543 | break; |
| 544 | } |
Alex Lorenz | b44b4cb | 2017-01-03 12:16:02 +0000 | [diff] [blame] | 545 | case Decl::StaticAssert: { |
| 546 | Out << "<static assert>\n"; |
| 547 | break; |
| 548 | } |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 549 | default: |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 550 | Out << "DeclKind: " << DK << '"' << I << "\"\n"; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 551 | llvm_unreachable("decl unhandled"); |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | } |
David Blaikie | 6beb6aa | 2014-08-10 19:56:51 +0000 | [diff] [blame] | 555 | std::unique_ptr<ASTConsumer> clang::CreateDeclContextPrinter() { |
| 556 | return llvm::make_unique<DeclContextPrinter>(); |
Zhongxing Xu | 9aabf02 | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 557 | } |