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