blob: b0746b290cf4e58b17625c86ef9db9efb0a36f04 [file] [log] [blame]
Chris Lattner97e8b6f2007-10-07 06:04:32 +00001//===--- ASTConsumers.cpp - ASTConsumer implementations -------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner97e8b6f2007-10-07 06:04:32 +000010// AST Consumer Implementations.
Reid Spencer5f016e22007-07-11 17:01:13 +000011//
12//===----------------------------------------------------------------------===//
13
Eli Friedman39d7c4d2009-05-18 22:50:54 +000014#include "clang/Frontend/ASTConsumers.h"
Nico Weberdae86962008-08-09 18:32:11 +000015#include "clang/Basic/Diagnostic.h"
Ted Kremenek54117722007-12-20 00:34:58 +000016#include "clang/Basic/SourceManager.h"
17#include "clang/Basic/FileManager.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000018#include "clang/AST/AST.h"
Chris Lattner3d4997d2007-09-15 23:02:28 +000019#include "clang/AST/ASTConsumer.h"
Chris Lattner557c5b12009-03-28 04:27:18 +000020#include "clang/AST/ASTContext.h"
Anders Carlsson78762eb2009-09-24 18:54:49 +000021#include "clang/AST/RecordLayout.h"
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000022#include "clang/AST/PrettyPrinter.h"
Ted Kremenek815c78f2008-08-05 18:50:11 +000023#include "llvm/Module.h"
Ted Kremenekcb330932008-02-18 21:21:23 +000024#include "llvm/Support/Timer.h"
Ted Kremeneka95d3752008-09-13 05:16:45 +000025#include "llvm/Support/raw_ostream.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000026#include "llvm/Support/Path.h"
Chris Lattner6000dac2007-08-08 22:51:59 +000027using namespace clang;
Reid Spencer5f016e22007-07-11 17:01:13 +000028
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000029//===----------------------------------------------------------------------===//
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000030/// ASTPrinter - Pretty-printer and dumper of ASTs
Chris Lattner6000dac2007-08-08 22:51:59 +000031
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000032namespace {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000033 class ASTPrinter : public ASTConsumer {
Chris Lattner5f9e2722011-07-23 10:55:15 +000034 raw_ostream &Out;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000035 bool Dump;
Mike Stump1eb44332009-09-09 15:08:12 +000036
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000037 public:
Chris Lattner5f9e2722011-07-23 10:55:15 +000038 ASTPrinter(raw_ostream* o = NULL, bool Dump = false)
Argyrios Kyrtzidisbc1e1462010-08-03 17:29:57 +000039 : Out(o? *o : llvm::outs()), Dump(Dump) { }
Mike Stump1eb44332009-09-09 15:08:12 +000040
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000041 virtual void HandleTranslationUnit(ASTContext &Context) {
42 PrintingPolicy Policy = Context.PrintingPolicy;
43 Policy.Dump = Dump;
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +000044 Context.getTranslationUnitDecl()->print(Out, Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +000045 }
Chris Lattner3d4997d2007-09-15 23:02:28 +000046 };
Chris Lattnerb23ff6b2009-03-28 05:44:17 +000047} // end anonymous namespace
Chris Lattner6000dac2007-08-08 22:51:59 +000048
Chris Lattner5f9e2722011-07-23 10:55:15 +000049ASTConsumer *clang::CreateASTPrinter(raw_ostream* out) {
Ted Kremenekea75c552007-11-28 21:32:21 +000050 return new ASTPrinter(out);
51}
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000052
Mike Stump1eb44332009-09-09 15:08:12 +000053ASTConsumer *clang::CreateASTDumper() {
54 return new ASTPrinter(0, true);
Douglas Gregor609e72f2009-04-26 02:02:08 +000055}
Chris Lattner3d4997d2007-09-15 23:02:28 +000056
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000057//===----------------------------------------------------------------------===//
58/// ASTViewer - AST Visualization
59
Ted Kremenek80de08f2007-09-19 21:29:43 +000060namespace {
61 class ASTViewer : public ASTConsumer {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000062 ASTContext *Context;
Ted Kremenek80de08f2007-09-19 21:29:43 +000063 public:
Ted Kremenek95041a22007-12-19 22:51:13 +000064 void Initialize(ASTContext &Context) {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000065 this->Context = &Context;
Ted Kremenek80de08f2007-09-19 21:29:43 +000066 }
Chris Lattner682bf922009-03-29 16:50:03 +000067
68 virtual void HandleTopLevelDecl(DeclGroupRef D) {
69 for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I)
70 HandleTopLevelSingleDecl(*I);
71 }
Mike Stump1eb44332009-09-09 15:08:12 +000072
Chris Lattner682bf922009-03-29 16:50:03 +000073 void HandleTopLevelSingleDecl(Decl *D);
Ted Kremenek80de08f2007-09-19 21:29:43 +000074 };
75}
76
Chris Lattner682bf922009-03-29 16:50:03 +000077void ASTViewer::HandleTopLevelSingleDecl(Decl *D) {
Argyrios Kyrtzidis9d96f922010-07-07 11:31:23 +000078 if (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)) {
79 D->print(llvm::errs());
80
81 if (Stmt *Body = D->getBody()) {
Benjamin Kramer6cb7c1a2009-08-23 12:08:50 +000082 llvm::errs() << '\n';
Douglas Gregoraf3280f2009-09-12 00:08:48 +000083 Body->viewAST();
Benjamin Kramer6cb7c1a2009-08-23 12:08:50 +000084 llvm::errs() << '\n';
Chris Lattnerb23ff6b2009-03-28 05:44:17 +000085 }
Chris Lattnerb23ff6b2009-03-28 05:44:17 +000086 }
87}
88
89
Ted Kremenek80de08f2007-09-19 21:29:43 +000090ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); }
91
Ted Kremenek74bf2c92007-09-07 23:47:56 +000092//===----------------------------------------------------------------------===//
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +000093/// DeclContextPrinter - Decl and DeclContext Visualization
94
95namespace {
96
97class DeclContextPrinter : public ASTConsumer {
Chris Lattner5f9e2722011-07-23 10:55:15 +000098 raw_ostream& Out;
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +000099public:
100 DeclContextPrinter() : Out(llvm::errs()) {}
101
Chris Lattnerdacbc5d2009-03-28 04:11:33 +0000102 void HandleTranslationUnit(ASTContext &C) {
103 PrintDeclContext(C.getTranslationUnitDecl(), 4);
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000104 }
105
106 void PrintDeclContext(const DeclContext* DC, unsigned Indentation);
107};
Chris Lattnerb23ff6b2009-03-28 05:44:17 +0000108} // end anonymous namespace
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000109
Mike Stump1eb44332009-09-09 15:08:12 +0000110void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000111 unsigned Indentation) {
112 // Print DeclContext name.
Argyrios Kyrtzidis9b9ca012009-01-13 13:11:58 +0000113 switch (DC->getDeclKind()) {
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000114 case Decl::TranslationUnit:
115 Out << "[translation unit] " << DC;
116 break;
117 case Decl::Namespace: {
118 Out << "[namespace] ";
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000119 const NamespaceDecl* ND = cast<NamespaceDecl>(DC);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000120 Out << ND;
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000121 break;
122 }
Zhongxing Xu867c39e2009-01-13 02:41:08 +0000123 case Decl::Enum: {
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000124 const EnumDecl* ED = cast<EnumDecl>(DC);
Zhongxing Xu867c39e2009-01-13 02:41:08 +0000125 if (ED->isDefinition())
126 Out << "[enum] ";
127 else
128 Out << "<enum> ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000129 Out << ED;
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000130 break;
Zhongxing Xu867c39e2009-01-13 02:41:08 +0000131 }
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000132 case Decl::Record: {
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000133 const RecordDecl* RD = cast<RecordDecl>(DC);
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000134 if (RD->isDefinition())
135 Out << "[struct] ";
136 else
137 Out << "<struct> ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000138 Out << RD;
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000139 break;
140 }
141 case Decl::CXXRecord: {
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000142 const CXXRecordDecl* RD = cast<CXXRecordDecl>(DC);
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000143 if (RD->isDefinition())
144 Out << "[class] ";
145 else
146 Out << "<class> ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000147 Out << RD << ' ' << DC;
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000148 break;
149 }
150 case Decl::ObjCMethod:
151 Out << "[objc method]";
152 break;
153 case Decl::ObjCInterface:
154 Out << "[objc interface]";
155 break;
156 case Decl::ObjCCategory:
157 Out << "[objc category]";
158 break;
159 case Decl::ObjCProtocol:
160 Out << "[objc protocol]";
161 break;
162 case Decl::ObjCImplementation:
163 Out << "[objc implementation]";
164 break;
165 case Decl::ObjCCategoryImpl:
166 Out << "[objc categoryimpl]";
167 break;
168 case Decl::LinkageSpec:
169 Out << "[linkage spec]";
170 break;
171 case Decl::Block:
172 Out << "[block]";
173 break;
174 case Decl::Function: {
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000175 const FunctionDecl* FD = cast<FunctionDecl>(DC);
Sean Hunt10620eb2011-05-06 20:44:56 +0000176 if (FD->doesThisDeclarationHaveABody())
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000177 Out << "[function] ";
178 else
179 Out << "<function> ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000180 Out << FD;
Zhongxing Xuca04ce42009-01-13 06:25:33 +0000181 // Print the parameters.
182 Out << "(";
183 bool PrintComma = false;
Mike Stump1eb44332009-09-09 15:08:12 +0000184 for (FunctionDecl::param_const_iterator I = FD->param_begin(),
Zhongxing Xuca04ce42009-01-13 06:25:33 +0000185 E = FD->param_end(); I != E; ++I) {
186 if (PrintComma)
187 Out << ", ";
188 else
189 PrintComma = true;
Benjamin Kramer900fc632010-04-17 09:33:03 +0000190 Out << *I;
Zhongxing Xuca04ce42009-01-13 06:25:33 +0000191 }
192 Out << ")";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000193 break;
194 }
195 case Decl::CXXMethod: {
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000196 const CXXMethodDecl* D = cast<CXXMethodDecl>(DC);
Argyrios Kyrtzidisf5cecfb2009-06-17 22:49:50 +0000197 if (D->isOutOfLine())
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000198 Out << "[c++ method] ";
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000199 else if (D->isImplicit())
200 Out << "(c++ method) ";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000201 else
202 Out << "<c++ method> ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000203 Out << D;
Zhongxing Xuca04ce42009-01-13 06:25:33 +0000204 // Print the parameters.
205 Out << "(";
206 bool PrintComma = false;
Mike Stump1eb44332009-09-09 15:08:12 +0000207 for (FunctionDecl::param_const_iterator I = D->param_begin(),
Zhongxing Xuca04ce42009-01-13 06:25:33 +0000208 E = D->param_end(); I != E; ++I) {
209 if (PrintComma)
210 Out << ", ";
211 else
212 PrintComma = true;
Benjamin Kramer900fc632010-04-17 09:33:03 +0000213 Out << *I;
Zhongxing Xuca04ce42009-01-13 06:25:33 +0000214 }
215 Out << ")";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000216
217 // Check the semantic DeclContext.
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000218 const DeclContext* SemaDC = D->getDeclContext();
219 const DeclContext* LexicalDC = D->getLexicalDeclContext();
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000220 if (SemaDC != LexicalDC)
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000221 Out << " [[" << SemaDC << "]]";
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000222
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000223 break;
224 }
225 case Decl::CXXConstructor: {
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000226 const CXXConstructorDecl* D = cast<CXXConstructorDecl>(DC);
Argyrios Kyrtzidisf5cecfb2009-06-17 22:49:50 +0000227 if (D->isOutOfLine())
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000228 Out << "[c++ ctor] ";
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000229 else if (D->isImplicit())
230 Out << "(c++ ctor) ";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000231 else
232 Out << "<c++ ctor> ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000233 Out << D;
Zhongxing Xuca04ce42009-01-13 06:25:33 +0000234 // Print the parameters.
235 Out << "(";
236 bool PrintComma = false;
Mike Stump1eb44332009-09-09 15:08:12 +0000237 for (FunctionDecl::param_const_iterator I = D->param_begin(),
Zhongxing Xuca04ce42009-01-13 06:25:33 +0000238 E = D->param_end(); I != E; ++I) {
239 if (PrintComma)
240 Out << ", ";
241 else
242 PrintComma = true;
Benjamin Kramer900fc632010-04-17 09:33:03 +0000243 Out << *I;
Zhongxing Xuca04ce42009-01-13 06:25:33 +0000244 }
245 Out << ")";
246
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000247 // Check the semantic DC.
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000248 const DeclContext* SemaDC = D->getDeclContext();
249 const DeclContext* LexicalDC = D->getLexicalDeclContext();
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000250 if (SemaDC != LexicalDC)
251 Out << " [[" << SemaDC << "]]";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000252 break;
253 }
254 case Decl::CXXDestructor: {
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000255 const CXXDestructorDecl* D = cast<CXXDestructorDecl>(DC);
Argyrios Kyrtzidisf5cecfb2009-06-17 22:49:50 +0000256 if (D->isOutOfLine())
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000257 Out << "[c++ dtor] ";
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000258 else if (D->isImplicit())
259 Out << "(c++ dtor) ";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000260 else
261 Out << "<c++ dtor> ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000262 Out << D;
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000263 // Check the semantic DC.
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000264 const DeclContext* SemaDC = D->getDeclContext();
265 const DeclContext* LexicalDC = D->getLexicalDeclContext();
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000266 if (SemaDC != LexicalDC)
267 Out << " [[" << SemaDC << "]]";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000268 break;
269 }
270 case Decl::CXXConversion: {
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000271 const CXXConversionDecl* D = cast<CXXConversionDecl>(DC);
Argyrios Kyrtzidisf5cecfb2009-06-17 22:49:50 +0000272 if (D->isOutOfLine())
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000273 Out << "[c++ conversion] ";
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000274 else if (D->isImplicit())
275 Out << "(c++ conversion) ";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000276 else
277 Out << "<c++ conversion> ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000278 Out << D;
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000279 // Check the semantic DC.
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000280 const DeclContext* SemaDC = D->getDeclContext();
281 const DeclContext* LexicalDC = D->getLexicalDeclContext();
Zhongxing Xu2a3eb0e2009-01-13 03:26:38 +0000282 if (SemaDC != LexicalDC)
283 Out << " [[" << SemaDC << "]]";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000284 break;
285 }
286
287 default:
288 assert(0 && "a decl that inherits DeclContext isn't handled");
289 }
290
291 Out << "\n";
292
293 // Print decls in the DeclContext.
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000294 for (DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end();
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000295 I != E; ++I) {
296 for (unsigned i = 0; i < Indentation; ++i)
Mike Stump071e4da2009-02-10 20:16:46 +0000297 Out << " ";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000298
299 Decl::Kind DK = I->getKind();
300 switch (DK) {
301 case Decl::Namespace:
302 case Decl::Enum:
303 case Decl::Record:
304 case Decl::CXXRecord:
305 case Decl::ObjCMethod:
306 case Decl::ObjCInterface:
Mike Stump1eb44332009-09-09 15:08:12 +0000307 case Decl::ObjCCategory:
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000308 case Decl::ObjCProtocol:
309 case Decl::ObjCImplementation:
310 case Decl::ObjCCategoryImpl:
311 case Decl::LinkageSpec:
312 case Decl::Block:
313 case Decl::Function:
314 case Decl::CXXMethod:
315 case Decl::CXXConstructor:
316 case Decl::CXXDestructor:
317 case Decl::CXXConversion:
318 {
Argyrios Kyrtzidis7ad5bf32009-02-16 14:29:59 +0000319 DeclContext* DC = cast<DeclContext>(*I);
Mike Stump071e4da2009-02-10 20:16:46 +0000320 PrintDeclContext(DC, Indentation+2);
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000321 break;
322 }
Francois Picheta3d39c02010-12-21 03:08:02 +0000323 case Decl::IndirectField: {
324 IndirectFieldDecl* IFD = cast<IndirectFieldDecl>(*I);
325 Out << "<IndirectField> " << IFD << '\n';
326 break;
327 }
Chris Lattner21ac10d2011-02-18 00:52:55 +0000328 case Decl::Label: {
329 LabelDecl *LD = cast<LabelDecl>(*I);
330 Out << "<Label> " << LD << '\n';
331 break;
332 }
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000333 case Decl::Field: {
Chris Lattner21ac10d2011-02-18 00:52:55 +0000334 FieldDecl *FD = cast<FieldDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000335 Out << "<field> " << FD << '\n';
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000336 break;
337 }
Richard Smith162e1c12011-04-15 14:24:37 +0000338 case Decl::Typedef:
339 case Decl::TypeAlias: {
340 TypedefNameDecl* TD = cast<TypedefNameDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000341 Out << "<typedef> " << TD << '\n';
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000342 break;
343 }
344 case Decl::EnumConstant: {
345 EnumConstantDecl* ECD = cast<EnumConstantDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000346 Out << "<enum constant> " << ECD << '\n';
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000347 break;
348 }
349 case Decl::Var: {
350 VarDecl* VD = cast<VarDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000351 Out << "<var> " << VD << '\n';
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000352 break;
353 }
354 case Decl::ImplicitParam: {
355 ImplicitParamDecl* IPD = cast<ImplicitParamDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000356 Out << "<implicit parameter> " << IPD << '\n';
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000357 break;
358 }
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000359 case Decl::ParmVar: {
360 ParmVarDecl* PVD = cast<ParmVarDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000361 Out << "<parameter> " << PVD << '\n';
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000362 break;
363 }
364 case Decl::ObjCProperty: {
365 ObjCPropertyDecl* OPD = cast<ObjCPropertyDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000366 Out << "<objc property> " << OPD << '\n';
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000367 break;
368 }
Eli Friedman7ac1c9e2009-12-08 06:22:37 +0000369 case Decl::FunctionTemplate: {
370 FunctionTemplateDecl* FTD = cast<FunctionTemplateDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000371 Out << "<function template> " << FTD << '\n';
Eli Friedman7ac1c9e2009-12-08 06:22:37 +0000372 break;
373 }
Eli Friedman368a55d2010-01-03 02:01:11 +0000374 case Decl::FileScopeAsm: {
375 Out << "<file-scope asm>\n";
376 break;
377 }
378 case Decl::UsingDirective: {
379 Out << "<using directive>\n";
380 break;
381 }
382 case Decl::NamespaceAlias: {
383 NamespaceAliasDecl* NAD = cast<NamespaceAliasDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000384 Out << "<namespace alias> " << NAD << '\n';
Eli Friedman368a55d2010-01-03 02:01:11 +0000385 break;
386 }
Zhongxing Xu2f3cd9c2010-01-20 03:21:28 +0000387 case Decl::ClassTemplate: {
388 ClassTemplateDecl *CTD = cast<ClassTemplateDecl>(*I);
Benjamin Kramer900fc632010-04-17 09:33:03 +0000389 Out << "<class template> " << CTD << '\n';
Zhongxing Xu2f3cd9c2010-01-20 03:21:28 +0000390 break;
391 }
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000392 default:
Benjamin Kramer900fc632010-04-17 09:33:03 +0000393 Out << "DeclKind: " << DK << '"' << *I << "\"\n";
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000394 assert(0 && "decl unhandled");
395 }
396 }
397}
Mike Stump1eb44332009-09-09 15:08:12 +0000398ASTConsumer *clang::CreateDeclContextPrinter() {
399 return new DeclContextPrinter();
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +0000400}
401
402//===----------------------------------------------------------------------===//
John McCallf3514242010-11-24 11:21:45 +0000403/// ASTDumperXML - In-depth XML dumping.
404
405namespace {
406class ASTDumpXML : public ASTConsumer {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000407 raw_ostream &OS;
John McCallf3514242010-11-24 11:21:45 +0000408
409public:
Chris Lattner5f9e2722011-07-23 10:55:15 +0000410 ASTDumpXML(raw_ostream &OS) : OS(OS) {}
John McCallf3514242010-11-24 11:21:45 +0000411
412 void HandleTranslationUnit(ASTContext &C) {
413 C.getTranslationUnitDecl()->dumpXML(OS);
414 }
415};
416}
417
Chris Lattner5f9e2722011-07-23 10:55:15 +0000418ASTConsumer *clang::CreateASTDumperXML(raw_ostream &OS) {
John McCallf3514242010-11-24 11:21:45 +0000419 return new ASTDumpXML(OS);
420}