blob: 5cfaab26e53350db790b79a17231d32b45d318d6 [file] [log] [blame]
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001//===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattnercbe4f772007-08-08 22:51:59 +000010// This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which
11// pretty print the AST back out to C code.
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000012//
13//===----------------------------------------------------------------------===//
14
Benjamin Kramer4ab984e2012-07-04 20:19:54 +000015#include "clang/AST/ASTContext.h"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000016#include "clang/AST/Attr.h"
Douglas Gregorc7acfdf2009-01-06 05:10:23 +000017#include "clang/AST/DeclCXX.h"
Ted Kremenek5c84c012007-10-17 18:36:42 +000018#include "clang/AST/DeclObjC.h"
Douglas Gregorcdbc5392011-01-15 01:15:58 +000019#include "clang/AST/DeclTemplate.h"
Douglas Gregor882211c2010-04-28 22:16:22 +000020#include "clang/AST/Expr.h"
Douglas Gregor2b88c112010-09-08 00:15:04 +000021#include "clang/AST/ExprCXX.h"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000022#include "clang/AST/PrettyPrinter.h"
23#include "clang/AST/StmtVisitor.h"
Jordan Rose00d1b592013-02-08 22:30:27 +000024#include "clang/Basic/CharInfo.h"
Benjamin Kramer49038022012-02-04 13:45:25 +000025#include "llvm/ADT/SmallString.h"
Jordan Rose00d1b592013-02-08 22:30:27 +000026#include "llvm/Support/Format.h"
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000027using namespace clang;
28
29//===----------------------------------------------------------------------===//
30// StmtPrinter Visitor
31//===----------------------------------------------------------------------===//
32
33namespace {
Benjamin Kramer26222b62009-11-28 19:03:38 +000034 class StmtPrinter : public StmtVisitor<StmtPrinter> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000035 raw_ostream &OS;
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000036 unsigned IndentLevel;
Ted Kremenek04f3cee2007-08-31 21:30:12 +000037 clang::PrinterHelper* Helper;
Douglas Gregor7de59662009-05-29 20:38:28 +000038 PrintingPolicy Policy;
39
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000040 public:
Richard Smith235341b2012-08-16 03:56:14 +000041 StmtPrinter(raw_ostream &os, PrinterHelper* helper,
Chris Lattnerc61089a2009-06-30 01:26:17 +000042 const PrintingPolicy &Policy,
Douglas Gregor7de59662009-05-29 20:38:28 +000043 unsigned Indentation = 0)
Richard Smith235341b2012-08-16 03:56:14 +000044 : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy) {}
Mike Stump11289f42009-09-09 15:08:12 +000045
Douglas Gregor7de59662009-05-29 20:38:28 +000046 void PrintStmt(Stmt *S) {
47 PrintStmt(S, Policy.Indentation);
48 }
49
50 void PrintStmt(Stmt *S, int SubIndent) {
Chris Lattnerb9eb5a12007-05-20 22:52:15 +000051 IndentLevel += SubIndent;
Chris Lattnera076fde2007-05-31 18:21:33 +000052 if (S && isa<Expr>(S)) {
Chris Lattner882f7882006-11-04 18:52:07 +000053 // If this is an expr used in a stmt context, indent and newline it.
54 Indent();
Chris Lattner62249a62007-08-21 04:04:25 +000055 Visit(S);
Chris Lattnerfc068c12007-05-30 17:57:36 +000056 OS << ";\n";
Chris Lattner882f7882006-11-04 18:52:07 +000057 } else if (S) {
Chris Lattner62249a62007-08-21 04:04:25 +000058 Visit(S);
Chris Lattner882f7882006-11-04 18:52:07 +000059 } else {
Chris Lattner2f6ac262007-05-28 01:47:47 +000060 Indent() << "<<<NULL STATEMENT>>>\n";
Chris Lattner882f7882006-11-04 18:52:07 +000061 }
Chris Lattnerb9eb5a12007-05-20 22:52:15 +000062 IndentLevel -= SubIndent;
Chris Lattner882f7882006-11-04 18:52:07 +000063 }
Eli Friedman15ea8802009-05-30 00:19:54 +000064
Chris Lattner073926e2007-05-20 23:04:55 +000065 void PrintRawCompoundStmt(CompoundStmt *S);
Chris Lattnerfdc195a2007-06-05 20:52:47 +000066 void PrintRawDecl(Decl *D);
Eli Friedmanf86e5072012-10-16 23:45:15 +000067 void PrintRawDeclStmt(const DeclStmt *S);
Chris Lattnerc0a38dd2007-06-11 22:26:23 +000068 void PrintRawIfStmt(IfStmt *If);
Sebastian Redl9b244a82008-12-22 21:35:02 +000069 void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
Peter Collingbourne4b279a02011-02-08 21:17:54 +000070 void PrintCallArgs(CallExpr *E);
John Wiegley1c0675e2011-04-28 01:08:34 +000071 void PrintRawSEHExceptHandler(SEHExceptStmt *S);
72 void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +000073 void PrintOMPExecutableDirective(OMPExecutableDirective *S);
Mike Stump11289f42009-09-09 15:08:12 +000074
Chris Lattner882f7882006-11-04 18:52:07 +000075 void PrintExpr(Expr *E) {
76 if (E)
Chris Lattner62249a62007-08-21 04:04:25 +000077 Visit(E);
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000078 else
Chris Lattner882f7882006-11-04 18:52:07 +000079 OS << "<null expr>";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000080 }
Mike Stump11289f42009-09-09 15:08:12 +000081
Chris Lattner0e62c1c2011-07-23 10:55:15 +000082 raw_ostream &Indent(int Delta = 0) {
Douglas Gregor7de59662009-05-29 20:38:28 +000083 for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
84 OS << " ";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000085 return OS;
86 }
Mike Stump11289f42009-09-09 15:08:12 +000087
Mike Stump11289f42009-09-09 15:08:12 +000088 void Visit(Stmt* S) {
Ted Kremenek04f3cee2007-08-31 21:30:12 +000089 if (Helper && Helper->handledStmt(S,OS))
90 return;
91 else StmtVisitor<StmtPrinter>::Visit(S);
92 }
Alexey Bataev1b59ab52014-02-27 08:29:12 +000093
Chandler Carruthb7967b92010-10-23 08:21:37 +000094 void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
Argyrios Kyrtzidis30805532010-08-15 01:15:33 +000095 Indent() << "<<unknown stmt type>>\n";
96 }
Chandler Carruthb7967b92010-10-23 08:21:37 +000097 void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
Argyrios Kyrtzidis30805532010-08-15 01:15:33 +000098 OS << "<<unknown expr type>>";
99 }
100 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000101
Argyrios Kyrtzidis30805532010-08-15 01:15:33 +0000102#define ABSTRACT_STMT(CLASS)
Douglas Gregorbe35ce92008-11-14 12:46:07 +0000103#define STMT(CLASS, PARENT) \
Chris Lattner62249a62007-08-21 04:04:25 +0000104 void Visit##CLASS(CLASS *Node);
Alexis Hunt656bb312010-05-05 15:24:00 +0000105#include "clang/AST/StmtNodes.inc"
Chris Lattner71e23ce2006-11-04 20:18:38 +0000106 };
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000107}
108
Chris Lattner71e23ce2006-11-04 20:18:38 +0000109//===----------------------------------------------------------------------===//
110// Stmt printing methods.
111//===----------------------------------------------------------------------===//
112
Chris Lattner073926e2007-05-20 23:04:55 +0000113/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
114/// with no newline after the }.
115void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
116 OS << "{\n";
Aaron Ballmanc7e4e212014-03-17 14:19:37 +0000117 for (auto *I : Node->body())
118 PrintStmt(I);
Mike Stump11289f42009-09-09 15:08:12 +0000119
Chris Lattner073926e2007-05-20 23:04:55 +0000120 Indent() << "}";
121}
122
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000123void StmtPrinter::PrintRawDecl(Decl *D) {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000124 D->print(OS, Policy, IndentLevel);
Mike Stump74a76472009-02-10 20:16:46 +0000125}
126
Eli Friedmanf86e5072012-10-16 23:45:15 +0000127void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
Aaron Ballman535bbcc2014-03-14 17:01:24 +0000128 SmallVector<Decl*, 2> Decls(S->decls());
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000129 Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
Ted Kremenek15e6b402008-10-06 18:39:36 +0000130}
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000131
132void StmtPrinter::VisitNullStmt(NullStmt *Node) {
133 Indent() << ";\n";
134}
135
136void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
Eli Friedman15ea8802009-05-30 00:19:54 +0000137 Indent();
138 PrintRawDeclStmt(Node);
139 OS << ";\n";
Steve Naroff2a8ad182007-05-29 22:59:26 +0000140}
141
Chris Lattner073926e2007-05-20 23:04:55 +0000142void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
143 Indent();
144 PrintRawCompoundStmt(Node);
Chris Lattnerdf3cafb2007-05-31 05:08:56 +0000145 OS << "\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000146}
147
Chris Lattner6c0ff132006-11-05 00:19:50 +0000148void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000149 Indent(-1) << "case ";
Chris Lattner6c0ff132006-11-05 00:19:50 +0000150 PrintExpr(Node->getLHS());
151 if (Node->getRHS()) {
152 OS << " ... ";
153 PrintExpr(Node->getRHS());
154 }
155 OS << ":\n";
Mike Stump11289f42009-09-09 15:08:12 +0000156
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000157 PrintStmt(Node->getSubStmt(), 0);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000158}
159
160void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000161 Indent(-1) << "default:\n";
162 PrintStmt(Node->getSubStmt(), 0);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000163}
164
165void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
Chris Lattnereefa10e2007-05-28 06:56:27 +0000166 Indent(-1) << Node->getName() << ":\n";
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000167 PrintStmt(Node->getSubStmt(), 0);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000168}
169
Richard Smithc202b282012-04-14 00:33:13 +0000170void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
171 OS << "[[";
172 bool first = true;
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000173 for (ArrayRef<const Attr*>::iterator it = Node->getAttrs().begin(),
174 end = Node->getAttrs().end();
175 it != end; ++it) {
Richard Smithc202b282012-04-14 00:33:13 +0000176 if (!first) {
177 OS << ", ";
178 first = false;
179 }
180 // TODO: check this
Richard Smith52f04a22012-08-16 02:43:29 +0000181 (*it)->printPretty(OS, Policy);
Richard Smithc202b282012-04-14 00:33:13 +0000182 }
183 OS << "]] ";
184 PrintStmt(Node->getSubStmt(), 0);
185}
186
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000187void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
Sebastian Redl7b7cec62009-02-07 20:05:48 +0000188 OS << "if (";
Eli Friedmanf86e5072012-10-16 23:45:15 +0000189 if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
190 PrintRawDeclStmt(DS);
191 else
192 PrintExpr(If->getCond());
Sebastian Redl7b7cec62009-02-07 20:05:48 +0000193 OS << ')';
Mike Stump11289f42009-09-09 15:08:12 +0000194
Chris Lattner073926e2007-05-20 23:04:55 +0000195 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
196 OS << ' ';
197 PrintRawCompoundStmt(CS);
198 OS << (If->getElse() ? ' ' : '\n');
199 } else {
200 OS << '\n';
201 PrintStmt(If->getThen());
202 if (If->getElse()) Indent();
203 }
Mike Stump11289f42009-09-09 15:08:12 +0000204
Chris Lattner073926e2007-05-20 23:04:55 +0000205 if (Stmt *Else = If->getElse()) {
206 OS << "else";
Mike Stump11289f42009-09-09 15:08:12 +0000207
Chris Lattner073926e2007-05-20 23:04:55 +0000208 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
209 OS << ' ';
210 PrintRawCompoundStmt(CS);
211 OS << '\n';
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000212 } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
213 OS << ' ';
214 PrintRawIfStmt(ElseIf);
Chris Lattner073926e2007-05-20 23:04:55 +0000215 } else {
216 OS << '\n';
217 PrintStmt(If->getElse());
218 }
Chris Lattner882f7882006-11-04 18:52:07 +0000219 }
Chris Lattner85ed8732006-11-04 20:40:44 +0000220}
221
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000222void StmtPrinter::VisitIfStmt(IfStmt *If) {
223 Indent();
224 PrintRawIfStmt(If);
225}
226
Chris Lattnerf2174b62006-11-04 20:59:27 +0000227void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
228 Indent() << "switch (";
Eli Friedmanf86e5072012-10-16 23:45:15 +0000229 if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
230 PrintRawDeclStmt(DS);
231 else
232 PrintExpr(Node->getCond());
Chris Lattner073926e2007-05-20 23:04:55 +0000233 OS << ")";
Mike Stump11289f42009-09-09 15:08:12 +0000234
Chris Lattner073926e2007-05-20 23:04:55 +0000235 // Pretty print compoundstmt bodies (very common).
236 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
237 OS << " ";
238 PrintRawCompoundStmt(CS);
239 OS << "\n";
240 } else {
241 OS << "\n";
242 PrintStmt(Node->getBody());
243 }
Chris Lattnerf2174b62006-11-04 20:59:27 +0000244}
245
Chris Lattner85ed8732006-11-04 20:40:44 +0000246void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
247 Indent() << "while (";
Eli Friedmanf86e5072012-10-16 23:45:15 +0000248 if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
249 PrintRawDeclStmt(DS);
250 else
251 PrintExpr(Node->getCond());
Chris Lattner85ed8732006-11-04 20:40:44 +0000252 OS << ")\n";
253 PrintStmt(Node->getBody());
254}
255
256void StmtPrinter::VisitDoStmt(DoStmt *Node) {
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000257 Indent() << "do ";
258 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
259 PrintRawCompoundStmt(CS);
260 OS << " ";
261 } else {
262 OS << "\n";
263 PrintStmt(Node->getBody());
264 Indent();
265 }
Mike Stump11289f42009-09-09 15:08:12 +0000266
Eli Friedman8f1d33e2009-05-17 01:05:34 +0000267 OS << "while (";
Chris Lattner85ed8732006-11-04 20:40:44 +0000268 PrintExpr(Node->getCond());
Eli Friedman8f1d33e2009-05-17 01:05:34 +0000269 OS << ");\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000270}
271
Chris Lattner71e23ce2006-11-04 20:18:38 +0000272void StmtPrinter::VisitForStmt(ForStmt *Node) {
273 Indent() << "for (";
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000274 if (Node->getInit()) {
275 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
Ted Kremenek15e6b402008-10-06 18:39:36 +0000276 PrintRawDeclStmt(DS);
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000277 else
278 PrintExpr(cast<Expr>(Node->getInit()));
279 }
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000280 OS << ";";
281 if (Node->getCond()) {
282 OS << " ";
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000283 PrintExpr(Node->getCond());
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000284 }
285 OS << ";";
286 if (Node->getInc()) {
287 OS << " ";
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000288 PrintExpr(Node->getInc());
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000289 }
290 OS << ") ";
Mike Stump11289f42009-09-09 15:08:12 +0000291
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000292 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
293 PrintRawCompoundStmt(CS);
294 OS << "\n";
295 } else {
296 OS << "\n";
297 PrintStmt(Node->getBody());
298 }
Chris Lattner71e23ce2006-11-04 20:18:38 +0000299}
300
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000301void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
Fariborz Jahanian83615522008-01-02 22:54:34 +0000302 Indent() << "for (";
303 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
Ted Kremenek15e6b402008-10-06 18:39:36 +0000304 PrintRawDeclStmt(DS);
Fariborz Jahanian83615522008-01-02 22:54:34 +0000305 else
306 PrintExpr(cast<Expr>(Node->getElement()));
307 OS << " in ";
308 PrintExpr(Node->getCollection());
309 OS << ") ";
Mike Stump11289f42009-09-09 15:08:12 +0000310
Fariborz Jahanian83615522008-01-02 22:54:34 +0000311 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
312 PrintRawCompoundStmt(CS);
313 OS << "\n";
314 } else {
315 OS << "\n";
316 PrintStmt(Node->getBody());
317 }
318}
319
Richard Smith02e85f32011-04-14 22:09:26 +0000320void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
321 Indent() << "for (";
322 PrintingPolicy SubPolicy(Policy);
323 SubPolicy.SuppressInitializers = true;
324 Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
325 OS << " : ";
326 PrintExpr(Node->getRangeInit());
327 OS << ") {\n";
328 PrintStmt(Node->getBody());
Ted Kremenek88446602013-12-11 23:44:02 +0000329 Indent() << "}";
330 if (Policy.IncludeNewlines) OS << "\n";
Richard Smith02e85f32011-04-14 22:09:26 +0000331}
332
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000333void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
334 Indent();
335 if (Node->isIfExists())
336 OS << "__if_exists (";
337 else
338 OS << "__if_not_exists (";
339
340 if (NestedNameSpecifier *Qualifier
341 = Node->getQualifierLoc().getNestedNameSpecifier())
342 Qualifier->print(OS, Policy);
343
344 OS << Node->getNameInfo() << ") ";
345
346 PrintRawCompoundStmt(Node->getSubStmt());
347}
348
Chris Lattner16976d32006-11-05 01:46:01 +0000349void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
Ted Kremenek88446602013-12-11 23:44:02 +0000350 Indent() << "goto " << Node->getLabel()->getName() << ";";
351 if (Policy.IncludeNewlines) OS << "\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000352}
353
354void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
Chris Lattner36ad1232006-11-05 01:51:06 +0000355 Indent() << "goto *";
Chris Lattner16976d32006-11-05 01:46:01 +0000356 PrintExpr(Node->getTarget());
Ted Kremenek88446602013-12-11 23:44:02 +0000357 OS << ";";
358 if (Policy.IncludeNewlines) OS << "\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000359}
360
361void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
Ted Kremenek88446602013-12-11 23:44:02 +0000362 Indent() << "continue;";
363 if (Policy.IncludeNewlines) OS << "\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000364}
365
366void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
Ted Kremenek88446602013-12-11 23:44:02 +0000367 Indent() << "break;";
368 if (Policy.IncludeNewlines) OS << "\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000369}
370
371
Chris Lattner882f7882006-11-04 18:52:07 +0000372void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
373 Indent() << "return";
374 if (Node->getRetValue()) {
375 OS << " ";
376 PrintExpr(Node->getRetValue());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000377 }
Ted Kremenek88446602013-12-11 23:44:02 +0000378 OS << ";";
379 if (Policy.IncludeNewlines) OS << "\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000380}
381
Chris Lattner73c56c02007-10-29 04:04:16 +0000382
Chad Rosierde70e0e2012-08-25 00:11:56 +0000383void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
Anders Carlsson660bdd12007-11-23 23:12:25 +0000384 Indent() << "asm ";
Mike Stump11289f42009-09-09 15:08:12 +0000385
Anders Carlsson660bdd12007-11-23 23:12:25 +0000386 if (Node->isVolatile())
387 OS << "volatile ";
Mike Stump11289f42009-09-09 15:08:12 +0000388
Anders Carlsson660bdd12007-11-23 23:12:25 +0000389 OS << "(";
Anders Carlsson81a5a692007-11-20 19:21:03 +0000390 VisitStringLiteral(Node->getAsmString());
Mike Stump11289f42009-09-09 15:08:12 +0000391
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000392 // Outputs
393 if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
394 Node->getNumClobbers() != 0)
395 OS << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000396
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000397 for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
398 if (i != 0)
399 OS << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000400
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000401 if (!Node->getOutputName(i).empty()) {
402 OS << '[';
403 OS << Node->getOutputName(i);
404 OS << "] ";
405 }
Mike Stump11289f42009-09-09 15:08:12 +0000406
Chris Lattner72bbf172009-03-10 04:59:06 +0000407 VisitStringLiteral(Node->getOutputConstraintLiteral(i));
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000408 OS << " ";
409 Visit(Node->getOutputExpr(i));
410 }
Mike Stump11289f42009-09-09 15:08:12 +0000411
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000412 // Inputs
413 if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
414 OS << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000415
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000416 for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
417 if (i != 0)
418 OS << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000419
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000420 if (!Node->getInputName(i).empty()) {
421 OS << '[';
422 OS << Node->getInputName(i);
423 OS << "] ";
424 }
Mike Stump11289f42009-09-09 15:08:12 +0000425
Chris Lattner72bbf172009-03-10 04:59:06 +0000426 VisitStringLiteral(Node->getInputConstraintLiteral(i));
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000427 OS << " ";
428 Visit(Node->getInputExpr(i));
429 }
Mike Stump11289f42009-09-09 15:08:12 +0000430
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000431 // Clobbers
432 if (Node->getNumClobbers() != 0)
433 OS << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000434
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000435 for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
436 if (i != 0)
437 OS << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000438
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000439 VisitStringLiteral(Node->getClobberStringLiteral(i));
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000440 }
Mike Stump11289f42009-09-09 15:08:12 +0000441
Ted Kremenek88446602013-12-11 23:44:02 +0000442 OS << ");";
443 if (Policy.IncludeNewlines) OS << "\n";
Chris Lattner73c56c02007-10-29 04:04:16 +0000444}
445
Chad Rosier32503022012-06-11 20:47:18 +0000446void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
447 // FIXME: Implement MS style inline asm statement printer.
Chad Rosierb6f46c12012-08-15 16:53:30 +0000448 Indent() << "__asm ";
449 if (Node->hasBraces())
450 OS << "{\n";
John McCallf413f5e2013-05-03 00:10:13 +0000451 OS << Node->getAsmString() << "\n";
Chad Rosierb6f46c12012-08-15 16:53:30 +0000452 if (Node->hasBraces())
453 Indent() << "}\n";
Chad Rosier32503022012-06-11 20:47:18 +0000454}
455
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000456void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000457 PrintStmt(Node->getCapturedDecl()->getBody());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000458}
459
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000460void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
Fariborz Jahanian88157952007-11-02 18:16:07 +0000461 Indent() << "@try";
462 if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
463 PrintRawCompoundStmt(TS);
464 OS << "\n";
465 }
Mike Stump11289f42009-09-09 15:08:12 +0000466
Douglas Gregor96c79492010-04-23 22:50:49 +0000467 for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
468 ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
Fariborz Jahanian88157952007-11-02 18:16:07 +0000469 Indent() << "@catch(";
Steve Naroff371b8fb2009-03-03 19:52:17 +0000470 if (catchStmt->getCatchParamDecl()) {
471 if (Decl *DS = catchStmt->getCatchParamDecl())
472 PrintRawDecl(DS);
Fariborz Jahanian88157952007-11-02 18:16:07 +0000473 }
474 OS << ")";
Mike Stump11289f42009-09-09 15:08:12 +0000475 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
476 PrintRawCompoundStmt(CS);
477 OS << "\n";
478 }
Fariborz Jahanian88157952007-11-02 18:16:07 +0000479 }
Mike Stump11289f42009-09-09 15:08:12 +0000480
481 if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
482 Node->getFinallyStmt())) {
Fariborz Jahaniandefbf9a2007-11-07 00:46:42 +0000483 Indent() << "@finally";
484 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
Fariborz Jahanian88157952007-11-02 18:16:07 +0000485 OS << "\n";
Mike Stump11289f42009-09-09 15:08:12 +0000486 }
Fariborz Jahanian65590b22007-11-01 21:12:44 +0000487}
488
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000489void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
Fariborz Jahanian65590b22007-11-01 21:12:44 +0000490}
491
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000492void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
Fariborz Jahanian65590b22007-11-01 21:12:44 +0000493 Indent() << "@catch (...) { /* todo */ } \n";
494}
495
Fariborz Jahanian049fa582008-01-30 17:38:29 +0000496void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
Fariborz Jahanianadfbbc32007-11-07 02:00:49 +0000497 Indent() << "@throw";
498 if (Node->getThrowExpr()) {
499 OS << " ";
500 PrintExpr(Node->getThrowExpr());
501 }
502 OS << ";\n";
503}
504
Fariborz Jahanian049fa582008-01-30 17:38:29 +0000505void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
Fariborz Jahanianf89ca382008-01-29 18:21:32 +0000506 Indent() << "@synchronized (";
507 PrintExpr(Node->getSynchExpr());
508 OS << ")";
Fariborz Jahanian049fa582008-01-30 17:38:29 +0000509 PrintRawCompoundStmt(Node->getSynchBody());
510 OS << "\n";
Fariborz Jahanianf89ca382008-01-29 18:21:32 +0000511}
512
John McCall31168b02011-06-15 23:02:42 +0000513void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
514 Indent() << "@autoreleasepool";
515 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
516 OS << "\n";
517}
518
Sebastian Redl9b244a82008-12-22 21:35:02 +0000519void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
520 OS << "catch (";
Sebastian Redl54c04d42008-12-22 19:15:10 +0000521 if (Decl *ExDecl = Node->getExceptionDecl())
522 PrintRawDecl(ExDecl);
523 else
524 OS << "...";
525 OS << ") ";
526 PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
Sebastian Redl9b244a82008-12-22 21:35:02 +0000527}
528
529void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
530 Indent();
531 PrintRawCXXCatchStmt(Node);
532 OS << "\n";
533}
534
535void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
536 Indent() << "try ";
537 PrintRawCompoundStmt(Node->getTryBlock());
Mike Stump11289f42009-09-09 15:08:12 +0000538 for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
Sebastian Redl9b244a82008-12-22 21:35:02 +0000539 OS << " ";
540 PrintRawCXXCatchStmt(Node->getHandler(i));
541 }
Sebastian Redl54c04d42008-12-22 19:15:10 +0000542 OS << "\n";
543}
544
John Wiegley1c0675e2011-04-28 01:08:34 +0000545void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
546 Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
547 PrintRawCompoundStmt(Node->getTryBlock());
548 SEHExceptStmt *E = Node->getExceptHandler();
549 SEHFinallyStmt *F = Node->getFinallyHandler();
550 if(E)
551 PrintRawSEHExceptHandler(E);
552 else {
553 assert(F && "Must have a finally block...");
554 PrintRawSEHFinallyStmt(F);
555 }
556 OS << "\n";
557}
558
559void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
560 OS << "__finally ";
561 PrintRawCompoundStmt(Node->getBlock());
562 OS << "\n";
563}
564
565void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
566 OS << "__except (";
567 VisitExpr(Node->getFilterExpr());
Joao Matos566359c2012-09-04 17:49:35 +0000568 OS << ")\n";
John Wiegley1c0675e2011-04-28 01:08:34 +0000569 PrintRawCompoundStmt(Node->getBlock());
570 OS << "\n";
571}
572
573void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
574 Indent();
575 PrintRawSEHExceptHandler(Node);
576 OS << "\n";
577}
578
579void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
580 Indent();
581 PrintRawSEHFinallyStmt(Node);
582 OS << "\n";
583}
584
Chris Lattner71e23ce2006-11-04 20:18:38 +0000585//===----------------------------------------------------------------------===//
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000586// OpenMP clauses printing methods
587//===----------------------------------------------------------------------===//
588
589namespace {
590class OMPClausePrinter : public OMPClauseVisitor<OMPClausePrinter> {
591 raw_ostream &OS;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000592 const PrintingPolicy &Policy;
Alexey Bataev756c1962013-09-24 03:17:45 +0000593 /// \brief Process clauses with list of variables.
594 template <typename T>
595 void VisitOMPClauseList(T *Node, char StartSym);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000596public:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000597 OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
598 : OS(OS), Policy(Policy) { }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000599#define OPENMP_CLAUSE(Name, Class) \
600 void Visit##Class(Class *S);
601#include "clang/Basic/OpenMPKinds.def"
602};
603
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000604void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
605 OS << "if(";
606 Node->getCondition()->printPretty(OS, 0, Policy, 0);
607 OS << ")";
608}
609
Alexey Bataev568a8332014-03-06 06:15:19 +0000610void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
611 OS << "num_threads(";
612 Node->getNumThreads()->printPretty(OS, 0, Policy, 0);
613 OS << ")";
614}
615
Alexey Bataev62c87d22014-03-21 04:51:18 +0000616void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
617 OS << "safelen(";
618 Node->getSafelen()->printPretty(OS, 0, Policy, 0);
619 OS << ")";
620}
621
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000622void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
623 OS << "default("
624 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
625 << ")";
626}
627
Alexey Bataev756c1962013-09-24 03:17:45 +0000628template<typename T>
629void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
630 for (typename T::varlist_iterator I = Node->varlist_begin(),
631 E = Node->varlist_end();
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000632 I != E; ++I) {
633 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(*I)) {
634 OS << (I == Node->varlist_begin() ? StartSym : ',');
635 cast<NamedDecl>(DRE->getDecl())->printQualifiedName(OS);
636 } else {
637 OS << (I == Node->varlist_begin() ? StartSym : ',');
638 (*I)->printPretty(OS, 0, Policy, 0);
639 }
640 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000641}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000642
643void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
644 if (!Node->varlist_empty()) {
645 OS << "private";
Alexey Bataev756c1962013-09-24 03:17:45 +0000646 VisitOMPClauseList(Node, '(');
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000647 OS << ")";
648 }
649}
650
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000651void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
652 if (!Node->varlist_empty()) {
653 OS << "firstprivate";
654 VisitOMPClauseList(Node, '(');
655 OS << ")";
656 }
657}
658
Alexey Bataev758e55e2013-09-06 18:03:48 +0000659void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
660 if (!Node->varlist_empty()) {
661 OS << "shared";
Alexey Bataev756c1962013-09-24 03:17:45 +0000662 VisitOMPClauseList(Node, '(');
Alexey Bataev758e55e2013-09-06 18:03:48 +0000663 OS << ")";
664 }
665}
666
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000667void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
668 if (!Node->varlist_empty()) {
669 OS << "copyin";
670 VisitOMPClauseList(Node, '(');
671 OS << ")";
672 }
673}
674
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000675}
676
677//===----------------------------------------------------------------------===//
678// OpenMP directives printing methods
679//===----------------------------------------------------------------------===//
680
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000681void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S) {
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000682 OMPClausePrinter Printer(OS, Policy);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000683 ArrayRef<OMPClause *> Clauses = S->clauses();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000684 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
685 I != E; ++I)
686 if (*I && !(*I)->isImplicit()) {
687 Printer.Visit(*I);
688 OS << ' ';
689 }
690 OS << "\n";
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000691 if (S->getAssociatedStmt()) {
692 assert(isa<CapturedStmt>(S->getAssociatedStmt()) &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000693 "Expected captured statement!");
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000694 Stmt *CS = cast<CapturedStmt>(S->getAssociatedStmt())->getCapturedStmt();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000695 PrintStmt(CS);
696 }
697}
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000698
699void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
700 Indent() << "#pragma omp parallel ";
701 PrintOMPExecutableDirective(Node);
702}
703
704void StmtPrinter::VisitOMPSimdDirective(OMPSimdDirective *Node) {
705 Indent() << "#pragma omp simd ";
706 PrintOMPExecutableDirective(Node);
707}
708
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000709//===----------------------------------------------------------------------===//
Chris Lattner71e23ce2006-11-04 20:18:38 +0000710// Expr printing methods.
711//===----------------------------------------------------------------------===//
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000712
Chris Lattner882f7882006-11-04 18:52:07 +0000713void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000714 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
715 Qualifier->print(OS, Policy);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000716 if (Node->hasTemplateKeyword())
717 OS << "template ";
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000718 OS << Node->getNameInfo();
John McCallb3774b52010-08-19 23:49:38 +0000719 if (Node->hasExplicitTemplateArgs())
Benjamin Kramer9170e912013-02-22 15:46:01 +0000720 TemplateSpecializationType::PrintTemplateArgumentList(
721 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Douglas Gregorc7acfdf2009-01-06 05:10:23 +0000722}
723
John McCall8cd78132009-11-19 22:55:06 +0000724void StmtPrinter::VisitDependentScopeDeclRefExpr(
725 DependentScopeDeclRefExpr *Node) {
Axel Naumann20b27862011-01-24 15:44:00 +0000726 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
727 Qualifier->print(OS, Policy);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000728 if (Node->hasTemplateKeyword())
729 OS << "template ";
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000730 OS << Node->getNameInfo();
John McCalle66edc12009-11-24 19:00:30 +0000731 if (Node->hasExplicitTemplateArgs())
Benjamin Kramer9170e912013-02-22 15:46:01 +0000732 TemplateSpecializationType::PrintTemplateArgumentList(
733 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Douglas Gregor90a1a652009-03-19 17:26:29 +0000734}
735
John McCalld14a8642009-11-21 08:51:07 +0000736void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
Douglas Gregora727cb92009-06-30 22:34:41 +0000737 if (Node->getQualifier())
738 Node->getQualifier()->print(OS, Policy);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000739 if (Node->hasTemplateKeyword())
740 OS << "template ";
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000741 OS << Node->getNameInfo();
John McCalle66edc12009-11-24 19:00:30 +0000742 if (Node->hasExplicitTemplateArgs())
Benjamin Kramer9170e912013-02-22 15:46:01 +0000743 TemplateSpecializationType::PrintTemplateArgumentList(
744 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Douglas Gregora727cb92009-06-30 22:34:41 +0000745}
746
Steve Naroffe46504b2007-11-12 14:29:37 +0000747void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Fariborz Jahanian21f54ee2007-11-12 22:29:28 +0000748 if (Node->getBase()) {
749 PrintExpr(Node->getBase());
750 OS << (Node->isArrow() ? "->" : ".");
751 }
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000752 OS << *Node->getDecl();
Steve Naroffe46504b2007-11-12 14:29:37 +0000753}
754
Steve Naroffec944032008-05-30 00:40:33 +0000755void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000756 if (Node->isSuperReceiver())
757 OS << "super.";
Richard Trieu6d92e502014-02-06 23:26:23 +0000758 else if (Node->isObjectReceiver() && Node->getBase()) {
Steve Naroffec944032008-05-30 00:40:33 +0000759 PrintExpr(Node->getBase());
760 OS << ".";
Richard Trieu6d92e502014-02-06 23:26:23 +0000761 } else if (Node->isClassReceiver() && Node->getClassReceiver()) {
762 OS << Node->getClassReceiver()->getName() << ".";
Steve Naroffec944032008-05-30 00:40:33 +0000763 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000764
John McCallb7bd14f2010-12-02 01:19:52 +0000765 if (Node->isImplicitProperty())
Aaron Ballmanb190f972014-01-03 17:59:55 +0000766 Node->getImplicitPropertyGetter()->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +0000767 else
768 OS << Node->getExplicitProperty()->getName();
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +0000769}
770
Ted Kremeneke65b0862012-03-06 20:05:56 +0000771void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
772
773 PrintExpr(Node->getBaseExpr());
774 OS << "[";
775 PrintExpr(Node->getKeyExpr());
776 OS << "]";
777}
778
Chris Lattner6307f192008-08-10 01:53:14 +0000779void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
Anders Carlsson625bfc82007-07-21 05:21:51 +0000780 switch (Node->getIdentType()) {
781 default:
David Blaikie83d382b2011-09-23 05:06:16 +0000782 llvm_unreachable("unknown case");
Chris Lattner6307f192008-08-10 01:53:14 +0000783 case PredefinedExpr::Func:
Anders Carlsson625bfc82007-07-21 05:21:51 +0000784 OS << "__func__";
785 break;
Chris Lattner6307f192008-08-10 01:53:14 +0000786 case PredefinedExpr::Function:
Anders Carlsson625bfc82007-07-21 05:21:51 +0000787 OS << "__FUNCTION__";
788 break;
David Majnemerbed356a2013-11-06 23:31:56 +0000789 case PredefinedExpr::FuncDName:
790 OS << "__FUNCDNAME__";
791 break;
Reid Kleckner52eddda2014-04-08 18:13:24 +0000792 case PredefinedExpr::FuncSig:
793 OS << "__FUNCSIG__";
794 break;
Nico Weber3a691a32012-06-23 02:07:59 +0000795 case PredefinedExpr::LFunction:
796 OS << "L__FUNCTION__";
797 break;
Chris Lattner6307f192008-08-10 01:53:14 +0000798 case PredefinedExpr::PrettyFunction:
Anders Carlsson625bfc82007-07-21 05:21:51 +0000799 OS << "__PRETTY_FUNCTION__";
800 break;
801 }
802}
803
Steve Naroffae4143e2007-04-26 20:39:23 +0000804void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000805 unsigned value = Node->getValue();
Douglas Gregorfb65e592011-07-27 05:40:30 +0000806
807 switch (Node->getKind()) {
808 case CharacterLiteral::Ascii: break; // no prefix.
809 case CharacterLiteral::Wide: OS << 'L'; break;
810 case CharacterLiteral::UTF16: OS << 'u'; break;
811 case CharacterLiteral::UTF32: OS << 'U'; break;
812 }
813
Chris Lattner666115c2007-07-13 23:58:20 +0000814 switch (value) {
815 case '\\':
816 OS << "'\\\\'";
817 break;
818 case '\'':
819 OS << "'\\''";
820 break;
821 case '\a':
822 // TODO: K&R: the meaning of '\\a' is different in traditional C
823 OS << "'\\a'";
824 break;
825 case '\b':
826 OS << "'\\b'";
827 break;
828 // Nonstandard escape sequence.
829 /*case '\e':
830 OS << "'\\e'";
831 break;*/
832 case '\f':
833 OS << "'\\f'";
834 break;
835 case '\n':
836 OS << "'\\n'";
837 break;
838 case '\r':
839 OS << "'\\r'";
840 break;
841 case '\t':
842 OS << "'\\t'";
843 break;
844 case '\v':
845 OS << "'\\v'";
846 break;
847 default:
Jordan Rose00d1b592013-02-08 22:30:27 +0000848 if (value < 256 && isPrintable((unsigned char)value))
Chris Lattner666115c2007-07-13 23:58:20 +0000849 OS << "'" << (char)value << "'";
Jordan Rose00d1b592013-02-08 22:30:27 +0000850 else if (value < 256)
851 OS << "'\\x" << llvm::format("%02x", value) << "'";
852 else if (value <= 0xFFFF)
853 OS << "'\\u" << llvm::format("%04x", value) << "'";
854 else
855 OS << "'\\U" << llvm::format("%08x", value) << "'";
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000856 }
Steve Naroffae4143e2007-04-26 20:39:23 +0000857}
858
Steve Naroffdf7855b2007-02-21 23:46:25 +0000859void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
Chris Lattner06430412007-05-21 05:45:03 +0000860 bool isSigned = Node->getType()->isSignedIntegerType();
861 OS << Node->getValue().toString(10, isSigned);
Mike Stump11289f42009-09-09 15:08:12 +0000862
Chris Lattner06430412007-05-21 05:45:03 +0000863 // Emit suffixes. Integer literals are always a builtin integer type.
John McCall9dd450b2009-09-21 23:43:11 +0000864 switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
David Blaikie83d382b2011-09-23 05:06:16 +0000865 default: llvm_unreachable("Unexpected type for integer literal!");
Richard Trieu8b626ba2011-11-07 18:40:31 +0000866 // FIXME: The Short and UShort cases are to handle cases where a short
867 // integeral literal is formed during template instantiation. They should
868 // be removed when template instantiation no longer needs integer literals.
869 case BuiltinType::Short:
870 case BuiltinType::UShort:
Chris Lattner06430412007-05-21 05:45:03 +0000871 case BuiltinType::Int: break; // no suffix.
872 case BuiltinType::UInt: OS << 'U'; break;
873 case BuiltinType::Long: OS << 'L'; break;
874 case BuiltinType::ULong: OS << "UL"; break;
875 case BuiltinType::LongLong: OS << "LL"; break;
876 case BuiltinType::ULongLong: OS << "ULL"; break;
Richard Trieu8b626ba2011-11-07 18:40:31 +0000877 case BuiltinType::Int128: OS << "i128"; break;
878 case BuiltinType::UInt128: OS << "Ui128"; break;
Chris Lattner06430412007-05-21 05:45:03 +0000879 }
Chris Lattner882f7882006-11-04 18:52:07 +0000880}
Benjamin Kramer8a526762012-09-20 14:07:17 +0000881
882static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
883 bool PrintSuffix) {
Dylan Noblesmith2c1dd272012-02-05 02:13:05 +0000884 SmallString<16> Str;
Eli Friedman53392062011-10-05 20:32:03 +0000885 Node->getValue().toString(Str);
886 OS << Str;
Benjamin Kramer8a526762012-09-20 14:07:17 +0000887 if (Str.find_first_not_of("-0123456789") == StringRef::npos)
888 OS << '.'; // Trailing dot in order to separate from ints.
889
890 if (!PrintSuffix)
891 return;
892
893 // Emit suffixes. Float literals are always a builtin float type.
894 switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
895 default: llvm_unreachable("Unexpected type for float literal!");
896 case BuiltinType::Half: break; // FIXME: suffix?
897 case BuiltinType::Double: break; // no suffix.
898 case BuiltinType::Float: OS << 'F'; break;
899 case BuiltinType::LongDouble: OS << 'L'; break;
900 }
901}
902
903void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
904 PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
Chris Lattner882f7882006-11-04 18:52:07 +0000905}
Chris Lattner1c20a172007-08-26 03:42:43 +0000906
907void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
908 PrintExpr(Node->getSubExpr());
909 OS << "i";
910}
911
Steve Naroffdf7855b2007-02-21 23:46:25 +0000912void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
Richard Trieudc355912012-06-13 20:25:24 +0000913 Str->outputString(OS);
Chris Lattner882f7882006-11-04 18:52:07 +0000914}
915void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
916 OS << "(";
917 PrintExpr(Node->getSubExpr());
Chris Lattnera076fde2007-05-31 18:21:33 +0000918 OS << ")";
Chris Lattner882f7882006-11-04 18:52:07 +0000919}
920void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattnere5b60442007-08-23 21:46:40 +0000921 if (!Node->isPostfix()) {
Chris Lattner15768702006-11-05 23:54:51 +0000922 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Mike Stump11289f42009-09-09 15:08:12 +0000923
Eli Friedman1cf25362009-06-14 22:39:26 +0000924 // Print a space if this is an "identifier operator" like __real, or if
925 // it might be concatenated incorrectly like '+'.
Chris Lattnere5b60442007-08-23 21:46:40 +0000926 switch (Node->getOpcode()) {
927 default: break;
John McCalle3027922010-08-25 11:45:40 +0000928 case UO_Real:
929 case UO_Imag:
930 case UO_Extension:
Chris Lattnere5b60442007-08-23 21:46:40 +0000931 OS << ' ';
932 break;
John McCalle3027922010-08-25 11:45:40 +0000933 case UO_Plus:
934 case UO_Minus:
Eli Friedman1cf25362009-06-14 22:39:26 +0000935 if (isa<UnaryOperator>(Node->getSubExpr()))
936 OS << ' ';
937 break;
Chris Lattnere5b60442007-08-23 21:46:40 +0000938 }
939 }
Chris Lattner882f7882006-11-04 18:52:07 +0000940 PrintExpr(Node->getSubExpr());
Mike Stump11289f42009-09-09 15:08:12 +0000941
Chris Lattner15768702006-11-05 23:54:51 +0000942 if (Node->isPostfix())
943 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Chris Lattner882f7882006-11-04 18:52:07 +0000944}
Chris Lattner98dbf0a2007-08-30 17:59:59 +0000945
Douglas Gregor882211c2010-04-28 22:16:22 +0000946void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
947 OS << "__builtin_offsetof(";
Benjamin Kramerc5720e92013-02-22 14:19:01 +0000948 Node->getTypeSourceInfo()->getType().print(OS, Policy);
949 OS << ", ";
Douglas Gregor882211c2010-04-28 22:16:22 +0000950 bool PrintedSomething = false;
951 for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
952 OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i);
953 if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Array) {
954 // Array node
955 OS << "[";
956 PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
957 OS << "]";
958 PrintedSomething = true;
959 continue;
960 }
Douglas Gregord1702062010-04-29 00:18:15 +0000961
962 // Skip implicit base indirections.
963 if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Base)
964 continue;
965
Douglas Gregor882211c2010-04-28 22:16:22 +0000966 // Field or identifier node.
967 IdentifierInfo *Id = ON.getFieldName();
968 if (!Id)
969 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000970
Douglas Gregor882211c2010-04-28 22:16:22 +0000971 if (PrintedSomething)
972 OS << ".";
973 else
974 PrintedSomething = true;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000975 OS << Id->getName();
Douglas Gregor882211c2010-04-28 22:16:22 +0000976 }
977 OS << ")";
978}
979
Peter Collingbournee190dee2011-03-11 19:24:49 +0000980void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
981 switch(Node->getKind()) {
982 case UETT_SizeOf:
983 OS << "sizeof";
984 break;
985 case UETT_AlignOf:
Jordan Rose58d54722012-06-30 21:33:57 +0000986 if (Policy.LangOpts.CPlusPlus)
987 OS << "alignof";
988 else if (Policy.LangOpts.C11)
989 OS << "_Alignof";
990 else
991 OS << "__alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +0000992 break;
993 case UETT_VecStep:
994 OS << "vec_step";
995 break;
996 }
Benjamin Kramerc5720e92013-02-22 14:19:01 +0000997 if (Node->isArgumentType()) {
998 OS << '(';
999 Node->getArgumentType().print(OS, Policy);
1000 OS << ')';
1001 } else {
Sebastian Redl6f282892008-11-11 17:56:53 +00001002 OS << " ";
1003 PrintExpr(Node->getArgumentExpr());
1004 }
Chris Lattner882f7882006-11-04 18:52:07 +00001005}
Peter Collingbourne91147592011-04-15 00:35:48 +00001006
1007void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
1008 OS << "_Generic(";
1009 PrintExpr(Node->getControllingExpr());
1010 for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
1011 OS << ", ";
1012 QualType T = Node->getAssocType(i);
1013 if (T.isNull())
1014 OS << "default";
1015 else
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001016 T.print(OS, Policy);
Peter Collingbourne91147592011-04-15 00:35:48 +00001017 OS << ": ";
1018 PrintExpr(Node->getAssocExpr(i));
1019 }
1020 OS << ")";
1021}
1022
Chris Lattner882f7882006-11-04 18:52:07 +00001023void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
Ted Kremenekc81614d2007-08-20 16:18:38 +00001024 PrintExpr(Node->getLHS());
Chris Lattner882f7882006-11-04 18:52:07 +00001025 OS << "[";
Ted Kremenekc81614d2007-08-20 16:18:38 +00001026 PrintExpr(Node->getRHS());
Chris Lattner882f7882006-11-04 18:52:07 +00001027 OS << "]";
1028}
1029
Peter Collingbourne4b279a02011-02-08 21:17:54 +00001030void StmtPrinter::PrintCallArgs(CallExpr *Call) {
Chris Lattner882f7882006-11-04 18:52:07 +00001031 for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
Chris Lattneraa9c7ae2008-04-08 04:40:51 +00001032 if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
1033 // Don't print any defaulted arguments
1034 break;
1035 }
1036
Chris Lattner882f7882006-11-04 18:52:07 +00001037 if (i) OS << ", ";
1038 PrintExpr(Call->getArg(i));
1039 }
Peter Collingbourne4b279a02011-02-08 21:17:54 +00001040}
1041
1042void StmtPrinter::VisitCallExpr(CallExpr *Call) {
1043 PrintExpr(Call->getCallee());
1044 OS << "(";
1045 PrintCallArgs(Call);
Chris Lattner882f7882006-11-04 18:52:07 +00001046 OS << ")";
1047}
1048void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
Douglas Gregore4b414c2009-01-08 22:45:41 +00001049 // FIXME: Suppress printing implicit bases (like "this")
1050 PrintExpr(Node->getBase());
David Blaikie8fab8e52012-11-12 19:12:12 +00001051
1052 MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
David Blaikie6bffd6f2012-11-12 19:32:32 +00001053 FieldDecl *ParentDecl = ParentMember
1054 ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()) : NULL;
David Blaikie8fab8e52012-11-12 19:12:12 +00001055
David Blaikie6bffd6f2012-11-12 19:32:32 +00001056 if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
David Blaikie8fab8e52012-11-12 19:12:12 +00001057 OS << (Node->isArrow() ? "->" : ".");
David Blaikie8fab8e52012-11-12 19:12:12 +00001058
Fariborz Jahanian2990c022010-01-11 21:17:32 +00001059 if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1060 if (FD->isAnonymousStructOrUnion())
1061 return;
David Blaikie8fab8e52012-11-12 19:12:12 +00001062
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001063 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1064 Qualifier->print(OS, Policy);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001065 if (Node->hasTemplateKeyword())
1066 OS << "template ";
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001067 OS << Node->getMemberNameInfo();
John McCallb3774b52010-08-19 23:49:38 +00001068 if (Node->hasExplicitTemplateArgs())
Benjamin Kramer9170e912013-02-22 15:46:01 +00001069 TemplateSpecializationType::PrintTemplateArgumentList(
1070 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001071}
Steve Naroffe87026a2009-07-24 17:54:45 +00001072void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1073 PrintExpr(Node->getBase());
1074 OS << (Node->isArrow() ? "->isa" : ".isa");
1075}
1076
Nate Begemance4d7fc2008-04-18 23:10:10 +00001077void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Steve Narofff7a5da12007-07-28 23:10:27 +00001078 PrintExpr(Node->getBase());
1079 OS << ".";
1080 OS << Node->getAccessor().getName();
1081}
Douglas Gregorf19b2312008-10-28 15:36:24 +00001082void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001083 OS << '(';
1084 Node->getTypeAsWritten().print(OS, Policy);
1085 OS << ')';
Chris Lattner882f7882006-11-04 18:52:07 +00001086 PrintExpr(Node->getSubExpr());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001087}
Steve Naroff57eb2c52007-07-19 21:32:11 +00001088void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001089 OS << '(';
1090 Node->getType().print(OS, Policy);
1091 OS << ')';
Steve Naroff57eb2c52007-07-19 21:32:11 +00001092 PrintExpr(Node->getInitializer());
1093}
Steve Naroff7a5af782007-07-13 16:58:59 +00001094void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
Alp Toker028ed912013-12-06 17:56:43 +00001095 // No need to print anything, simply forward to the subexpression.
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001096 PrintExpr(Node->getSubExpr());
Steve Naroff7a5af782007-07-13 16:58:59 +00001097}
Chris Lattner882f7882006-11-04 18:52:07 +00001098void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1099 PrintExpr(Node->getLHS());
1100 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1101 PrintExpr(Node->getRHS());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001102}
Chris Lattner86928112007-08-25 02:00:02 +00001103void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1104 PrintExpr(Node->getLHS());
1105 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1106 PrintExpr(Node->getRHS());
1107}
Chris Lattner882f7882006-11-04 18:52:07 +00001108void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1109 PrintExpr(Node->getCond());
John McCallc07a0c72011-02-17 10:25:35 +00001110 OS << " ? ";
1111 PrintExpr(Node->getLHS());
1112 OS << " : ";
Chris Lattner882f7882006-11-04 18:52:07 +00001113 PrintExpr(Node->getRHS());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001114}
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001115
Chris Lattnereefa10e2007-05-28 06:56:27 +00001116// GNU extensions.
1117
John McCallc07a0c72011-02-17 10:25:35 +00001118void
1119StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1120 PrintExpr(Node->getCommon());
1121 OS << " ?: ";
1122 PrintExpr(Node->getFalseExpr());
1123}
Chris Lattnerd268a7a2007-08-03 17:31:20 +00001124void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattnereefa10e2007-05-28 06:56:27 +00001125 OS << "&&" << Node->getLabel()->getName();
Chris Lattnereefa10e2007-05-28 06:56:27 +00001126}
1127
Chris Lattner366727f2007-07-24 16:58:17 +00001128void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1129 OS << "(";
1130 PrintRawCompoundStmt(E->getSubStmt());
1131 OS << ")";
1132}
1133
Steve Naroff9efdabc2007-08-03 21:21:27 +00001134void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1135 OS << "__builtin_choose_expr(";
1136 PrintExpr(Node->getCond());
Chris Lattner81a96882007-08-04 00:20:15 +00001137 OS << ", ";
Steve Naroff9efdabc2007-08-03 21:21:27 +00001138 PrintExpr(Node->getLHS());
Chris Lattner81a96882007-08-04 00:20:15 +00001139 OS << ", ";
Steve Naroff9efdabc2007-08-03 21:21:27 +00001140 PrintExpr(Node->getRHS());
1141 OS << ")";
1142}
Chris Lattner366727f2007-07-24 16:58:17 +00001143
Douglas Gregor3be4b122008-11-29 04:51:27 +00001144void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1145 OS << "__null";
1146}
1147
Eli Friedmana1b4ed82008-05-14 19:38:39 +00001148void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1149 OS << "__builtin_shufflevector(";
1150 for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
1151 if (i) OS << ", ";
1152 PrintExpr(Node->getExpr(i));
1153 }
1154 OS << ")";
1155}
1156
Hal Finkelc4d7c822013-09-18 03:29:45 +00001157void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1158 OS << "__builtin_convertvector(";
1159 PrintExpr(Node->getSrcExpr());
1160 OS << ", ";
1161 Node->getType().print(OS, Policy);
1162 OS << ")";
1163}
1164
Anders Carlsson4692db02007-08-31 04:56:16 +00001165void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
Douglas Gregor36098ff2009-05-30 00:56:08 +00001166 if (Node->getSyntacticForm()) {
1167 Visit(Node->getSyntacticForm());
1168 return;
1169 }
1170
Anders Carlsson4692db02007-08-31 04:56:16 +00001171 OS << "{ ";
1172 for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
1173 if (i) OS << ", ";
Douglas Gregor347f7ea2009-01-28 21:54:33 +00001174 if (Node->getInit(i))
1175 PrintExpr(Node->getInit(i));
1176 else
1177 OS << "0";
Anders Carlsson4692db02007-08-31 04:56:16 +00001178 }
1179 OS << " }";
1180}
1181
Nate Begeman5ec4b312009-08-10 23:49:36 +00001182void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1183 OS << "( ";
1184 for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
1185 if (i) OS << ", ";
1186 PrintExpr(Node->getExpr(i));
1187 }
1188 OS << " )";
1189}
1190
Douglas Gregore4a0bb72009-01-22 00:58:24 +00001191void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
Douglas Gregor347f7ea2009-01-28 21:54:33 +00001192 for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
1193 DEnd = Node->designators_end();
1194 D != DEnd; ++D) {
1195 if (D->isFieldDesignator()) {
1196 if (D->getDotLoc().isInvalid())
1197 OS << D->getFieldName()->getName() << ":";
1198 else
1199 OS << "." << D->getFieldName()->getName();
1200 } else {
1201 OS << "[";
1202 if (D->isArrayDesignator()) {
1203 PrintExpr(Node->getArrayIndex(*D));
1204 } else {
1205 PrintExpr(Node->getArrayRangeStart(*D));
1206 OS << " ... ";
Mike Stump11289f42009-09-09 15:08:12 +00001207 PrintExpr(Node->getArrayRangeEnd(*D));
Douglas Gregor347f7ea2009-01-28 21:54:33 +00001208 }
1209 OS << "]";
1210 }
1211 }
1212
1213 OS << " = ";
1214 PrintExpr(Node->getInit());
Douglas Gregore4a0bb72009-01-22 00:58:24 +00001215}
1216
Douglas Gregor0202cb42009-01-29 17:44:32 +00001217void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001218 if (Policy.LangOpts.CPlusPlus) {
1219 OS << "/*implicit*/";
1220 Node->getType().print(OS, Policy);
1221 OS << "()";
1222 } else {
1223 OS << "/*implicit*/(";
1224 Node->getType().print(OS, Policy);
1225 OS << ')';
Douglas Gregor278f52e2009-05-30 00:08:05 +00001226 if (Node->getType()->isRecordType())
1227 OS << "{}";
1228 else
1229 OS << 0;
1230 }
Douglas Gregor0202cb42009-01-29 17:44:32 +00001231}
1232
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001233void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
Eli Friedman79635842009-05-30 04:20:30 +00001234 OS << "__builtin_va_arg(";
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001235 PrintExpr(Node->getSubExpr());
1236 OS << ", ";
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001237 Node->getType().print(OS, Policy);
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001238 OS << ")";
1239}
1240
John McCallfe96e0b2011-11-06 09:01:30 +00001241void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1242 PrintExpr(Node->getSyntacticForm());
1243}
1244
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001245void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
Eli Friedmanc2025562011-10-11 20:00:47 +00001246 const char *Name = 0;
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001247 switch (Node->getOp()) {
Richard Smithfeea8832012-04-12 05:08:17 +00001248#define BUILTIN(ID, TYPE, ATTRS)
1249#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1250 case AtomicExpr::AO ## ID: \
1251 Name = #ID "("; \
1252 break;
1253#include "clang/Basic/Builtins.def"
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001254 }
1255 OS << Name;
Richard Smithfeea8832012-04-12 05:08:17 +00001256
1257 // AtomicExpr stores its subexpressions in a permuted order.
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001258 PrintExpr(Node->getPtr());
Richard Smithfeea8832012-04-12 05:08:17 +00001259 if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1260 Node->getOp() != AtomicExpr::AO__atomic_load_n) {
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001261 OS << ", ";
Richard Smithdf6bee82013-05-01 19:02:43 +00001262 PrintExpr(Node->getVal1());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001263 }
Richard Smithfeea8832012-04-12 05:08:17 +00001264 if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1265 Node->isCmpXChg()) {
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001266 OS << ", ";
Richard Smithdf6bee82013-05-01 19:02:43 +00001267 PrintExpr(Node->getVal2());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001268 }
Richard Smithfeea8832012-04-12 05:08:17 +00001269 if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1270 Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
Richard Smithfeea8832012-04-12 05:08:17 +00001271 OS << ", ";
Richard Smithdf6bee82013-05-01 19:02:43 +00001272 PrintExpr(Node->getWeak());
Richard Smithfeea8832012-04-12 05:08:17 +00001273 }
Richard Smithdf6bee82013-05-01 19:02:43 +00001274 if (Node->getOp() != AtomicExpr::AO__c11_atomic_init) {
1275 OS << ", ";
David Chisnallfa35df62012-01-16 17:27:18 +00001276 PrintExpr(Node->getOrder());
Richard Smithdf6bee82013-05-01 19:02:43 +00001277 }
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001278 if (Node->isCmpXChg()) {
1279 OS << ", ";
1280 PrintExpr(Node->getOrderFail());
1281 }
1282 OS << ")";
1283}
1284
Chris Lattnereefa10e2007-05-28 06:56:27 +00001285// C++
Douglas Gregor993603d2008-11-14 16:09:21 +00001286void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1287 const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
1288 "",
1289#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1290 Spelling,
1291#include "clang/Basic/OperatorKinds.def"
1292 };
1293
1294 OverloadedOperatorKind Kind = Node->getOperator();
1295 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1296 if (Node->getNumArgs() == 1) {
1297 OS << OpStrings[Kind] << ' ';
1298 PrintExpr(Node->getArg(0));
1299 } else {
1300 PrintExpr(Node->getArg(0));
1301 OS << ' ' << OpStrings[Kind];
1302 }
Eli Friedman8e236422012-10-12 22:45:14 +00001303 } else if (Kind == OO_Arrow) {
1304 PrintExpr(Node->getArg(0));
Douglas Gregor993603d2008-11-14 16:09:21 +00001305 } else if (Kind == OO_Call) {
1306 PrintExpr(Node->getArg(0));
1307 OS << '(';
1308 for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1309 if (ArgIdx > 1)
1310 OS << ", ";
1311 if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1312 PrintExpr(Node->getArg(ArgIdx));
1313 }
1314 OS << ')';
1315 } else if (Kind == OO_Subscript) {
1316 PrintExpr(Node->getArg(0));
1317 OS << '[';
1318 PrintExpr(Node->getArg(1));
1319 OS << ']';
1320 } else if (Node->getNumArgs() == 1) {
1321 OS << OpStrings[Kind] << ' ';
1322 PrintExpr(Node->getArg(0));
1323 } else if (Node->getNumArgs() == 2) {
1324 PrintExpr(Node->getArg(0));
1325 OS << ' ' << OpStrings[Kind] << ' ';
1326 PrintExpr(Node->getArg(1));
1327 } else {
David Blaikie83d382b2011-09-23 05:06:16 +00001328 llvm_unreachable("unknown overloaded operator");
Douglas Gregor993603d2008-11-14 16:09:21 +00001329 }
1330}
Chris Lattnereefa10e2007-05-28 06:56:27 +00001331
Douglas Gregor97fd6e22008-12-22 05:46:06 +00001332void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
Benjamin Kramer00e8a192014-02-25 18:03:55 +00001333 // If we have a conversion operator call only print the argument.
1334 CXXMethodDecl *MD = Node->getMethodDecl();
1335 if (MD && isa<CXXConversionDecl>(MD)) {
1336 PrintExpr(Node->getImplicitObjectArgument());
1337 return;
1338 }
Douglas Gregor97fd6e22008-12-22 05:46:06 +00001339 VisitCallExpr(cast<CallExpr>(Node));
1340}
1341
Peter Collingbourne41f85462011-02-09 21:07:24 +00001342void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
1343 PrintExpr(Node->getCallee());
1344 OS << "<<<";
1345 PrintCallArgs(Node->getConfig());
1346 OS << ">>>(";
1347 PrintCallArgs(Node);
1348 OS << ")";
1349}
1350
Douglas Gregore200adc2008-10-27 19:41:14 +00001351void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
1352 OS << Node->getCastName() << '<';
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001353 Node->getTypeAsWritten().print(OS, Policy);
1354 OS << ">(";
Chris Lattnereefa10e2007-05-28 06:56:27 +00001355 PrintExpr(Node->getSubExpr());
1356 OS << ")";
1357}
1358
Douglas Gregore200adc2008-10-27 19:41:14 +00001359void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
1360 VisitCXXNamedCastExpr(Node);
1361}
1362
1363void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
1364 VisitCXXNamedCastExpr(Node);
1365}
1366
1367void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
1368 VisitCXXNamedCastExpr(Node);
1369}
1370
1371void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
1372 VisitCXXNamedCastExpr(Node);
1373}
1374
Sebastian Redlc4704762008-11-11 11:37:55 +00001375void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
1376 OS << "typeid(";
1377 if (Node->isTypeOperand()) {
David Majnemer143c55e2013-09-27 07:04:31 +00001378 Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
Sebastian Redlc4704762008-11-11 11:37:55 +00001379 } else {
1380 PrintExpr(Node->getExprOperand());
1381 }
1382 OS << ")";
1383}
1384
Francois Pichet9f4f2072010-09-08 12:20:18 +00001385void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
1386 OS << "__uuidof(";
1387 if (Node->isTypeOperand()) {
David Majnemer143c55e2013-09-27 07:04:31 +00001388 Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
Francois Pichet9f4f2072010-09-08 12:20:18 +00001389 } else {
1390 PrintExpr(Node->getExprOperand());
1391 }
1392 OS << ")";
1393}
1394
John McCall5e77d762013-04-16 07:28:30 +00001395void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
1396 PrintExpr(Node->getBaseExpr());
1397 if (Node->isArrow())
1398 OS << "->";
1399 else
1400 OS << ".";
1401 if (NestedNameSpecifier *Qualifier =
1402 Node->getQualifierLoc().getNestedNameSpecifier())
1403 Qualifier->print(OS, Policy);
1404 OS << Node->getPropertyDecl()->getDeclName();
1405}
1406
Richard Smithc67fdd42012-03-07 08:35:16 +00001407void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
1408 switch (Node->getLiteralOperatorKind()) {
1409 case UserDefinedLiteral::LOK_Raw:
Richard Smith29e95952012-03-09 10:10:02 +00001410 OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
Richard Smithc67fdd42012-03-07 08:35:16 +00001411 break;
1412 case UserDefinedLiteral::LOK_Template: {
Richard Smith29e95952012-03-09 10:10:02 +00001413 DeclRefExpr *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
1414 const TemplateArgumentList *Args =
1415 cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
1416 assert(Args);
1417 const TemplateArgument &Pack = Args->get(0);
1418 for (TemplateArgument::pack_iterator I = Pack.pack_begin(),
1419 E = Pack.pack_end(); I != E; ++I) {
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001420 char C = (char)I->getAsIntegral().getZExtValue();
Richard Smithc67fdd42012-03-07 08:35:16 +00001421 OS << C;
1422 }
1423 break;
1424 }
Richard Smith75025ba2012-03-08 09:02:38 +00001425 case UserDefinedLiteral::LOK_Integer: {
1426 // Print integer literal without suffix.
1427 IntegerLiteral *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
1428 OS << Int->getValue().toString(10, /*isSigned*/false);
1429 break;
1430 }
Benjamin Kramer8a526762012-09-20 14:07:17 +00001431 case UserDefinedLiteral::LOK_Floating: {
1432 // Print floating literal without suffix.
1433 FloatingLiteral *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
1434 PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
1435 break;
1436 }
Richard Smithc67fdd42012-03-07 08:35:16 +00001437 case UserDefinedLiteral::LOK_String:
1438 case UserDefinedLiteral::LOK_Character:
1439 PrintExpr(Node->getCookedLiteral());
1440 break;
1441 }
1442 OS << Node->getUDSuffix()->getName();
1443}
1444
Chris Lattnereefa10e2007-05-28 06:56:27 +00001445void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
1446 OS << (Node->getValue() ? "true" : "false");
1447}
1448
Sebastian Redl576fd422009-05-10 18:38:11 +00001449void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1450 OS << "nullptr";
1451}
1452
Douglas Gregor97a9c812008-11-04 14:32:21 +00001453void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1454 OS << "this";
1455}
1456
Chris Lattnerb7e656b2008-02-26 00:51:44 +00001457void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
1458 if (Node->getSubExpr() == 0)
1459 OS << "throw";
1460 else {
1461 OS << "throw ";
1462 PrintExpr(Node->getSubExpr());
1463 }
1464}
1465
Chris Lattneraa9c7ae2008-04-08 04:40:51 +00001466void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
Richard Smith852c9db2013-04-20 22:23:05 +00001467 // Nothing to print: we picked up the default argument.
1468}
1469
1470void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
1471 // Nothing to print: we picked up the default initializer.
Chris Lattneraa9c7ae2008-04-08 04:40:51 +00001472}
1473
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001474void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001475 Node->getType().print(OS, Policy);
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001476 OS << "(";
1477 PrintExpr(Node->getSubExpr());
1478 OS << ")";
1479}
1480
Anders Carlsson993a4b32009-05-30 20:03:25 +00001481void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1482 PrintExpr(Node->getSubExpr());
1483}
1484
Douglas Gregordd04d332009-01-16 18:33:17 +00001485void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001486 Node->getType().print(OS, Policy);
Douglas Gregordd04d332009-01-16 18:33:17 +00001487 OS << "(";
1488 for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
Mike Stump11289f42009-09-09 15:08:12 +00001489 ArgEnd = Node->arg_end();
Douglas Gregordd04d332009-01-16 18:33:17 +00001490 Arg != ArgEnd; ++Arg) {
Rafael Espindola6f6f3c42013-05-24 16:11:44 +00001491 if (Arg->isDefaultArgument())
1492 break;
Douglas Gregordd04d332009-01-16 18:33:17 +00001493 if (Arg != Node->arg_begin())
1494 OS << ", ";
1495 PrintExpr(*Arg);
1496 }
1497 OS << ")";
1498}
1499
Douglas Gregore31e6062012-02-07 10:09:13 +00001500void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
1501 OS << '[';
1502 bool NeedComma = false;
1503 switch (Node->getCaptureDefault()) {
1504 case LCD_None:
1505 break;
1506
1507 case LCD_ByCopy:
1508 OS << '=';
1509 NeedComma = true;
1510 break;
1511
1512 case LCD_ByRef:
1513 OS << '&';
1514 NeedComma = true;
1515 break;
1516 }
1517 for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
1518 CEnd = Node->explicit_capture_end();
1519 C != CEnd;
1520 ++C) {
1521 if (NeedComma)
1522 OS << ", ";
1523 NeedComma = true;
1524
1525 switch (C->getCaptureKind()) {
1526 case LCK_This:
1527 OS << "this";
1528 break;
1529
1530 case LCK_ByRef:
Richard Smithbb13c9a2013-09-28 04:02:39 +00001531 if (Node->getCaptureDefault() != LCD_ByRef || C->isInitCapture())
Douglas Gregore31e6062012-02-07 10:09:13 +00001532 OS << '&';
1533 OS << C->getCapturedVar()->getName();
1534 break;
1535
1536 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001537 OS << C->getCapturedVar()->getName();
1538 break;
1539 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00001540
1541 if (C->isInitCapture())
1542 PrintExpr(C->getCapturedVar()->getInit());
Douglas Gregore31e6062012-02-07 10:09:13 +00001543 }
1544 OS << ']';
1545
1546 if (Node->hasExplicitParameters()) {
1547 OS << " (";
1548 CXXMethodDecl *Method = Node->getCallOperator();
1549 NeedComma = false;
Aaron Ballman43b68be2014-03-07 17:50:17 +00001550 for (auto P : Method->params()) {
Douglas Gregore31e6062012-02-07 10:09:13 +00001551 if (NeedComma) {
1552 OS << ", ";
1553 } else {
1554 NeedComma = true;
1555 }
Aaron Ballman43b68be2014-03-07 17:50:17 +00001556 std::string ParamStr = P->getNameAsString();
1557 P->getOriginalType().print(OS, Policy, ParamStr);
Douglas Gregore31e6062012-02-07 10:09:13 +00001558 }
1559 if (Method->isVariadic()) {
1560 if (NeedComma)
1561 OS << ", ";
1562 OS << "...";
1563 }
1564 OS << ')';
1565
1566 if (Node->isMutable())
1567 OS << " mutable";
1568
1569 const FunctionProtoType *Proto
1570 = Method->getType()->getAs<FunctionProtoType>();
Benjamin Kramer9170e912013-02-22 15:46:01 +00001571 Proto->printExceptionSpecification(OS, Policy);
Douglas Gregore31e6062012-02-07 10:09:13 +00001572
Bill Wendling44426052012-12-20 19:22:21 +00001573 // FIXME: Attributes
Douglas Gregore31e6062012-02-07 10:09:13 +00001574
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00001575 // Print the trailing return type if it was specified in the source.
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001576 if (Node->hasExplicitResultType()) {
1577 OS << " -> ";
Alp Toker314cc812014-01-25 16:55:45 +00001578 Proto->getReturnType().print(OS, Policy);
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001579 }
Douglas Gregore31e6062012-02-07 10:09:13 +00001580 }
1581
1582 // Print the body.
1583 CompoundStmt *Body = Node->getBody();
1584 OS << ' ';
1585 PrintStmt(Body);
1586}
1587
Douglas Gregor747eb782010-07-08 06:14:04 +00001588void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00001589 if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001590 TSInfo->getType().print(OS, Policy);
Douglas Gregor2b88c112010-09-08 00:15:04 +00001591 else
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001592 Node->getType().print(OS, Policy);
1593 OS << "()";
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001594}
1595
Sebastian Redlbd150f42008-11-21 19:14:01 +00001596void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
1597 if (E->isGlobalNew())
1598 OS << "::";
1599 OS << "new ";
1600 unsigned NumPlace = E->getNumPlacementArgs();
Eli Friedmana6fdfaa2012-10-18 20:54:37 +00001601 if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
Sebastian Redlbd150f42008-11-21 19:14:01 +00001602 OS << "(";
1603 PrintExpr(E->getPlacementArg(0));
1604 for (unsigned i = 1; i < NumPlace; ++i) {
Eli Friedmana6fdfaa2012-10-18 20:54:37 +00001605 if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
1606 break;
Sebastian Redlbd150f42008-11-21 19:14:01 +00001607 OS << ", ";
1608 PrintExpr(E->getPlacementArg(i));
1609 }
1610 OS << ") ";
1611 }
1612 if (E->isParenTypeId())
1613 OS << "(";
Sebastian Redld6d55ee2008-12-02 22:08:59 +00001614 std::string TypeS;
1615 if (Expr *Size = E->getArraySize()) {
1616 llvm::raw_string_ostream s(TypeS);
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001617 s << '[';
Richard Smith235341b2012-08-16 03:56:14 +00001618 Size->printPretty(s, Helper, Policy);
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001619 s << ']';
Sebastian Redld6d55ee2008-12-02 22:08:59 +00001620 }
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001621 E->getAllocatedType().print(OS, Policy, TypeS);
Sebastian Redlbd150f42008-11-21 19:14:01 +00001622 if (E->isParenTypeId())
1623 OS << ")";
1624
Sebastian Redl6047f072012-02-16 12:22:20 +00001625 CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
1626 if (InitStyle) {
1627 if (InitStyle == CXXNewExpr::CallInit)
1628 OS << "(";
1629 PrintExpr(E->getInitializer());
1630 if (InitStyle == CXXNewExpr::CallInit)
1631 OS << ")";
Sebastian Redlbd150f42008-11-21 19:14:01 +00001632 }
1633}
1634
1635void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1636 if (E->isGlobalDelete())
1637 OS << "::";
1638 OS << "delete ";
1639 if (E->isArrayForm())
1640 OS << "[] ";
1641 PrintExpr(E->getArgument());
1642}
1643
Douglas Gregorad8a3362009-09-04 17:36:40 +00001644void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1645 PrintExpr(E->getBase());
1646 if (E->isArrow())
1647 OS << "->";
1648 else
1649 OS << '.';
1650 if (E->getQualifier())
1651 E->getQualifier()->print(OS, Policy);
Eli Friedman9cc8ac52012-10-23 20:26:57 +00001652 OS << "~";
Mike Stump11289f42009-09-09 15:08:12 +00001653
Douglas Gregor678f90d2010-02-25 01:56:36 +00001654 if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
1655 OS << II->getName();
1656 else
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001657 E->getDestroyedType().print(OS, Policy);
Douglas Gregorad8a3362009-09-04 17:36:40 +00001658}
1659
Anders Carlsson0781ce72009-04-23 02:32:43 +00001660void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00001661 if (E->isListInitialization())
1662 OS << "{ ";
1663
Douglas Gregorbaba85d2011-01-24 17:25:03 +00001664 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
1665 if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
1666 // Don't print any defaulted arguments
1667 break;
1668 }
1669
1670 if (i) OS << ", ";
1671 PrintExpr(E->getArg(i));
Fariborz Jahaniand0bbf662010-01-13 21:41:11 +00001672 }
Richard Smithd59b8322012-12-19 01:39:02 +00001673
1674 if (E->isListInitialization())
1675 OS << " }";
Anders Carlsson0781ce72009-04-23 02:32:43 +00001676}
1677
Richard Smithcc1b96d2013-06-12 22:31:48 +00001678void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1679 PrintExpr(E->getSubExpr());
1680}
1681
John McCall5d413782010-12-06 08:20:24 +00001682void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
Alp Toker028ed912013-12-06 17:56:43 +00001683 // Just forward to the subexpression.
Anders Carlssondefc6442009-04-24 22:47:04 +00001684 PrintExpr(E->getSubExpr());
1685}
1686
Mike Stump11289f42009-09-09 15:08:12 +00001687void
Douglas Gregorce934142009-05-20 18:46:25 +00001688StmtPrinter::VisitCXXUnresolvedConstructExpr(
1689 CXXUnresolvedConstructExpr *Node) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001690 Node->getTypeAsWritten().print(OS, Policy);
Douglas Gregorce934142009-05-20 18:46:25 +00001691 OS << "(";
1692 for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
Mike Stump11289f42009-09-09 15:08:12 +00001693 ArgEnd = Node->arg_end();
Douglas Gregorce934142009-05-20 18:46:25 +00001694 Arg != ArgEnd; ++Arg) {
1695 if (Arg != Node->arg_begin())
1696 OS << ", ";
1697 PrintExpr(*Arg);
1698 }
1699 OS << ")";
1700}
1701
John McCall8cd78132009-11-19 22:55:06 +00001702void StmtPrinter::VisitCXXDependentScopeMemberExpr(
1703 CXXDependentScopeMemberExpr *Node) {
John McCall2d74de92009-12-01 22:10:20 +00001704 if (!Node->isImplicitAccess()) {
1705 PrintExpr(Node->getBase());
1706 OS << (Node->isArrow() ? "->" : ".");
1707 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001708 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1709 Qualifier->print(OS, Policy);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001710 if (Node->hasTemplateKeyword())
Douglas Gregor308047d2009-09-09 00:23:06 +00001711 OS << "template ";
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001712 OS << Node->getMemberNameInfo();
Benjamin Kramer9170e912013-02-22 15:46:01 +00001713 if (Node->hasExplicitTemplateArgs())
1714 TemplateSpecializationType::PrintTemplateArgumentList(
1715 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Douglas Gregora8db9542009-05-22 21:13:27 +00001716}
1717
John McCall10eae182009-11-30 22:42:35 +00001718void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
John McCall2d74de92009-12-01 22:10:20 +00001719 if (!Node->isImplicitAccess()) {
1720 PrintExpr(Node->getBase());
1721 OS << (Node->isArrow() ? "->" : ".");
1722 }
John McCall10eae182009-11-30 22:42:35 +00001723 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1724 Qualifier->print(OS, Policy);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001725 if (Node->hasTemplateKeyword())
1726 OS << "template ";
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001727 OS << Node->getMemberNameInfo();
Benjamin Kramer9170e912013-02-22 15:46:01 +00001728 if (Node->hasExplicitTemplateArgs())
1729 TemplateSpecializationType::PrintTemplateArgumentList(
1730 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
John McCall10eae182009-11-30 22:42:35 +00001731}
1732
Douglas Gregor29c42f22012-02-24 07:38:34 +00001733static const char *getTypeTraitName(TypeTrait TT) {
1734 switch (TT) {
Alp Toker95e7ff22014-01-01 05:57:51 +00001735#define TYPE_TRAIT_1(Spelling, Name, Key) \
1736case clang::UTT_##Name: return #Spelling;
Alp Tokercbb90342013-12-13 20:49:58 +00001737#define TYPE_TRAIT_2(Spelling, Name, Key) \
1738case clang::BTT_##Name: return #Spelling;
Alp Toker40f9b1c2013-12-12 21:23:03 +00001739#define TYPE_TRAIT_N(Spelling, Name, Key) \
1740 case clang::TT_##Name: return #Spelling;
1741#include "clang/Basic/TokenKinds.def"
Douglas Gregor29c42f22012-02-24 07:38:34 +00001742 }
1743 llvm_unreachable("Type trait not covered by switch");
1744}
1745
John Wiegley6242b6a2011-04-28 00:16:57 +00001746static const char *getTypeTraitName(ArrayTypeTrait ATT) {
1747 switch (ATT) {
1748 case ATT_ArrayRank: return "__array_rank";
1749 case ATT_ArrayExtent: return "__array_extent";
1750 }
Chandler Carruthe46eaf32011-05-01 07:23:23 +00001751 llvm_unreachable("Array type trait not covered by switch");
John Wiegley6242b6a2011-04-28 00:16:57 +00001752}
1753
John Wiegleyf9f65842011-04-25 06:54:41 +00001754static const char *getExpressionTraitName(ExpressionTrait ET) {
1755 switch (ET) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001756 case ET_IsLValueExpr: return "__is_lvalue_expr";
1757 case ET_IsRValueExpr: return "__is_rvalue_expr";
1758 }
Chandler Carruthe46eaf32011-05-01 07:23:23 +00001759 llvm_unreachable("Expression type trait not covered by switch");
John Wiegleyf9f65842011-04-25 06:54:41 +00001760}
1761
Douglas Gregor29c42f22012-02-24 07:38:34 +00001762void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1763 OS << getTypeTraitName(E->getTrait()) << "(";
1764 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
1765 if (I > 0)
1766 OS << ", ";
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001767 E->getArg(I)->getType().print(OS, Policy);
Douglas Gregor29c42f22012-02-24 07:38:34 +00001768 }
1769 OS << ")";
1770}
1771
John Wiegley6242b6a2011-04-28 00:16:57 +00001772void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001773 OS << getTypeTraitName(E->getTrait()) << '(';
1774 E->getQueriedType().print(OS, Policy);
1775 OS << ')';
John Wiegley6242b6a2011-04-28 00:16:57 +00001776}
1777
John Wiegleyf9f65842011-04-25 06:54:41 +00001778void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001779 OS << getExpressionTraitName(E->getTrait()) << '(';
1780 PrintExpr(E->getQueriedExpression());
1781 OS << ')';
John Wiegleyf9f65842011-04-25 06:54:41 +00001782}
1783
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001784void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1785 OS << "noexcept(";
1786 PrintExpr(E->getOperand());
1787 OS << ")";
1788}
1789
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001790void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001791 PrintExpr(E->getPattern());
1792 OS << "...";
1793}
1794
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001795void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
Benjamin Kramerdb0fc512012-02-07 11:57:57 +00001796 OS << "sizeof...(" << *E->getPack() << ")";
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001797}
1798
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001799void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
1800 SubstNonTypeTemplateParmPackExpr *Node) {
Benjamin Kramerdb0fc512012-02-07 11:57:57 +00001801 OS << *Node->getParameterPack();
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001802}
1803
John McCall7c454bb2011-07-15 05:09:51 +00001804void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
1805 SubstNonTypeTemplateParmExpr *Node) {
1806 Visit(Node->getReplacement());
1807}
1808
Richard Smithb15fe3a2012-09-12 00:56:43 +00001809void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1810 OS << *E->getParameterPack();
1811}
1812
Douglas Gregorfe314812011-06-21 17:03:29 +00001813void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
1814 PrintExpr(Node->GetTemporaryExpr());
1815}
1816
Mike Stump11289f42009-09-09 15:08:12 +00001817// Obj-C
Anders Carlsson76f4a902007-08-21 17:43:55 +00001818
1819void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
1820 OS << "@";
1821 VisitStringLiteral(Node->getString());
1822}
Chris Lattnereefa10e2007-05-28 06:56:27 +00001823
Patrick Beard0caa3942012-04-19 00:25:12 +00001824void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001825 OS << "@";
Patrick Beard0caa3942012-04-19 00:25:12 +00001826 Visit(E->getSubExpr());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001827}
1828
1829void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1830 OS << "@[ ";
1831 StmtRange ch = E->children();
1832 if (ch.first != ch.second) {
1833 while (1) {
1834 Visit(*ch.first);
1835 ++ch.first;
1836 if (ch.first == ch.second) break;
1837 OS << ", ";
1838 }
1839 }
1840 OS << " ]";
1841}
1842
1843void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1844 OS << "@{ ";
1845 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
1846 if (I > 0)
1847 OS << ", ";
1848
1849 ObjCDictionaryElement Element = E->getKeyValueElement(I);
1850 Visit(Element.Key);
1851 OS << " : ";
1852 Visit(Element.Value);
1853 if (Element.isPackExpansion())
1854 OS << "...";
1855 }
1856 OS << " }";
1857}
1858
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001859void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001860 OS << "@encode(";
1861 Node->getEncodedType().print(OS, Policy);
1862 OS << ')';
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001863}
1864
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001865void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
Aaron Ballmanb190f972014-01-03 17:59:55 +00001866 OS << "@selector(";
1867 Node->getSelector().print(OS);
1868 OS << ')';
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001869}
1870
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001871void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001872 OS << "@protocol(" << *Node->getProtocol() << ')';
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001873}
1874
Steve Naroffd54978b2007-09-18 23:55:05 +00001875void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
1876 OS << "[";
Douglas Gregor9a129192010-04-21 00:45:42 +00001877 switch (Mess->getReceiverKind()) {
1878 case ObjCMessageExpr::Instance:
1879 PrintExpr(Mess->getInstanceReceiver());
1880 break;
1881
1882 case ObjCMessageExpr::Class:
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001883 Mess->getClassReceiver().print(OS, Policy);
Douglas Gregor9a129192010-04-21 00:45:42 +00001884 break;
1885
1886 case ObjCMessageExpr::SuperInstance:
1887 case ObjCMessageExpr::SuperClass:
1888 OS << "Super";
1889 break;
1890 }
1891
Ted Kremeneka06e7122008-05-02 17:32:38 +00001892 OS << ' ';
Ted Kremenekb65a67d2008-04-16 04:30:16 +00001893 Selector selector = Mess->getSelector();
Steve Naroffc6814ea2007-10-02 20:01:56 +00001894 if (selector.isUnarySelector()) {
Douglas Gregoraf2a6ae2011-02-18 22:29:55 +00001895 OS << selector.getNameForSlot(0);
Steve Naroffc6814ea2007-10-02 20:01:56 +00001896 } else {
1897 for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
Ted Kremeneka06e7122008-05-02 17:32:38 +00001898 if (i < selector.getNumArgs()) {
1899 if (i > 0) OS << ' ';
1900 if (selector.getIdentifierInfoForSlot(i))
Chris Lattner1cbaacc2008-11-24 04:00:27 +00001901 OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
Ted Kremeneka06e7122008-05-02 17:32:38 +00001902 else
1903 OS << ":";
1904 }
1905 else OS << ", "; // Handle variadic methods.
Mike Stump11289f42009-09-09 15:08:12 +00001906
Steve Naroffc6814ea2007-10-02 20:01:56 +00001907 PrintExpr(Mess->getArg(i));
1908 }
Steve Naroffd54978b2007-09-18 23:55:05 +00001909 }
1910 OS << "]";
1911}
1912
Ted Kremeneke65b0862012-03-06 20:05:56 +00001913void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
1914 OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
1915}
1916
John McCall31168b02011-06-15 23:02:42 +00001917void
1918StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
1919 PrintExpr(E->getSubExpr());
1920}
1921
1922void
1923StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001924 OS << '(' << E->getBridgeKindName();
1925 E->getType().print(OS, Policy);
1926 OS << ')';
John McCall31168b02011-06-15 23:02:42 +00001927 PrintExpr(E->getSubExpr());
1928}
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001929
Steve Naroffc540d662008-09-03 18:15:37 +00001930void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
Steve Naroff415d3d52008-10-08 17:01:13 +00001931 BlockDecl *BD = Node->getBlockDecl();
Steve Naroffc540d662008-09-03 18:15:37 +00001932 OS << "^";
Mike Stump11289f42009-09-09 15:08:12 +00001933
Steve Naroffc540d662008-09-03 18:15:37 +00001934 const FunctionType *AFT = Node->getFunctionType();
Mike Stump11289f42009-09-09 15:08:12 +00001935
Douglas Gregordeaad8c2009-02-26 23:50:07 +00001936 if (isa<FunctionNoProtoType>(AFT)) {
Steve Naroffc540d662008-09-03 18:15:37 +00001937 OS << "()";
Douglas Gregordeaad8c2009-02-26 23:50:07 +00001938 } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
Steve Naroffc540d662008-09-03 18:15:37 +00001939 OS << '(';
Steve Naroff415d3d52008-10-08 17:01:13 +00001940 for (BlockDecl::param_iterator AI = BD->param_begin(),
1941 E = BD->param_end(); AI != E; ++AI) {
1942 if (AI != BD->param_begin()) OS << ", ";
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001943 std::string ParamStr = (*AI)->getNameAsString();
1944 (*AI)->getType().print(OS, Policy, ParamStr);
Steve Naroffc540d662008-09-03 18:15:37 +00001945 }
Mike Stump11289f42009-09-09 15:08:12 +00001946
Douglas Gregordeaad8c2009-02-26 23:50:07 +00001947 const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
Steve Naroffc540d662008-09-03 18:15:37 +00001948 if (FT->isVariadic()) {
Steve Naroff415d3d52008-10-08 17:01:13 +00001949 if (!BD->param_empty()) OS << ", ";
Steve Naroffc540d662008-09-03 18:15:37 +00001950 OS << "...";
1951 }
1952 OS << ')';
1953 }
Fariborz Jahanian1ace8cb2012-12-04 21:15:23 +00001954 OS << "{ }";
Steve Naroffc540d662008-09-03 18:15:37 +00001955}
1956
Ted Kremenekf551f322011-11-30 22:08:08 +00001957void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
1958 PrintExpr(Node->getSourceExpr());
1959}
John McCall8d69a212010-11-15 23:31:06 +00001960
Tanya Lattner55808c12011-06-04 00:47:47 +00001961void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
1962 OS << "__builtin_astype(";
1963 PrintExpr(Node->getSrcExpr());
Benjamin Kramerc5720e92013-02-22 14:19:01 +00001964 OS << ", ";
1965 Node->getType().print(OS, Policy);
Tanya Lattner55808c12011-06-04 00:47:47 +00001966 OS << ")";
1967}
1968
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001969//===----------------------------------------------------------------------===//
1970// Stmt method implementations
1971//===----------------------------------------------------------------------===//
1972
Craig Topperc571c812013-08-22 06:02:26 +00001973void Stmt::dumpPretty(const ASTContext &Context) const {
Richard Smith235341b2012-08-16 03:56:14 +00001974 printPretty(llvm::errs(), 0, PrintingPolicy(Context.getLangOpts()));
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001975}
1976
Richard Smith235341b2012-08-16 03:56:14 +00001977void Stmt::printPretty(raw_ostream &OS,
1978 PrinterHelper *Helper,
Douglas Gregor7de59662009-05-29 20:38:28 +00001979 const PrintingPolicy &Policy,
1980 unsigned Indentation) const {
Chris Lattner882f7882006-11-04 18:52:07 +00001981 if (this == 0) {
1982 OS << "<NULL>";
1983 return;
1984 }
1985
Richard Smith235341b2012-08-16 03:56:14 +00001986 StmtPrinter P(OS, Helper, Policy, Indentation);
Chris Lattner62249a62007-08-21 04:04:25 +00001987 P.Visit(const_cast<Stmt*>(this));
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001988}
Ted Kremenek04f3cee2007-08-31 21:30:12 +00001989
1990//===----------------------------------------------------------------------===//
1991// PrinterHelper
1992//===----------------------------------------------------------------------===//
1993
1994// Implement virtual destructor.
Gabor Greif412af032007-09-11 15:32:40 +00001995PrinterHelper::~PrinterHelper() {}