xref: /minix3/external/bsd/llvm/dist/clang/lib/AST/StmtPrinter.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc //===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===//
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7*f4a2713aSLionel Sambuc //
8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9*f4a2713aSLionel Sambuc //
10*f4a2713aSLionel Sambuc // This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which
11*f4a2713aSLionel Sambuc // pretty print the AST back out to C code.
12*f4a2713aSLionel Sambuc //
13*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc #include "clang/AST/ASTContext.h"
16*f4a2713aSLionel Sambuc #include "clang/AST/Attr.h"
17*f4a2713aSLionel Sambuc #include "clang/AST/DeclCXX.h"
18*f4a2713aSLionel Sambuc #include "clang/AST/DeclObjC.h"
19*f4a2713aSLionel Sambuc #include "clang/AST/DeclTemplate.h"
20*f4a2713aSLionel Sambuc #include "clang/AST/Expr.h"
21*f4a2713aSLionel Sambuc #include "clang/AST/ExprCXX.h"
22*f4a2713aSLionel Sambuc #include "clang/AST/PrettyPrinter.h"
23*f4a2713aSLionel Sambuc #include "clang/AST/StmtVisitor.h"
24*f4a2713aSLionel Sambuc #include "clang/Basic/CharInfo.h"
25*f4a2713aSLionel Sambuc #include "llvm/ADT/SmallString.h"
26*f4a2713aSLionel Sambuc #include "llvm/Support/Format.h"
27*f4a2713aSLionel Sambuc using namespace clang;
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
30*f4a2713aSLionel Sambuc // StmtPrinter Visitor
31*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc namespace  {
34*f4a2713aSLionel Sambuc   class StmtPrinter : public StmtVisitor<StmtPrinter> {
35*f4a2713aSLionel Sambuc     raw_ostream &OS;
36*f4a2713aSLionel Sambuc     unsigned IndentLevel;
37*f4a2713aSLionel Sambuc     clang::PrinterHelper* Helper;
38*f4a2713aSLionel Sambuc     PrintingPolicy Policy;
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc   public:
41*f4a2713aSLionel Sambuc     StmtPrinter(raw_ostream &os, PrinterHelper* helper,
42*f4a2713aSLionel Sambuc                 const PrintingPolicy &Policy,
43*f4a2713aSLionel Sambuc                 unsigned Indentation = 0)
44*f4a2713aSLionel Sambuc       : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy) {}
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc     void PrintStmt(Stmt *S) {
47*f4a2713aSLionel Sambuc       PrintStmt(S, Policy.Indentation);
48*f4a2713aSLionel Sambuc     }
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc     void PrintStmt(Stmt *S, int SubIndent) {
51*f4a2713aSLionel Sambuc       IndentLevel += SubIndent;
52*f4a2713aSLionel Sambuc       if (S && isa<Expr>(S)) {
53*f4a2713aSLionel Sambuc         // If this is an expr used in a stmt context, indent and newline it.
54*f4a2713aSLionel Sambuc         Indent();
55*f4a2713aSLionel Sambuc         Visit(S);
56*f4a2713aSLionel Sambuc         OS << ";\n";
57*f4a2713aSLionel Sambuc       } else if (S) {
58*f4a2713aSLionel Sambuc         Visit(S);
59*f4a2713aSLionel Sambuc       } else {
60*f4a2713aSLionel Sambuc         Indent() << "<<<NULL STATEMENT>>>\n";
61*f4a2713aSLionel Sambuc       }
62*f4a2713aSLionel Sambuc       IndentLevel -= SubIndent;
63*f4a2713aSLionel Sambuc     }
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc     void PrintRawCompoundStmt(CompoundStmt *S);
66*f4a2713aSLionel Sambuc     void PrintRawDecl(Decl *D);
67*f4a2713aSLionel Sambuc     void PrintRawDeclStmt(const DeclStmt *S);
68*f4a2713aSLionel Sambuc     void PrintRawIfStmt(IfStmt *If);
69*f4a2713aSLionel Sambuc     void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
70*f4a2713aSLionel Sambuc     void PrintCallArgs(CallExpr *E);
71*f4a2713aSLionel Sambuc     void PrintRawSEHExceptHandler(SEHExceptStmt *S);
72*f4a2713aSLionel Sambuc     void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc     void PrintExpr(Expr *E) {
75*f4a2713aSLionel Sambuc       if (E)
76*f4a2713aSLionel Sambuc         Visit(E);
77*f4a2713aSLionel Sambuc       else
78*f4a2713aSLionel Sambuc         OS << "<null expr>";
79*f4a2713aSLionel Sambuc     }
80*f4a2713aSLionel Sambuc 
81*f4a2713aSLionel Sambuc     raw_ostream &Indent(int Delta = 0) {
82*f4a2713aSLionel Sambuc       for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
83*f4a2713aSLionel Sambuc         OS << "  ";
84*f4a2713aSLionel Sambuc       return OS;
85*f4a2713aSLionel Sambuc     }
86*f4a2713aSLionel Sambuc 
87*f4a2713aSLionel Sambuc     void Visit(Stmt* S) {
88*f4a2713aSLionel Sambuc       if (Helper && Helper->handledStmt(S,OS))
89*f4a2713aSLionel Sambuc           return;
90*f4a2713aSLionel Sambuc       else StmtVisitor<StmtPrinter>::Visit(S);
91*f4a2713aSLionel Sambuc     }
92*f4a2713aSLionel Sambuc 
93*f4a2713aSLionel Sambuc     void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
94*f4a2713aSLionel Sambuc       Indent() << "<<unknown stmt type>>\n";
95*f4a2713aSLionel Sambuc     }
96*f4a2713aSLionel Sambuc     void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
97*f4a2713aSLionel Sambuc       OS << "<<unknown expr type>>";
98*f4a2713aSLionel Sambuc     }
99*f4a2713aSLionel Sambuc     void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
100*f4a2713aSLionel Sambuc 
101*f4a2713aSLionel Sambuc #define ABSTRACT_STMT(CLASS)
102*f4a2713aSLionel Sambuc #define STMT(CLASS, PARENT) \
103*f4a2713aSLionel Sambuc     void Visit##CLASS(CLASS *Node);
104*f4a2713aSLionel Sambuc #include "clang/AST/StmtNodes.inc"
105*f4a2713aSLionel Sambuc   };
106*f4a2713aSLionel Sambuc }
107*f4a2713aSLionel Sambuc 
108*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
109*f4a2713aSLionel Sambuc //  Stmt printing methods.
110*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
111*f4a2713aSLionel Sambuc 
112*f4a2713aSLionel Sambuc /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
113*f4a2713aSLionel Sambuc /// with no newline after the }.
114*f4a2713aSLionel Sambuc void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
115*f4a2713aSLionel Sambuc   OS << "{\n";
116*f4a2713aSLionel Sambuc   for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
117*f4a2713aSLionel Sambuc        I != E; ++I)
118*f4a2713aSLionel Sambuc     PrintStmt(*I);
119*f4a2713aSLionel Sambuc 
120*f4a2713aSLionel Sambuc   Indent() << "}";
121*f4a2713aSLionel Sambuc }
122*f4a2713aSLionel Sambuc 
123*f4a2713aSLionel Sambuc void StmtPrinter::PrintRawDecl(Decl *D) {
124*f4a2713aSLionel Sambuc   D->print(OS, Policy, IndentLevel);
125*f4a2713aSLionel Sambuc }
126*f4a2713aSLionel Sambuc 
127*f4a2713aSLionel Sambuc void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
128*f4a2713aSLionel Sambuc   DeclStmt::const_decl_iterator Begin = S->decl_begin(), End = S->decl_end();
129*f4a2713aSLionel Sambuc   SmallVector<Decl*, 2> Decls;
130*f4a2713aSLionel Sambuc   for ( ; Begin != End; ++Begin)
131*f4a2713aSLionel Sambuc     Decls.push_back(*Begin);
132*f4a2713aSLionel Sambuc 
133*f4a2713aSLionel Sambuc   Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
134*f4a2713aSLionel Sambuc }
135*f4a2713aSLionel Sambuc 
136*f4a2713aSLionel Sambuc void StmtPrinter::VisitNullStmt(NullStmt *Node) {
137*f4a2713aSLionel Sambuc   Indent() << ";\n";
138*f4a2713aSLionel Sambuc }
139*f4a2713aSLionel Sambuc 
140*f4a2713aSLionel Sambuc void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
141*f4a2713aSLionel Sambuc   Indent();
142*f4a2713aSLionel Sambuc   PrintRawDeclStmt(Node);
143*f4a2713aSLionel Sambuc   OS << ";\n";
144*f4a2713aSLionel Sambuc }
145*f4a2713aSLionel Sambuc 
146*f4a2713aSLionel Sambuc void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
147*f4a2713aSLionel Sambuc   Indent();
148*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(Node);
149*f4a2713aSLionel Sambuc   OS << "\n";
150*f4a2713aSLionel Sambuc }
151*f4a2713aSLionel Sambuc 
152*f4a2713aSLionel Sambuc void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
153*f4a2713aSLionel Sambuc   Indent(-1) << "case ";
154*f4a2713aSLionel Sambuc   PrintExpr(Node->getLHS());
155*f4a2713aSLionel Sambuc   if (Node->getRHS()) {
156*f4a2713aSLionel Sambuc     OS << " ... ";
157*f4a2713aSLionel Sambuc     PrintExpr(Node->getRHS());
158*f4a2713aSLionel Sambuc   }
159*f4a2713aSLionel Sambuc   OS << ":\n";
160*f4a2713aSLionel Sambuc 
161*f4a2713aSLionel Sambuc   PrintStmt(Node->getSubStmt(), 0);
162*f4a2713aSLionel Sambuc }
163*f4a2713aSLionel Sambuc 
164*f4a2713aSLionel Sambuc void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
165*f4a2713aSLionel Sambuc   Indent(-1) << "default:\n";
166*f4a2713aSLionel Sambuc   PrintStmt(Node->getSubStmt(), 0);
167*f4a2713aSLionel Sambuc }
168*f4a2713aSLionel Sambuc 
169*f4a2713aSLionel Sambuc void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
170*f4a2713aSLionel Sambuc   Indent(-1) << Node->getName() << ":\n";
171*f4a2713aSLionel Sambuc   PrintStmt(Node->getSubStmt(), 0);
172*f4a2713aSLionel Sambuc }
173*f4a2713aSLionel Sambuc 
174*f4a2713aSLionel Sambuc void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
175*f4a2713aSLionel Sambuc   OS << "[[";
176*f4a2713aSLionel Sambuc   bool first = true;
177*f4a2713aSLionel Sambuc   for (ArrayRef<const Attr*>::iterator it = Node->getAttrs().begin(),
178*f4a2713aSLionel Sambuc                                        end = Node->getAttrs().end();
179*f4a2713aSLionel Sambuc                                        it != end; ++it) {
180*f4a2713aSLionel Sambuc     if (!first) {
181*f4a2713aSLionel Sambuc       OS << ", ";
182*f4a2713aSLionel Sambuc       first = false;
183*f4a2713aSLionel Sambuc     }
184*f4a2713aSLionel Sambuc     // TODO: check this
185*f4a2713aSLionel Sambuc     (*it)->printPretty(OS, Policy);
186*f4a2713aSLionel Sambuc   }
187*f4a2713aSLionel Sambuc   OS << "]] ";
188*f4a2713aSLionel Sambuc   PrintStmt(Node->getSubStmt(), 0);
189*f4a2713aSLionel Sambuc }
190*f4a2713aSLionel Sambuc 
191*f4a2713aSLionel Sambuc void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
192*f4a2713aSLionel Sambuc   OS << "if (";
193*f4a2713aSLionel Sambuc   if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
194*f4a2713aSLionel Sambuc     PrintRawDeclStmt(DS);
195*f4a2713aSLionel Sambuc   else
196*f4a2713aSLionel Sambuc     PrintExpr(If->getCond());
197*f4a2713aSLionel Sambuc   OS << ')';
198*f4a2713aSLionel Sambuc 
199*f4a2713aSLionel Sambuc   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
200*f4a2713aSLionel Sambuc     OS << ' ';
201*f4a2713aSLionel Sambuc     PrintRawCompoundStmt(CS);
202*f4a2713aSLionel Sambuc     OS << (If->getElse() ? ' ' : '\n');
203*f4a2713aSLionel Sambuc   } else {
204*f4a2713aSLionel Sambuc     OS << '\n';
205*f4a2713aSLionel Sambuc     PrintStmt(If->getThen());
206*f4a2713aSLionel Sambuc     if (If->getElse()) Indent();
207*f4a2713aSLionel Sambuc   }
208*f4a2713aSLionel Sambuc 
209*f4a2713aSLionel Sambuc   if (Stmt *Else = If->getElse()) {
210*f4a2713aSLionel Sambuc     OS << "else";
211*f4a2713aSLionel Sambuc 
212*f4a2713aSLionel Sambuc     if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
213*f4a2713aSLionel Sambuc       OS << ' ';
214*f4a2713aSLionel Sambuc       PrintRawCompoundStmt(CS);
215*f4a2713aSLionel Sambuc       OS << '\n';
216*f4a2713aSLionel Sambuc     } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
217*f4a2713aSLionel Sambuc       OS << ' ';
218*f4a2713aSLionel Sambuc       PrintRawIfStmt(ElseIf);
219*f4a2713aSLionel Sambuc     } else {
220*f4a2713aSLionel Sambuc       OS << '\n';
221*f4a2713aSLionel Sambuc       PrintStmt(If->getElse());
222*f4a2713aSLionel Sambuc     }
223*f4a2713aSLionel Sambuc   }
224*f4a2713aSLionel Sambuc }
225*f4a2713aSLionel Sambuc 
226*f4a2713aSLionel Sambuc void StmtPrinter::VisitIfStmt(IfStmt *If) {
227*f4a2713aSLionel Sambuc   Indent();
228*f4a2713aSLionel Sambuc   PrintRawIfStmt(If);
229*f4a2713aSLionel Sambuc }
230*f4a2713aSLionel Sambuc 
231*f4a2713aSLionel Sambuc void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
232*f4a2713aSLionel Sambuc   Indent() << "switch (";
233*f4a2713aSLionel Sambuc   if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
234*f4a2713aSLionel Sambuc     PrintRawDeclStmt(DS);
235*f4a2713aSLionel Sambuc   else
236*f4a2713aSLionel Sambuc     PrintExpr(Node->getCond());
237*f4a2713aSLionel Sambuc   OS << ")";
238*f4a2713aSLionel Sambuc 
239*f4a2713aSLionel Sambuc   // Pretty print compoundstmt bodies (very common).
240*f4a2713aSLionel Sambuc   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
241*f4a2713aSLionel Sambuc     OS << " ";
242*f4a2713aSLionel Sambuc     PrintRawCompoundStmt(CS);
243*f4a2713aSLionel Sambuc     OS << "\n";
244*f4a2713aSLionel Sambuc   } else {
245*f4a2713aSLionel Sambuc     OS << "\n";
246*f4a2713aSLionel Sambuc     PrintStmt(Node->getBody());
247*f4a2713aSLionel Sambuc   }
248*f4a2713aSLionel Sambuc }
249*f4a2713aSLionel Sambuc 
250*f4a2713aSLionel Sambuc void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
251*f4a2713aSLionel Sambuc   Indent() << "while (";
252*f4a2713aSLionel Sambuc   if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
253*f4a2713aSLionel Sambuc     PrintRawDeclStmt(DS);
254*f4a2713aSLionel Sambuc   else
255*f4a2713aSLionel Sambuc     PrintExpr(Node->getCond());
256*f4a2713aSLionel Sambuc   OS << ")\n";
257*f4a2713aSLionel Sambuc   PrintStmt(Node->getBody());
258*f4a2713aSLionel Sambuc }
259*f4a2713aSLionel Sambuc 
260*f4a2713aSLionel Sambuc void StmtPrinter::VisitDoStmt(DoStmt *Node) {
261*f4a2713aSLionel Sambuc   Indent() << "do ";
262*f4a2713aSLionel Sambuc   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
263*f4a2713aSLionel Sambuc     PrintRawCompoundStmt(CS);
264*f4a2713aSLionel Sambuc     OS << " ";
265*f4a2713aSLionel Sambuc   } else {
266*f4a2713aSLionel Sambuc     OS << "\n";
267*f4a2713aSLionel Sambuc     PrintStmt(Node->getBody());
268*f4a2713aSLionel Sambuc     Indent();
269*f4a2713aSLionel Sambuc   }
270*f4a2713aSLionel Sambuc 
271*f4a2713aSLionel Sambuc   OS << "while (";
272*f4a2713aSLionel Sambuc   PrintExpr(Node->getCond());
273*f4a2713aSLionel Sambuc   OS << ");\n";
274*f4a2713aSLionel Sambuc }
275*f4a2713aSLionel Sambuc 
276*f4a2713aSLionel Sambuc void StmtPrinter::VisitForStmt(ForStmt *Node) {
277*f4a2713aSLionel Sambuc   Indent() << "for (";
278*f4a2713aSLionel Sambuc   if (Node->getInit()) {
279*f4a2713aSLionel Sambuc     if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
280*f4a2713aSLionel Sambuc       PrintRawDeclStmt(DS);
281*f4a2713aSLionel Sambuc     else
282*f4a2713aSLionel Sambuc       PrintExpr(cast<Expr>(Node->getInit()));
283*f4a2713aSLionel Sambuc   }
284*f4a2713aSLionel Sambuc   OS << ";";
285*f4a2713aSLionel Sambuc   if (Node->getCond()) {
286*f4a2713aSLionel Sambuc     OS << " ";
287*f4a2713aSLionel Sambuc     PrintExpr(Node->getCond());
288*f4a2713aSLionel Sambuc   }
289*f4a2713aSLionel Sambuc   OS << ";";
290*f4a2713aSLionel Sambuc   if (Node->getInc()) {
291*f4a2713aSLionel Sambuc     OS << " ";
292*f4a2713aSLionel Sambuc     PrintExpr(Node->getInc());
293*f4a2713aSLionel Sambuc   }
294*f4a2713aSLionel Sambuc   OS << ") ";
295*f4a2713aSLionel Sambuc 
296*f4a2713aSLionel Sambuc   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
297*f4a2713aSLionel Sambuc     PrintRawCompoundStmt(CS);
298*f4a2713aSLionel Sambuc     OS << "\n";
299*f4a2713aSLionel Sambuc   } else {
300*f4a2713aSLionel Sambuc     OS << "\n";
301*f4a2713aSLionel Sambuc     PrintStmt(Node->getBody());
302*f4a2713aSLionel Sambuc   }
303*f4a2713aSLionel Sambuc }
304*f4a2713aSLionel Sambuc 
305*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
306*f4a2713aSLionel Sambuc   Indent() << "for (";
307*f4a2713aSLionel Sambuc   if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
308*f4a2713aSLionel Sambuc     PrintRawDeclStmt(DS);
309*f4a2713aSLionel Sambuc   else
310*f4a2713aSLionel Sambuc     PrintExpr(cast<Expr>(Node->getElement()));
311*f4a2713aSLionel Sambuc   OS << " in ";
312*f4a2713aSLionel Sambuc   PrintExpr(Node->getCollection());
313*f4a2713aSLionel Sambuc   OS << ") ";
314*f4a2713aSLionel Sambuc 
315*f4a2713aSLionel Sambuc   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
316*f4a2713aSLionel Sambuc     PrintRawCompoundStmt(CS);
317*f4a2713aSLionel Sambuc     OS << "\n";
318*f4a2713aSLionel Sambuc   } else {
319*f4a2713aSLionel Sambuc     OS << "\n";
320*f4a2713aSLionel Sambuc     PrintStmt(Node->getBody());
321*f4a2713aSLionel Sambuc   }
322*f4a2713aSLionel Sambuc }
323*f4a2713aSLionel Sambuc 
324*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
325*f4a2713aSLionel Sambuc   Indent() << "for (";
326*f4a2713aSLionel Sambuc   PrintingPolicy SubPolicy(Policy);
327*f4a2713aSLionel Sambuc   SubPolicy.SuppressInitializers = true;
328*f4a2713aSLionel Sambuc   Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
329*f4a2713aSLionel Sambuc   OS << " : ";
330*f4a2713aSLionel Sambuc   PrintExpr(Node->getRangeInit());
331*f4a2713aSLionel Sambuc   OS << ") {\n";
332*f4a2713aSLionel Sambuc   PrintStmt(Node->getBody());
333*f4a2713aSLionel Sambuc   Indent() << "}\n";
334*f4a2713aSLionel Sambuc }
335*f4a2713aSLionel Sambuc 
336*f4a2713aSLionel Sambuc void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
337*f4a2713aSLionel Sambuc   Indent();
338*f4a2713aSLionel Sambuc   if (Node->isIfExists())
339*f4a2713aSLionel Sambuc     OS << "__if_exists (";
340*f4a2713aSLionel Sambuc   else
341*f4a2713aSLionel Sambuc     OS << "__if_not_exists (";
342*f4a2713aSLionel Sambuc 
343*f4a2713aSLionel Sambuc   if (NestedNameSpecifier *Qualifier
344*f4a2713aSLionel Sambuc         = Node->getQualifierLoc().getNestedNameSpecifier())
345*f4a2713aSLionel Sambuc     Qualifier->print(OS, Policy);
346*f4a2713aSLionel Sambuc 
347*f4a2713aSLionel Sambuc   OS << Node->getNameInfo() << ") ";
348*f4a2713aSLionel Sambuc 
349*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(Node->getSubStmt());
350*f4a2713aSLionel Sambuc }
351*f4a2713aSLionel Sambuc 
352*f4a2713aSLionel Sambuc void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
353*f4a2713aSLionel Sambuc   Indent() << "goto " << Node->getLabel()->getName() << ";\n";
354*f4a2713aSLionel Sambuc }
355*f4a2713aSLionel Sambuc 
356*f4a2713aSLionel Sambuc void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
357*f4a2713aSLionel Sambuc   Indent() << "goto *";
358*f4a2713aSLionel Sambuc   PrintExpr(Node->getTarget());
359*f4a2713aSLionel Sambuc   OS << ";\n";
360*f4a2713aSLionel Sambuc }
361*f4a2713aSLionel Sambuc 
362*f4a2713aSLionel Sambuc void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
363*f4a2713aSLionel Sambuc   Indent() << "continue;\n";
364*f4a2713aSLionel Sambuc }
365*f4a2713aSLionel Sambuc 
366*f4a2713aSLionel Sambuc void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
367*f4a2713aSLionel Sambuc   Indent() << "break;\n";
368*f4a2713aSLionel Sambuc }
369*f4a2713aSLionel Sambuc 
370*f4a2713aSLionel Sambuc 
371*f4a2713aSLionel Sambuc void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
372*f4a2713aSLionel Sambuc   Indent() << "return";
373*f4a2713aSLionel Sambuc   if (Node->getRetValue()) {
374*f4a2713aSLionel Sambuc     OS << " ";
375*f4a2713aSLionel Sambuc     PrintExpr(Node->getRetValue());
376*f4a2713aSLionel Sambuc   }
377*f4a2713aSLionel Sambuc   OS << ";\n";
378*f4a2713aSLionel Sambuc }
379*f4a2713aSLionel Sambuc 
380*f4a2713aSLionel Sambuc 
381*f4a2713aSLionel Sambuc void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
382*f4a2713aSLionel Sambuc   Indent() << "asm ";
383*f4a2713aSLionel Sambuc 
384*f4a2713aSLionel Sambuc   if (Node->isVolatile())
385*f4a2713aSLionel Sambuc     OS << "volatile ";
386*f4a2713aSLionel Sambuc 
387*f4a2713aSLionel Sambuc   OS << "(";
388*f4a2713aSLionel Sambuc   VisitStringLiteral(Node->getAsmString());
389*f4a2713aSLionel Sambuc 
390*f4a2713aSLionel Sambuc   // Outputs
391*f4a2713aSLionel Sambuc   if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
392*f4a2713aSLionel Sambuc       Node->getNumClobbers() != 0)
393*f4a2713aSLionel Sambuc     OS << " : ";
394*f4a2713aSLionel Sambuc 
395*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
396*f4a2713aSLionel Sambuc     if (i != 0)
397*f4a2713aSLionel Sambuc       OS << ", ";
398*f4a2713aSLionel Sambuc 
399*f4a2713aSLionel Sambuc     if (!Node->getOutputName(i).empty()) {
400*f4a2713aSLionel Sambuc       OS << '[';
401*f4a2713aSLionel Sambuc       OS << Node->getOutputName(i);
402*f4a2713aSLionel Sambuc       OS << "] ";
403*f4a2713aSLionel Sambuc     }
404*f4a2713aSLionel Sambuc 
405*f4a2713aSLionel Sambuc     VisitStringLiteral(Node->getOutputConstraintLiteral(i));
406*f4a2713aSLionel Sambuc     OS << " ";
407*f4a2713aSLionel Sambuc     Visit(Node->getOutputExpr(i));
408*f4a2713aSLionel Sambuc   }
409*f4a2713aSLionel Sambuc 
410*f4a2713aSLionel Sambuc   // Inputs
411*f4a2713aSLionel Sambuc   if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
412*f4a2713aSLionel Sambuc     OS << " : ";
413*f4a2713aSLionel Sambuc 
414*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
415*f4a2713aSLionel Sambuc     if (i != 0)
416*f4a2713aSLionel Sambuc       OS << ", ";
417*f4a2713aSLionel Sambuc 
418*f4a2713aSLionel Sambuc     if (!Node->getInputName(i).empty()) {
419*f4a2713aSLionel Sambuc       OS << '[';
420*f4a2713aSLionel Sambuc       OS << Node->getInputName(i);
421*f4a2713aSLionel Sambuc       OS << "] ";
422*f4a2713aSLionel Sambuc     }
423*f4a2713aSLionel Sambuc 
424*f4a2713aSLionel Sambuc     VisitStringLiteral(Node->getInputConstraintLiteral(i));
425*f4a2713aSLionel Sambuc     OS << " ";
426*f4a2713aSLionel Sambuc     Visit(Node->getInputExpr(i));
427*f4a2713aSLionel Sambuc   }
428*f4a2713aSLionel Sambuc 
429*f4a2713aSLionel Sambuc   // Clobbers
430*f4a2713aSLionel Sambuc   if (Node->getNumClobbers() != 0)
431*f4a2713aSLionel Sambuc     OS << " : ";
432*f4a2713aSLionel Sambuc 
433*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
434*f4a2713aSLionel Sambuc     if (i != 0)
435*f4a2713aSLionel Sambuc       OS << ", ";
436*f4a2713aSLionel Sambuc 
437*f4a2713aSLionel Sambuc     VisitStringLiteral(Node->getClobberStringLiteral(i));
438*f4a2713aSLionel Sambuc   }
439*f4a2713aSLionel Sambuc 
440*f4a2713aSLionel Sambuc   OS << ");\n";
441*f4a2713aSLionel Sambuc }
442*f4a2713aSLionel Sambuc 
443*f4a2713aSLionel Sambuc void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
444*f4a2713aSLionel Sambuc   // FIXME: Implement MS style inline asm statement printer.
445*f4a2713aSLionel Sambuc   Indent() << "__asm ";
446*f4a2713aSLionel Sambuc   if (Node->hasBraces())
447*f4a2713aSLionel Sambuc     OS << "{\n";
448*f4a2713aSLionel Sambuc   OS << Node->getAsmString() << "\n";
449*f4a2713aSLionel Sambuc   if (Node->hasBraces())
450*f4a2713aSLionel Sambuc     Indent() << "}\n";
451*f4a2713aSLionel Sambuc }
452*f4a2713aSLionel Sambuc 
453*f4a2713aSLionel Sambuc void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
454*f4a2713aSLionel Sambuc   PrintStmt(Node->getCapturedDecl()->getBody());
455*f4a2713aSLionel Sambuc }
456*f4a2713aSLionel Sambuc 
457*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
458*f4a2713aSLionel Sambuc   Indent() << "@try";
459*f4a2713aSLionel Sambuc   if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
460*f4a2713aSLionel Sambuc     PrintRawCompoundStmt(TS);
461*f4a2713aSLionel Sambuc     OS << "\n";
462*f4a2713aSLionel Sambuc   }
463*f4a2713aSLionel Sambuc 
464*f4a2713aSLionel Sambuc   for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
465*f4a2713aSLionel Sambuc     ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
466*f4a2713aSLionel Sambuc     Indent() << "@catch(";
467*f4a2713aSLionel Sambuc     if (catchStmt->getCatchParamDecl()) {
468*f4a2713aSLionel Sambuc       if (Decl *DS = catchStmt->getCatchParamDecl())
469*f4a2713aSLionel Sambuc         PrintRawDecl(DS);
470*f4a2713aSLionel Sambuc     }
471*f4a2713aSLionel Sambuc     OS << ")";
472*f4a2713aSLionel Sambuc     if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
473*f4a2713aSLionel Sambuc       PrintRawCompoundStmt(CS);
474*f4a2713aSLionel Sambuc       OS << "\n";
475*f4a2713aSLionel Sambuc     }
476*f4a2713aSLionel Sambuc   }
477*f4a2713aSLionel Sambuc 
478*f4a2713aSLionel Sambuc   if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
479*f4a2713aSLionel Sambuc         Node->getFinallyStmt())) {
480*f4a2713aSLionel Sambuc     Indent() << "@finally";
481*f4a2713aSLionel Sambuc     PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
482*f4a2713aSLionel Sambuc     OS << "\n";
483*f4a2713aSLionel Sambuc   }
484*f4a2713aSLionel Sambuc }
485*f4a2713aSLionel Sambuc 
486*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
487*f4a2713aSLionel Sambuc }
488*f4a2713aSLionel Sambuc 
489*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
490*f4a2713aSLionel Sambuc   Indent() << "@catch (...) { /* todo */ } \n";
491*f4a2713aSLionel Sambuc }
492*f4a2713aSLionel Sambuc 
493*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
494*f4a2713aSLionel Sambuc   Indent() << "@throw";
495*f4a2713aSLionel Sambuc   if (Node->getThrowExpr()) {
496*f4a2713aSLionel Sambuc     OS << " ";
497*f4a2713aSLionel Sambuc     PrintExpr(Node->getThrowExpr());
498*f4a2713aSLionel Sambuc   }
499*f4a2713aSLionel Sambuc   OS << ";\n";
500*f4a2713aSLionel Sambuc }
501*f4a2713aSLionel Sambuc 
502*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
503*f4a2713aSLionel Sambuc   Indent() << "@synchronized (";
504*f4a2713aSLionel Sambuc   PrintExpr(Node->getSynchExpr());
505*f4a2713aSLionel Sambuc   OS << ")";
506*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(Node->getSynchBody());
507*f4a2713aSLionel Sambuc   OS << "\n";
508*f4a2713aSLionel Sambuc }
509*f4a2713aSLionel Sambuc 
510*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
511*f4a2713aSLionel Sambuc   Indent() << "@autoreleasepool";
512*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
513*f4a2713aSLionel Sambuc   OS << "\n";
514*f4a2713aSLionel Sambuc }
515*f4a2713aSLionel Sambuc 
516*f4a2713aSLionel Sambuc void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
517*f4a2713aSLionel Sambuc   OS << "catch (";
518*f4a2713aSLionel Sambuc   if (Decl *ExDecl = Node->getExceptionDecl())
519*f4a2713aSLionel Sambuc     PrintRawDecl(ExDecl);
520*f4a2713aSLionel Sambuc   else
521*f4a2713aSLionel Sambuc     OS << "...";
522*f4a2713aSLionel Sambuc   OS << ") ";
523*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
524*f4a2713aSLionel Sambuc }
525*f4a2713aSLionel Sambuc 
526*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
527*f4a2713aSLionel Sambuc   Indent();
528*f4a2713aSLionel Sambuc   PrintRawCXXCatchStmt(Node);
529*f4a2713aSLionel Sambuc   OS << "\n";
530*f4a2713aSLionel Sambuc }
531*f4a2713aSLionel Sambuc 
532*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
533*f4a2713aSLionel Sambuc   Indent() << "try ";
534*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(Node->getTryBlock());
535*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
536*f4a2713aSLionel Sambuc     OS << " ";
537*f4a2713aSLionel Sambuc     PrintRawCXXCatchStmt(Node->getHandler(i));
538*f4a2713aSLionel Sambuc   }
539*f4a2713aSLionel Sambuc   OS << "\n";
540*f4a2713aSLionel Sambuc }
541*f4a2713aSLionel Sambuc 
542*f4a2713aSLionel Sambuc void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
543*f4a2713aSLionel Sambuc   Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
544*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(Node->getTryBlock());
545*f4a2713aSLionel Sambuc   SEHExceptStmt *E = Node->getExceptHandler();
546*f4a2713aSLionel Sambuc   SEHFinallyStmt *F = Node->getFinallyHandler();
547*f4a2713aSLionel Sambuc   if(E)
548*f4a2713aSLionel Sambuc     PrintRawSEHExceptHandler(E);
549*f4a2713aSLionel Sambuc   else {
550*f4a2713aSLionel Sambuc     assert(F && "Must have a finally block...");
551*f4a2713aSLionel Sambuc     PrintRawSEHFinallyStmt(F);
552*f4a2713aSLionel Sambuc   }
553*f4a2713aSLionel Sambuc   OS << "\n";
554*f4a2713aSLionel Sambuc }
555*f4a2713aSLionel Sambuc 
556*f4a2713aSLionel Sambuc void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
557*f4a2713aSLionel Sambuc   OS << "__finally ";
558*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(Node->getBlock());
559*f4a2713aSLionel Sambuc   OS << "\n";
560*f4a2713aSLionel Sambuc }
561*f4a2713aSLionel Sambuc 
562*f4a2713aSLionel Sambuc void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
563*f4a2713aSLionel Sambuc   OS << "__except (";
564*f4a2713aSLionel Sambuc   VisitExpr(Node->getFilterExpr());
565*f4a2713aSLionel Sambuc   OS << ")\n";
566*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(Node->getBlock());
567*f4a2713aSLionel Sambuc   OS << "\n";
568*f4a2713aSLionel Sambuc }
569*f4a2713aSLionel Sambuc 
570*f4a2713aSLionel Sambuc void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
571*f4a2713aSLionel Sambuc   Indent();
572*f4a2713aSLionel Sambuc   PrintRawSEHExceptHandler(Node);
573*f4a2713aSLionel Sambuc   OS << "\n";
574*f4a2713aSLionel Sambuc }
575*f4a2713aSLionel Sambuc 
576*f4a2713aSLionel Sambuc void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
577*f4a2713aSLionel Sambuc   Indent();
578*f4a2713aSLionel Sambuc   PrintRawSEHFinallyStmt(Node);
579*f4a2713aSLionel Sambuc   OS << "\n";
580*f4a2713aSLionel Sambuc }
581*f4a2713aSLionel Sambuc 
582*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
583*f4a2713aSLionel Sambuc //  OpenMP clauses printing methods
584*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
585*f4a2713aSLionel Sambuc 
586*f4a2713aSLionel Sambuc namespace {
587*f4a2713aSLionel Sambuc class OMPClausePrinter : public OMPClauseVisitor<OMPClausePrinter> {
588*f4a2713aSLionel Sambuc   raw_ostream &OS;
589*f4a2713aSLionel Sambuc   /// \brief Process clauses with list of variables.
590*f4a2713aSLionel Sambuc   template <typename T>
591*f4a2713aSLionel Sambuc   void VisitOMPClauseList(T *Node, char StartSym);
592*f4a2713aSLionel Sambuc public:
593*f4a2713aSLionel Sambuc   OMPClausePrinter(raw_ostream &OS) : OS(OS) { }
594*f4a2713aSLionel Sambuc #define OPENMP_CLAUSE(Name, Class)                              \
595*f4a2713aSLionel Sambuc   void Visit##Class(Class *S);
596*f4a2713aSLionel Sambuc #include "clang/Basic/OpenMPKinds.def"
597*f4a2713aSLionel Sambuc };
598*f4a2713aSLionel Sambuc 
599*f4a2713aSLionel Sambuc void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
600*f4a2713aSLionel Sambuc   OS << "default("
601*f4a2713aSLionel Sambuc      << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
602*f4a2713aSLionel Sambuc      << ")";
603*f4a2713aSLionel Sambuc }
604*f4a2713aSLionel Sambuc 
605*f4a2713aSLionel Sambuc template<typename T>
606*f4a2713aSLionel Sambuc void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
607*f4a2713aSLionel Sambuc   for (typename T::varlist_iterator I = Node->varlist_begin(),
608*f4a2713aSLionel Sambuc                                     E = Node->varlist_end();
609*f4a2713aSLionel Sambuc          I != E; ++I)
610*f4a2713aSLionel Sambuc     OS << (I == Node->varlist_begin() ? StartSym : ',')
611*f4a2713aSLionel Sambuc        << *cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl());
612*f4a2713aSLionel Sambuc }
613*f4a2713aSLionel Sambuc 
614*f4a2713aSLionel Sambuc void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
615*f4a2713aSLionel Sambuc   if (!Node->varlist_empty()) {
616*f4a2713aSLionel Sambuc     OS << "private";
617*f4a2713aSLionel Sambuc     VisitOMPClauseList(Node, '(');
618*f4a2713aSLionel Sambuc     OS << ")";
619*f4a2713aSLionel Sambuc   }
620*f4a2713aSLionel Sambuc }
621*f4a2713aSLionel Sambuc 
622*f4a2713aSLionel Sambuc void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
623*f4a2713aSLionel Sambuc   if (!Node->varlist_empty()) {
624*f4a2713aSLionel Sambuc     OS << "firstprivate";
625*f4a2713aSLionel Sambuc     VisitOMPClauseList(Node, '(');
626*f4a2713aSLionel Sambuc     OS << ")";
627*f4a2713aSLionel Sambuc   }
628*f4a2713aSLionel Sambuc }
629*f4a2713aSLionel Sambuc 
630*f4a2713aSLionel Sambuc void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
631*f4a2713aSLionel Sambuc   if (!Node->varlist_empty()) {
632*f4a2713aSLionel Sambuc     OS << "shared";
633*f4a2713aSLionel Sambuc     VisitOMPClauseList(Node, '(');
634*f4a2713aSLionel Sambuc     OS << ")";
635*f4a2713aSLionel Sambuc   }
636*f4a2713aSLionel Sambuc }
637*f4a2713aSLionel Sambuc 
638*f4a2713aSLionel Sambuc }
639*f4a2713aSLionel Sambuc 
640*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
641*f4a2713aSLionel Sambuc //  OpenMP directives printing methods
642*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
643*f4a2713aSLionel Sambuc 
644*f4a2713aSLionel Sambuc void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
645*f4a2713aSLionel Sambuc   Indent() << "#pragma omp parallel ";
646*f4a2713aSLionel Sambuc 
647*f4a2713aSLionel Sambuc   OMPClausePrinter Printer(OS);
648*f4a2713aSLionel Sambuc   ArrayRef<OMPClause *> Clauses = Node->clauses();
649*f4a2713aSLionel Sambuc   for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
650*f4a2713aSLionel Sambuc        I != E; ++I)
651*f4a2713aSLionel Sambuc     if (*I && !(*I)->isImplicit()) {
652*f4a2713aSLionel Sambuc       Printer.Visit(*I);
653*f4a2713aSLionel Sambuc       OS << ' ';
654*f4a2713aSLionel Sambuc     }
655*f4a2713aSLionel Sambuc   OS << "\n";
656*f4a2713aSLionel Sambuc   if (Node->getAssociatedStmt()) {
657*f4a2713aSLionel Sambuc     assert(isa<CapturedStmt>(Node->getAssociatedStmt()) &&
658*f4a2713aSLionel Sambuc            "Expected captured statement!");
659*f4a2713aSLionel Sambuc     Stmt *CS = cast<CapturedStmt>(Node->getAssociatedStmt())->getCapturedStmt();
660*f4a2713aSLionel Sambuc     PrintStmt(CS);
661*f4a2713aSLionel Sambuc   }
662*f4a2713aSLionel Sambuc }
663*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
664*f4a2713aSLionel Sambuc //  Expr printing methods.
665*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
666*f4a2713aSLionel Sambuc 
667*f4a2713aSLionel Sambuc void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
668*f4a2713aSLionel Sambuc   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
669*f4a2713aSLionel Sambuc     Qualifier->print(OS, Policy);
670*f4a2713aSLionel Sambuc   if (Node->hasTemplateKeyword())
671*f4a2713aSLionel Sambuc     OS << "template ";
672*f4a2713aSLionel Sambuc   OS << Node->getNameInfo();
673*f4a2713aSLionel Sambuc   if (Node->hasExplicitTemplateArgs())
674*f4a2713aSLionel Sambuc     TemplateSpecializationType::PrintTemplateArgumentList(
675*f4a2713aSLionel Sambuc         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
676*f4a2713aSLionel Sambuc }
677*f4a2713aSLionel Sambuc 
678*f4a2713aSLionel Sambuc void StmtPrinter::VisitDependentScopeDeclRefExpr(
679*f4a2713aSLionel Sambuc                                            DependentScopeDeclRefExpr *Node) {
680*f4a2713aSLionel Sambuc   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
681*f4a2713aSLionel Sambuc     Qualifier->print(OS, Policy);
682*f4a2713aSLionel Sambuc   if (Node->hasTemplateKeyword())
683*f4a2713aSLionel Sambuc     OS << "template ";
684*f4a2713aSLionel Sambuc   OS << Node->getNameInfo();
685*f4a2713aSLionel Sambuc   if (Node->hasExplicitTemplateArgs())
686*f4a2713aSLionel Sambuc     TemplateSpecializationType::PrintTemplateArgumentList(
687*f4a2713aSLionel Sambuc         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
688*f4a2713aSLionel Sambuc }
689*f4a2713aSLionel Sambuc 
690*f4a2713aSLionel Sambuc void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
691*f4a2713aSLionel Sambuc   if (Node->getQualifier())
692*f4a2713aSLionel Sambuc     Node->getQualifier()->print(OS, Policy);
693*f4a2713aSLionel Sambuc   if (Node->hasTemplateKeyword())
694*f4a2713aSLionel Sambuc     OS << "template ";
695*f4a2713aSLionel Sambuc   OS << Node->getNameInfo();
696*f4a2713aSLionel Sambuc   if (Node->hasExplicitTemplateArgs())
697*f4a2713aSLionel Sambuc     TemplateSpecializationType::PrintTemplateArgumentList(
698*f4a2713aSLionel Sambuc         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
699*f4a2713aSLionel Sambuc }
700*f4a2713aSLionel Sambuc 
701*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
702*f4a2713aSLionel Sambuc   if (Node->getBase()) {
703*f4a2713aSLionel Sambuc     PrintExpr(Node->getBase());
704*f4a2713aSLionel Sambuc     OS << (Node->isArrow() ? "->" : ".");
705*f4a2713aSLionel Sambuc   }
706*f4a2713aSLionel Sambuc   OS << *Node->getDecl();
707*f4a2713aSLionel Sambuc }
708*f4a2713aSLionel Sambuc 
709*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
710*f4a2713aSLionel Sambuc   if (Node->isSuperReceiver())
711*f4a2713aSLionel Sambuc     OS << "super.";
712*f4a2713aSLionel Sambuc   else if (Node->getBase()) {
713*f4a2713aSLionel Sambuc     PrintExpr(Node->getBase());
714*f4a2713aSLionel Sambuc     OS << ".";
715*f4a2713aSLionel Sambuc   }
716*f4a2713aSLionel Sambuc 
717*f4a2713aSLionel Sambuc   if (Node->isImplicitProperty())
718*f4a2713aSLionel Sambuc     OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
719*f4a2713aSLionel Sambuc   else
720*f4a2713aSLionel Sambuc     OS << Node->getExplicitProperty()->getName();
721*f4a2713aSLionel Sambuc }
722*f4a2713aSLionel Sambuc 
723*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
724*f4a2713aSLionel Sambuc 
725*f4a2713aSLionel Sambuc   PrintExpr(Node->getBaseExpr());
726*f4a2713aSLionel Sambuc   OS << "[";
727*f4a2713aSLionel Sambuc   PrintExpr(Node->getKeyExpr());
728*f4a2713aSLionel Sambuc   OS << "]";
729*f4a2713aSLionel Sambuc }
730*f4a2713aSLionel Sambuc 
731*f4a2713aSLionel Sambuc void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
732*f4a2713aSLionel Sambuc   switch (Node->getIdentType()) {
733*f4a2713aSLionel Sambuc     default:
734*f4a2713aSLionel Sambuc       llvm_unreachable("unknown case");
735*f4a2713aSLionel Sambuc     case PredefinedExpr::Func:
736*f4a2713aSLionel Sambuc       OS << "__func__";
737*f4a2713aSLionel Sambuc       break;
738*f4a2713aSLionel Sambuc     case PredefinedExpr::Function:
739*f4a2713aSLionel Sambuc       OS << "__FUNCTION__";
740*f4a2713aSLionel Sambuc       break;
741*f4a2713aSLionel Sambuc     case PredefinedExpr::FuncDName:
742*f4a2713aSLionel Sambuc       OS << "__FUNCDNAME__";
743*f4a2713aSLionel Sambuc       break;
744*f4a2713aSLionel Sambuc     case PredefinedExpr::LFunction:
745*f4a2713aSLionel Sambuc       OS << "L__FUNCTION__";
746*f4a2713aSLionel Sambuc       break;
747*f4a2713aSLionel Sambuc     case PredefinedExpr::PrettyFunction:
748*f4a2713aSLionel Sambuc       OS << "__PRETTY_FUNCTION__";
749*f4a2713aSLionel Sambuc       break;
750*f4a2713aSLionel Sambuc   }
751*f4a2713aSLionel Sambuc }
752*f4a2713aSLionel Sambuc 
753*f4a2713aSLionel Sambuc void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
754*f4a2713aSLionel Sambuc   unsigned value = Node->getValue();
755*f4a2713aSLionel Sambuc 
756*f4a2713aSLionel Sambuc   switch (Node->getKind()) {
757*f4a2713aSLionel Sambuc   case CharacterLiteral::Ascii: break; // no prefix.
758*f4a2713aSLionel Sambuc   case CharacterLiteral::Wide:  OS << 'L'; break;
759*f4a2713aSLionel Sambuc   case CharacterLiteral::UTF16: OS << 'u'; break;
760*f4a2713aSLionel Sambuc   case CharacterLiteral::UTF32: OS << 'U'; break;
761*f4a2713aSLionel Sambuc   }
762*f4a2713aSLionel Sambuc 
763*f4a2713aSLionel Sambuc   switch (value) {
764*f4a2713aSLionel Sambuc   case '\\':
765*f4a2713aSLionel Sambuc     OS << "'\\\\'";
766*f4a2713aSLionel Sambuc     break;
767*f4a2713aSLionel Sambuc   case '\'':
768*f4a2713aSLionel Sambuc     OS << "'\\''";
769*f4a2713aSLionel Sambuc     break;
770*f4a2713aSLionel Sambuc   case '\a':
771*f4a2713aSLionel Sambuc     // TODO: K&R: the meaning of '\\a' is different in traditional C
772*f4a2713aSLionel Sambuc     OS << "'\\a'";
773*f4a2713aSLionel Sambuc     break;
774*f4a2713aSLionel Sambuc   case '\b':
775*f4a2713aSLionel Sambuc     OS << "'\\b'";
776*f4a2713aSLionel Sambuc     break;
777*f4a2713aSLionel Sambuc   // Nonstandard escape sequence.
778*f4a2713aSLionel Sambuc   /*case '\e':
779*f4a2713aSLionel Sambuc     OS << "'\\e'";
780*f4a2713aSLionel Sambuc     break;*/
781*f4a2713aSLionel Sambuc   case '\f':
782*f4a2713aSLionel Sambuc     OS << "'\\f'";
783*f4a2713aSLionel Sambuc     break;
784*f4a2713aSLionel Sambuc   case '\n':
785*f4a2713aSLionel Sambuc     OS << "'\\n'";
786*f4a2713aSLionel Sambuc     break;
787*f4a2713aSLionel Sambuc   case '\r':
788*f4a2713aSLionel Sambuc     OS << "'\\r'";
789*f4a2713aSLionel Sambuc     break;
790*f4a2713aSLionel Sambuc   case '\t':
791*f4a2713aSLionel Sambuc     OS << "'\\t'";
792*f4a2713aSLionel Sambuc     break;
793*f4a2713aSLionel Sambuc   case '\v':
794*f4a2713aSLionel Sambuc     OS << "'\\v'";
795*f4a2713aSLionel Sambuc     break;
796*f4a2713aSLionel Sambuc   default:
797*f4a2713aSLionel Sambuc     if (value < 256 && isPrintable((unsigned char)value))
798*f4a2713aSLionel Sambuc       OS << "'" << (char)value << "'";
799*f4a2713aSLionel Sambuc     else if (value < 256)
800*f4a2713aSLionel Sambuc       OS << "'\\x" << llvm::format("%02x", value) << "'";
801*f4a2713aSLionel Sambuc     else if (value <= 0xFFFF)
802*f4a2713aSLionel Sambuc       OS << "'\\u" << llvm::format("%04x", value) << "'";
803*f4a2713aSLionel Sambuc     else
804*f4a2713aSLionel Sambuc       OS << "'\\U" << llvm::format("%08x", value) << "'";
805*f4a2713aSLionel Sambuc   }
806*f4a2713aSLionel Sambuc }
807*f4a2713aSLionel Sambuc 
808*f4a2713aSLionel Sambuc void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
809*f4a2713aSLionel Sambuc   bool isSigned = Node->getType()->isSignedIntegerType();
810*f4a2713aSLionel Sambuc   OS << Node->getValue().toString(10, isSigned);
811*f4a2713aSLionel Sambuc 
812*f4a2713aSLionel Sambuc   // Emit suffixes.  Integer literals are always a builtin integer type.
813*f4a2713aSLionel Sambuc   switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
814*f4a2713aSLionel Sambuc   default: llvm_unreachable("Unexpected type for integer literal!");
815*f4a2713aSLionel Sambuc   // FIXME: The Short and UShort cases are to handle cases where a short
816*f4a2713aSLionel Sambuc   // integeral literal is formed during template instantiation.  They should
817*f4a2713aSLionel Sambuc   // be removed when template instantiation no longer needs integer literals.
818*f4a2713aSLionel Sambuc   case BuiltinType::Short:
819*f4a2713aSLionel Sambuc   case BuiltinType::UShort:
820*f4a2713aSLionel Sambuc   case BuiltinType::Int:       break; // no suffix.
821*f4a2713aSLionel Sambuc   case BuiltinType::UInt:      OS << 'U'; break;
822*f4a2713aSLionel Sambuc   case BuiltinType::Long:      OS << 'L'; break;
823*f4a2713aSLionel Sambuc   case BuiltinType::ULong:     OS << "UL"; break;
824*f4a2713aSLionel Sambuc   case BuiltinType::LongLong:  OS << "LL"; break;
825*f4a2713aSLionel Sambuc   case BuiltinType::ULongLong: OS << "ULL"; break;
826*f4a2713aSLionel Sambuc   case BuiltinType::Int128:    OS << "i128"; break;
827*f4a2713aSLionel Sambuc   case BuiltinType::UInt128:   OS << "Ui128"; break;
828*f4a2713aSLionel Sambuc   }
829*f4a2713aSLionel Sambuc }
830*f4a2713aSLionel Sambuc 
831*f4a2713aSLionel Sambuc static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
832*f4a2713aSLionel Sambuc                                  bool PrintSuffix) {
833*f4a2713aSLionel Sambuc   SmallString<16> Str;
834*f4a2713aSLionel Sambuc   Node->getValue().toString(Str);
835*f4a2713aSLionel Sambuc   OS << Str;
836*f4a2713aSLionel Sambuc   if (Str.find_first_not_of("-0123456789") == StringRef::npos)
837*f4a2713aSLionel Sambuc     OS << '.'; // Trailing dot in order to separate from ints.
838*f4a2713aSLionel Sambuc 
839*f4a2713aSLionel Sambuc   if (!PrintSuffix)
840*f4a2713aSLionel Sambuc     return;
841*f4a2713aSLionel Sambuc 
842*f4a2713aSLionel Sambuc   // Emit suffixes.  Float literals are always a builtin float type.
843*f4a2713aSLionel Sambuc   switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
844*f4a2713aSLionel Sambuc   default: llvm_unreachable("Unexpected type for float literal!");
845*f4a2713aSLionel Sambuc   case BuiltinType::Half:       break; // FIXME: suffix?
846*f4a2713aSLionel Sambuc   case BuiltinType::Double:     break; // no suffix.
847*f4a2713aSLionel Sambuc   case BuiltinType::Float:      OS << 'F'; break;
848*f4a2713aSLionel Sambuc   case BuiltinType::LongDouble: OS << 'L'; break;
849*f4a2713aSLionel Sambuc   }
850*f4a2713aSLionel Sambuc }
851*f4a2713aSLionel Sambuc 
852*f4a2713aSLionel Sambuc void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
853*f4a2713aSLionel Sambuc   PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
854*f4a2713aSLionel Sambuc }
855*f4a2713aSLionel Sambuc 
856*f4a2713aSLionel Sambuc void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
857*f4a2713aSLionel Sambuc   PrintExpr(Node->getSubExpr());
858*f4a2713aSLionel Sambuc   OS << "i";
859*f4a2713aSLionel Sambuc }
860*f4a2713aSLionel Sambuc 
861*f4a2713aSLionel Sambuc void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
862*f4a2713aSLionel Sambuc   Str->outputString(OS);
863*f4a2713aSLionel Sambuc }
864*f4a2713aSLionel Sambuc void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
865*f4a2713aSLionel Sambuc   OS << "(";
866*f4a2713aSLionel Sambuc   PrintExpr(Node->getSubExpr());
867*f4a2713aSLionel Sambuc   OS << ")";
868*f4a2713aSLionel Sambuc }
869*f4a2713aSLionel Sambuc void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
870*f4a2713aSLionel Sambuc   if (!Node->isPostfix()) {
871*f4a2713aSLionel Sambuc     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
872*f4a2713aSLionel Sambuc 
873*f4a2713aSLionel Sambuc     // Print a space if this is an "identifier operator" like __real, or if
874*f4a2713aSLionel Sambuc     // it might be concatenated incorrectly like '+'.
875*f4a2713aSLionel Sambuc     switch (Node->getOpcode()) {
876*f4a2713aSLionel Sambuc     default: break;
877*f4a2713aSLionel Sambuc     case UO_Real:
878*f4a2713aSLionel Sambuc     case UO_Imag:
879*f4a2713aSLionel Sambuc     case UO_Extension:
880*f4a2713aSLionel Sambuc       OS << ' ';
881*f4a2713aSLionel Sambuc       break;
882*f4a2713aSLionel Sambuc     case UO_Plus:
883*f4a2713aSLionel Sambuc     case UO_Minus:
884*f4a2713aSLionel Sambuc       if (isa<UnaryOperator>(Node->getSubExpr()))
885*f4a2713aSLionel Sambuc         OS << ' ';
886*f4a2713aSLionel Sambuc       break;
887*f4a2713aSLionel Sambuc     }
888*f4a2713aSLionel Sambuc   }
889*f4a2713aSLionel Sambuc   PrintExpr(Node->getSubExpr());
890*f4a2713aSLionel Sambuc 
891*f4a2713aSLionel Sambuc   if (Node->isPostfix())
892*f4a2713aSLionel Sambuc     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
893*f4a2713aSLionel Sambuc }
894*f4a2713aSLionel Sambuc 
895*f4a2713aSLionel Sambuc void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
896*f4a2713aSLionel Sambuc   OS << "__builtin_offsetof(";
897*f4a2713aSLionel Sambuc   Node->getTypeSourceInfo()->getType().print(OS, Policy);
898*f4a2713aSLionel Sambuc   OS << ", ";
899*f4a2713aSLionel Sambuc   bool PrintedSomething = false;
900*f4a2713aSLionel Sambuc   for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
901*f4a2713aSLionel Sambuc     OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i);
902*f4a2713aSLionel Sambuc     if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Array) {
903*f4a2713aSLionel Sambuc       // Array node
904*f4a2713aSLionel Sambuc       OS << "[";
905*f4a2713aSLionel Sambuc       PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
906*f4a2713aSLionel Sambuc       OS << "]";
907*f4a2713aSLionel Sambuc       PrintedSomething = true;
908*f4a2713aSLionel Sambuc       continue;
909*f4a2713aSLionel Sambuc     }
910*f4a2713aSLionel Sambuc 
911*f4a2713aSLionel Sambuc     // Skip implicit base indirections.
912*f4a2713aSLionel Sambuc     if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Base)
913*f4a2713aSLionel Sambuc       continue;
914*f4a2713aSLionel Sambuc 
915*f4a2713aSLionel Sambuc     // Field or identifier node.
916*f4a2713aSLionel Sambuc     IdentifierInfo *Id = ON.getFieldName();
917*f4a2713aSLionel Sambuc     if (!Id)
918*f4a2713aSLionel Sambuc       continue;
919*f4a2713aSLionel Sambuc 
920*f4a2713aSLionel Sambuc     if (PrintedSomething)
921*f4a2713aSLionel Sambuc       OS << ".";
922*f4a2713aSLionel Sambuc     else
923*f4a2713aSLionel Sambuc       PrintedSomething = true;
924*f4a2713aSLionel Sambuc     OS << Id->getName();
925*f4a2713aSLionel Sambuc   }
926*f4a2713aSLionel Sambuc   OS << ")";
927*f4a2713aSLionel Sambuc }
928*f4a2713aSLionel Sambuc 
929*f4a2713aSLionel Sambuc void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
930*f4a2713aSLionel Sambuc   switch(Node->getKind()) {
931*f4a2713aSLionel Sambuc   case UETT_SizeOf:
932*f4a2713aSLionel Sambuc     OS << "sizeof";
933*f4a2713aSLionel Sambuc     break;
934*f4a2713aSLionel Sambuc   case UETT_AlignOf:
935*f4a2713aSLionel Sambuc     if (Policy.LangOpts.CPlusPlus)
936*f4a2713aSLionel Sambuc       OS << "alignof";
937*f4a2713aSLionel Sambuc     else if (Policy.LangOpts.C11)
938*f4a2713aSLionel Sambuc       OS << "_Alignof";
939*f4a2713aSLionel Sambuc     else
940*f4a2713aSLionel Sambuc       OS << "__alignof";
941*f4a2713aSLionel Sambuc     break;
942*f4a2713aSLionel Sambuc   case UETT_VecStep:
943*f4a2713aSLionel Sambuc     OS << "vec_step";
944*f4a2713aSLionel Sambuc     break;
945*f4a2713aSLionel Sambuc   }
946*f4a2713aSLionel Sambuc   if (Node->isArgumentType()) {
947*f4a2713aSLionel Sambuc     OS << '(';
948*f4a2713aSLionel Sambuc     Node->getArgumentType().print(OS, Policy);
949*f4a2713aSLionel Sambuc     OS << ')';
950*f4a2713aSLionel Sambuc   } else {
951*f4a2713aSLionel Sambuc     OS << " ";
952*f4a2713aSLionel Sambuc     PrintExpr(Node->getArgumentExpr());
953*f4a2713aSLionel Sambuc   }
954*f4a2713aSLionel Sambuc }
955*f4a2713aSLionel Sambuc 
956*f4a2713aSLionel Sambuc void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
957*f4a2713aSLionel Sambuc   OS << "_Generic(";
958*f4a2713aSLionel Sambuc   PrintExpr(Node->getControllingExpr());
959*f4a2713aSLionel Sambuc   for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
960*f4a2713aSLionel Sambuc     OS << ", ";
961*f4a2713aSLionel Sambuc     QualType T = Node->getAssocType(i);
962*f4a2713aSLionel Sambuc     if (T.isNull())
963*f4a2713aSLionel Sambuc       OS << "default";
964*f4a2713aSLionel Sambuc     else
965*f4a2713aSLionel Sambuc       T.print(OS, Policy);
966*f4a2713aSLionel Sambuc     OS << ": ";
967*f4a2713aSLionel Sambuc     PrintExpr(Node->getAssocExpr(i));
968*f4a2713aSLionel Sambuc   }
969*f4a2713aSLionel Sambuc   OS << ")";
970*f4a2713aSLionel Sambuc }
971*f4a2713aSLionel Sambuc 
972*f4a2713aSLionel Sambuc void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
973*f4a2713aSLionel Sambuc   PrintExpr(Node->getLHS());
974*f4a2713aSLionel Sambuc   OS << "[";
975*f4a2713aSLionel Sambuc   PrintExpr(Node->getRHS());
976*f4a2713aSLionel Sambuc   OS << "]";
977*f4a2713aSLionel Sambuc }
978*f4a2713aSLionel Sambuc 
979*f4a2713aSLionel Sambuc void StmtPrinter::PrintCallArgs(CallExpr *Call) {
980*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
981*f4a2713aSLionel Sambuc     if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
982*f4a2713aSLionel Sambuc       // Don't print any defaulted arguments
983*f4a2713aSLionel Sambuc       break;
984*f4a2713aSLionel Sambuc     }
985*f4a2713aSLionel Sambuc 
986*f4a2713aSLionel Sambuc     if (i) OS << ", ";
987*f4a2713aSLionel Sambuc     PrintExpr(Call->getArg(i));
988*f4a2713aSLionel Sambuc   }
989*f4a2713aSLionel Sambuc }
990*f4a2713aSLionel Sambuc 
991*f4a2713aSLionel Sambuc void StmtPrinter::VisitCallExpr(CallExpr *Call) {
992*f4a2713aSLionel Sambuc   PrintExpr(Call->getCallee());
993*f4a2713aSLionel Sambuc   OS << "(";
994*f4a2713aSLionel Sambuc   PrintCallArgs(Call);
995*f4a2713aSLionel Sambuc   OS << ")";
996*f4a2713aSLionel Sambuc }
997*f4a2713aSLionel Sambuc void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
998*f4a2713aSLionel Sambuc   // FIXME: Suppress printing implicit bases (like "this")
999*f4a2713aSLionel Sambuc   PrintExpr(Node->getBase());
1000*f4a2713aSLionel Sambuc 
1001*f4a2713aSLionel Sambuc   MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
1002*f4a2713aSLionel Sambuc   FieldDecl  *ParentDecl   = ParentMember
1003*f4a2713aSLionel Sambuc     ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()) : NULL;
1004*f4a2713aSLionel Sambuc 
1005*f4a2713aSLionel Sambuc   if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
1006*f4a2713aSLionel Sambuc     OS << (Node->isArrow() ? "->" : ".");
1007*f4a2713aSLionel Sambuc 
1008*f4a2713aSLionel Sambuc   if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1009*f4a2713aSLionel Sambuc     if (FD->isAnonymousStructOrUnion())
1010*f4a2713aSLionel Sambuc       return;
1011*f4a2713aSLionel Sambuc 
1012*f4a2713aSLionel Sambuc   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1013*f4a2713aSLionel Sambuc     Qualifier->print(OS, Policy);
1014*f4a2713aSLionel Sambuc   if (Node->hasTemplateKeyword())
1015*f4a2713aSLionel Sambuc     OS << "template ";
1016*f4a2713aSLionel Sambuc   OS << Node->getMemberNameInfo();
1017*f4a2713aSLionel Sambuc   if (Node->hasExplicitTemplateArgs())
1018*f4a2713aSLionel Sambuc     TemplateSpecializationType::PrintTemplateArgumentList(
1019*f4a2713aSLionel Sambuc         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1020*f4a2713aSLionel Sambuc }
1021*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1022*f4a2713aSLionel Sambuc   PrintExpr(Node->getBase());
1023*f4a2713aSLionel Sambuc   OS << (Node->isArrow() ? "->isa" : ".isa");
1024*f4a2713aSLionel Sambuc }
1025*f4a2713aSLionel Sambuc 
1026*f4a2713aSLionel Sambuc void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
1027*f4a2713aSLionel Sambuc   PrintExpr(Node->getBase());
1028*f4a2713aSLionel Sambuc   OS << ".";
1029*f4a2713aSLionel Sambuc   OS << Node->getAccessor().getName();
1030*f4a2713aSLionel Sambuc }
1031*f4a2713aSLionel Sambuc void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
1032*f4a2713aSLionel Sambuc   OS << '(';
1033*f4a2713aSLionel Sambuc   Node->getTypeAsWritten().print(OS, Policy);
1034*f4a2713aSLionel Sambuc   OS << ')';
1035*f4a2713aSLionel Sambuc   PrintExpr(Node->getSubExpr());
1036*f4a2713aSLionel Sambuc }
1037*f4a2713aSLionel Sambuc void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
1038*f4a2713aSLionel Sambuc   OS << '(';
1039*f4a2713aSLionel Sambuc   Node->getType().print(OS, Policy);
1040*f4a2713aSLionel Sambuc   OS << ')';
1041*f4a2713aSLionel Sambuc   PrintExpr(Node->getInitializer());
1042*f4a2713aSLionel Sambuc }
1043*f4a2713aSLionel Sambuc void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
1044*f4a2713aSLionel Sambuc   // No need to print anything, simply forward to the sub expression.
1045*f4a2713aSLionel Sambuc   PrintExpr(Node->getSubExpr());
1046*f4a2713aSLionel Sambuc }
1047*f4a2713aSLionel Sambuc void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1048*f4a2713aSLionel Sambuc   PrintExpr(Node->getLHS());
1049*f4a2713aSLionel Sambuc   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1050*f4a2713aSLionel Sambuc   PrintExpr(Node->getRHS());
1051*f4a2713aSLionel Sambuc }
1052*f4a2713aSLionel Sambuc void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1053*f4a2713aSLionel Sambuc   PrintExpr(Node->getLHS());
1054*f4a2713aSLionel Sambuc   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1055*f4a2713aSLionel Sambuc   PrintExpr(Node->getRHS());
1056*f4a2713aSLionel Sambuc }
1057*f4a2713aSLionel Sambuc void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1058*f4a2713aSLionel Sambuc   PrintExpr(Node->getCond());
1059*f4a2713aSLionel Sambuc   OS << " ? ";
1060*f4a2713aSLionel Sambuc   PrintExpr(Node->getLHS());
1061*f4a2713aSLionel Sambuc   OS << " : ";
1062*f4a2713aSLionel Sambuc   PrintExpr(Node->getRHS());
1063*f4a2713aSLionel Sambuc }
1064*f4a2713aSLionel Sambuc 
1065*f4a2713aSLionel Sambuc // GNU extensions.
1066*f4a2713aSLionel Sambuc 
1067*f4a2713aSLionel Sambuc void
1068*f4a2713aSLionel Sambuc StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1069*f4a2713aSLionel Sambuc   PrintExpr(Node->getCommon());
1070*f4a2713aSLionel Sambuc   OS << " ?: ";
1071*f4a2713aSLionel Sambuc   PrintExpr(Node->getFalseExpr());
1072*f4a2713aSLionel Sambuc }
1073*f4a2713aSLionel Sambuc void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
1074*f4a2713aSLionel Sambuc   OS << "&&" << Node->getLabel()->getName();
1075*f4a2713aSLionel Sambuc }
1076*f4a2713aSLionel Sambuc 
1077*f4a2713aSLionel Sambuc void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1078*f4a2713aSLionel Sambuc   OS << "(";
1079*f4a2713aSLionel Sambuc   PrintRawCompoundStmt(E->getSubStmt());
1080*f4a2713aSLionel Sambuc   OS << ")";
1081*f4a2713aSLionel Sambuc }
1082*f4a2713aSLionel Sambuc 
1083*f4a2713aSLionel Sambuc void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1084*f4a2713aSLionel Sambuc   OS << "__builtin_choose_expr(";
1085*f4a2713aSLionel Sambuc   PrintExpr(Node->getCond());
1086*f4a2713aSLionel Sambuc   OS << ", ";
1087*f4a2713aSLionel Sambuc   PrintExpr(Node->getLHS());
1088*f4a2713aSLionel Sambuc   OS << ", ";
1089*f4a2713aSLionel Sambuc   PrintExpr(Node->getRHS());
1090*f4a2713aSLionel Sambuc   OS << ")";
1091*f4a2713aSLionel Sambuc }
1092*f4a2713aSLionel Sambuc 
1093*f4a2713aSLionel Sambuc void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1094*f4a2713aSLionel Sambuc   OS << "__null";
1095*f4a2713aSLionel Sambuc }
1096*f4a2713aSLionel Sambuc 
1097*f4a2713aSLionel Sambuc void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1098*f4a2713aSLionel Sambuc   OS << "__builtin_shufflevector(";
1099*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
1100*f4a2713aSLionel Sambuc     if (i) OS << ", ";
1101*f4a2713aSLionel Sambuc     PrintExpr(Node->getExpr(i));
1102*f4a2713aSLionel Sambuc   }
1103*f4a2713aSLionel Sambuc   OS << ")";
1104*f4a2713aSLionel Sambuc }
1105*f4a2713aSLionel Sambuc 
1106*f4a2713aSLionel Sambuc void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1107*f4a2713aSLionel Sambuc   OS << "__builtin_convertvector(";
1108*f4a2713aSLionel Sambuc   PrintExpr(Node->getSrcExpr());
1109*f4a2713aSLionel Sambuc   OS << ", ";
1110*f4a2713aSLionel Sambuc   Node->getType().print(OS, Policy);
1111*f4a2713aSLionel Sambuc   OS << ")";
1112*f4a2713aSLionel Sambuc }
1113*f4a2713aSLionel Sambuc 
1114*f4a2713aSLionel Sambuc void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
1115*f4a2713aSLionel Sambuc   if (Node->getSyntacticForm()) {
1116*f4a2713aSLionel Sambuc     Visit(Node->getSyntacticForm());
1117*f4a2713aSLionel Sambuc     return;
1118*f4a2713aSLionel Sambuc   }
1119*f4a2713aSLionel Sambuc 
1120*f4a2713aSLionel Sambuc   OS << "{ ";
1121*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
1122*f4a2713aSLionel Sambuc     if (i) OS << ", ";
1123*f4a2713aSLionel Sambuc     if (Node->getInit(i))
1124*f4a2713aSLionel Sambuc       PrintExpr(Node->getInit(i));
1125*f4a2713aSLionel Sambuc     else
1126*f4a2713aSLionel Sambuc       OS << "0";
1127*f4a2713aSLionel Sambuc   }
1128*f4a2713aSLionel Sambuc   OS << " }";
1129*f4a2713aSLionel Sambuc }
1130*f4a2713aSLionel Sambuc 
1131*f4a2713aSLionel Sambuc void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1132*f4a2713aSLionel Sambuc   OS << "( ";
1133*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
1134*f4a2713aSLionel Sambuc     if (i) OS << ", ";
1135*f4a2713aSLionel Sambuc     PrintExpr(Node->getExpr(i));
1136*f4a2713aSLionel Sambuc   }
1137*f4a2713aSLionel Sambuc   OS << " )";
1138*f4a2713aSLionel Sambuc }
1139*f4a2713aSLionel Sambuc 
1140*f4a2713aSLionel Sambuc void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
1141*f4a2713aSLionel Sambuc   for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
1142*f4a2713aSLionel Sambuc                       DEnd = Node->designators_end();
1143*f4a2713aSLionel Sambuc        D != DEnd; ++D) {
1144*f4a2713aSLionel Sambuc     if (D->isFieldDesignator()) {
1145*f4a2713aSLionel Sambuc       if (D->getDotLoc().isInvalid())
1146*f4a2713aSLionel Sambuc         OS << D->getFieldName()->getName() << ":";
1147*f4a2713aSLionel Sambuc       else
1148*f4a2713aSLionel Sambuc         OS << "." << D->getFieldName()->getName();
1149*f4a2713aSLionel Sambuc     } else {
1150*f4a2713aSLionel Sambuc       OS << "[";
1151*f4a2713aSLionel Sambuc       if (D->isArrayDesignator()) {
1152*f4a2713aSLionel Sambuc         PrintExpr(Node->getArrayIndex(*D));
1153*f4a2713aSLionel Sambuc       } else {
1154*f4a2713aSLionel Sambuc         PrintExpr(Node->getArrayRangeStart(*D));
1155*f4a2713aSLionel Sambuc         OS << " ... ";
1156*f4a2713aSLionel Sambuc         PrintExpr(Node->getArrayRangeEnd(*D));
1157*f4a2713aSLionel Sambuc       }
1158*f4a2713aSLionel Sambuc       OS << "]";
1159*f4a2713aSLionel Sambuc     }
1160*f4a2713aSLionel Sambuc   }
1161*f4a2713aSLionel Sambuc 
1162*f4a2713aSLionel Sambuc   OS << " = ";
1163*f4a2713aSLionel Sambuc   PrintExpr(Node->getInit());
1164*f4a2713aSLionel Sambuc }
1165*f4a2713aSLionel Sambuc 
1166*f4a2713aSLionel Sambuc void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
1167*f4a2713aSLionel Sambuc   if (Policy.LangOpts.CPlusPlus) {
1168*f4a2713aSLionel Sambuc     OS << "/*implicit*/";
1169*f4a2713aSLionel Sambuc     Node->getType().print(OS, Policy);
1170*f4a2713aSLionel Sambuc     OS << "()";
1171*f4a2713aSLionel Sambuc   } else {
1172*f4a2713aSLionel Sambuc     OS << "/*implicit*/(";
1173*f4a2713aSLionel Sambuc     Node->getType().print(OS, Policy);
1174*f4a2713aSLionel Sambuc     OS << ')';
1175*f4a2713aSLionel Sambuc     if (Node->getType()->isRecordType())
1176*f4a2713aSLionel Sambuc       OS << "{}";
1177*f4a2713aSLionel Sambuc     else
1178*f4a2713aSLionel Sambuc       OS << 0;
1179*f4a2713aSLionel Sambuc   }
1180*f4a2713aSLionel Sambuc }
1181*f4a2713aSLionel Sambuc 
1182*f4a2713aSLionel Sambuc void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
1183*f4a2713aSLionel Sambuc   OS << "__builtin_va_arg(";
1184*f4a2713aSLionel Sambuc   PrintExpr(Node->getSubExpr());
1185*f4a2713aSLionel Sambuc   OS << ", ";
1186*f4a2713aSLionel Sambuc   Node->getType().print(OS, Policy);
1187*f4a2713aSLionel Sambuc   OS << ")";
1188*f4a2713aSLionel Sambuc }
1189*f4a2713aSLionel Sambuc 
1190*f4a2713aSLionel Sambuc void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1191*f4a2713aSLionel Sambuc   PrintExpr(Node->getSyntacticForm());
1192*f4a2713aSLionel Sambuc }
1193*f4a2713aSLionel Sambuc 
1194*f4a2713aSLionel Sambuc void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
1195*f4a2713aSLionel Sambuc   const char *Name = 0;
1196*f4a2713aSLionel Sambuc   switch (Node->getOp()) {
1197*f4a2713aSLionel Sambuc #define BUILTIN(ID, TYPE, ATTRS)
1198*f4a2713aSLionel Sambuc #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1199*f4a2713aSLionel Sambuc   case AtomicExpr::AO ## ID: \
1200*f4a2713aSLionel Sambuc     Name = #ID "("; \
1201*f4a2713aSLionel Sambuc     break;
1202*f4a2713aSLionel Sambuc #include "clang/Basic/Builtins.def"
1203*f4a2713aSLionel Sambuc   }
1204*f4a2713aSLionel Sambuc   OS << Name;
1205*f4a2713aSLionel Sambuc 
1206*f4a2713aSLionel Sambuc   // AtomicExpr stores its subexpressions in a permuted order.
1207*f4a2713aSLionel Sambuc   PrintExpr(Node->getPtr());
1208*f4a2713aSLionel Sambuc   if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1209*f4a2713aSLionel Sambuc       Node->getOp() != AtomicExpr::AO__atomic_load_n) {
1210*f4a2713aSLionel Sambuc     OS << ", ";
1211*f4a2713aSLionel Sambuc     PrintExpr(Node->getVal1());
1212*f4a2713aSLionel Sambuc   }
1213*f4a2713aSLionel Sambuc   if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1214*f4a2713aSLionel Sambuc       Node->isCmpXChg()) {
1215*f4a2713aSLionel Sambuc     OS << ", ";
1216*f4a2713aSLionel Sambuc     PrintExpr(Node->getVal2());
1217*f4a2713aSLionel Sambuc   }
1218*f4a2713aSLionel Sambuc   if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1219*f4a2713aSLionel Sambuc       Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
1220*f4a2713aSLionel Sambuc     OS << ", ";
1221*f4a2713aSLionel Sambuc     PrintExpr(Node->getWeak());
1222*f4a2713aSLionel Sambuc   }
1223*f4a2713aSLionel Sambuc   if (Node->getOp() != AtomicExpr::AO__c11_atomic_init) {
1224*f4a2713aSLionel Sambuc     OS << ", ";
1225*f4a2713aSLionel Sambuc     PrintExpr(Node->getOrder());
1226*f4a2713aSLionel Sambuc   }
1227*f4a2713aSLionel Sambuc   if (Node->isCmpXChg()) {
1228*f4a2713aSLionel Sambuc     OS << ", ";
1229*f4a2713aSLionel Sambuc     PrintExpr(Node->getOrderFail());
1230*f4a2713aSLionel Sambuc   }
1231*f4a2713aSLionel Sambuc   OS << ")";
1232*f4a2713aSLionel Sambuc }
1233*f4a2713aSLionel Sambuc 
1234*f4a2713aSLionel Sambuc // C++
1235*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1236*f4a2713aSLionel Sambuc   const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
1237*f4a2713aSLionel Sambuc     "",
1238*f4a2713aSLionel Sambuc #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1239*f4a2713aSLionel Sambuc     Spelling,
1240*f4a2713aSLionel Sambuc #include "clang/Basic/OperatorKinds.def"
1241*f4a2713aSLionel Sambuc   };
1242*f4a2713aSLionel Sambuc 
1243*f4a2713aSLionel Sambuc   OverloadedOperatorKind Kind = Node->getOperator();
1244*f4a2713aSLionel Sambuc   if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1245*f4a2713aSLionel Sambuc     if (Node->getNumArgs() == 1) {
1246*f4a2713aSLionel Sambuc       OS << OpStrings[Kind] << ' ';
1247*f4a2713aSLionel Sambuc       PrintExpr(Node->getArg(0));
1248*f4a2713aSLionel Sambuc     } else {
1249*f4a2713aSLionel Sambuc       PrintExpr(Node->getArg(0));
1250*f4a2713aSLionel Sambuc       OS << ' ' << OpStrings[Kind];
1251*f4a2713aSLionel Sambuc     }
1252*f4a2713aSLionel Sambuc   } else if (Kind == OO_Arrow) {
1253*f4a2713aSLionel Sambuc     PrintExpr(Node->getArg(0));
1254*f4a2713aSLionel Sambuc   } else if (Kind == OO_Call) {
1255*f4a2713aSLionel Sambuc     PrintExpr(Node->getArg(0));
1256*f4a2713aSLionel Sambuc     OS << '(';
1257*f4a2713aSLionel Sambuc     for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1258*f4a2713aSLionel Sambuc       if (ArgIdx > 1)
1259*f4a2713aSLionel Sambuc         OS << ", ";
1260*f4a2713aSLionel Sambuc       if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1261*f4a2713aSLionel Sambuc         PrintExpr(Node->getArg(ArgIdx));
1262*f4a2713aSLionel Sambuc     }
1263*f4a2713aSLionel Sambuc     OS << ')';
1264*f4a2713aSLionel Sambuc   } else if (Kind == OO_Subscript) {
1265*f4a2713aSLionel Sambuc     PrintExpr(Node->getArg(0));
1266*f4a2713aSLionel Sambuc     OS << '[';
1267*f4a2713aSLionel Sambuc     PrintExpr(Node->getArg(1));
1268*f4a2713aSLionel Sambuc     OS << ']';
1269*f4a2713aSLionel Sambuc   } else if (Node->getNumArgs() == 1) {
1270*f4a2713aSLionel Sambuc     OS << OpStrings[Kind] << ' ';
1271*f4a2713aSLionel Sambuc     PrintExpr(Node->getArg(0));
1272*f4a2713aSLionel Sambuc   } else if (Node->getNumArgs() == 2) {
1273*f4a2713aSLionel Sambuc     PrintExpr(Node->getArg(0));
1274*f4a2713aSLionel Sambuc     OS << ' ' << OpStrings[Kind] << ' ';
1275*f4a2713aSLionel Sambuc     PrintExpr(Node->getArg(1));
1276*f4a2713aSLionel Sambuc   } else {
1277*f4a2713aSLionel Sambuc     llvm_unreachable("unknown overloaded operator");
1278*f4a2713aSLionel Sambuc   }
1279*f4a2713aSLionel Sambuc }
1280*f4a2713aSLionel Sambuc 
1281*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
1282*f4a2713aSLionel Sambuc   VisitCallExpr(cast<CallExpr>(Node));
1283*f4a2713aSLionel Sambuc }
1284*f4a2713aSLionel Sambuc 
1285*f4a2713aSLionel Sambuc void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
1286*f4a2713aSLionel Sambuc   PrintExpr(Node->getCallee());
1287*f4a2713aSLionel Sambuc   OS << "<<<";
1288*f4a2713aSLionel Sambuc   PrintCallArgs(Node->getConfig());
1289*f4a2713aSLionel Sambuc   OS << ">>>(";
1290*f4a2713aSLionel Sambuc   PrintCallArgs(Node);
1291*f4a2713aSLionel Sambuc   OS << ")";
1292*f4a2713aSLionel Sambuc }
1293*f4a2713aSLionel Sambuc 
1294*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
1295*f4a2713aSLionel Sambuc   OS << Node->getCastName() << '<';
1296*f4a2713aSLionel Sambuc   Node->getTypeAsWritten().print(OS, Policy);
1297*f4a2713aSLionel Sambuc   OS << ">(";
1298*f4a2713aSLionel Sambuc   PrintExpr(Node->getSubExpr());
1299*f4a2713aSLionel Sambuc   OS << ")";
1300*f4a2713aSLionel Sambuc }
1301*f4a2713aSLionel Sambuc 
1302*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
1303*f4a2713aSLionel Sambuc   VisitCXXNamedCastExpr(Node);
1304*f4a2713aSLionel Sambuc }
1305*f4a2713aSLionel Sambuc 
1306*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
1307*f4a2713aSLionel Sambuc   VisitCXXNamedCastExpr(Node);
1308*f4a2713aSLionel Sambuc }
1309*f4a2713aSLionel Sambuc 
1310*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
1311*f4a2713aSLionel Sambuc   VisitCXXNamedCastExpr(Node);
1312*f4a2713aSLionel Sambuc }
1313*f4a2713aSLionel Sambuc 
1314*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
1315*f4a2713aSLionel Sambuc   VisitCXXNamedCastExpr(Node);
1316*f4a2713aSLionel Sambuc }
1317*f4a2713aSLionel Sambuc 
1318*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
1319*f4a2713aSLionel Sambuc   OS << "typeid(";
1320*f4a2713aSLionel Sambuc   if (Node->isTypeOperand()) {
1321*f4a2713aSLionel Sambuc     Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1322*f4a2713aSLionel Sambuc   } else {
1323*f4a2713aSLionel Sambuc     PrintExpr(Node->getExprOperand());
1324*f4a2713aSLionel Sambuc   }
1325*f4a2713aSLionel Sambuc   OS << ")";
1326*f4a2713aSLionel Sambuc }
1327*f4a2713aSLionel Sambuc 
1328*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
1329*f4a2713aSLionel Sambuc   OS << "__uuidof(";
1330*f4a2713aSLionel Sambuc   if (Node->isTypeOperand()) {
1331*f4a2713aSLionel Sambuc     Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1332*f4a2713aSLionel Sambuc   } else {
1333*f4a2713aSLionel Sambuc     PrintExpr(Node->getExprOperand());
1334*f4a2713aSLionel Sambuc   }
1335*f4a2713aSLionel Sambuc   OS << ")";
1336*f4a2713aSLionel Sambuc }
1337*f4a2713aSLionel Sambuc 
1338*f4a2713aSLionel Sambuc void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
1339*f4a2713aSLionel Sambuc   PrintExpr(Node->getBaseExpr());
1340*f4a2713aSLionel Sambuc   if (Node->isArrow())
1341*f4a2713aSLionel Sambuc     OS << "->";
1342*f4a2713aSLionel Sambuc   else
1343*f4a2713aSLionel Sambuc     OS << ".";
1344*f4a2713aSLionel Sambuc   if (NestedNameSpecifier *Qualifier =
1345*f4a2713aSLionel Sambuc       Node->getQualifierLoc().getNestedNameSpecifier())
1346*f4a2713aSLionel Sambuc     Qualifier->print(OS, Policy);
1347*f4a2713aSLionel Sambuc   OS << Node->getPropertyDecl()->getDeclName();
1348*f4a2713aSLionel Sambuc }
1349*f4a2713aSLionel Sambuc 
1350*f4a2713aSLionel Sambuc void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
1351*f4a2713aSLionel Sambuc   switch (Node->getLiteralOperatorKind()) {
1352*f4a2713aSLionel Sambuc   case UserDefinedLiteral::LOK_Raw:
1353*f4a2713aSLionel Sambuc     OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
1354*f4a2713aSLionel Sambuc     break;
1355*f4a2713aSLionel Sambuc   case UserDefinedLiteral::LOK_Template: {
1356*f4a2713aSLionel Sambuc     DeclRefExpr *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
1357*f4a2713aSLionel Sambuc     const TemplateArgumentList *Args =
1358*f4a2713aSLionel Sambuc       cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
1359*f4a2713aSLionel Sambuc     assert(Args);
1360*f4a2713aSLionel Sambuc     const TemplateArgument &Pack = Args->get(0);
1361*f4a2713aSLionel Sambuc     for (TemplateArgument::pack_iterator I = Pack.pack_begin(),
1362*f4a2713aSLionel Sambuc                                          E = Pack.pack_end(); I != E; ++I) {
1363*f4a2713aSLionel Sambuc       char C = (char)I->getAsIntegral().getZExtValue();
1364*f4a2713aSLionel Sambuc       OS << C;
1365*f4a2713aSLionel Sambuc     }
1366*f4a2713aSLionel Sambuc     break;
1367*f4a2713aSLionel Sambuc   }
1368*f4a2713aSLionel Sambuc   case UserDefinedLiteral::LOK_Integer: {
1369*f4a2713aSLionel Sambuc     // Print integer literal without suffix.
1370*f4a2713aSLionel Sambuc     IntegerLiteral *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
1371*f4a2713aSLionel Sambuc     OS << Int->getValue().toString(10, /*isSigned*/false);
1372*f4a2713aSLionel Sambuc     break;
1373*f4a2713aSLionel Sambuc   }
1374*f4a2713aSLionel Sambuc   case UserDefinedLiteral::LOK_Floating: {
1375*f4a2713aSLionel Sambuc     // Print floating literal without suffix.
1376*f4a2713aSLionel Sambuc     FloatingLiteral *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
1377*f4a2713aSLionel Sambuc     PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
1378*f4a2713aSLionel Sambuc     break;
1379*f4a2713aSLionel Sambuc   }
1380*f4a2713aSLionel Sambuc   case UserDefinedLiteral::LOK_String:
1381*f4a2713aSLionel Sambuc   case UserDefinedLiteral::LOK_Character:
1382*f4a2713aSLionel Sambuc     PrintExpr(Node->getCookedLiteral());
1383*f4a2713aSLionel Sambuc     break;
1384*f4a2713aSLionel Sambuc   }
1385*f4a2713aSLionel Sambuc   OS << Node->getUDSuffix()->getName();
1386*f4a2713aSLionel Sambuc }
1387*f4a2713aSLionel Sambuc 
1388*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
1389*f4a2713aSLionel Sambuc   OS << (Node->getValue() ? "true" : "false");
1390*f4a2713aSLionel Sambuc }
1391*f4a2713aSLionel Sambuc 
1392*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1393*f4a2713aSLionel Sambuc   OS << "nullptr";
1394*f4a2713aSLionel Sambuc }
1395*f4a2713aSLionel Sambuc 
1396*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1397*f4a2713aSLionel Sambuc   OS << "this";
1398*f4a2713aSLionel Sambuc }
1399*f4a2713aSLionel Sambuc 
1400*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
1401*f4a2713aSLionel Sambuc   if (Node->getSubExpr() == 0)
1402*f4a2713aSLionel Sambuc     OS << "throw";
1403*f4a2713aSLionel Sambuc   else {
1404*f4a2713aSLionel Sambuc     OS << "throw ";
1405*f4a2713aSLionel Sambuc     PrintExpr(Node->getSubExpr());
1406*f4a2713aSLionel Sambuc   }
1407*f4a2713aSLionel Sambuc }
1408*f4a2713aSLionel Sambuc 
1409*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
1410*f4a2713aSLionel Sambuc   // Nothing to print: we picked up the default argument.
1411*f4a2713aSLionel Sambuc }
1412*f4a2713aSLionel Sambuc 
1413*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
1414*f4a2713aSLionel Sambuc   // Nothing to print: we picked up the default initializer.
1415*f4a2713aSLionel Sambuc }
1416*f4a2713aSLionel Sambuc 
1417*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
1418*f4a2713aSLionel Sambuc   Node->getType().print(OS, Policy);
1419*f4a2713aSLionel Sambuc   OS << "(";
1420*f4a2713aSLionel Sambuc   PrintExpr(Node->getSubExpr());
1421*f4a2713aSLionel Sambuc   OS << ")";
1422*f4a2713aSLionel Sambuc }
1423*f4a2713aSLionel Sambuc 
1424*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1425*f4a2713aSLionel Sambuc   PrintExpr(Node->getSubExpr());
1426*f4a2713aSLionel Sambuc }
1427*f4a2713aSLionel Sambuc 
1428*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
1429*f4a2713aSLionel Sambuc   Node->getType().print(OS, Policy);
1430*f4a2713aSLionel Sambuc   OS << "(";
1431*f4a2713aSLionel Sambuc   for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
1432*f4a2713aSLionel Sambuc                                          ArgEnd = Node->arg_end();
1433*f4a2713aSLionel Sambuc        Arg != ArgEnd; ++Arg) {
1434*f4a2713aSLionel Sambuc     if (Arg->isDefaultArgument())
1435*f4a2713aSLionel Sambuc       break;
1436*f4a2713aSLionel Sambuc     if (Arg != Node->arg_begin())
1437*f4a2713aSLionel Sambuc       OS << ", ";
1438*f4a2713aSLionel Sambuc     PrintExpr(*Arg);
1439*f4a2713aSLionel Sambuc   }
1440*f4a2713aSLionel Sambuc   OS << ")";
1441*f4a2713aSLionel Sambuc }
1442*f4a2713aSLionel Sambuc 
1443*f4a2713aSLionel Sambuc void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
1444*f4a2713aSLionel Sambuc   OS << '[';
1445*f4a2713aSLionel Sambuc   bool NeedComma = false;
1446*f4a2713aSLionel Sambuc   switch (Node->getCaptureDefault()) {
1447*f4a2713aSLionel Sambuc   case LCD_None:
1448*f4a2713aSLionel Sambuc     break;
1449*f4a2713aSLionel Sambuc 
1450*f4a2713aSLionel Sambuc   case LCD_ByCopy:
1451*f4a2713aSLionel Sambuc     OS << '=';
1452*f4a2713aSLionel Sambuc     NeedComma = true;
1453*f4a2713aSLionel Sambuc     break;
1454*f4a2713aSLionel Sambuc 
1455*f4a2713aSLionel Sambuc   case LCD_ByRef:
1456*f4a2713aSLionel Sambuc     OS << '&';
1457*f4a2713aSLionel Sambuc     NeedComma = true;
1458*f4a2713aSLionel Sambuc     break;
1459*f4a2713aSLionel Sambuc   }
1460*f4a2713aSLionel Sambuc   for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
1461*f4a2713aSLionel Sambuc                                  CEnd = Node->explicit_capture_end();
1462*f4a2713aSLionel Sambuc        C != CEnd;
1463*f4a2713aSLionel Sambuc        ++C) {
1464*f4a2713aSLionel Sambuc     if (NeedComma)
1465*f4a2713aSLionel Sambuc       OS << ", ";
1466*f4a2713aSLionel Sambuc     NeedComma = true;
1467*f4a2713aSLionel Sambuc 
1468*f4a2713aSLionel Sambuc     switch (C->getCaptureKind()) {
1469*f4a2713aSLionel Sambuc     case LCK_This:
1470*f4a2713aSLionel Sambuc       OS << "this";
1471*f4a2713aSLionel Sambuc       break;
1472*f4a2713aSLionel Sambuc 
1473*f4a2713aSLionel Sambuc     case LCK_ByRef:
1474*f4a2713aSLionel Sambuc       if (Node->getCaptureDefault() != LCD_ByRef || C->isInitCapture())
1475*f4a2713aSLionel Sambuc         OS << '&';
1476*f4a2713aSLionel Sambuc       OS << C->getCapturedVar()->getName();
1477*f4a2713aSLionel Sambuc       break;
1478*f4a2713aSLionel Sambuc 
1479*f4a2713aSLionel Sambuc     case LCK_ByCopy:
1480*f4a2713aSLionel Sambuc       OS << C->getCapturedVar()->getName();
1481*f4a2713aSLionel Sambuc       break;
1482*f4a2713aSLionel Sambuc     }
1483*f4a2713aSLionel Sambuc 
1484*f4a2713aSLionel Sambuc     if (C->isInitCapture())
1485*f4a2713aSLionel Sambuc       PrintExpr(C->getCapturedVar()->getInit());
1486*f4a2713aSLionel Sambuc   }
1487*f4a2713aSLionel Sambuc   OS << ']';
1488*f4a2713aSLionel Sambuc 
1489*f4a2713aSLionel Sambuc   if (Node->hasExplicitParameters()) {
1490*f4a2713aSLionel Sambuc     OS << " (";
1491*f4a2713aSLionel Sambuc     CXXMethodDecl *Method = Node->getCallOperator();
1492*f4a2713aSLionel Sambuc     NeedComma = false;
1493*f4a2713aSLionel Sambuc     for (CXXMethodDecl::param_iterator P = Method->param_begin(),
1494*f4a2713aSLionel Sambuc                                     PEnd = Method->param_end();
1495*f4a2713aSLionel Sambuc          P != PEnd; ++P) {
1496*f4a2713aSLionel Sambuc       if (NeedComma) {
1497*f4a2713aSLionel Sambuc         OS << ", ";
1498*f4a2713aSLionel Sambuc       } else {
1499*f4a2713aSLionel Sambuc         NeedComma = true;
1500*f4a2713aSLionel Sambuc       }
1501*f4a2713aSLionel Sambuc       std::string ParamStr = (*P)->getNameAsString();
1502*f4a2713aSLionel Sambuc       (*P)->getOriginalType().print(OS, Policy, ParamStr);
1503*f4a2713aSLionel Sambuc     }
1504*f4a2713aSLionel Sambuc     if (Method->isVariadic()) {
1505*f4a2713aSLionel Sambuc       if (NeedComma)
1506*f4a2713aSLionel Sambuc         OS << ", ";
1507*f4a2713aSLionel Sambuc       OS << "...";
1508*f4a2713aSLionel Sambuc     }
1509*f4a2713aSLionel Sambuc     OS << ')';
1510*f4a2713aSLionel Sambuc 
1511*f4a2713aSLionel Sambuc     if (Node->isMutable())
1512*f4a2713aSLionel Sambuc       OS << " mutable";
1513*f4a2713aSLionel Sambuc 
1514*f4a2713aSLionel Sambuc     const FunctionProtoType *Proto
1515*f4a2713aSLionel Sambuc       = Method->getType()->getAs<FunctionProtoType>();
1516*f4a2713aSLionel Sambuc     Proto->printExceptionSpecification(OS, Policy);
1517*f4a2713aSLionel Sambuc 
1518*f4a2713aSLionel Sambuc     // FIXME: Attributes
1519*f4a2713aSLionel Sambuc 
1520*f4a2713aSLionel Sambuc     // Print the trailing return type if it was specified in the source.
1521*f4a2713aSLionel Sambuc     if (Node->hasExplicitResultType()) {
1522*f4a2713aSLionel Sambuc       OS << " -> ";
1523*f4a2713aSLionel Sambuc       Proto->getResultType().print(OS, Policy);
1524*f4a2713aSLionel Sambuc     }
1525*f4a2713aSLionel Sambuc   }
1526*f4a2713aSLionel Sambuc 
1527*f4a2713aSLionel Sambuc   // Print the body.
1528*f4a2713aSLionel Sambuc   CompoundStmt *Body = Node->getBody();
1529*f4a2713aSLionel Sambuc   OS << ' ';
1530*f4a2713aSLionel Sambuc   PrintStmt(Body);
1531*f4a2713aSLionel Sambuc }
1532*f4a2713aSLionel Sambuc 
1533*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
1534*f4a2713aSLionel Sambuc   if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
1535*f4a2713aSLionel Sambuc     TSInfo->getType().print(OS, Policy);
1536*f4a2713aSLionel Sambuc   else
1537*f4a2713aSLionel Sambuc     Node->getType().print(OS, Policy);
1538*f4a2713aSLionel Sambuc   OS << "()";
1539*f4a2713aSLionel Sambuc }
1540*f4a2713aSLionel Sambuc 
1541*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
1542*f4a2713aSLionel Sambuc   if (E->isGlobalNew())
1543*f4a2713aSLionel Sambuc     OS << "::";
1544*f4a2713aSLionel Sambuc   OS << "new ";
1545*f4a2713aSLionel Sambuc   unsigned NumPlace = E->getNumPlacementArgs();
1546*f4a2713aSLionel Sambuc   if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
1547*f4a2713aSLionel Sambuc     OS << "(";
1548*f4a2713aSLionel Sambuc     PrintExpr(E->getPlacementArg(0));
1549*f4a2713aSLionel Sambuc     for (unsigned i = 1; i < NumPlace; ++i) {
1550*f4a2713aSLionel Sambuc       if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
1551*f4a2713aSLionel Sambuc         break;
1552*f4a2713aSLionel Sambuc       OS << ", ";
1553*f4a2713aSLionel Sambuc       PrintExpr(E->getPlacementArg(i));
1554*f4a2713aSLionel Sambuc     }
1555*f4a2713aSLionel Sambuc     OS << ") ";
1556*f4a2713aSLionel Sambuc   }
1557*f4a2713aSLionel Sambuc   if (E->isParenTypeId())
1558*f4a2713aSLionel Sambuc     OS << "(";
1559*f4a2713aSLionel Sambuc   std::string TypeS;
1560*f4a2713aSLionel Sambuc   if (Expr *Size = E->getArraySize()) {
1561*f4a2713aSLionel Sambuc     llvm::raw_string_ostream s(TypeS);
1562*f4a2713aSLionel Sambuc     s << '[';
1563*f4a2713aSLionel Sambuc     Size->printPretty(s, Helper, Policy);
1564*f4a2713aSLionel Sambuc     s << ']';
1565*f4a2713aSLionel Sambuc   }
1566*f4a2713aSLionel Sambuc   E->getAllocatedType().print(OS, Policy, TypeS);
1567*f4a2713aSLionel Sambuc   if (E->isParenTypeId())
1568*f4a2713aSLionel Sambuc     OS << ")";
1569*f4a2713aSLionel Sambuc 
1570*f4a2713aSLionel Sambuc   CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
1571*f4a2713aSLionel Sambuc   if (InitStyle) {
1572*f4a2713aSLionel Sambuc     if (InitStyle == CXXNewExpr::CallInit)
1573*f4a2713aSLionel Sambuc       OS << "(";
1574*f4a2713aSLionel Sambuc     PrintExpr(E->getInitializer());
1575*f4a2713aSLionel Sambuc     if (InitStyle == CXXNewExpr::CallInit)
1576*f4a2713aSLionel Sambuc       OS << ")";
1577*f4a2713aSLionel Sambuc   }
1578*f4a2713aSLionel Sambuc }
1579*f4a2713aSLionel Sambuc 
1580*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1581*f4a2713aSLionel Sambuc   if (E->isGlobalDelete())
1582*f4a2713aSLionel Sambuc     OS << "::";
1583*f4a2713aSLionel Sambuc   OS << "delete ";
1584*f4a2713aSLionel Sambuc   if (E->isArrayForm())
1585*f4a2713aSLionel Sambuc     OS << "[] ";
1586*f4a2713aSLionel Sambuc   PrintExpr(E->getArgument());
1587*f4a2713aSLionel Sambuc }
1588*f4a2713aSLionel Sambuc 
1589*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1590*f4a2713aSLionel Sambuc   PrintExpr(E->getBase());
1591*f4a2713aSLionel Sambuc   if (E->isArrow())
1592*f4a2713aSLionel Sambuc     OS << "->";
1593*f4a2713aSLionel Sambuc   else
1594*f4a2713aSLionel Sambuc     OS << '.';
1595*f4a2713aSLionel Sambuc   if (E->getQualifier())
1596*f4a2713aSLionel Sambuc     E->getQualifier()->print(OS, Policy);
1597*f4a2713aSLionel Sambuc   OS << "~";
1598*f4a2713aSLionel Sambuc 
1599*f4a2713aSLionel Sambuc   if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
1600*f4a2713aSLionel Sambuc     OS << II->getName();
1601*f4a2713aSLionel Sambuc   else
1602*f4a2713aSLionel Sambuc     E->getDestroyedType().print(OS, Policy);
1603*f4a2713aSLionel Sambuc }
1604*f4a2713aSLionel Sambuc 
1605*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1606*f4a2713aSLionel Sambuc   if (E->isListInitialization())
1607*f4a2713aSLionel Sambuc     OS << "{ ";
1608*f4a2713aSLionel Sambuc 
1609*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
1610*f4a2713aSLionel Sambuc     if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
1611*f4a2713aSLionel Sambuc       // Don't print any defaulted arguments
1612*f4a2713aSLionel Sambuc       break;
1613*f4a2713aSLionel Sambuc     }
1614*f4a2713aSLionel Sambuc 
1615*f4a2713aSLionel Sambuc     if (i) OS << ", ";
1616*f4a2713aSLionel Sambuc     PrintExpr(E->getArg(i));
1617*f4a2713aSLionel Sambuc   }
1618*f4a2713aSLionel Sambuc 
1619*f4a2713aSLionel Sambuc   if (E->isListInitialization())
1620*f4a2713aSLionel Sambuc     OS << " }";
1621*f4a2713aSLionel Sambuc }
1622*f4a2713aSLionel Sambuc 
1623*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1624*f4a2713aSLionel Sambuc   PrintExpr(E->getSubExpr());
1625*f4a2713aSLionel Sambuc }
1626*f4a2713aSLionel Sambuc 
1627*f4a2713aSLionel Sambuc void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
1628*f4a2713aSLionel Sambuc   // Just forward to the sub expression.
1629*f4a2713aSLionel Sambuc   PrintExpr(E->getSubExpr());
1630*f4a2713aSLionel Sambuc }
1631*f4a2713aSLionel Sambuc 
1632*f4a2713aSLionel Sambuc void
1633*f4a2713aSLionel Sambuc StmtPrinter::VisitCXXUnresolvedConstructExpr(
1634*f4a2713aSLionel Sambuc                                            CXXUnresolvedConstructExpr *Node) {
1635*f4a2713aSLionel Sambuc   Node->getTypeAsWritten().print(OS, Policy);
1636*f4a2713aSLionel Sambuc   OS << "(";
1637*f4a2713aSLionel Sambuc   for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
1638*f4a2713aSLionel Sambuc                                              ArgEnd = Node->arg_end();
1639*f4a2713aSLionel Sambuc        Arg != ArgEnd; ++Arg) {
1640*f4a2713aSLionel Sambuc     if (Arg != Node->arg_begin())
1641*f4a2713aSLionel Sambuc       OS << ", ";
1642*f4a2713aSLionel Sambuc     PrintExpr(*Arg);
1643*f4a2713aSLionel Sambuc   }
1644*f4a2713aSLionel Sambuc   OS << ")";
1645*f4a2713aSLionel Sambuc }
1646*f4a2713aSLionel Sambuc 
1647*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXDependentScopeMemberExpr(
1648*f4a2713aSLionel Sambuc                                          CXXDependentScopeMemberExpr *Node) {
1649*f4a2713aSLionel Sambuc   if (!Node->isImplicitAccess()) {
1650*f4a2713aSLionel Sambuc     PrintExpr(Node->getBase());
1651*f4a2713aSLionel Sambuc     OS << (Node->isArrow() ? "->" : ".");
1652*f4a2713aSLionel Sambuc   }
1653*f4a2713aSLionel Sambuc   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1654*f4a2713aSLionel Sambuc     Qualifier->print(OS, Policy);
1655*f4a2713aSLionel Sambuc   if (Node->hasTemplateKeyword())
1656*f4a2713aSLionel Sambuc     OS << "template ";
1657*f4a2713aSLionel Sambuc   OS << Node->getMemberNameInfo();
1658*f4a2713aSLionel Sambuc   if (Node->hasExplicitTemplateArgs())
1659*f4a2713aSLionel Sambuc     TemplateSpecializationType::PrintTemplateArgumentList(
1660*f4a2713aSLionel Sambuc         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1661*f4a2713aSLionel Sambuc }
1662*f4a2713aSLionel Sambuc 
1663*f4a2713aSLionel Sambuc void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
1664*f4a2713aSLionel Sambuc   if (!Node->isImplicitAccess()) {
1665*f4a2713aSLionel Sambuc     PrintExpr(Node->getBase());
1666*f4a2713aSLionel Sambuc     OS << (Node->isArrow() ? "->" : ".");
1667*f4a2713aSLionel Sambuc   }
1668*f4a2713aSLionel Sambuc   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1669*f4a2713aSLionel Sambuc     Qualifier->print(OS, Policy);
1670*f4a2713aSLionel Sambuc   if (Node->hasTemplateKeyword())
1671*f4a2713aSLionel Sambuc     OS << "template ";
1672*f4a2713aSLionel Sambuc   OS << Node->getMemberNameInfo();
1673*f4a2713aSLionel Sambuc   if (Node->hasExplicitTemplateArgs())
1674*f4a2713aSLionel Sambuc     TemplateSpecializationType::PrintTemplateArgumentList(
1675*f4a2713aSLionel Sambuc         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1676*f4a2713aSLionel Sambuc }
1677*f4a2713aSLionel Sambuc 
1678*f4a2713aSLionel Sambuc static const char *getTypeTraitName(UnaryTypeTrait UTT) {
1679*f4a2713aSLionel Sambuc   switch (UTT) {
1680*f4a2713aSLionel Sambuc   case UTT_HasNothrowAssign:      return "__has_nothrow_assign";
1681*f4a2713aSLionel Sambuc   case UTT_HasNothrowMoveAssign:  return "__has_nothrow_move_assign";
1682*f4a2713aSLionel Sambuc   case UTT_HasNothrowConstructor: return "__has_nothrow_constructor";
1683*f4a2713aSLionel Sambuc   case UTT_HasNothrowCopy:          return "__has_nothrow_copy";
1684*f4a2713aSLionel Sambuc   case UTT_HasTrivialAssign:      return "__has_trivial_assign";
1685*f4a2713aSLionel Sambuc   case UTT_HasTrivialMoveAssign:      return "__has_trivial_move_assign";
1686*f4a2713aSLionel Sambuc   case UTT_HasTrivialMoveConstructor: return "__has_trivial_move_constructor";
1687*f4a2713aSLionel Sambuc   case UTT_HasTrivialDefaultConstructor: return "__has_trivial_constructor";
1688*f4a2713aSLionel Sambuc   case UTT_HasTrivialCopy:          return "__has_trivial_copy";
1689*f4a2713aSLionel Sambuc   case UTT_HasTrivialDestructor:  return "__has_trivial_destructor";
1690*f4a2713aSLionel Sambuc   case UTT_HasVirtualDestructor:  return "__has_virtual_destructor";
1691*f4a2713aSLionel Sambuc   case UTT_IsAbstract:            return "__is_abstract";
1692*f4a2713aSLionel Sambuc   case UTT_IsArithmetic:            return "__is_arithmetic";
1693*f4a2713aSLionel Sambuc   case UTT_IsArray:                 return "__is_array";
1694*f4a2713aSLionel Sambuc   case UTT_IsClass:               return "__is_class";
1695*f4a2713aSLionel Sambuc   case UTT_IsCompleteType:          return "__is_complete_type";
1696*f4a2713aSLionel Sambuc   case UTT_IsCompound:              return "__is_compound";
1697*f4a2713aSLionel Sambuc   case UTT_IsConst:                 return "__is_const";
1698*f4a2713aSLionel Sambuc   case UTT_IsEmpty:               return "__is_empty";
1699*f4a2713aSLionel Sambuc   case UTT_IsEnum:                return "__is_enum";
1700*f4a2713aSLionel Sambuc   case UTT_IsFinal:                 return "__is_final";
1701*f4a2713aSLionel Sambuc   case UTT_IsFloatingPoint:         return "__is_floating_point";
1702*f4a2713aSLionel Sambuc   case UTT_IsFunction:              return "__is_function";
1703*f4a2713aSLionel Sambuc   case UTT_IsFundamental:           return "__is_fundamental";
1704*f4a2713aSLionel Sambuc   case UTT_IsIntegral:              return "__is_integral";
1705*f4a2713aSLionel Sambuc   case UTT_IsInterfaceClass:        return "__is_interface_class";
1706*f4a2713aSLionel Sambuc   case UTT_IsLiteral:               return "__is_literal";
1707*f4a2713aSLionel Sambuc   case UTT_IsLvalueReference:       return "__is_lvalue_reference";
1708*f4a2713aSLionel Sambuc   case UTT_IsMemberFunctionPointer: return "__is_member_function_pointer";
1709*f4a2713aSLionel Sambuc   case UTT_IsMemberObjectPointer:   return "__is_member_object_pointer";
1710*f4a2713aSLionel Sambuc   case UTT_IsMemberPointer:         return "__is_member_pointer";
1711*f4a2713aSLionel Sambuc   case UTT_IsObject:                return "__is_object";
1712*f4a2713aSLionel Sambuc   case UTT_IsPOD:                 return "__is_pod";
1713*f4a2713aSLionel Sambuc   case UTT_IsPointer:               return "__is_pointer";
1714*f4a2713aSLionel Sambuc   case UTT_IsPolymorphic:         return "__is_polymorphic";
1715*f4a2713aSLionel Sambuc   case UTT_IsReference:             return "__is_reference";
1716*f4a2713aSLionel Sambuc   case UTT_IsRvalueReference:       return "__is_rvalue_reference";
1717*f4a2713aSLionel Sambuc   case UTT_IsScalar:                return "__is_scalar";
1718*f4a2713aSLionel Sambuc   case UTT_IsSealed:                return "__is_sealed";
1719*f4a2713aSLionel Sambuc   case UTT_IsSigned:                return "__is_signed";
1720*f4a2713aSLionel Sambuc   case UTT_IsStandardLayout:        return "__is_standard_layout";
1721*f4a2713aSLionel Sambuc   case UTT_IsTrivial:               return "__is_trivial";
1722*f4a2713aSLionel Sambuc   case UTT_IsTriviallyCopyable:     return "__is_trivially_copyable";
1723*f4a2713aSLionel Sambuc   case UTT_IsUnion:               return "__is_union";
1724*f4a2713aSLionel Sambuc   case UTT_IsUnsigned:              return "__is_unsigned";
1725*f4a2713aSLionel Sambuc   case UTT_IsVoid:                  return "__is_void";
1726*f4a2713aSLionel Sambuc   case UTT_IsVolatile:              return "__is_volatile";
1727*f4a2713aSLionel Sambuc   }
1728*f4a2713aSLionel Sambuc   llvm_unreachable("Type trait not covered by switch statement");
1729*f4a2713aSLionel Sambuc }
1730*f4a2713aSLionel Sambuc 
1731*f4a2713aSLionel Sambuc static const char *getTypeTraitName(BinaryTypeTrait BTT) {
1732*f4a2713aSLionel Sambuc   switch (BTT) {
1733*f4a2713aSLionel Sambuc   case BTT_IsBaseOf:              return "__is_base_of";
1734*f4a2713aSLionel Sambuc   case BTT_IsConvertible:         return "__is_convertible";
1735*f4a2713aSLionel Sambuc   case BTT_IsSame:                return "__is_same";
1736*f4a2713aSLionel Sambuc   case BTT_TypeCompatible:        return "__builtin_types_compatible_p";
1737*f4a2713aSLionel Sambuc   case BTT_IsConvertibleTo:       return "__is_convertible_to";
1738*f4a2713aSLionel Sambuc   case BTT_IsTriviallyAssignable: return "__is_trivially_assignable";
1739*f4a2713aSLionel Sambuc   }
1740*f4a2713aSLionel Sambuc   llvm_unreachable("Binary type trait not covered by switch");
1741*f4a2713aSLionel Sambuc }
1742*f4a2713aSLionel Sambuc 
1743*f4a2713aSLionel Sambuc static const char *getTypeTraitName(TypeTrait TT) {
1744*f4a2713aSLionel Sambuc   switch (TT) {
1745*f4a2713aSLionel Sambuc   case clang::TT_IsTriviallyConstructible:return "__is_trivially_constructible";
1746*f4a2713aSLionel Sambuc   }
1747*f4a2713aSLionel Sambuc   llvm_unreachable("Type trait not covered by switch");
1748*f4a2713aSLionel Sambuc }
1749*f4a2713aSLionel Sambuc 
1750*f4a2713aSLionel Sambuc static const char *getTypeTraitName(ArrayTypeTrait ATT) {
1751*f4a2713aSLionel Sambuc   switch (ATT) {
1752*f4a2713aSLionel Sambuc   case ATT_ArrayRank:        return "__array_rank";
1753*f4a2713aSLionel Sambuc   case ATT_ArrayExtent:      return "__array_extent";
1754*f4a2713aSLionel Sambuc   }
1755*f4a2713aSLionel Sambuc   llvm_unreachable("Array type trait not covered by switch");
1756*f4a2713aSLionel Sambuc }
1757*f4a2713aSLionel Sambuc 
1758*f4a2713aSLionel Sambuc static const char *getExpressionTraitName(ExpressionTrait ET) {
1759*f4a2713aSLionel Sambuc   switch (ET) {
1760*f4a2713aSLionel Sambuc   case ET_IsLValueExpr:      return "__is_lvalue_expr";
1761*f4a2713aSLionel Sambuc   case ET_IsRValueExpr:      return "__is_rvalue_expr";
1762*f4a2713aSLionel Sambuc   }
1763*f4a2713aSLionel Sambuc   llvm_unreachable("Expression type trait not covered by switch");
1764*f4a2713aSLionel Sambuc }
1765*f4a2713aSLionel Sambuc 
1766*f4a2713aSLionel Sambuc void StmtPrinter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
1767*f4a2713aSLionel Sambuc   OS << getTypeTraitName(E->getTrait()) << '(';
1768*f4a2713aSLionel Sambuc   E->getQueriedType().print(OS, Policy);
1769*f4a2713aSLionel Sambuc   OS << ')';
1770*f4a2713aSLionel Sambuc }
1771*f4a2713aSLionel Sambuc 
1772*f4a2713aSLionel Sambuc void StmtPrinter::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
1773*f4a2713aSLionel Sambuc   OS << getTypeTraitName(E->getTrait()) << '(';
1774*f4a2713aSLionel Sambuc   E->getLhsType().print(OS, Policy);
1775*f4a2713aSLionel Sambuc   OS << ',';
1776*f4a2713aSLionel Sambuc   E->getRhsType().print(OS, Policy);
1777*f4a2713aSLionel Sambuc   OS << ')';
1778*f4a2713aSLionel Sambuc }
1779*f4a2713aSLionel Sambuc 
1780*f4a2713aSLionel Sambuc void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1781*f4a2713aSLionel Sambuc   OS << getTypeTraitName(E->getTrait()) << "(";
1782*f4a2713aSLionel Sambuc   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
1783*f4a2713aSLionel Sambuc     if (I > 0)
1784*f4a2713aSLionel Sambuc       OS << ", ";
1785*f4a2713aSLionel Sambuc     E->getArg(I)->getType().print(OS, Policy);
1786*f4a2713aSLionel Sambuc   }
1787*f4a2713aSLionel Sambuc   OS << ")";
1788*f4a2713aSLionel Sambuc }
1789*f4a2713aSLionel Sambuc 
1790*f4a2713aSLionel Sambuc void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1791*f4a2713aSLionel Sambuc   OS << getTypeTraitName(E->getTrait()) << '(';
1792*f4a2713aSLionel Sambuc   E->getQueriedType().print(OS, Policy);
1793*f4a2713aSLionel Sambuc   OS << ')';
1794*f4a2713aSLionel Sambuc }
1795*f4a2713aSLionel Sambuc 
1796*f4a2713aSLionel Sambuc void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1797*f4a2713aSLionel Sambuc   OS << getExpressionTraitName(E->getTrait()) << '(';
1798*f4a2713aSLionel Sambuc   PrintExpr(E->getQueriedExpression());
1799*f4a2713aSLionel Sambuc   OS << ')';
1800*f4a2713aSLionel Sambuc }
1801*f4a2713aSLionel Sambuc 
1802*f4a2713aSLionel Sambuc void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1803*f4a2713aSLionel Sambuc   OS << "noexcept(";
1804*f4a2713aSLionel Sambuc   PrintExpr(E->getOperand());
1805*f4a2713aSLionel Sambuc   OS << ")";
1806*f4a2713aSLionel Sambuc }
1807*f4a2713aSLionel Sambuc 
1808*f4a2713aSLionel Sambuc void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1809*f4a2713aSLionel Sambuc   PrintExpr(E->getPattern());
1810*f4a2713aSLionel Sambuc   OS << "...";
1811*f4a2713aSLionel Sambuc }
1812*f4a2713aSLionel Sambuc 
1813*f4a2713aSLionel Sambuc void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1814*f4a2713aSLionel Sambuc   OS << "sizeof...(" << *E->getPack() << ")";
1815*f4a2713aSLionel Sambuc }
1816*f4a2713aSLionel Sambuc 
1817*f4a2713aSLionel Sambuc void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
1818*f4a2713aSLionel Sambuc                                        SubstNonTypeTemplateParmPackExpr *Node) {
1819*f4a2713aSLionel Sambuc   OS << *Node->getParameterPack();
1820*f4a2713aSLionel Sambuc }
1821*f4a2713aSLionel Sambuc 
1822*f4a2713aSLionel Sambuc void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
1823*f4a2713aSLionel Sambuc                                        SubstNonTypeTemplateParmExpr *Node) {
1824*f4a2713aSLionel Sambuc   Visit(Node->getReplacement());
1825*f4a2713aSLionel Sambuc }
1826*f4a2713aSLionel Sambuc 
1827*f4a2713aSLionel Sambuc void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1828*f4a2713aSLionel Sambuc   OS << *E->getParameterPack();
1829*f4a2713aSLionel Sambuc }
1830*f4a2713aSLionel Sambuc 
1831*f4a2713aSLionel Sambuc void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
1832*f4a2713aSLionel Sambuc   PrintExpr(Node->GetTemporaryExpr());
1833*f4a2713aSLionel Sambuc }
1834*f4a2713aSLionel Sambuc 
1835*f4a2713aSLionel Sambuc // Obj-C
1836*f4a2713aSLionel Sambuc 
1837*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
1838*f4a2713aSLionel Sambuc   OS << "@";
1839*f4a2713aSLionel Sambuc   VisitStringLiteral(Node->getString());
1840*f4a2713aSLionel Sambuc }
1841*f4a2713aSLionel Sambuc 
1842*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1843*f4a2713aSLionel Sambuc   OS << "@";
1844*f4a2713aSLionel Sambuc   Visit(E->getSubExpr());
1845*f4a2713aSLionel Sambuc }
1846*f4a2713aSLionel Sambuc 
1847*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1848*f4a2713aSLionel Sambuc   OS << "@[ ";
1849*f4a2713aSLionel Sambuc   StmtRange ch = E->children();
1850*f4a2713aSLionel Sambuc   if (ch.first != ch.second) {
1851*f4a2713aSLionel Sambuc     while (1) {
1852*f4a2713aSLionel Sambuc       Visit(*ch.first);
1853*f4a2713aSLionel Sambuc       ++ch.first;
1854*f4a2713aSLionel Sambuc       if (ch.first == ch.second) break;
1855*f4a2713aSLionel Sambuc       OS << ", ";
1856*f4a2713aSLionel Sambuc     }
1857*f4a2713aSLionel Sambuc   }
1858*f4a2713aSLionel Sambuc   OS << " ]";
1859*f4a2713aSLionel Sambuc }
1860*f4a2713aSLionel Sambuc 
1861*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1862*f4a2713aSLionel Sambuc   OS << "@{ ";
1863*f4a2713aSLionel Sambuc   for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
1864*f4a2713aSLionel Sambuc     if (I > 0)
1865*f4a2713aSLionel Sambuc       OS << ", ";
1866*f4a2713aSLionel Sambuc 
1867*f4a2713aSLionel Sambuc     ObjCDictionaryElement Element = E->getKeyValueElement(I);
1868*f4a2713aSLionel Sambuc     Visit(Element.Key);
1869*f4a2713aSLionel Sambuc     OS << " : ";
1870*f4a2713aSLionel Sambuc     Visit(Element.Value);
1871*f4a2713aSLionel Sambuc     if (Element.isPackExpansion())
1872*f4a2713aSLionel Sambuc       OS << "...";
1873*f4a2713aSLionel Sambuc   }
1874*f4a2713aSLionel Sambuc   OS << " }";
1875*f4a2713aSLionel Sambuc }
1876*f4a2713aSLionel Sambuc 
1877*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
1878*f4a2713aSLionel Sambuc   OS << "@encode(";
1879*f4a2713aSLionel Sambuc   Node->getEncodedType().print(OS, Policy);
1880*f4a2713aSLionel Sambuc   OS << ')';
1881*f4a2713aSLionel Sambuc }
1882*f4a2713aSLionel Sambuc 
1883*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
1884*f4a2713aSLionel Sambuc   OS << "@selector(" << Node->getSelector().getAsString() << ')';
1885*f4a2713aSLionel Sambuc }
1886*f4a2713aSLionel Sambuc 
1887*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
1888*f4a2713aSLionel Sambuc   OS << "@protocol(" << *Node->getProtocol() << ')';
1889*f4a2713aSLionel Sambuc }
1890*f4a2713aSLionel Sambuc 
1891*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
1892*f4a2713aSLionel Sambuc   OS << "[";
1893*f4a2713aSLionel Sambuc   switch (Mess->getReceiverKind()) {
1894*f4a2713aSLionel Sambuc   case ObjCMessageExpr::Instance:
1895*f4a2713aSLionel Sambuc     PrintExpr(Mess->getInstanceReceiver());
1896*f4a2713aSLionel Sambuc     break;
1897*f4a2713aSLionel Sambuc 
1898*f4a2713aSLionel Sambuc   case ObjCMessageExpr::Class:
1899*f4a2713aSLionel Sambuc     Mess->getClassReceiver().print(OS, Policy);
1900*f4a2713aSLionel Sambuc     break;
1901*f4a2713aSLionel Sambuc 
1902*f4a2713aSLionel Sambuc   case ObjCMessageExpr::SuperInstance:
1903*f4a2713aSLionel Sambuc   case ObjCMessageExpr::SuperClass:
1904*f4a2713aSLionel Sambuc     OS << "Super";
1905*f4a2713aSLionel Sambuc     break;
1906*f4a2713aSLionel Sambuc   }
1907*f4a2713aSLionel Sambuc 
1908*f4a2713aSLionel Sambuc   OS << ' ';
1909*f4a2713aSLionel Sambuc   Selector selector = Mess->getSelector();
1910*f4a2713aSLionel Sambuc   if (selector.isUnarySelector()) {
1911*f4a2713aSLionel Sambuc     OS << selector.getNameForSlot(0);
1912*f4a2713aSLionel Sambuc   } else {
1913*f4a2713aSLionel Sambuc     for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
1914*f4a2713aSLionel Sambuc       if (i < selector.getNumArgs()) {
1915*f4a2713aSLionel Sambuc         if (i > 0) OS << ' ';
1916*f4a2713aSLionel Sambuc         if (selector.getIdentifierInfoForSlot(i))
1917*f4a2713aSLionel Sambuc           OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
1918*f4a2713aSLionel Sambuc         else
1919*f4a2713aSLionel Sambuc            OS << ":";
1920*f4a2713aSLionel Sambuc       }
1921*f4a2713aSLionel Sambuc       else OS << ", "; // Handle variadic methods.
1922*f4a2713aSLionel Sambuc 
1923*f4a2713aSLionel Sambuc       PrintExpr(Mess->getArg(i));
1924*f4a2713aSLionel Sambuc     }
1925*f4a2713aSLionel Sambuc   }
1926*f4a2713aSLionel Sambuc   OS << "]";
1927*f4a2713aSLionel Sambuc }
1928*f4a2713aSLionel Sambuc 
1929*f4a2713aSLionel Sambuc void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
1930*f4a2713aSLionel Sambuc   OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
1931*f4a2713aSLionel Sambuc }
1932*f4a2713aSLionel Sambuc 
1933*f4a2713aSLionel Sambuc void
1934*f4a2713aSLionel Sambuc StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
1935*f4a2713aSLionel Sambuc   PrintExpr(E->getSubExpr());
1936*f4a2713aSLionel Sambuc }
1937*f4a2713aSLionel Sambuc 
1938*f4a2713aSLionel Sambuc void
1939*f4a2713aSLionel Sambuc StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
1940*f4a2713aSLionel Sambuc   OS << '(' << E->getBridgeKindName();
1941*f4a2713aSLionel Sambuc   E->getType().print(OS, Policy);
1942*f4a2713aSLionel Sambuc   OS << ')';
1943*f4a2713aSLionel Sambuc   PrintExpr(E->getSubExpr());
1944*f4a2713aSLionel Sambuc }
1945*f4a2713aSLionel Sambuc 
1946*f4a2713aSLionel Sambuc void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
1947*f4a2713aSLionel Sambuc   BlockDecl *BD = Node->getBlockDecl();
1948*f4a2713aSLionel Sambuc   OS << "^";
1949*f4a2713aSLionel Sambuc 
1950*f4a2713aSLionel Sambuc   const FunctionType *AFT = Node->getFunctionType();
1951*f4a2713aSLionel Sambuc 
1952*f4a2713aSLionel Sambuc   if (isa<FunctionNoProtoType>(AFT)) {
1953*f4a2713aSLionel Sambuc     OS << "()";
1954*f4a2713aSLionel Sambuc   } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
1955*f4a2713aSLionel Sambuc     OS << '(';
1956*f4a2713aSLionel Sambuc     for (BlockDecl::param_iterator AI = BD->param_begin(),
1957*f4a2713aSLionel Sambuc          E = BD->param_end(); AI != E; ++AI) {
1958*f4a2713aSLionel Sambuc       if (AI != BD->param_begin()) OS << ", ";
1959*f4a2713aSLionel Sambuc       std::string ParamStr = (*AI)->getNameAsString();
1960*f4a2713aSLionel Sambuc       (*AI)->getType().print(OS, Policy, ParamStr);
1961*f4a2713aSLionel Sambuc     }
1962*f4a2713aSLionel Sambuc 
1963*f4a2713aSLionel Sambuc     const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
1964*f4a2713aSLionel Sambuc     if (FT->isVariadic()) {
1965*f4a2713aSLionel Sambuc       if (!BD->param_empty()) OS << ", ";
1966*f4a2713aSLionel Sambuc       OS << "...";
1967*f4a2713aSLionel Sambuc     }
1968*f4a2713aSLionel Sambuc     OS << ')';
1969*f4a2713aSLionel Sambuc   }
1970*f4a2713aSLionel Sambuc   OS << "{ }";
1971*f4a2713aSLionel Sambuc }
1972*f4a2713aSLionel Sambuc 
1973*f4a2713aSLionel Sambuc void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
1974*f4a2713aSLionel Sambuc   PrintExpr(Node->getSourceExpr());
1975*f4a2713aSLionel Sambuc }
1976*f4a2713aSLionel Sambuc 
1977*f4a2713aSLionel Sambuc void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
1978*f4a2713aSLionel Sambuc   OS << "__builtin_astype(";
1979*f4a2713aSLionel Sambuc   PrintExpr(Node->getSrcExpr());
1980*f4a2713aSLionel Sambuc   OS << ", ";
1981*f4a2713aSLionel Sambuc   Node->getType().print(OS, Policy);
1982*f4a2713aSLionel Sambuc   OS << ")";
1983*f4a2713aSLionel Sambuc }
1984*f4a2713aSLionel Sambuc 
1985*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1986*f4a2713aSLionel Sambuc // Stmt method implementations
1987*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1988*f4a2713aSLionel Sambuc 
1989*f4a2713aSLionel Sambuc void Stmt::dumpPretty(const ASTContext &Context) const {
1990*f4a2713aSLionel Sambuc   printPretty(llvm::errs(), 0, PrintingPolicy(Context.getLangOpts()));
1991*f4a2713aSLionel Sambuc }
1992*f4a2713aSLionel Sambuc 
1993*f4a2713aSLionel Sambuc void Stmt::printPretty(raw_ostream &OS,
1994*f4a2713aSLionel Sambuc                        PrinterHelper *Helper,
1995*f4a2713aSLionel Sambuc                        const PrintingPolicy &Policy,
1996*f4a2713aSLionel Sambuc                        unsigned Indentation) const {
1997*f4a2713aSLionel Sambuc   if (this == 0) {
1998*f4a2713aSLionel Sambuc     OS << "<NULL>";
1999*f4a2713aSLionel Sambuc     return;
2000*f4a2713aSLionel Sambuc   }
2001*f4a2713aSLionel Sambuc 
2002*f4a2713aSLionel Sambuc   StmtPrinter P(OS, Helper, Policy, Indentation);
2003*f4a2713aSLionel Sambuc   P.Visit(const_cast<Stmt*>(this));
2004*f4a2713aSLionel Sambuc }
2005*f4a2713aSLionel Sambuc 
2006*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2007*f4a2713aSLionel Sambuc // PrinterHelper
2008*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
2009*f4a2713aSLionel Sambuc 
2010*f4a2713aSLionel Sambuc // Implement virtual destructor.
2011*f4a2713aSLionel Sambuc PrinterHelper::~PrinterHelper() {}
2012