blob: 1d01e655655301fb916b4e1fa71791ef77e86b74 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===//
2//
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 Lattner6000dac2007-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.
Reid Spencer5f016e22007-07-11 17:01:13 +000012//
13//===----------------------------------------------------------------------===//
14
Benjamin Kramer471c8b42012-07-04 20:19:54 +000015#include "clang/AST/ASTContext.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000016#include "clang/AST/Attr.h"
Douglas Gregor1a49af92009-01-06 05:10:23 +000017#include "clang/AST/DeclCXX.h"
Ted Kremenek91d1d7a2007-10-17 18:36:42 +000018#include "clang/AST/DeclObjC.h"
Douglas Gregorc7793c72011-01-15 01:15:58 +000019#include "clang/AST/DeclTemplate.h"
Douglas Gregor8ecdb652010-04-28 22:16:22 +000020#include "clang/AST/Expr.h"
Douglas Gregorab6677e2010-09-08 00:15:04 +000021#include "clang/AST/ExprCXX.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000022#include "clang/AST/PrettyPrinter.h"
23#include "clang/AST/StmtVisitor.h"
Jordan Rose6d4f7342013-02-08 22:30:27 +000024#include "clang/Basic/CharInfo.h"
Benjamin Kramer8fe83e12012-02-04 13:45:25 +000025#include "llvm/ADT/SmallString.h"
Jordan Rose6d4f7342013-02-08 22:30:27 +000026#include "llvm/Support/Format.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000027using namespace clang;
28
29//===----------------------------------------------------------------------===//
30// StmtPrinter Visitor
31//===----------------------------------------------------------------------===//
32
33namespace {
Benjamin Kramer770b4a82009-11-28 19:03:38 +000034 class StmtPrinter : public StmtVisitor<StmtPrinter> {
Chris Lattner5f9e2722011-07-23 10:55:15 +000035 raw_ostream &OS;
Reid Spencer5f016e22007-07-11 17:01:13 +000036 unsigned IndentLevel;
Ted Kremenek42a509f2007-08-31 21:30:12 +000037 clang::PrinterHelper* Helper;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000038 PrintingPolicy Policy;
39
Reid Spencer5f016e22007-07-11 17:01:13 +000040 public:
Richard Smithd1420c62012-08-16 03:56:14 +000041 StmtPrinter(raw_ostream &os, PrinterHelper* helper,
Chris Lattnere4f21422009-06-30 01:26:17 +000042 const PrintingPolicy &Policy,
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000043 unsigned Indentation = 0)
Richard Smithd1420c62012-08-16 03:56:14 +000044 : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy) {}
Mike Stump1eb44332009-09-09 15:08:12 +000045
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000046 void PrintStmt(Stmt *S) {
47 PrintStmt(S, Policy.Indentation);
48 }
49
50 void PrintStmt(Stmt *S, int SubIndent) {
Reid Spencer5f016e22007-07-11 17:01:13 +000051 IndentLevel += SubIndent;
52 if (S && isa<Expr>(S)) {
53 // If this is an expr used in a stmt context, indent and newline it.
54 Indent();
Chris Lattnerc5598cb2007-08-21 04:04:25 +000055 Visit(S);
Reid Spencer5f016e22007-07-11 17:01:13 +000056 OS << ";\n";
57 } else if (S) {
Chris Lattnerc5598cb2007-08-21 04:04:25 +000058 Visit(S);
Reid Spencer5f016e22007-07-11 17:01:13 +000059 } else {
60 Indent() << "<<<NULL STATEMENT>>>\n";
61 }
62 IndentLevel -= SubIndent;
63 }
Eli Friedmandb23b152009-05-30 00:19:54 +000064
Reid Spencer5f016e22007-07-11 17:01:13 +000065 void PrintRawCompoundStmt(CompoundStmt *S);
66 void PrintRawDecl(Decl *D);
Eli Friedman915c07d2012-10-16 23:45:15 +000067 void PrintRawDeclStmt(const DeclStmt *S);
Reid Spencer5f016e22007-07-11 17:01:13 +000068 void PrintRawIfStmt(IfStmt *If);
Sebastian Redl8351da02008-12-22 21:35:02 +000069 void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
Peter Collingbourned64e2372011-02-08 21:17:54 +000070 void PrintCallArgs(CallExpr *E);
John Wiegley28bbe4b2011-04-28 01:08:34 +000071 void PrintRawSEHExceptHandler(SEHExceptStmt *S);
72 void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
Stephen Hines651f13c2014-04-23 16:59:28 -070073 void PrintOMPExecutableDirective(OMPExecutableDirective *S);
Mike Stump1eb44332009-09-09 15:08:12 +000074
Reid Spencer5f016e22007-07-11 17:01:13 +000075 void PrintExpr(Expr *E) {
76 if (E)
Chris Lattnerc5598cb2007-08-21 04:04:25 +000077 Visit(E);
Reid Spencer5f016e22007-07-11 17:01:13 +000078 else
79 OS << "<null expr>";
80 }
Mike Stump1eb44332009-09-09 15:08:12 +000081
Chris Lattner5f9e2722011-07-23 10:55:15 +000082 raw_ostream &Indent(int Delta = 0) {
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000083 for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
84 OS << " ";
Reid Spencer5f016e22007-07-11 17:01:13 +000085 return OS;
86 }
Mike Stump1eb44332009-09-09 15:08:12 +000087
Mike Stump1eb44332009-09-09 15:08:12 +000088 void Visit(Stmt* S) {
Ted Kremenek42a509f2007-08-31 21:30:12 +000089 if (Helper && Helper->handledStmt(S,OS))
90 return;
91 else StmtVisitor<StmtPrinter>::Visit(S);
92 }
Stephen Hines651f13c2014-04-23 16:59:28 -070093
Chandler Carruth61e38282010-10-23 08:21:37 +000094 void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
Argyrios Kyrtzidis78e4cc72010-08-15 01:15:33 +000095 Indent() << "<<unknown stmt type>>\n";
96 }
Chandler Carruth61e38282010-10-23 08:21:37 +000097 void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
Argyrios Kyrtzidis78e4cc72010-08-15 01:15:33 +000098 OS << "<<unknown expr type>>";
99 }
100 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000101
Argyrios Kyrtzidis78e4cc72010-08-15 01:15:33 +0000102#define ABSTRACT_STMT(CLASS)
Douglas Gregorf2cad862008-11-14 12:46:07 +0000103#define STMT(CLASS, PARENT) \
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000104 void Visit##CLASS(CLASS *Node);
Sean Hunt4bfe1962010-05-05 15:24:00 +0000105#include "clang/AST/StmtNodes.inc"
Reid Spencer5f016e22007-07-11 17:01:13 +0000106 };
107}
108
109//===----------------------------------------------------------------------===//
110// Stmt printing methods.
111//===----------------------------------------------------------------------===//
112
Reid Spencer5f016e22007-07-11 17:01:13 +0000113/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
114/// with no newline after the }.
115void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
116 OS << "{\n";
Stephen Hines651f13c2014-04-23 16:59:28 -0700117 for (auto *I : Node->body())
118 PrintStmt(I);
Mike Stump1eb44332009-09-09 15:08:12 +0000119
Reid Spencer5f016e22007-07-11 17:01:13 +0000120 Indent() << "}";
121}
122
123void StmtPrinter::PrintRawDecl(Decl *D) {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000124 D->print(OS, Policy, IndentLevel);
Mike Stump071e4da2009-02-10 20:16:46 +0000125}
126
Eli Friedman915c07d2012-10-16 23:45:15 +0000127void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700128 SmallVector<Decl*, 2> Decls(S->decls());
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000129 Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
Ted Kremenekecd64c52008-10-06 18:39:36 +0000130}
Reid Spencer5f016e22007-07-11 17:01:13 +0000131
132void StmtPrinter::VisitNullStmt(NullStmt *Node) {
133 Indent() << ";\n";
134}
135
136void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
Eli Friedmandb23b152009-05-30 00:19:54 +0000137 Indent();
138 PrintRawDeclStmt(Node);
139 OS << ";\n";
Reid Spencer5f016e22007-07-11 17:01:13 +0000140}
141
142void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
143 Indent();
144 PrintRawCompoundStmt(Node);
145 OS << "\n";
146}
147
148void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
149 Indent(-1) << "case ";
150 PrintExpr(Node->getLHS());
151 if (Node->getRHS()) {
152 OS << " ... ";
153 PrintExpr(Node->getRHS());
154 }
155 OS << ":\n";
Mike Stump1eb44332009-09-09 15:08:12 +0000156
Reid Spencer5f016e22007-07-11 17:01:13 +0000157 PrintStmt(Node->getSubStmt(), 0);
158}
159
160void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
161 Indent(-1) << "default:\n";
162 PrintStmt(Node->getSubStmt(), 0);
163}
164
165void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
166 Indent(-1) << Node->getName() << ":\n";
167 PrintStmt(Node->getSubStmt(), 0);
168}
169
Richard Smith534986f2012-04-14 00:33:13 +0000170void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700171 for (const auto *Attr : Node->getAttrs()) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700172 Attr->printPretty(OS, Policy);
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700173 }
174
Richard Smith534986f2012-04-14 00:33:13 +0000175 PrintStmt(Node->getSubStmt(), 0);
176}
177
Reid Spencer5f016e22007-07-11 17:01:13 +0000178void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
Sebastian Redlbfee9b22009-02-07 20:05:48 +0000179 OS << "if (";
Eli Friedman915c07d2012-10-16 23:45:15 +0000180 if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
181 PrintRawDeclStmt(DS);
182 else
183 PrintExpr(If->getCond());
Sebastian Redlbfee9b22009-02-07 20:05:48 +0000184 OS << ')';
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Reid Spencer5f016e22007-07-11 17:01:13 +0000186 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
187 OS << ' ';
188 PrintRawCompoundStmt(CS);
189 OS << (If->getElse() ? ' ' : '\n');
190 } else {
191 OS << '\n';
192 PrintStmt(If->getThen());
193 if (If->getElse()) Indent();
194 }
Mike Stump1eb44332009-09-09 15:08:12 +0000195
Reid Spencer5f016e22007-07-11 17:01:13 +0000196 if (Stmt *Else = If->getElse()) {
197 OS << "else";
Mike Stump1eb44332009-09-09 15:08:12 +0000198
Reid Spencer5f016e22007-07-11 17:01:13 +0000199 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
200 OS << ' ';
201 PrintRawCompoundStmt(CS);
202 OS << '\n';
203 } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
204 OS << ' ';
205 PrintRawIfStmt(ElseIf);
206 } else {
207 OS << '\n';
208 PrintStmt(If->getElse());
209 }
210 }
211}
212
213void StmtPrinter::VisitIfStmt(IfStmt *If) {
214 Indent();
215 PrintRawIfStmt(If);
216}
217
218void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
219 Indent() << "switch (";
Eli Friedman915c07d2012-10-16 23:45:15 +0000220 if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
221 PrintRawDeclStmt(DS);
222 else
223 PrintExpr(Node->getCond());
Reid Spencer5f016e22007-07-11 17:01:13 +0000224 OS << ")";
Mike Stump1eb44332009-09-09 15:08:12 +0000225
Reid Spencer5f016e22007-07-11 17:01:13 +0000226 // Pretty print compoundstmt bodies (very common).
227 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
228 OS << " ";
229 PrintRawCompoundStmt(CS);
230 OS << "\n";
231 } else {
232 OS << "\n";
233 PrintStmt(Node->getBody());
234 }
235}
236
237void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
238 Indent() << "while (";
Eli Friedman915c07d2012-10-16 23:45:15 +0000239 if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
240 PrintRawDeclStmt(DS);
241 else
242 PrintExpr(Node->getCond());
Reid Spencer5f016e22007-07-11 17:01:13 +0000243 OS << ")\n";
244 PrintStmt(Node->getBody());
245}
246
247void StmtPrinter::VisitDoStmt(DoStmt *Node) {
Chris Lattner8bdcc472007-09-15 21:49:37 +0000248 Indent() << "do ";
249 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
250 PrintRawCompoundStmt(CS);
251 OS << " ";
252 } else {
253 OS << "\n";
254 PrintStmt(Node->getBody());
255 Indent();
256 }
Mike Stump1eb44332009-09-09 15:08:12 +0000257
Eli Friedmanb3e22962009-05-17 01:05:34 +0000258 OS << "while (";
Reid Spencer5f016e22007-07-11 17:01:13 +0000259 PrintExpr(Node->getCond());
Eli Friedmanb3e22962009-05-17 01:05:34 +0000260 OS << ");\n";
Reid Spencer5f016e22007-07-11 17:01:13 +0000261}
262
263void StmtPrinter::VisitForStmt(ForStmt *Node) {
264 Indent() << "for (";
265 if (Node->getInit()) {
266 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
Ted Kremenekecd64c52008-10-06 18:39:36 +0000267 PrintRawDeclStmt(DS);
Reid Spencer5f016e22007-07-11 17:01:13 +0000268 else
269 PrintExpr(cast<Expr>(Node->getInit()));
270 }
Chris Lattner8bdcc472007-09-15 21:49:37 +0000271 OS << ";";
272 if (Node->getCond()) {
273 OS << " ";
Reid Spencer5f016e22007-07-11 17:01:13 +0000274 PrintExpr(Node->getCond());
Chris Lattner8bdcc472007-09-15 21:49:37 +0000275 }
276 OS << ";";
277 if (Node->getInc()) {
278 OS << " ";
Reid Spencer5f016e22007-07-11 17:01:13 +0000279 PrintExpr(Node->getInc());
Chris Lattner8bdcc472007-09-15 21:49:37 +0000280 }
281 OS << ") ";
Mike Stump1eb44332009-09-09 15:08:12 +0000282
Chris Lattner8bdcc472007-09-15 21:49:37 +0000283 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
284 PrintRawCompoundStmt(CS);
285 OS << "\n";
286 } else {
287 OS << "\n";
288 PrintStmt(Node->getBody());
289 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000290}
291
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000292void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
Fariborz Jahanian0196cab2008-01-02 22:54:34 +0000293 Indent() << "for (";
294 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
Ted Kremenekecd64c52008-10-06 18:39:36 +0000295 PrintRawDeclStmt(DS);
Fariborz Jahanian0196cab2008-01-02 22:54:34 +0000296 else
297 PrintExpr(cast<Expr>(Node->getElement()));
298 OS << " in ";
299 PrintExpr(Node->getCollection());
300 OS << ") ";
Mike Stump1eb44332009-09-09 15:08:12 +0000301
Fariborz Jahanian0196cab2008-01-02 22:54:34 +0000302 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
303 PrintRawCompoundStmt(CS);
304 OS << "\n";
305 } else {
306 OS << "\n";
307 PrintStmt(Node->getBody());
308 }
309}
310
Richard Smithad762fc2011-04-14 22:09:26 +0000311void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
312 Indent() << "for (";
313 PrintingPolicy SubPolicy(Policy);
314 SubPolicy.SuppressInitializers = true;
315 Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
316 OS << " : ";
317 PrintExpr(Node->getRangeInit());
318 OS << ") {\n";
319 PrintStmt(Node->getBody());
Stephen Hines651f13c2014-04-23 16:59:28 -0700320 Indent() << "}";
321 if (Policy.IncludeNewlines) OS << "\n";
Richard Smithad762fc2011-04-14 22:09:26 +0000322}
323
Douglas Gregorba0513d2011-10-25 01:33:02 +0000324void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
325 Indent();
326 if (Node->isIfExists())
327 OS << "__if_exists (";
328 else
329 OS << "__if_not_exists (";
330
331 if (NestedNameSpecifier *Qualifier
332 = Node->getQualifierLoc().getNestedNameSpecifier())
333 Qualifier->print(OS, Policy);
334
335 OS << Node->getNameInfo() << ") ";
336
337 PrintRawCompoundStmt(Node->getSubStmt());
338}
339
Reid Spencer5f016e22007-07-11 17:01:13 +0000340void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700341 Indent() << "goto " << Node->getLabel()->getName() << ";";
342 if (Policy.IncludeNewlines) OS << "\n";
Reid Spencer5f016e22007-07-11 17:01:13 +0000343}
344
345void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
346 Indent() << "goto *";
347 PrintExpr(Node->getTarget());
Stephen Hines651f13c2014-04-23 16:59:28 -0700348 OS << ";";
349 if (Policy.IncludeNewlines) OS << "\n";
Reid Spencer5f016e22007-07-11 17:01:13 +0000350}
351
352void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700353 Indent() << "continue;";
354 if (Policy.IncludeNewlines) OS << "\n";
Reid Spencer5f016e22007-07-11 17:01:13 +0000355}
356
357void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700358 Indent() << "break;";
359 if (Policy.IncludeNewlines) OS << "\n";
Reid Spencer5f016e22007-07-11 17:01:13 +0000360}
361
362
363void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
364 Indent() << "return";
365 if (Node->getRetValue()) {
366 OS << " ";
367 PrintExpr(Node->getRetValue());
368 }
Stephen Hines651f13c2014-04-23 16:59:28 -0700369 OS << ";";
370 if (Policy.IncludeNewlines) OS << "\n";
Reid Spencer5f016e22007-07-11 17:01:13 +0000371}
372
Chris Lattnerfe795952007-10-29 04:04:16 +0000373
Chad Rosierdf5faf52012-08-25 00:11:56 +0000374void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
Anders Carlsson39c47b52007-11-23 23:12:25 +0000375 Indent() << "asm ";
Mike Stump1eb44332009-09-09 15:08:12 +0000376
Anders Carlsson39c47b52007-11-23 23:12:25 +0000377 if (Node->isVolatile())
378 OS << "volatile ";
Mike Stump1eb44332009-09-09 15:08:12 +0000379
Anders Carlsson39c47b52007-11-23 23:12:25 +0000380 OS << "(";
Anders Carlsson6a0ef4b2007-11-20 19:21:03 +0000381 VisitStringLiteral(Node->getAsmString());
Mike Stump1eb44332009-09-09 15:08:12 +0000382
Anders Carlssonb235fc22007-11-22 01:36:19 +0000383 // Outputs
384 if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
385 Node->getNumClobbers() != 0)
386 OS << " : ";
Mike Stump1eb44332009-09-09 15:08:12 +0000387
Anders Carlssonb235fc22007-11-22 01:36:19 +0000388 for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
389 if (i != 0)
390 OS << ", ";
Mike Stump1eb44332009-09-09 15:08:12 +0000391
Anders Carlssonb235fc22007-11-22 01:36:19 +0000392 if (!Node->getOutputName(i).empty()) {
393 OS << '[';
394 OS << Node->getOutputName(i);
395 OS << "] ";
396 }
Mike Stump1eb44332009-09-09 15:08:12 +0000397
Chris Lattnerb3277932009-03-10 04:59:06 +0000398 VisitStringLiteral(Node->getOutputConstraintLiteral(i));
Anders Carlssonb235fc22007-11-22 01:36:19 +0000399 OS << " ";
400 Visit(Node->getOutputExpr(i));
401 }
Mike Stump1eb44332009-09-09 15:08:12 +0000402
Anders Carlssonb235fc22007-11-22 01:36:19 +0000403 // Inputs
404 if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
405 OS << " : ";
Mike Stump1eb44332009-09-09 15:08:12 +0000406
Anders Carlssonb235fc22007-11-22 01:36:19 +0000407 for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
408 if (i != 0)
409 OS << ", ";
Mike Stump1eb44332009-09-09 15:08:12 +0000410
Anders Carlssonb235fc22007-11-22 01:36:19 +0000411 if (!Node->getInputName(i).empty()) {
412 OS << '[';
413 OS << Node->getInputName(i);
414 OS << "] ";
415 }
Mike Stump1eb44332009-09-09 15:08:12 +0000416
Chris Lattnerb3277932009-03-10 04:59:06 +0000417 VisitStringLiteral(Node->getInputConstraintLiteral(i));
Anders Carlssonb235fc22007-11-22 01:36:19 +0000418 OS << " ";
419 Visit(Node->getInputExpr(i));
420 }
Mike Stump1eb44332009-09-09 15:08:12 +0000421
Anders Carlssonb235fc22007-11-22 01:36:19 +0000422 // Clobbers
423 if (Node->getNumClobbers() != 0)
424 OS << " : ";
Mike Stump1eb44332009-09-09 15:08:12 +0000425
Anders Carlssonb235fc22007-11-22 01:36:19 +0000426 for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
427 if (i != 0)
428 OS << ", ";
Mike Stump1eb44332009-09-09 15:08:12 +0000429
Chad Rosier5c7f5942012-08-27 23:28:41 +0000430 VisitStringLiteral(Node->getClobberStringLiteral(i));
Anders Carlssonb235fc22007-11-22 01:36:19 +0000431 }
Mike Stump1eb44332009-09-09 15:08:12 +0000432
Stephen Hines651f13c2014-04-23 16:59:28 -0700433 OS << ");";
434 if (Policy.IncludeNewlines) OS << "\n";
Chris Lattnerfe795952007-10-29 04:04:16 +0000435}
436
Chad Rosier8cd64b42012-06-11 20:47:18 +0000437void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
438 // FIXME: Implement MS style inline asm statement printer.
Chad Rosier7bd092b2012-08-15 16:53:30 +0000439 Indent() << "__asm ";
440 if (Node->hasBraces())
441 OS << "{\n";
John McCallaeeacf72013-05-03 00:10:13 +0000442 OS << Node->getAsmString() << "\n";
Chad Rosier7bd092b2012-08-15 16:53:30 +0000443 if (Node->hasBraces())
444 Indent() << "}\n";
Chad Rosier8cd64b42012-06-11 20:47:18 +0000445}
446
Tareq A. Siraj051303c2013-04-16 18:53:08 +0000447void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
Tareq A. Siraj6afcf882013-04-16 19:37:38 +0000448 PrintStmt(Node->getCapturedDecl()->getBody());
Tareq A. Siraj051303c2013-04-16 18:53:08 +0000449}
450
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000451void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
Fariborz Jahanian7794cb82007-11-02 18:16:07 +0000452 Indent() << "@try";
453 if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
454 PrintRawCompoundStmt(TS);
455 OS << "\n";
456 }
Mike Stump1eb44332009-09-09 15:08:12 +0000457
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000458 for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
459 ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
Fariborz Jahanian7794cb82007-11-02 18:16:07 +0000460 Indent() << "@catch(";
Steve Naroff7ba138a2009-03-03 19:52:17 +0000461 if (catchStmt->getCatchParamDecl()) {
462 if (Decl *DS = catchStmt->getCatchParamDecl())
463 PrintRawDecl(DS);
Fariborz Jahanian7794cb82007-11-02 18:16:07 +0000464 }
465 OS << ")";
Mike Stump1eb44332009-09-09 15:08:12 +0000466 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
467 PrintRawCompoundStmt(CS);
468 OS << "\n";
469 }
Fariborz Jahanian7794cb82007-11-02 18:16:07 +0000470 }
Mike Stump1eb44332009-09-09 15:08:12 +0000471
472 if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
473 Node->getFinallyStmt())) {
Fariborz Jahanian1e7eab42007-11-07 00:46:42 +0000474 Indent() << "@finally";
475 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
Fariborz Jahanian7794cb82007-11-02 18:16:07 +0000476 OS << "\n";
Mike Stump1eb44332009-09-09 15:08:12 +0000477 }
Fariborz Jahanianb210bd02007-11-01 21:12:44 +0000478}
479
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000480void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
Fariborz Jahanianb210bd02007-11-01 21:12:44 +0000481}
482
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000483void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
Fariborz Jahanianb210bd02007-11-01 21:12:44 +0000484 Indent() << "@catch (...) { /* todo */ } \n";
485}
486
Fariborz Jahanian78a677b2008-01-30 17:38:29 +0000487void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
Fariborz Jahanian39f8f152007-11-07 02:00:49 +0000488 Indent() << "@throw";
489 if (Node->getThrowExpr()) {
490 OS << " ";
491 PrintExpr(Node->getThrowExpr());
492 }
493 OS << ";\n";
494}
495
Fariborz Jahanian78a677b2008-01-30 17:38:29 +0000496void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
Fariborz Jahanianc385c902008-01-29 18:21:32 +0000497 Indent() << "@synchronized (";
498 PrintExpr(Node->getSynchExpr());
499 OS << ")";
Fariborz Jahanian78a677b2008-01-30 17:38:29 +0000500 PrintRawCompoundStmt(Node->getSynchBody());
501 OS << "\n";
Fariborz Jahanianc385c902008-01-29 18:21:32 +0000502}
503
John McCallf85e1932011-06-15 23:02:42 +0000504void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
505 Indent() << "@autoreleasepool";
506 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
507 OS << "\n";
508}
509
Sebastian Redl8351da02008-12-22 21:35:02 +0000510void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
511 OS << "catch (";
Sebastian Redl4b07b292008-12-22 19:15:10 +0000512 if (Decl *ExDecl = Node->getExceptionDecl())
513 PrintRawDecl(ExDecl);
514 else
515 OS << "...";
516 OS << ") ";
517 PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
Sebastian Redl8351da02008-12-22 21:35:02 +0000518}
519
520void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
521 Indent();
522 PrintRawCXXCatchStmt(Node);
523 OS << "\n";
524}
525
526void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
527 Indent() << "try ";
528 PrintRawCompoundStmt(Node->getTryBlock());
Mike Stump1eb44332009-09-09 15:08:12 +0000529 for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
Sebastian Redl8351da02008-12-22 21:35:02 +0000530 OS << " ";
531 PrintRawCXXCatchStmt(Node->getHandler(i));
532 }
Sebastian Redl4b07b292008-12-22 19:15:10 +0000533 OS << "\n";
534}
535
John Wiegley28bbe4b2011-04-28 01:08:34 +0000536void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
537 Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
538 PrintRawCompoundStmt(Node->getTryBlock());
539 SEHExceptStmt *E = Node->getExceptHandler();
540 SEHFinallyStmt *F = Node->getFinallyHandler();
541 if(E)
542 PrintRawSEHExceptHandler(E);
543 else {
544 assert(F && "Must have a finally block...");
545 PrintRawSEHFinallyStmt(F);
546 }
547 OS << "\n";
548}
549
550void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
551 OS << "__finally ";
552 PrintRawCompoundStmt(Node->getBlock());
553 OS << "\n";
554}
555
556void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
557 OS << "__except (";
558 VisitExpr(Node->getFilterExpr());
Joao Matos568ba872012-09-04 17:49:35 +0000559 OS << ")\n";
John Wiegley28bbe4b2011-04-28 01:08:34 +0000560 PrintRawCompoundStmt(Node->getBlock());
561 OS << "\n";
562}
563
564void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
565 Indent();
566 PrintRawSEHExceptHandler(Node);
567 OS << "\n";
568}
569
570void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
571 Indent();
572 PrintRawSEHFinallyStmt(Node);
573 OS << "\n";
574}
575
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700576void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) {
577 Indent() << "__leave;";
578 if (Policy.IncludeNewlines) OS << "\n";
579}
580
Reid Spencer5f016e22007-07-11 17:01:13 +0000581//===----------------------------------------------------------------------===//
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000582// OpenMP clauses printing methods
583//===----------------------------------------------------------------------===//
584
585namespace {
586class OMPClausePrinter : public OMPClauseVisitor<OMPClausePrinter> {
587 raw_ostream &OS;
Stephen Hines651f13c2014-04-23 16:59:28 -0700588 const PrintingPolicy &Policy;
Alexey Bataev543c4ae2013-09-24 03:17:45 +0000589 /// \brief Process clauses with list of variables.
590 template <typename T>
591 void VisitOMPClauseList(T *Node, char StartSym);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000592public:
Stephen Hines651f13c2014-04-23 16:59:28 -0700593 OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
594 : OS(OS), Policy(Policy) { }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000595#define OPENMP_CLAUSE(Name, Class) \
596 void Visit##Class(Class *S);
597#include "clang/Basic/OpenMPKinds.def"
598};
599
Stephen Hines651f13c2014-04-23 16:59:28 -0700600void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
601 OS << "if(";
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700602 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
Stephen Hines651f13c2014-04-23 16:59:28 -0700603 OS << ")";
604}
605
606void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
607 OS << "num_threads(";
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700608 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
Stephen Hines651f13c2014-04-23 16:59:28 -0700609 OS << ")";
610}
611
612void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
613 OS << "safelen(";
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700614 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
615 OS << ")";
616}
617
618void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
619 OS << "collapse(";
620 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
Stephen Hines651f13c2014-04-23 16:59:28 -0700621 OS << ")";
622}
623
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000624void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
625 OS << "default("
626 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
627 << ")";
628}
629
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700630void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
631 OS << "proc_bind("
632 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
633 << ")";
634}
635
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700636void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
637 OS << "schedule("
638 << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
639 if (Node->getChunkSize()) {
640 OS << ", ";
641 Node->getChunkSize()->printPretty(OS, nullptr, Policy);
642 }
643 OS << ")";
644}
645
646void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *) {
647 OS << "ordered";
648}
649
650void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
651 OS << "nowait";
652}
653
Alexey Bataev543c4ae2013-09-24 03:17:45 +0000654template<typename T>
655void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
656 for (typename T::varlist_iterator I = Node->varlist_begin(),
657 E = Node->varlist_end();
Stephen Hines651f13c2014-04-23 16:59:28 -0700658 I != E; ++I) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700659 assert(*I && "Expected non-null Stmt");
Stephen Hines651f13c2014-04-23 16:59:28 -0700660 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(*I)) {
661 OS << (I == Node->varlist_begin() ? StartSym : ',');
662 cast<NamedDecl>(DRE->getDecl())->printQualifiedName(OS);
663 } else {
664 OS << (I == Node->varlist_begin() ? StartSym : ',');
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700665 (*I)->printPretty(OS, nullptr, Policy, 0);
Stephen Hines651f13c2014-04-23 16:59:28 -0700666 }
667 }
Alexey Bataev543c4ae2013-09-24 03:17:45 +0000668}
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000669
670void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
671 if (!Node->varlist_empty()) {
672 OS << "private";
Alexey Bataev543c4ae2013-09-24 03:17:45 +0000673 VisitOMPClauseList(Node, '(');
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000674 OS << ")";
675 }
676}
677
Alexey Bataevd195bc32013-10-01 05:32:34 +0000678void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
679 if (!Node->varlist_empty()) {
680 OS << "firstprivate";
681 VisitOMPClauseList(Node, '(');
682 OS << ")";
683 }
684}
685
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700686void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
687 if (!Node->varlist_empty()) {
688 OS << "lastprivate";
689 VisitOMPClauseList(Node, '(');
690 OS << ")";
691 }
692}
693
Alexey Bataev0c018352013-09-06 18:03:48 +0000694void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
695 if (!Node->varlist_empty()) {
696 OS << "shared";
Alexey Bataev543c4ae2013-09-24 03:17:45 +0000697 VisitOMPClauseList(Node, '(');
Alexey Bataev0c018352013-09-06 18:03:48 +0000698 OS << ")";
699 }
700}
701
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700702void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
703 if (!Node->varlist_empty()) {
704 OS << "reduction(";
705 NestedNameSpecifier *QualifierLoc =
706 Node->getQualifierLoc().getNestedNameSpecifier();
707 OverloadedOperatorKind OOK =
708 Node->getNameInfo().getName().getCXXOverloadedOperator();
709 if (QualifierLoc == nullptr && OOK != OO_None) {
710 // Print reduction identifier in C format
711 OS << getOperatorSpelling(OOK);
712 } else {
713 // Use C++ format
714 if (QualifierLoc != nullptr)
715 QualifierLoc->print(OS, Policy);
716 OS << Node->getNameInfo();
717 }
718 OS << ":";
719 VisitOMPClauseList(Node, ' ');
720 OS << ")";
721 }
722}
723
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700724void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
725 if (!Node->varlist_empty()) {
726 OS << "linear";
727 VisitOMPClauseList(Node, '(');
728 if (Node->getStep() != nullptr) {
729 OS << ": ";
730 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
731 }
732 OS << ")";
733 }
734}
735
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700736void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
737 if (!Node->varlist_empty()) {
738 OS << "aligned";
739 VisitOMPClauseList(Node, '(');
740 if (Node->getAlignment() != nullptr) {
741 OS << ": ";
742 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
743 }
744 OS << ")";
745 }
746}
747
Stephen Hines651f13c2014-04-23 16:59:28 -0700748void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
749 if (!Node->varlist_empty()) {
750 OS << "copyin";
751 VisitOMPClauseList(Node, '(');
752 OS << ")";
753 }
754}
755
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700756void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
757 if (!Node->varlist_empty()) {
758 OS << "copyprivate";
759 VisitOMPClauseList(Node, '(');
760 OS << ")";
761 }
762}
763
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000764}
765
766//===----------------------------------------------------------------------===//
767// OpenMP directives printing methods
768//===----------------------------------------------------------------------===//
769
Stephen Hines651f13c2014-04-23 16:59:28 -0700770void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S) {
771 OMPClausePrinter Printer(OS, Policy);
772 ArrayRef<OMPClause *> Clauses = S->clauses();
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000773 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
774 I != E; ++I)
775 if (*I && !(*I)->isImplicit()) {
776 Printer.Visit(*I);
777 OS << ' ';
778 }
779 OS << "\n";
Stephen Hines651f13c2014-04-23 16:59:28 -0700780 if (S->getAssociatedStmt()) {
781 assert(isa<CapturedStmt>(S->getAssociatedStmt()) &&
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000782 "Expected captured statement!");
Stephen Hines651f13c2014-04-23 16:59:28 -0700783 Stmt *CS = cast<CapturedStmt>(S->getAssociatedStmt())->getCapturedStmt();
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000784 PrintStmt(CS);
785 }
786}
Stephen Hines651f13c2014-04-23 16:59:28 -0700787
788void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
789 Indent() << "#pragma omp parallel ";
790 PrintOMPExecutableDirective(Node);
791}
792
793void StmtPrinter::VisitOMPSimdDirective(OMPSimdDirective *Node) {
794 Indent() << "#pragma omp simd ";
795 PrintOMPExecutableDirective(Node);
796}
797
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700798void StmtPrinter::VisitOMPForDirective(OMPForDirective *Node) {
799 Indent() << "#pragma omp for ";
800 PrintOMPExecutableDirective(Node);
801}
802
803void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) {
804 Indent() << "#pragma omp sections ";
805 PrintOMPExecutableDirective(Node);
806}
807
808void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) {
809 Indent() << "#pragma omp section";
810 PrintOMPExecutableDirective(Node);
811}
812
813void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) {
814 Indent() << "#pragma omp single ";
815 PrintOMPExecutableDirective(Node);
816}
817
818void StmtPrinter::VisitOMPParallelForDirective(OMPParallelForDirective *Node) {
819 Indent() << "#pragma omp parallel for ";
820 PrintOMPExecutableDirective(Node);
821}
822
823void StmtPrinter::VisitOMPParallelSectionsDirective(
824 OMPParallelSectionsDirective *Node) {
825 Indent() << "#pragma omp parallel sections ";
826 PrintOMPExecutableDirective(Node);
827}
828
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000829//===----------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +0000830// Expr printing methods.
831//===----------------------------------------------------------------------===//
832
Reid Spencer5f016e22007-07-11 17:01:13 +0000833void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000834 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
835 Qualifier->print(OS, Policy);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000836 if (Node->hasTemplateKeyword())
837 OS << "template ";
Abramo Bagnara25777432010-08-11 22:01:17 +0000838 OS << Node->getNameInfo();
John McCall096832c2010-08-19 23:49:38 +0000839 if (Node->hasExplicitTemplateArgs())
Benjamin Kramer5eada842013-02-22 15:46:01 +0000840 TemplateSpecializationType::PrintTemplateArgumentList(
841 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Douglas Gregor1a49af92009-01-06 05:10:23 +0000842}
843
John McCall865d4472009-11-19 22:55:06 +0000844void StmtPrinter::VisitDependentScopeDeclRefExpr(
845 DependentScopeDeclRefExpr *Node) {
Axel Naumann274f83c2011-01-24 15:44:00 +0000846 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
847 Qualifier->print(OS, Policy);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000848 if (Node->hasTemplateKeyword())
849 OS << "template ";
Abramo Bagnara25777432010-08-11 22:01:17 +0000850 OS << Node->getNameInfo();
John McCallf7a1a742009-11-24 19:00:30 +0000851 if (Node->hasExplicitTemplateArgs())
Benjamin Kramer5eada842013-02-22 15:46:01 +0000852 TemplateSpecializationType::PrintTemplateArgumentList(
853 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Douglas Gregor5953d8b2009-03-19 17:26:29 +0000854}
855
John McCallba135432009-11-21 08:51:07 +0000856void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
Douglas Gregoredce4dd2009-06-30 22:34:41 +0000857 if (Node->getQualifier())
858 Node->getQualifier()->print(OS, Policy);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000859 if (Node->hasTemplateKeyword())
860 OS << "template ";
Abramo Bagnara25777432010-08-11 22:01:17 +0000861 OS << Node->getNameInfo();
John McCallf7a1a742009-11-24 19:00:30 +0000862 if (Node->hasExplicitTemplateArgs())
Benjamin Kramer5eada842013-02-22 15:46:01 +0000863 TemplateSpecializationType::PrintTemplateArgumentList(
864 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Douglas Gregoredce4dd2009-06-30 22:34:41 +0000865}
866
Steve Naroff7779db42007-11-12 14:29:37 +0000867void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Fariborz Jahanian232220c2007-11-12 22:29:28 +0000868 if (Node->getBase()) {
869 PrintExpr(Node->getBase());
870 OS << (Node->isArrow() ? "->" : ".");
871 }
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000872 OS << *Node->getDecl();
Steve Naroff7779db42007-11-12 14:29:37 +0000873}
874
Steve Naroffae784072008-05-30 00:40:33 +0000875void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000876 if (Node->isSuperReceiver())
877 OS << "super.";
Stephen Hines651f13c2014-04-23 16:59:28 -0700878 else if (Node->isObjectReceiver() && Node->getBase()) {
Steve Naroffae784072008-05-30 00:40:33 +0000879 PrintExpr(Node->getBase());
880 OS << ".";
Stephen Hines651f13c2014-04-23 16:59:28 -0700881 } else if (Node->isClassReceiver() && Node->getClassReceiver()) {
882 OS << Node->getClassReceiver()->getName() << ".";
Steve Naroffae784072008-05-30 00:40:33 +0000883 }
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000884
John McCall12f78a62010-12-02 01:19:52 +0000885 if (Node->isImplicitProperty())
Stephen Hines651f13c2014-04-23 16:59:28 -0700886 Node->getImplicitPropertyGetter()->getSelector().print(OS);
John McCall12f78a62010-12-02 01:19:52 +0000887 else
888 OS << Node->getExplicitProperty()->getName();
Fariborz Jahanian5daf5702008-11-22 18:39:36 +0000889}
890
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000891void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
892
893 PrintExpr(Node->getBaseExpr());
894 OS << "[";
895 PrintExpr(Node->getKeyExpr());
896 OS << "]";
897}
898
Chris Lattnerd9f69102008-08-10 01:53:14 +0000899void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
Anders Carlsson22742662007-07-21 05:21:51 +0000900 switch (Node->getIdentType()) {
901 default:
David Blaikieb219cfc2011-09-23 05:06:16 +0000902 llvm_unreachable("unknown case");
Chris Lattnerd9f69102008-08-10 01:53:14 +0000903 case PredefinedExpr::Func:
Anders Carlsson22742662007-07-21 05:21:51 +0000904 OS << "__func__";
905 break;
Chris Lattnerd9f69102008-08-10 01:53:14 +0000906 case PredefinedExpr::Function:
Anders Carlsson22742662007-07-21 05:21:51 +0000907 OS << "__FUNCTION__";
908 break;
David Majnemerbafa74f2013-11-06 23:31:56 +0000909 case PredefinedExpr::FuncDName:
910 OS << "__FUNCDNAME__";
911 break;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700912 case PredefinedExpr::FuncSig:
913 OS << "__FUNCSIG__";
914 break;
Nico Weber28ad0632012-06-23 02:07:59 +0000915 case PredefinedExpr::LFunction:
916 OS << "L__FUNCTION__";
917 break;
Chris Lattnerd9f69102008-08-10 01:53:14 +0000918 case PredefinedExpr::PrettyFunction:
Anders Carlsson22742662007-07-21 05:21:51 +0000919 OS << "__PRETTY_FUNCTION__";
920 break;
921 }
922}
923
Reid Spencer5f016e22007-07-11 17:01:13 +0000924void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnerb0a721a2007-07-13 05:18:11 +0000925 unsigned value = Node->getValue();
Douglas Gregor5cee1192011-07-27 05:40:30 +0000926
927 switch (Node->getKind()) {
928 case CharacterLiteral::Ascii: break; // no prefix.
929 case CharacterLiteral::Wide: OS << 'L'; break;
930 case CharacterLiteral::UTF16: OS << 'u'; break;
931 case CharacterLiteral::UTF32: OS << 'U'; break;
932 }
933
Chris Lattner8bf9f072007-07-13 23:58:20 +0000934 switch (value) {
935 case '\\':
936 OS << "'\\\\'";
937 break;
938 case '\'':
939 OS << "'\\''";
940 break;
941 case '\a':
942 // TODO: K&R: the meaning of '\\a' is different in traditional C
943 OS << "'\\a'";
944 break;
945 case '\b':
946 OS << "'\\b'";
947 break;
948 // Nonstandard escape sequence.
949 /*case '\e':
950 OS << "'\\e'";
951 break;*/
952 case '\f':
953 OS << "'\\f'";
954 break;
955 case '\n':
956 OS << "'\\n'";
957 break;
958 case '\r':
959 OS << "'\\r'";
960 break;
961 case '\t':
962 OS << "'\\t'";
963 break;
964 case '\v':
965 OS << "'\\v'";
966 break;
967 default:
Jordan Rose6d4f7342013-02-08 22:30:27 +0000968 if (value < 256 && isPrintable((unsigned char)value))
Chris Lattner8bf9f072007-07-13 23:58:20 +0000969 OS << "'" << (char)value << "'";
Jordan Rose6d4f7342013-02-08 22:30:27 +0000970 else if (value < 256)
971 OS << "'\\x" << llvm::format("%02x", value) << "'";
972 else if (value <= 0xFFFF)
973 OS << "'\\u" << llvm::format("%04x", value) << "'";
974 else
975 OS << "'\\U" << llvm::format("%08x", value) << "'";
Chris Lattnerb0a721a2007-07-13 05:18:11 +0000976 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000977}
978
979void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
980 bool isSigned = Node->getType()->isSignedIntegerType();
981 OS << Node->getValue().toString(10, isSigned);
Mike Stump1eb44332009-09-09 15:08:12 +0000982
Reid Spencer5f016e22007-07-11 17:01:13 +0000983 // Emit suffixes. Integer literals are always a builtin integer type.
John McCall183700f2009-09-21 23:43:11 +0000984 switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000985 default: llvm_unreachable("Unexpected type for integer literal!");
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700986 case BuiltinType::SChar: OS << "i8"; break;
987 case BuiltinType::UChar: OS << "Ui8"; break;
988 case BuiltinType::Short: OS << "i16"; break;
989 case BuiltinType::UShort: OS << "Ui16"; break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000990 case BuiltinType::Int: break; // no suffix.
991 case BuiltinType::UInt: OS << 'U'; break;
992 case BuiltinType::Long: OS << 'L'; break;
993 case BuiltinType::ULong: OS << "UL"; break;
994 case BuiltinType::LongLong: OS << "LL"; break;
995 case BuiltinType::ULongLong: OS << "ULL"; break;
Richard Trieu11cbe2a2011-11-07 18:40:31 +0000996 case BuiltinType::Int128: OS << "i128"; break;
997 case BuiltinType::UInt128: OS << "Ui128"; break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000998 }
999}
Benjamin Kramera0a3c902012-09-20 14:07:17 +00001000
1001static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
1002 bool PrintSuffix) {
Dylan Noblesmithf7ccbad2012-02-05 02:13:05 +00001003 SmallString<16> Str;
Eli Friedmanb3909212011-10-05 20:32:03 +00001004 Node->getValue().toString(Str);
1005 OS << Str;
Benjamin Kramera0a3c902012-09-20 14:07:17 +00001006 if (Str.find_first_not_of("-0123456789") == StringRef::npos)
1007 OS << '.'; // Trailing dot in order to separate from ints.
1008
1009 if (!PrintSuffix)
1010 return;
1011
1012 // Emit suffixes. Float literals are always a builtin float type.
1013 switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
1014 default: llvm_unreachable("Unexpected type for float literal!");
1015 case BuiltinType::Half: break; // FIXME: suffix?
1016 case BuiltinType::Double: break; // no suffix.
1017 case BuiltinType::Float: OS << 'F'; break;
1018 case BuiltinType::LongDouble: OS << 'L'; break;
1019 }
1020}
1021
1022void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
1023 PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
Reid Spencer5f016e22007-07-11 17:01:13 +00001024}
Chris Lattner5d661452007-08-26 03:42:43 +00001025
1026void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
1027 PrintExpr(Node->getSubExpr());
1028 OS << "i";
1029}
1030
Reid Spencer5f016e22007-07-11 17:01:13 +00001031void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
Richard Trieu8ab09da2012-06-13 20:25:24 +00001032 Str->outputString(OS);
Reid Spencer5f016e22007-07-11 17:01:13 +00001033}
1034void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
1035 OS << "(";
1036 PrintExpr(Node->getSubExpr());
1037 OS << ")";
1038}
1039void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner296bf192007-08-23 21:46:40 +00001040 if (!Node->isPostfix()) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001041 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Mike Stump1eb44332009-09-09 15:08:12 +00001042
Eli Friedman7df71ac2009-06-14 22:39:26 +00001043 // Print a space if this is an "identifier operator" like __real, or if
1044 // it might be concatenated incorrectly like '+'.
Chris Lattner296bf192007-08-23 21:46:40 +00001045 switch (Node->getOpcode()) {
1046 default: break;
John McCall2de56d12010-08-25 11:45:40 +00001047 case UO_Real:
1048 case UO_Imag:
1049 case UO_Extension:
Chris Lattner296bf192007-08-23 21:46:40 +00001050 OS << ' ';
1051 break;
John McCall2de56d12010-08-25 11:45:40 +00001052 case UO_Plus:
1053 case UO_Minus:
Eli Friedman7df71ac2009-06-14 22:39:26 +00001054 if (isa<UnaryOperator>(Node->getSubExpr()))
1055 OS << ' ';
1056 break;
Chris Lattner296bf192007-08-23 21:46:40 +00001057 }
1058 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001059 PrintExpr(Node->getSubExpr());
Mike Stump1eb44332009-09-09 15:08:12 +00001060
Reid Spencer5f016e22007-07-11 17:01:13 +00001061 if (Node->isPostfix())
1062 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Reid Spencer5f016e22007-07-11 17:01:13 +00001063}
Chris Lattner704fe352007-08-30 17:59:59 +00001064
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001065void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
1066 OS << "__builtin_offsetof(";
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001067 Node->getTypeSourceInfo()->getType().print(OS, Policy);
1068 OS << ", ";
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001069 bool PrintedSomething = false;
1070 for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
1071 OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i);
1072 if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Array) {
1073 // Array node
1074 OS << "[";
1075 PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
1076 OS << "]";
1077 PrintedSomething = true;
1078 continue;
1079 }
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00001080
1081 // Skip implicit base indirections.
1082 if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Base)
1083 continue;
1084
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001085 // Field or identifier node.
1086 IdentifierInfo *Id = ON.getFieldName();
1087 if (!Id)
1088 continue;
Sean Huntc3021132010-05-05 15:23:54 +00001089
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001090 if (PrintedSomething)
1091 OS << ".";
1092 else
1093 PrintedSomething = true;
Sean Huntc3021132010-05-05 15:23:54 +00001094 OS << Id->getName();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001095 }
1096 OS << ")";
1097}
1098
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001099void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
1100 switch(Node->getKind()) {
1101 case UETT_SizeOf:
1102 OS << "sizeof";
1103 break;
1104 case UETT_AlignOf:
Jordan Rosef70a8862012-06-30 21:33:57 +00001105 if (Policy.LangOpts.CPlusPlus)
1106 OS << "alignof";
1107 else if (Policy.LangOpts.C11)
1108 OS << "_Alignof";
1109 else
1110 OS << "__alignof";
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001111 break;
1112 case UETT_VecStep:
1113 OS << "vec_step";
1114 break;
1115 }
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001116 if (Node->isArgumentType()) {
1117 OS << '(';
1118 Node->getArgumentType().print(OS, Policy);
1119 OS << ')';
1120 } else {
Sebastian Redl05189992008-11-11 17:56:53 +00001121 OS << " ";
1122 PrintExpr(Node->getArgumentExpr());
1123 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001124}
Peter Collingbournef111d932011-04-15 00:35:48 +00001125
1126void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
1127 OS << "_Generic(";
1128 PrintExpr(Node->getControllingExpr());
1129 for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
1130 OS << ", ";
1131 QualType T = Node->getAssocType(i);
1132 if (T.isNull())
1133 OS << "default";
1134 else
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001135 T.print(OS, Policy);
Peter Collingbournef111d932011-04-15 00:35:48 +00001136 OS << ": ";
1137 PrintExpr(Node->getAssocExpr(i));
1138 }
1139 OS << ")";
1140}
1141
Reid Spencer5f016e22007-07-11 17:01:13 +00001142void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
Ted Kremenek23245122007-08-20 16:18:38 +00001143 PrintExpr(Node->getLHS());
Reid Spencer5f016e22007-07-11 17:01:13 +00001144 OS << "[";
Ted Kremenek23245122007-08-20 16:18:38 +00001145 PrintExpr(Node->getRHS());
Reid Spencer5f016e22007-07-11 17:01:13 +00001146 OS << "]";
1147}
1148
Peter Collingbourned64e2372011-02-08 21:17:54 +00001149void StmtPrinter::PrintCallArgs(CallExpr *Call) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001150 for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
Chris Lattner04421082008-04-08 04:40:51 +00001151 if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
1152 // Don't print any defaulted arguments
1153 break;
1154 }
1155
Reid Spencer5f016e22007-07-11 17:01:13 +00001156 if (i) OS << ", ";
1157 PrintExpr(Call->getArg(i));
1158 }
Peter Collingbourned64e2372011-02-08 21:17:54 +00001159}
1160
1161void StmtPrinter::VisitCallExpr(CallExpr *Call) {
1162 PrintExpr(Call->getCallee());
1163 OS << "(";
1164 PrintCallArgs(Call);
Reid Spencer5f016e22007-07-11 17:01:13 +00001165 OS << ")";
1166}
1167void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
Douglas Gregorb3eef682009-01-08 22:45:41 +00001168 // FIXME: Suppress printing implicit bases (like "this")
1169 PrintExpr(Node->getBase());
David Blaikie383ec172012-11-12 19:12:12 +00001170
1171 MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
David Blaikie731de312012-11-12 19:32:32 +00001172 FieldDecl *ParentDecl = ParentMember
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001173 ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()) : nullptr;
David Blaikie383ec172012-11-12 19:12:12 +00001174
David Blaikie731de312012-11-12 19:32:32 +00001175 if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
David Blaikie383ec172012-11-12 19:12:12 +00001176 OS << (Node->isArrow() ? "->" : ".");
David Blaikie383ec172012-11-12 19:12:12 +00001177
Fariborz Jahanian97fd83a2010-01-11 21:17:32 +00001178 if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1179 if (FD->isAnonymousStructOrUnion())
1180 return;
David Blaikie383ec172012-11-12 19:12:12 +00001181
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001182 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1183 Qualifier->print(OS, Policy);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001184 if (Node->hasTemplateKeyword())
1185 OS << "template ";
Abramo Bagnara25777432010-08-11 22:01:17 +00001186 OS << Node->getMemberNameInfo();
John McCall096832c2010-08-19 23:49:38 +00001187 if (Node->hasExplicitTemplateArgs())
Benjamin Kramer5eada842013-02-22 15:46:01 +00001188 TemplateSpecializationType::PrintTemplateArgumentList(
1189 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001190}
Steve Narofff242b1b2009-07-24 17:54:45 +00001191void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1192 PrintExpr(Node->getBase());
1193 OS << (Node->isArrow() ? "->isa" : ".isa");
1194}
1195
Nate Begeman213541a2008-04-18 23:10:10 +00001196void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Steve Naroff31a45842007-07-28 23:10:27 +00001197 PrintExpr(Node->getBase());
1198 OS << ".";
1199 OS << Node->getAccessor().getName();
1200}
Douglas Gregor6eec8e82008-10-28 15:36:24 +00001201void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001202 OS << '(';
1203 Node->getTypeAsWritten().print(OS, Policy);
1204 OS << ')';
Reid Spencer5f016e22007-07-11 17:01:13 +00001205 PrintExpr(Node->getSubExpr());
1206}
Steve Naroffaff1edd2007-07-19 21:32:11 +00001207void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001208 OS << '(';
1209 Node->getType().print(OS, Policy);
1210 OS << ')';
Steve Naroffaff1edd2007-07-19 21:32:11 +00001211 PrintExpr(Node->getInitializer());
1212}
Steve Naroff49b45262007-07-13 16:58:59 +00001213void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001214 // No need to print anything, simply forward to the subexpression.
Steve Naroff90045e82007-07-13 23:32:42 +00001215 PrintExpr(Node->getSubExpr());
Steve Naroff49b45262007-07-13 16:58:59 +00001216}
Reid Spencer5f016e22007-07-11 17:01:13 +00001217void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1218 PrintExpr(Node->getLHS());
1219 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1220 PrintExpr(Node->getRHS());
1221}
Chris Lattnereb14fe82007-08-25 02:00:02 +00001222void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1223 PrintExpr(Node->getLHS());
1224 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1225 PrintExpr(Node->getRHS());
1226}
Reid Spencer5f016e22007-07-11 17:01:13 +00001227void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1228 PrintExpr(Node->getCond());
John McCall56ca35d2011-02-17 10:25:35 +00001229 OS << " ? ";
1230 PrintExpr(Node->getLHS());
1231 OS << " : ";
Reid Spencer5f016e22007-07-11 17:01:13 +00001232 PrintExpr(Node->getRHS());
1233}
1234
1235// GNU extensions.
1236
John McCall56ca35d2011-02-17 10:25:35 +00001237void
1238StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1239 PrintExpr(Node->getCommon());
1240 OS << " ?: ";
1241 PrintExpr(Node->getFalseExpr());
1242}
Chris Lattner6481a572007-08-03 17:31:20 +00001243void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001244 OS << "&&" << Node->getLabel()->getName();
Reid Spencer5f016e22007-07-11 17:01:13 +00001245}
1246
Chris Lattnerab18c4c2007-07-24 16:58:17 +00001247void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1248 OS << "(";
1249 PrintRawCompoundStmt(E->getSubStmt());
1250 OS << ")";
1251}
1252
Steve Naroffd04fdd52007-08-03 21:21:27 +00001253void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1254 OS << "__builtin_choose_expr(";
1255 PrintExpr(Node->getCond());
Chris Lattner94f05e32007-08-04 00:20:15 +00001256 OS << ", ";
Steve Naroffd04fdd52007-08-03 21:21:27 +00001257 PrintExpr(Node->getLHS());
Chris Lattner94f05e32007-08-04 00:20:15 +00001258 OS << ", ";
Steve Naroffd04fdd52007-08-03 21:21:27 +00001259 PrintExpr(Node->getRHS());
1260 OS << ")";
1261}
Chris Lattnerab18c4c2007-07-24 16:58:17 +00001262
Douglas Gregor2d8b2732008-11-29 04:51:27 +00001263void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1264 OS << "__null";
1265}
1266
Eli Friedmand38617c2008-05-14 19:38:39 +00001267void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1268 OS << "__builtin_shufflevector(";
1269 for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
1270 if (i) OS << ", ";
1271 PrintExpr(Node->getExpr(i));
1272 }
1273 OS << ")";
1274}
1275
Hal Finkel414a1bd2013-09-18 03:29:45 +00001276void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1277 OS << "__builtin_convertvector(";
1278 PrintExpr(Node->getSrcExpr());
1279 OS << ", ";
1280 Node->getType().print(OS, Policy);
1281 OS << ")";
1282}
1283
Anders Carlsson66b5a8a2007-08-31 04:56:16 +00001284void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
Douglas Gregor64f65002009-05-30 00:56:08 +00001285 if (Node->getSyntacticForm()) {
1286 Visit(Node->getSyntacticForm());
1287 return;
1288 }
1289
Anders Carlsson66b5a8a2007-08-31 04:56:16 +00001290 OS << "{ ";
1291 for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
1292 if (i) OS << ", ";
Douglas Gregor4c678342009-01-28 21:54:33 +00001293 if (Node->getInit(i))
1294 PrintExpr(Node->getInit(i));
1295 else
1296 OS << "0";
Anders Carlsson66b5a8a2007-08-31 04:56:16 +00001297 }
1298 OS << " }";
1299}
1300
Nate Begeman2ef13e52009-08-10 23:49:36 +00001301void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1302 OS << "( ";
1303 for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
1304 if (i) OS << ", ";
1305 PrintExpr(Node->getExpr(i));
1306 }
1307 OS << " )";
1308}
1309
Douglas Gregor05c13a32009-01-22 00:58:24 +00001310void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
Douglas Gregor4c678342009-01-28 21:54:33 +00001311 for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
1312 DEnd = Node->designators_end();
1313 D != DEnd; ++D) {
1314 if (D->isFieldDesignator()) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001315 if (D->getDotLoc().isInvalid()) {
1316 if (IdentifierInfo *II = D->getFieldName())
1317 OS << II->getName() << ":";
1318 } else {
Douglas Gregor4c678342009-01-28 21:54:33 +00001319 OS << "." << D->getFieldName()->getName();
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001320 }
Douglas Gregor4c678342009-01-28 21:54:33 +00001321 } else {
1322 OS << "[";
1323 if (D->isArrayDesignator()) {
1324 PrintExpr(Node->getArrayIndex(*D));
1325 } else {
1326 PrintExpr(Node->getArrayRangeStart(*D));
1327 OS << " ... ";
Mike Stump1eb44332009-09-09 15:08:12 +00001328 PrintExpr(Node->getArrayRangeEnd(*D));
Douglas Gregor4c678342009-01-28 21:54:33 +00001329 }
1330 OS << "]";
1331 }
1332 }
1333
1334 OS << " = ";
1335 PrintExpr(Node->getInit());
Douglas Gregor05c13a32009-01-22 00:58:24 +00001336}
1337
Douglas Gregor3498bdb2009-01-29 17:44:32 +00001338void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001339 if (Policy.LangOpts.CPlusPlus) {
1340 OS << "/*implicit*/";
1341 Node->getType().print(OS, Policy);
1342 OS << "()";
1343 } else {
1344 OS << "/*implicit*/(";
1345 Node->getType().print(OS, Policy);
1346 OS << ')';
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001347 if (Node->getType()->isRecordType())
1348 OS << "{}";
1349 else
1350 OS << 0;
1351 }
Douglas Gregor3498bdb2009-01-29 17:44:32 +00001352}
1353
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001354void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
Eli Friedman42f42c02009-05-30 04:20:30 +00001355 OS << "__builtin_va_arg(";
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001356 PrintExpr(Node->getSubExpr());
1357 OS << ", ";
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001358 Node->getType().print(OS, Policy);
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001359 OS << ")";
1360}
1361
John McCall4b9c2d22011-11-06 09:01:30 +00001362void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1363 PrintExpr(Node->getSyntacticForm());
1364}
1365
Eli Friedman276b0612011-10-11 02:20:01 +00001366void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001367 const char *Name = nullptr;
Eli Friedman276b0612011-10-11 02:20:01 +00001368 switch (Node->getOp()) {
Richard Smithff34d402012-04-12 05:08:17 +00001369#define BUILTIN(ID, TYPE, ATTRS)
1370#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1371 case AtomicExpr::AO ## ID: \
1372 Name = #ID "("; \
1373 break;
1374#include "clang/Basic/Builtins.def"
Eli Friedman276b0612011-10-11 02:20:01 +00001375 }
1376 OS << Name;
Richard Smithff34d402012-04-12 05:08:17 +00001377
1378 // AtomicExpr stores its subexpressions in a permuted order.
Eli Friedman276b0612011-10-11 02:20:01 +00001379 PrintExpr(Node->getPtr());
Richard Smithff34d402012-04-12 05:08:17 +00001380 if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1381 Node->getOp() != AtomicExpr::AO__atomic_load_n) {
Eli Friedman276b0612011-10-11 02:20:01 +00001382 OS << ", ";
Richard Smith28fff532013-05-01 19:02:43 +00001383 PrintExpr(Node->getVal1());
Eli Friedman276b0612011-10-11 02:20:01 +00001384 }
Richard Smithff34d402012-04-12 05:08:17 +00001385 if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1386 Node->isCmpXChg()) {
Eli Friedman276b0612011-10-11 02:20:01 +00001387 OS << ", ";
Richard Smith28fff532013-05-01 19:02:43 +00001388 PrintExpr(Node->getVal2());
Eli Friedman276b0612011-10-11 02:20:01 +00001389 }
Richard Smithff34d402012-04-12 05:08:17 +00001390 if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1391 Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
Richard Smithff34d402012-04-12 05:08:17 +00001392 OS << ", ";
Richard Smith28fff532013-05-01 19:02:43 +00001393 PrintExpr(Node->getWeak());
Richard Smithff34d402012-04-12 05:08:17 +00001394 }
Richard Smith28fff532013-05-01 19:02:43 +00001395 if (Node->getOp() != AtomicExpr::AO__c11_atomic_init) {
1396 OS << ", ";
David Chisnall7a7ee302012-01-16 17:27:18 +00001397 PrintExpr(Node->getOrder());
Richard Smith28fff532013-05-01 19:02:43 +00001398 }
Eli Friedman276b0612011-10-11 02:20:01 +00001399 if (Node->isCmpXChg()) {
1400 OS << ", ";
1401 PrintExpr(Node->getOrderFail());
1402 }
1403 OS << ")";
1404}
1405
Reid Spencer5f016e22007-07-11 17:01:13 +00001406// C++
Douglas Gregorb4609802008-11-14 16:09:21 +00001407void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1408 const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
1409 "",
1410#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1411 Spelling,
1412#include "clang/Basic/OperatorKinds.def"
1413 };
1414
1415 OverloadedOperatorKind Kind = Node->getOperator();
1416 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1417 if (Node->getNumArgs() == 1) {
1418 OS << OpStrings[Kind] << ' ';
1419 PrintExpr(Node->getArg(0));
1420 } else {
1421 PrintExpr(Node->getArg(0));
1422 OS << ' ' << OpStrings[Kind];
1423 }
Eli Friedmana143a9d2012-10-12 22:45:14 +00001424 } else if (Kind == OO_Arrow) {
1425 PrintExpr(Node->getArg(0));
Douglas Gregorb4609802008-11-14 16:09:21 +00001426 } else if (Kind == OO_Call) {
1427 PrintExpr(Node->getArg(0));
1428 OS << '(';
1429 for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1430 if (ArgIdx > 1)
1431 OS << ", ";
1432 if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1433 PrintExpr(Node->getArg(ArgIdx));
1434 }
1435 OS << ')';
1436 } else if (Kind == OO_Subscript) {
1437 PrintExpr(Node->getArg(0));
1438 OS << '[';
1439 PrintExpr(Node->getArg(1));
1440 OS << ']';
1441 } else if (Node->getNumArgs() == 1) {
1442 OS << OpStrings[Kind] << ' ';
1443 PrintExpr(Node->getArg(0));
1444 } else if (Node->getNumArgs() == 2) {
1445 PrintExpr(Node->getArg(0));
1446 OS << ' ' << OpStrings[Kind] << ' ';
1447 PrintExpr(Node->getArg(1));
1448 } else {
David Blaikieb219cfc2011-09-23 05:06:16 +00001449 llvm_unreachable("unknown overloaded operator");
Douglas Gregorb4609802008-11-14 16:09:21 +00001450 }
1451}
Reid Spencer5f016e22007-07-11 17:01:13 +00001452
Douglas Gregor88a35142008-12-22 05:46:06 +00001453void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001454 // If we have a conversion operator call only print the argument.
1455 CXXMethodDecl *MD = Node->getMethodDecl();
1456 if (MD && isa<CXXConversionDecl>(MD)) {
1457 PrintExpr(Node->getImplicitObjectArgument());
1458 return;
1459 }
Douglas Gregor88a35142008-12-22 05:46:06 +00001460 VisitCallExpr(cast<CallExpr>(Node));
1461}
1462
Peter Collingbournee08ce652011-02-09 21:07:24 +00001463void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
1464 PrintExpr(Node->getCallee());
1465 OS << "<<<";
1466 PrintCallArgs(Node->getConfig());
1467 OS << ">>>(";
1468 PrintCallArgs(Node);
1469 OS << ")";
1470}
1471
Douglas Gregor49badde2008-10-27 19:41:14 +00001472void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
1473 OS << Node->getCastName() << '<';
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001474 Node->getTypeAsWritten().print(OS, Policy);
1475 OS << ">(";
Reid Spencer5f016e22007-07-11 17:01:13 +00001476 PrintExpr(Node->getSubExpr());
1477 OS << ")";
1478}
1479
Douglas Gregor49badde2008-10-27 19:41:14 +00001480void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
1481 VisitCXXNamedCastExpr(Node);
1482}
1483
1484void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
1485 VisitCXXNamedCastExpr(Node);
1486}
1487
1488void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
1489 VisitCXXNamedCastExpr(Node);
1490}
1491
1492void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
1493 VisitCXXNamedCastExpr(Node);
1494}
1495
Sebastian Redlc42e1182008-11-11 11:37:55 +00001496void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
1497 OS << "typeid(";
1498 if (Node->isTypeOperand()) {
David Majnemerfe16aa32013-09-27 07:04:31 +00001499 Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
Sebastian Redlc42e1182008-11-11 11:37:55 +00001500 } else {
1501 PrintExpr(Node->getExprOperand());
1502 }
1503 OS << ")";
1504}
1505
Francois Pichet01b7c302010-09-08 12:20:18 +00001506void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
1507 OS << "__uuidof(";
1508 if (Node->isTypeOperand()) {
David Majnemerfe16aa32013-09-27 07:04:31 +00001509 Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
Francois Pichet01b7c302010-09-08 12:20:18 +00001510 } else {
1511 PrintExpr(Node->getExprOperand());
1512 }
1513 OS << ")";
1514}
1515
John McCall76da55d2013-04-16 07:28:30 +00001516void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
1517 PrintExpr(Node->getBaseExpr());
1518 if (Node->isArrow())
1519 OS << "->";
1520 else
1521 OS << ".";
1522 if (NestedNameSpecifier *Qualifier =
1523 Node->getQualifierLoc().getNestedNameSpecifier())
1524 Qualifier->print(OS, Policy);
1525 OS << Node->getPropertyDecl()->getDeclName();
1526}
1527
Richard Smith9fcce652012-03-07 08:35:16 +00001528void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
1529 switch (Node->getLiteralOperatorKind()) {
1530 case UserDefinedLiteral::LOK_Raw:
Richard Smithef9f2982012-03-09 10:10:02 +00001531 OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
Richard Smith9fcce652012-03-07 08:35:16 +00001532 break;
1533 case UserDefinedLiteral::LOK_Template: {
Richard Smithef9f2982012-03-09 10:10:02 +00001534 DeclRefExpr *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
1535 const TemplateArgumentList *Args =
1536 cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
1537 assert(Args);
1538 const TemplateArgument &Pack = Args->get(0);
1539 for (TemplateArgument::pack_iterator I = Pack.pack_begin(),
1540 E = Pack.pack_end(); I != E; ++I) {
Benjamin Kramer85524372012-06-07 15:09:51 +00001541 char C = (char)I->getAsIntegral().getZExtValue();
Richard Smith9fcce652012-03-07 08:35:16 +00001542 OS << C;
1543 }
1544 break;
1545 }
Richard Smith91688302012-03-08 09:02:38 +00001546 case UserDefinedLiteral::LOK_Integer: {
1547 // Print integer literal without suffix.
1548 IntegerLiteral *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
1549 OS << Int->getValue().toString(10, /*isSigned*/false);
1550 break;
1551 }
Benjamin Kramera0a3c902012-09-20 14:07:17 +00001552 case UserDefinedLiteral::LOK_Floating: {
1553 // Print floating literal without suffix.
1554 FloatingLiteral *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
1555 PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
1556 break;
1557 }
Richard Smith9fcce652012-03-07 08:35:16 +00001558 case UserDefinedLiteral::LOK_String:
1559 case UserDefinedLiteral::LOK_Character:
1560 PrintExpr(Node->getCookedLiteral());
1561 break;
1562 }
1563 OS << Node->getUDSuffix()->getName();
1564}
1565
Reid Spencer5f016e22007-07-11 17:01:13 +00001566void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
1567 OS << (Node->getValue() ? "true" : "false");
1568}
1569
Sebastian Redl6e8ed162009-05-10 18:38:11 +00001570void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1571 OS << "nullptr";
1572}
1573
Douglas Gregor796da182008-11-04 14:32:21 +00001574void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1575 OS << "this";
1576}
1577
Chris Lattner50dd2892008-02-26 00:51:44 +00001578void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001579 if (!Node->getSubExpr())
Chris Lattner50dd2892008-02-26 00:51:44 +00001580 OS << "throw";
1581 else {
1582 OS << "throw ";
1583 PrintExpr(Node->getSubExpr());
1584 }
1585}
1586
Chris Lattner04421082008-04-08 04:40:51 +00001587void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
Richard Smithc3bf52c2013-04-20 22:23:05 +00001588 // Nothing to print: we picked up the default argument.
1589}
1590
1591void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
1592 // Nothing to print: we picked up the default initializer.
Chris Lattner04421082008-04-08 04:40:51 +00001593}
1594
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00001595void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001596 Node->getType().print(OS, Policy);
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00001597 OS << "(";
1598 PrintExpr(Node->getSubExpr());
1599 OS << ")";
1600}
1601
Anders Carlssonfceb0a82009-05-30 20:03:25 +00001602void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1603 PrintExpr(Node->getSubExpr());
1604}
1605
Douglas Gregor506ae412009-01-16 18:33:17 +00001606void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001607 Node->getType().print(OS, Policy);
Douglas Gregor506ae412009-01-16 18:33:17 +00001608 OS << "(";
1609 for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
Mike Stump1eb44332009-09-09 15:08:12 +00001610 ArgEnd = Node->arg_end();
Douglas Gregor506ae412009-01-16 18:33:17 +00001611 Arg != ArgEnd; ++Arg) {
Rafael Espindolad3bb9ff2013-05-24 16:11:44 +00001612 if (Arg->isDefaultArgument())
1613 break;
Douglas Gregor506ae412009-01-16 18:33:17 +00001614 if (Arg != Node->arg_begin())
1615 OS << ", ";
1616 PrintExpr(*Arg);
1617 }
1618 OS << ")";
1619}
1620
Douglas Gregor01d08012012-02-07 10:09:13 +00001621void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
1622 OS << '[';
1623 bool NeedComma = false;
1624 switch (Node->getCaptureDefault()) {
1625 case LCD_None:
1626 break;
1627
1628 case LCD_ByCopy:
1629 OS << '=';
1630 NeedComma = true;
1631 break;
1632
1633 case LCD_ByRef:
1634 OS << '&';
1635 NeedComma = true;
1636 break;
1637 }
1638 for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
1639 CEnd = Node->explicit_capture_end();
1640 C != CEnd;
1641 ++C) {
1642 if (NeedComma)
1643 OS << ", ";
1644 NeedComma = true;
1645
1646 switch (C->getCaptureKind()) {
1647 case LCK_This:
1648 OS << "this";
1649 break;
1650
1651 case LCK_ByRef:
Richard Smith04fa7a32013-09-28 04:02:39 +00001652 if (Node->getCaptureDefault() != LCD_ByRef || C->isInitCapture())
Douglas Gregor01d08012012-02-07 10:09:13 +00001653 OS << '&';
1654 OS << C->getCapturedVar()->getName();
1655 break;
1656
1657 case LCK_ByCopy:
Douglas Gregor01d08012012-02-07 10:09:13 +00001658 OS << C->getCapturedVar()->getName();
1659 break;
1660 }
Richard Smith04fa7a32013-09-28 04:02:39 +00001661
1662 if (C->isInitCapture())
1663 PrintExpr(C->getCapturedVar()->getInit());
Douglas Gregor01d08012012-02-07 10:09:13 +00001664 }
1665 OS << ']';
1666
1667 if (Node->hasExplicitParameters()) {
1668 OS << " (";
1669 CXXMethodDecl *Method = Node->getCallOperator();
1670 NeedComma = false;
Stephen Hines651f13c2014-04-23 16:59:28 -07001671 for (auto P : Method->params()) {
Douglas Gregor01d08012012-02-07 10:09:13 +00001672 if (NeedComma) {
1673 OS << ", ";
1674 } else {
1675 NeedComma = true;
1676 }
Stephen Hines651f13c2014-04-23 16:59:28 -07001677 std::string ParamStr = P->getNameAsString();
1678 P->getOriginalType().print(OS, Policy, ParamStr);
Douglas Gregor01d08012012-02-07 10:09:13 +00001679 }
1680 if (Method->isVariadic()) {
1681 if (NeedComma)
1682 OS << ", ";
1683 OS << "...";
1684 }
1685 OS << ')';
1686
1687 if (Node->isMutable())
1688 OS << " mutable";
1689
1690 const FunctionProtoType *Proto
1691 = Method->getType()->getAs<FunctionProtoType>();
Benjamin Kramer5eada842013-02-22 15:46:01 +00001692 Proto->printExceptionSpecification(OS, Policy);
Douglas Gregor01d08012012-02-07 10:09:13 +00001693
Bill Wendlingad017fa2012-12-20 19:22:21 +00001694 // FIXME: Attributes
Douglas Gregor01d08012012-02-07 10:09:13 +00001695
Douglas Gregordfca6f52012-02-13 22:00:16 +00001696 // Print the trailing return type if it was specified in the source.
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001697 if (Node->hasExplicitResultType()) {
1698 OS << " -> ";
Stephen Hines651f13c2014-04-23 16:59:28 -07001699 Proto->getReturnType().print(OS, Policy);
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001700 }
Douglas Gregor01d08012012-02-07 10:09:13 +00001701 }
1702
1703 // Print the body.
1704 CompoundStmt *Body = Node->getBody();
1705 OS << ' ';
1706 PrintStmt(Body);
1707}
1708
Douglas Gregored8abf12010-07-08 06:14:04 +00001709void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00001710 if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001711 TSInfo->getType().print(OS, Policy);
Douglas Gregorab6677e2010-09-08 00:15:04 +00001712 else
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001713 Node->getType().print(OS, Policy);
1714 OS << "()";
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00001715}
1716
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001717void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
1718 if (E->isGlobalNew())
1719 OS << "::";
1720 OS << "new ";
1721 unsigned NumPlace = E->getNumPlacementArgs();
Eli Friedmand03ef042012-10-18 20:54:37 +00001722 if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001723 OS << "(";
1724 PrintExpr(E->getPlacementArg(0));
1725 for (unsigned i = 1; i < NumPlace; ++i) {
Eli Friedmand03ef042012-10-18 20:54:37 +00001726 if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
1727 break;
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001728 OS << ", ";
1729 PrintExpr(E->getPlacementArg(i));
1730 }
1731 OS << ") ";
1732 }
1733 if (E->isParenTypeId())
1734 OS << "(";
Sebastian Redl6fec6482008-12-02 22:08:59 +00001735 std::string TypeS;
1736 if (Expr *Size = E->getArraySize()) {
1737 llvm::raw_string_ostream s(TypeS);
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001738 s << '[';
Richard Smithd1420c62012-08-16 03:56:14 +00001739 Size->printPretty(s, Helper, Policy);
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001740 s << ']';
Sebastian Redl6fec6482008-12-02 22:08:59 +00001741 }
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001742 E->getAllocatedType().print(OS, Policy, TypeS);
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001743 if (E->isParenTypeId())
1744 OS << ")";
1745
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001746 CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
1747 if (InitStyle) {
1748 if (InitStyle == CXXNewExpr::CallInit)
1749 OS << "(";
1750 PrintExpr(E->getInitializer());
1751 if (InitStyle == CXXNewExpr::CallInit)
1752 OS << ")";
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001753 }
1754}
1755
1756void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1757 if (E->isGlobalDelete())
1758 OS << "::";
1759 OS << "delete ";
1760 if (E->isArrayForm())
1761 OS << "[] ";
1762 PrintExpr(E->getArgument());
1763}
1764
Douglas Gregora71d8192009-09-04 17:36:40 +00001765void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1766 PrintExpr(E->getBase());
1767 if (E->isArrow())
1768 OS << "->";
1769 else
1770 OS << '.';
1771 if (E->getQualifier())
1772 E->getQualifier()->print(OS, Policy);
Eli Friedmana7a38cb2012-10-23 20:26:57 +00001773 OS << "~";
Mike Stump1eb44332009-09-09 15:08:12 +00001774
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001775 if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
1776 OS << II->getName();
1777 else
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001778 E->getDestroyedType().print(OS, Policy);
Douglas Gregora71d8192009-09-04 17:36:40 +00001779}
1780
Anders Carlssone349bea2009-04-23 02:32:43 +00001781void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00001782 if (E->isListInitialization())
1783 OS << "{ ";
1784
Douglas Gregord0fb3ad2011-01-24 17:25:03 +00001785 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
1786 if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
1787 // Don't print any defaulted arguments
1788 break;
1789 }
1790
1791 if (i) OS << ", ";
1792 PrintExpr(E->getArg(i));
Fariborz Jahanianc75da512010-01-13 21:41:11 +00001793 }
Richard Smithc83c2302012-12-19 01:39:02 +00001794
1795 if (E->isListInitialization())
1796 OS << " }";
Anders Carlssone349bea2009-04-23 02:32:43 +00001797}
1798
Richard Smith7c3e6152013-06-12 22:31:48 +00001799void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1800 PrintExpr(E->getSubExpr());
1801}
1802
John McCall4765fa02010-12-06 08:20:24 +00001803void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001804 // Just forward to the subexpression.
Anders Carlsson02bbfa32009-04-24 22:47:04 +00001805 PrintExpr(E->getSubExpr());
1806}
1807
Mike Stump1eb44332009-09-09 15:08:12 +00001808void
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001809StmtPrinter::VisitCXXUnresolvedConstructExpr(
1810 CXXUnresolvedConstructExpr *Node) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001811 Node->getTypeAsWritten().print(OS, Policy);
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001812 OS << "(";
1813 for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
Mike Stump1eb44332009-09-09 15:08:12 +00001814 ArgEnd = Node->arg_end();
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001815 Arg != ArgEnd; ++Arg) {
1816 if (Arg != Node->arg_begin())
1817 OS << ", ";
1818 PrintExpr(*Arg);
1819 }
1820 OS << ")";
1821}
1822
John McCall865d4472009-11-19 22:55:06 +00001823void StmtPrinter::VisitCXXDependentScopeMemberExpr(
1824 CXXDependentScopeMemberExpr *Node) {
John McCallaa81e162009-12-01 22:10:20 +00001825 if (!Node->isImplicitAccess()) {
1826 PrintExpr(Node->getBase());
1827 OS << (Node->isArrow() ? "->" : ".");
1828 }
Douglas Gregora38c6872009-09-03 16:14:30 +00001829 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1830 Qualifier->print(OS, Policy);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001831 if (Node->hasTemplateKeyword())
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001832 OS << "template ";
Abramo Bagnara25777432010-08-11 22:01:17 +00001833 OS << Node->getMemberNameInfo();
Benjamin Kramer5eada842013-02-22 15:46:01 +00001834 if (Node->hasExplicitTemplateArgs())
1835 TemplateSpecializationType::PrintTemplateArgumentList(
1836 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
Douglas Gregor1c0ca592009-05-22 21:13:27 +00001837}
1838
John McCall129e2df2009-11-30 22:42:35 +00001839void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
John McCallaa81e162009-12-01 22:10:20 +00001840 if (!Node->isImplicitAccess()) {
1841 PrintExpr(Node->getBase());
1842 OS << (Node->isArrow() ? "->" : ".");
1843 }
John McCall129e2df2009-11-30 22:42:35 +00001844 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1845 Qualifier->print(OS, Policy);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001846 if (Node->hasTemplateKeyword())
1847 OS << "template ";
Abramo Bagnara25777432010-08-11 22:01:17 +00001848 OS << Node->getMemberNameInfo();
Benjamin Kramer5eada842013-02-22 15:46:01 +00001849 if (Node->hasExplicitTemplateArgs())
1850 TemplateSpecializationType::PrintTemplateArgumentList(
1851 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
John McCall129e2df2009-11-30 22:42:35 +00001852}
1853
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00001854static const char *getTypeTraitName(TypeTrait TT) {
1855 switch (TT) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001856#define TYPE_TRAIT_1(Spelling, Name, Key) \
1857case clang::UTT_##Name: return #Spelling;
1858#define TYPE_TRAIT_2(Spelling, Name, Key) \
1859case clang::BTT_##Name: return #Spelling;
1860#define TYPE_TRAIT_N(Spelling, Name, Key) \
1861 case clang::TT_##Name: return #Spelling;
1862#include "clang/Basic/TokenKinds.def"
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00001863 }
1864 llvm_unreachable("Type trait not covered by switch");
1865}
1866
John Wiegley21ff2e52011-04-28 00:16:57 +00001867static const char *getTypeTraitName(ArrayTypeTrait ATT) {
1868 switch (ATT) {
1869 case ATT_ArrayRank: return "__array_rank";
1870 case ATT_ArrayExtent: return "__array_extent";
1871 }
Chandler Carrutha280bc82011-05-01 07:23:23 +00001872 llvm_unreachable("Array type trait not covered by switch");
John Wiegley21ff2e52011-04-28 00:16:57 +00001873}
1874
John Wiegley55262202011-04-25 06:54:41 +00001875static const char *getExpressionTraitName(ExpressionTrait ET) {
1876 switch (ET) {
John Wiegley55262202011-04-25 06:54:41 +00001877 case ET_IsLValueExpr: return "__is_lvalue_expr";
1878 case ET_IsRValueExpr: return "__is_rvalue_expr";
1879 }
Chandler Carrutha280bc82011-05-01 07:23:23 +00001880 llvm_unreachable("Expression type trait not covered by switch");
John Wiegley55262202011-04-25 06:54:41 +00001881}
1882
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00001883void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1884 OS << getTypeTraitName(E->getTrait()) << "(";
1885 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
1886 if (I > 0)
1887 OS << ", ";
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001888 E->getArg(I)->getType().print(OS, Policy);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00001889 }
1890 OS << ")";
1891}
1892
John Wiegley21ff2e52011-04-28 00:16:57 +00001893void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001894 OS << getTypeTraitName(E->getTrait()) << '(';
1895 E->getQueriedType().print(OS, Policy);
1896 OS << ')';
John Wiegley21ff2e52011-04-28 00:16:57 +00001897}
1898
John Wiegley55262202011-04-25 06:54:41 +00001899void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001900 OS << getExpressionTraitName(E->getTrait()) << '(';
1901 PrintExpr(E->getQueriedExpression());
1902 OS << ')';
John Wiegley55262202011-04-25 06:54:41 +00001903}
1904
Sebastian Redl2e156222010-09-10 20:55:43 +00001905void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1906 OS << "noexcept(";
1907 PrintExpr(E->getOperand());
1908 OS << ")";
1909}
1910
Douglas Gregoree8aff02011-01-04 17:33:58 +00001911void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregorbe230c32011-01-03 17:17:50 +00001912 PrintExpr(E->getPattern());
1913 OS << "...";
1914}
1915
Douglas Gregoree8aff02011-01-04 17:33:58 +00001916void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +00001917 OS << "sizeof...(" << *E->getPack() << ")";
Douglas Gregoree8aff02011-01-04 17:33:58 +00001918}
1919
Douglas Gregorc7793c72011-01-15 01:15:58 +00001920void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
1921 SubstNonTypeTemplateParmPackExpr *Node) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +00001922 OS << *Node->getParameterPack();
Douglas Gregorc7793c72011-01-15 01:15:58 +00001923}
1924
John McCall91a57552011-07-15 05:09:51 +00001925void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
1926 SubstNonTypeTemplateParmExpr *Node) {
1927 Visit(Node->getReplacement());
1928}
1929
Richard Smith9a4db032012-09-12 00:56:43 +00001930void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1931 OS << *E->getParameterPack();
1932}
1933
Douglas Gregor03e80032011-06-21 17:03:29 +00001934void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
1935 PrintExpr(Node->GetTemporaryExpr());
1936}
1937
Mike Stump1eb44332009-09-09 15:08:12 +00001938// Obj-C
Anders Carlsson55085182007-08-21 17:43:55 +00001939
1940void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
1941 OS << "@";
1942 VisitStringLiteral(Node->getString());
1943}
Reid Spencer5f016e22007-07-11 17:01:13 +00001944
Patrick Beardeb382ec2012-04-19 00:25:12 +00001945void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001946 OS << "@";
Patrick Beardeb382ec2012-04-19 00:25:12 +00001947 Visit(E->getSubExpr());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001948}
1949
1950void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1951 OS << "@[ ";
1952 StmtRange ch = E->children();
1953 if (ch.first != ch.second) {
1954 while (1) {
1955 Visit(*ch.first);
1956 ++ch.first;
1957 if (ch.first == ch.second) break;
1958 OS << ", ";
1959 }
1960 }
1961 OS << " ]";
1962}
1963
1964void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1965 OS << "@{ ";
1966 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
1967 if (I > 0)
1968 OS << ", ";
1969
1970 ObjCDictionaryElement Element = E->getKeyValueElement(I);
1971 Visit(Element.Key);
1972 OS << " : ";
1973 Visit(Element.Value);
1974 if (Element.isPackExpansion())
1975 OS << "...";
1976 }
1977 OS << " }";
1978}
1979
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001980void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00001981 OS << "@encode(";
1982 Node->getEncodedType().print(OS, Policy);
1983 OS << ')';
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001984}
1985
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001986void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001987 OS << "@selector(";
1988 Node->getSelector().print(OS);
1989 OS << ')';
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001990}
1991
Fariborz Jahanian390d50a2007-10-17 16:58:11 +00001992void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001993 OS << "@protocol(" << *Node->getProtocol() << ')';
Fariborz Jahanian390d50a2007-10-17 16:58:11 +00001994}
1995
Steve Naroff563477d2007-09-18 23:55:05 +00001996void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
1997 OS << "[";
Douglas Gregor04badcf2010-04-21 00:45:42 +00001998 switch (Mess->getReceiverKind()) {
1999 case ObjCMessageExpr::Instance:
2000 PrintExpr(Mess->getInstanceReceiver());
2001 break;
2002
2003 case ObjCMessageExpr::Class:
Benjamin Kramer9d4df462013-02-22 14:19:01 +00002004 Mess->getClassReceiver().print(OS, Policy);
Douglas Gregor04badcf2010-04-21 00:45:42 +00002005 break;
2006
2007 case ObjCMessageExpr::SuperInstance:
2008 case ObjCMessageExpr::SuperClass:
2009 OS << "Super";
2010 break;
2011 }
2012
Ted Kremenekc29efd82008-05-02 17:32:38 +00002013 OS << ' ';
Ted Kremenek97b7f262008-04-16 04:30:16 +00002014 Selector selector = Mess->getSelector();
Steve Naroff6a8a9a42007-10-02 20:01:56 +00002015 if (selector.isUnarySelector()) {
Douglas Gregor813d8342011-02-18 22:29:55 +00002016 OS << selector.getNameForSlot(0);
Steve Naroff6a8a9a42007-10-02 20:01:56 +00002017 } else {
2018 for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
Ted Kremenekc29efd82008-05-02 17:32:38 +00002019 if (i < selector.getNumArgs()) {
2020 if (i > 0) OS << ' ';
2021 if (selector.getIdentifierInfoForSlot(i))
Chris Lattner39f34e92008-11-24 04:00:27 +00002022 OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
Ted Kremenekc29efd82008-05-02 17:32:38 +00002023 else
2024 OS << ":";
2025 }
2026 else OS << ", "; // Handle variadic methods.
Mike Stump1eb44332009-09-09 15:08:12 +00002027
Steve Naroff6a8a9a42007-10-02 20:01:56 +00002028 PrintExpr(Mess->getArg(i));
2029 }
Steve Naroff563477d2007-09-18 23:55:05 +00002030 }
2031 OS << "]";
2032}
2033
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002034void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
2035 OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
2036}
2037
John McCallf85e1932011-06-15 23:02:42 +00002038void
2039StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
2040 PrintExpr(E->getSubExpr());
2041}
2042
2043void
2044StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Benjamin Kramer9d4df462013-02-22 14:19:01 +00002045 OS << '(' << E->getBridgeKindName();
2046 E->getType().print(OS, Policy);
2047 OS << ')';
John McCallf85e1932011-06-15 23:02:42 +00002048 PrintExpr(E->getSubExpr());
2049}
Douglas Gregorcd9b46e2008-11-04 14:56:14 +00002050
Steve Naroff4eb206b2008-09-03 18:15:37 +00002051void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
Steve Naroff56ee6892008-10-08 17:01:13 +00002052 BlockDecl *BD = Node->getBlockDecl();
Steve Naroff4eb206b2008-09-03 18:15:37 +00002053 OS << "^";
Mike Stump1eb44332009-09-09 15:08:12 +00002054
Steve Naroff4eb206b2008-09-03 18:15:37 +00002055 const FunctionType *AFT = Node->getFunctionType();
Mike Stump1eb44332009-09-09 15:08:12 +00002056
Douglas Gregor72564e72009-02-26 23:50:07 +00002057 if (isa<FunctionNoProtoType>(AFT)) {
Steve Naroff4eb206b2008-09-03 18:15:37 +00002058 OS << "()";
Douglas Gregor72564e72009-02-26 23:50:07 +00002059 } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
Steve Naroff4eb206b2008-09-03 18:15:37 +00002060 OS << '(';
Steve Naroff56ee6892008-10-08 17:01:13 +00002061 for (BlockDecl::param_iterator AI = BD->param_begin(),
2062 E = BD->param_end(); AI != E; ++AI) {
2063 if (AI != BD->param_begin()) OS << ", ";
Benjamin Kramer9d4df462013-02-22 14:19:01 +00002064 std::string ParamStr = (*AI)->getNameAsString();
2065 (*AI)->getType().print(OS, Policy, ParamStr);
Steve Naroff4eb206b2008-09-03 18:15:37 +00002066 }
Mike Stump1eb44332009-09-09 15:08:12 +00002067
Douglas Gregor72564e72009-02-26 23:50:07 +00002068 const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
Steve Naroff4eb206b2008-09-03 18:15:37 +00002069 if (FT->isVariadic()) {
Steve Naroff56ee6892008-10-08 17:01:13 +00002070 if (!BD->param_empty()) OS << ", ";
Steve Naroff4eb206b2008-09-03 18:15:37 +00002071 OS << "...";
2072 }
2073 OS << ')';
2074 }
Fariborz Jahanian3e2fe862012-12-04 21:15:23 +00002075 OS << "{ }";
Steve Naroff4eb206b2008-09-03 18:15:37 +00002076}
2077
Ted Kremenek381c0662011-11-30 22:08:08 +00002078void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
2079 PrintExpr(Node->getSourceExpr());
2080}
John McCall7cd7d1a2010-11-15 23:31:06 +00002081
Tanya Lattner61eee0c2011-06-04 00:47:47 +00002082void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
2083 OS << "__builtin_astype(";
2084 PrintExpr(Node->getSrcExpr());
Benjamin Kramer9d4df462013-02-22 14:19:01 +00002085 OS << ", ";
2086 Node->getType().print(OS, Policy);
Tanya Lattner61eee0c2011-06-04 00:47:47 +00002087 OS << ")";
2088}
2089
Reid Spencer5f016e22007-07-11 17:01:13 +00002090//===----------------------------------------------------------------------===//
2091// Stmt method implementations
2092//===----------------------------------------------------------------------===//
2093
Craig Topper8b4b98b2013-08-22 06:02:26 +00002094void Stmt::dumpPretty(const ASTContext &Context) const {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002095 printPretty(llvm::errs(), nullptr, PrintingPolicy(Context.getLangOpts()));
Reid Spencer5f016e22007-07-11 17:01:13 +00002096}
2097
Richard Smithd1420c62012-08-16 03:56:14 +00002098void Stmt::printPretty(raw_ostream &OS,
2099 PrinterHelper *Helper,
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00002100 const PrintingPolicy &Policy,
2101 unsigned Indentation) const {
Richard Smithd1420c62012-08-16 03:56:14 +00002102 StmtPrinter P(OS, Helper, Policy, Indentation);
Chris Lattnerc5598cb2007-08-21 04:04:25 +00002103 P.Visit(const_cast<Stmt*>(this));
Reid Spencer5f016e22007-07-11 17:01:13 +00002104}
Ted Kremenek42a509f2007-08-31 21:30:12 +00002105
2106//===----------------------------------------------------------------------===//
2107// PrinterHelper
2108//===----------------------------------------------------------------------===//
2109
2110// Implement virtual destructor.
Gabor Greif84675832007-09-11 15:32:40 +00002111PrinterHelper::~PrinterHelper() {}