Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 10 | // This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which |
| 11 | // pretty print the AST back out to C code. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/AST/StmtVisitor.h" |
Douglas Gregor | 1a49af9 | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Ted Kremenek | 91d1d7a | 2007-10-17 18:36:42 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 19 | #include "clang/AST/PrettyPrinter.h" |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Format.h" |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExprCXX.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 23 | using namespace clang; |
| 24 | |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | // StmtPrinter Visitor |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | |
| 29 | namespace { |
Benjamin Kramer | 770b4a8 | 2009-11-28 19:03:38 +0000 | [diff] [blame] | 30 | class StmtPrinter : public StmtVisitor<StmtPrinter> { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 31 | raw_ostream &OS; |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 32 | ASTContext &Context; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 33 | unsigned IndentLevel; |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 34 | clang::PrinterHelper* Helper; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 35 | PrintingPolicy Policy; |
| 36 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 37 | public: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 38 | StmtPrinter(raw_ostream &os, ASTContext &C, PrinterHelper* helper, |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 39 | const PrintingPolicy &Policy, |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 40 | unsigned Indentation = 0) |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 41 | : OS(os), Context(C), IndentLevel(Indentation), Helper(helper), |
| 42 | Policy(Policy) {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 43 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 44 | void PrintStmt(Stmt *S) { |
| 45 | PrintStmt(S, Policy.Indentation); |
| 46 | } |
| 47 | |
| 48 | void PrintStmt(Stmt *S, int SubIndent) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 49 | IndentLevel += SubIndent; |
| 50 | if (S && isa<Expr>(S)) { |
| 51 | // If this is an expr used in a stmt context, indent and newline it. |
| 52 | Indent(); |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 53 | Visit(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 54 | OS << ";\n"; |
| 55 | } else if (S) { |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 56 | Visit(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 57 | } else { |
| 58 | Indent() << "<<<NULL STATEMENT>>>\n"; |
| 59 | } |
| 60 | IndentLevel -= SubIndent; |
| 61 | } |
Eli Friedman | db23b15 | 2009-05-30 00:19:54 +0000 | [diff] [blame] | 62 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 63 | void PrintRawCompoundStmt(CompoundStmt *S); |
| 64 | void PrintRawDecl(Decl *D); |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 65 | void PrintRawDeclStmt(DeclStmt *S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 66 | void PrintRawIfStmt(IfStmt *If); |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 67 | void PrintRawCXXCatchStmt(CXXCatchStmt *Catch); |
Peter Collingbourne | d64e237 | 2011-02-08 21:17:54 +0000 | [diff] [blame] | 68 | void PrintCallArgs(CallExpr *E); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 69 | void PrintRawSEHExceptHandler(SEHExceptStmt *S); |
| 70 | void PrintRawSEHFinallyStmt(SEHFinallyStmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 71 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 72 | void PrintExpr(Expr *E) { |
| 73 | if (E) |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 74 | Visit(E); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 75 | else |
| 76 | OS << "<null expr>"; |
| 77 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 78 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 79 | raw_ostream &Indent(int Delta = 0) { |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 80 | for (int i = 0, e = IndentLevel+Delta; i < e; ++i) |
| 81 | OS << " "; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 82 | return OS; |
| 83 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 85 | void Visit(Stmt* S) { |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 86 | if (Helper && Helper->handledStmt(S,OS)) |
| 87 | return; |
| 88 | else StmtVisitor<StmtPrinter>::Visit(S); |
| 89 | } |
Argyrios Kyrtzidis | 78e4cc7 | 2010-08-15 01:15:33 +0000 | [diff] [blame] | 90 | |
Chandler Carruth | 61e3828 | 2010-10-23 08:21:37 +0000 | [diff] [blame] | 91 | void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED { |
Argyrios Kyrtzidis | 78e4cc7 | 2010-08-15 01:15:33 +0000 | [diff] [blame] | 92 | Indent() << "<<unknown stmt type>>\n"; |
| 93 | } |
Chandler Carruth | 61e3828 | 2010-10-23 08:21:37 +0000 | [diff] [blame] | 94 | void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED { |
Argyrios Kyrtzidis | 78e4cc7 | 2010-08-15 01:15:33 +0000 | [diff] [blame] | 95 | OS << "<<unknown expr type>>"; |
| 96 | } |
| 97 | void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 98 | |
Argyrios Kyrtzidis | 78e4cc7 | 2010-08-15 01:15:33 +0000 | [diff] [blame] | 99 | #define ABSTRACT_STMT(CLASS) |
Douglas Gregor | f2cad86 | 2008-11-14 12:46:07 +0000 | [diff] [blame] | 100 | #define STMT(CLASS, PARENT) \ |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 101 | void Visit##CLASS(CLASS *Node); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 102 | #include "clang/AST/StmtNodes.inc" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 103 | }; |
| 104 | } |
| 105 | |
| 106 | //===----------------------------------------------------------------------===// |
| 107 | // Stmt printing methods. |
| 108 | //===----------------------------------------------------------------------===// |
| 109 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 110 | /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and |
| 111 | /// with no newline after the }. |
| 112 | void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) { |
| 113 | OS << "{\n"; |
| 114 | for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end(); |
| 115 | I != E; ++I) |
| 116 | PrintStmt(*I); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 118 | Indent() << "}"; |
| 119 | } |
| 120 | |
| 121 | void StmtPrinter::PrintRawDecl(Decl *D) { |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 122 | D->print(OS, Policy, IndentLevel); |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 125 | void StmtPrinter::PrintRawDeclStmt(DeclStmt *S) { |
Eli Friedman | db23b15 | 2009-05-30 00:19:54 +0000 | [diff] [blame] | 126 | DeclStmt::decl_iterator Begin = S->decl_begin(), End = S->decl_end(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 127 | SmallVector<Decl*, 2> Decls; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | for ( ; Begin != End; ++Begin) |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 129 | Decls.push_back(*Begin); |
Eli Friedman | db23b15 | 2009-05-30 00:19:54 +0000 | [diff] [blame] | 130 | |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 131 | Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel); |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 132 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 133 | |
| 134 | void StmtPrinter::VisitNullStmt(NullStmt *Node) { |
| 135 | Indent() << ";\n"; |
| 136 | } |
| 137 | |
| 138 | void StmtPrinter::VisitDeclStmt(DeclStmt *Node) { |
Eli Friedman | db23b15 | 2009-05-30 00:19:54 +0000 | [diff] [blame] | 139 | Indent(); |
| 140 | PrintRawDeclStmt(Node); |
| 141 | OS << ";\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) { |
| 145 | Indent(); |
| 146 | PrintRawCompoundStmt(Node); |
| 147 | OS << "\n"; |
| 148 | } |
| 149 | |
| 150 | void StmtPrinter::VisitCaseStmt(CaseStmt *Node) { |
| 151 | Indent(-1) << "case "; |
| 152 | PrintExpr(Node->getLHS()); |
| 153 | if (Node->getRHS()) { |
| 154 | OS << " ... "; |
| 155 | PrintExpr(Node->getRHS()); |
| 156 | } |
| 157 | OS << ":\n"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 159 | PrintStmt(Node->getSubStmt(), 0); |
| 160 | } |
| 161 | |
| 162 | void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) { |
| 163 | Indent(-1) << "default:\n"; |
| 164 | PrintStmt(Node->getSubStmt(), 0); |
| 165 | } |
| 166 | |
| 167 | void StmtPrinter::VisitLabelStmt(LabelStmt *Node) { |
| 168 | Indent(-1) << Node->getName() << ":\n"; |
| 169 | PrintStmt(Node->getSubStmt(), 0); |
| 170 | } |
| 171 | |
| 172 | void StmtPrinter::PrintRawIfStmt(IfStmt *If) { |
Sebastian Redl | bfee9b2 | 2009-02-07 20:05:48 +0000 | [diff] [blame] | 173 | OS << "if ("; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 174 | PrintExpr(If->getCond()); |
Sebastian Redl | bfee9b2 | 2009-02-07 20:05:48 +0000 | [diff] [blame] | 175 | OS << ')'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 176 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 177 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) { |
| 178 | OS << ' '; |
| 179 | PrintRawCompoundStmt(CS); |
| 180 | OS << (If->getElse() ? ' ' : '\n'); |
| 181 | } else { |
| 182 | OS << '\n'; |
| 183 | PrintStmt(If->getThen()); |
| 184 | if (If->getElse()) Indent(); |
| 185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 186 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 187 | if (Stmt *Else = If->getElse()) { |
| 188 | OS << "else"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 190 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) { |
| 191 | OS << ' '; |
| 192 | PrintRawCompoundStmt(CS); |
| 193 | OS << '\n'; |
| 194 | } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) { |
| 195 | OS << ' '; |
| 196 | PrintRawIfStmt(ElseIf); |
| 197 | } else { |
| 198 | OS << '\n'; |
| 199 | PrintStmt(If->getElse()); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | void StmtPrinter::VisitIfStmt(IfStmt *If) { |
| 205 | Indent(); |
| 206 | PrintRawIfStmt(If); |
| 207 | } |
| 208 | |
| 209 | void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) { |
| 210 | Indent() << "switch ("; |
| 211 | PrintExpr(Node->getCond()); |
| 212 | OS << ")"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 214 | // Pretty print compoundstmt bodies (very common). |
| 215 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) { |
| 216 | OS << " "; |
| 217 | PrintRawCompoundStmt(CS); |
| 218 | OS << "\n"; |
| 219 | } else { |
| 220 | OS << "\n"; |
| 221 | PrintStmt(Node->getBody()); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | void StmtPrinter::VisitWhileStmt(WhileStmt *Node) { |
| 226 | Indent() << "while ("; |
| 227 | PrintExpr(Node->getCond()); |
| 228 | OS << ")\n"; |
| 229 | PrintStmt(Node->getBody()); |
| 230 | } |
| 231 | |
| 232 | void StmtPrinter::VisitDoStmt(DoStmt *Node) { |
Chris Lattner | 8bdcc47 | 2007-09-15 21:49:37 +0000 | [diff] [blame] | 233 | Indent() << "do "; |
| 234 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) { |
| 235 | PrintRawCompoundStmt(CS); |
| 236 | OS << " "; |
| 237 | } else { |
| 238 | OS << "\n"; |
| 239 | PrintStmt(Node->getBody()); |
| 240 | Indent(); |
| 241 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | |
Eli Friedman | b3e2296 | 2009-05-17 01:05:34 +0000 | [diff] [blame] | 243 | OS << "while ("; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 244 | PrintExpr(Node->getCond()); |
Eli Friedman | b3e2296 | 2009-05-17 01:05:34 +0000 | [diff] [blame] | 245 | OS << ");\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void StmtPrinter::VisitForStmt(ForStmt *Node) { |
| 249 | Indent() << "for ("; |
| 250 | if (Node->getInit()) { |
| 251 | if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit())) |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 252 | PrintRawDeclStmt(DS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 253 | else |
| 254 | PrintExpr(cast<Expr>(Node->getInit())); |
| 255 | } |
Chris Lattner | 8bdcc47 | 2007-09-15 21:49:37 +0000 | [diff] [blame] | 256 | OS << ";"; |
| 257 | if (Node->getCond()) { |
| 258 | OS << " "; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 259 | PrintExpr(Node->getCond()); |
Chris Lattner | 8bdcc47 | 2007-09-15 21:49:37 +0000 | [diff] [blame] | 260 | } |
| 261 | OS << ";"; |
| 262 | if (Node->getInc()) { |
| 263 | OS << " "; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 264 | PrintExpr(Node->getInc()); |
Chris Lattner | 8bdcc47 | 2007-09-15 21:49:37 +0000 | [diff] [blame] | 265 | } |
| 266 | OS << ") "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 267 | |
Chris Lattner | 8bdcc47 | 2007-09-15 21:49:37 +0000 | [diff] [blame] | 268 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) { |
| 269 | PrintRawCompoundStmt(CS); |
| 270 | OS << "\n"; |
| 271 | } else { |
| 272 | OS << "\n"; |
| 273 | PrintStmt(Node->getBody()); |
| 274 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 277 | void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) { |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 278 | Indent() << "for ("; |
| 279 | if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement())) |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 280 | PrintRawDeclStmt(DS); |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 281 | else |
| 282 | PrintExpr(cast<Expr>(Node->getElement())); |
| 283 | OS << " in "; |
| 284 | PrintExpr(Node->getCollection()); |
| 285 | OS << ") "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 287 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) { |
| 288 | PrintRawCompoundStmt(CS); |
| 289 | OS << "\n"; |
| 290 | } else { |
| 291 | OS << "\n"; |
| 292 | PrintStmt(Node->getBody()); |
| 293 | } |
| 294 | } |
| 295 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 296 | void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) { |
| 297 | Indent() << "for ("; |
| 298 | PrintingPolicy SubPolicy(Policy); |
| 299 | SubPolicy.SuppressInitializers = true; |
| 300 | Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel); |
| 301 | OS << " : "; |
| 302 | PrintExpr(Node->getRangeInit()); |
| 303 | OS << ") {\n"; |
| 304 | PrintStmt(Node->getBody()); |
| 305 | Indent() << "}\n"; |
| 306 | } |
| 307 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 308 | void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) { |
| 309 | Indent(); |
| 310 | if (Node->isIfExists()) |
| 311 | OS << "__if_exists ("; |
| 312 | else |
| 313 | OS << "__if_not_exists ("; |
| 314 | |
| 315 | if (NestedNameSpecifier *Qualifier |
| 316 | = Node->getQualifierLoc().getNestedNameSpecifier()) |
| 317 | Qualifier->print(OS, Policy); |
| 318 | |
| 319 | OS << Node->getNameInfo() << ") "; |
| 320 | |
| 321 | PrintRawCompoundStmt(Node->getSubStmt()); |
| 322 | } |
| 323 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 324 | void StmtPrinter::VisitGotoStmt(GotoStmt *Node) { |
| 325 | Indent() << "goto " << Node->getLabel()->getName() << ";\n"; |
| 326 | } |
| 327 | |
| 328 | void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) { |
| 329 | Indent() << "goto *"; |
| 330 | PrintExpr(Node->getTarget()); |
| 331 | OS << ";\n"; |
| 332 | } |
| 333 | |
| 334 | void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) { |
| 335 | Indent() << "continue;\n"; |
| 336 | } |
| 337 | |
| 338 | void StmtPrinter::VisitBreakStmt(BreakStmt *Node) { |
| 339 | Indent() << "break;\n"; |
| 340 | } |
| 341 | |
| 342 | |
| 343 | void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) { |
| 344 | Indent() << "return"; |
| 345 | if (Node->getRetValue()) { |
| 346 | OS << " "; |
| 347 | PrintExpr(Node->getRetValue()); |
| 348 | } |
| 349 | OS << ";\n"; |
| 350 | } |
| 351 | |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 352 | |
| 353 | void StmtPrinter::VisitAsmStmt(AsmStmt *Node) { |
Anders Carlsson | 39c47b5 | 2007-11-23 23:12:25 +0000 | [diff] [blame] | 354 | Indent() << "asm "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | |
Anders Carlsson | 39c47b5 | 2007-11-23 23:12:25 +0000 | [diff] [blame] | 356 | if (Node->isVolatile()) |
| 357 | OS << "volatile "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | |
Anders Carlsson | 39c47b5 | 2007-11-23 23:12:25 +0000 | [diff] [blame] | 359 | OS << "("; |
Anders Carlsson | 6a0ef4b | 2007-11-20 19:21:03 +0000 | [diff] [blame] | 360 | VisitStringLiteral(Node->getAsmString()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 361 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 362 | // Outputs |
| 363 | if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 || |
| 364 | Node->getNumClobbers() != 0) |
| 365 | OS << " : "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 366 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 367 | for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) { |
| 368 | if (i != 0) |
| 369 | OS << ", "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 371 | if (!Node->getOutputName(i).empty()) { |
| 372 | OS << '['; |
| 373 | OS << Node->getOutputName(i); |
| 374 | OS << "] "; |
| 375 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 376 | |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 377 | VisitStringLiteral(Node->getOutputConstraintLiteral(i)); |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 378 | OS << " "; |
| 379 | Visit(Node->getOutputExpr(i)); |
| 380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 382 | // Inputs |
| 383 | if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0) |
| 384 | OS << " : "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 385 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 386 | for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) { |
| 387 | if (i != 0) |
| 388 | OS << ", "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 390 | if (!Node->getInputName(i).empty()) { |
| 391 | OS << '['; |
| 392 | OS << Node->getInputName(i); |
| 393 | OS << "] "; |
| 394 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 396 | VisitStringLiteral(Node->getInputConstraintLiteral(i)); |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 397 | OS << " "; |
| 398 | Visit(Node->getInputExpr(i)); |
| 399 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 401 | // Clobbers |
| 402 | if (Node->getNumClobbers() != 0) |
| 403 | OS << " : "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 405 | for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) { |
| 406 | if (i != 0) |
| 407 | OS << ", "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 409 | VisitStringLiteral(Node->getClobber(i)); |
| 410 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | |
Anders Carlsson | 6a0ef4b | 2007-11-20 19:21:03 +0000 | [diff] [blame] | 412 | OS << ");\n"; |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 415 | void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) { |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 416 | Indent() << "@try"; |
| 417 | if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) { |
| 418 | PrintRawCompoundStmt(TS); |
| 419 | OS << "\n"; |
| 420 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 421 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 422 | for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) { |
| 423 | ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I); |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 424 | Indent() << "@catch("; |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 425 | if (catchStmt->getCatchParamDecl()) { |
| 426 | if (Decl *DS = catchStmt->getCatchParamDecl()) |
| 427 | PrintRawDecl(DS); |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 428 | } |
| 429 | OS << ")"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) { |
| 431 | PrintRawCompoundStmt(CS); |
| 432 | OS << "\n"; |
| 433 | } |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 434 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 435 | |
| 436 | if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>( |
| 437 | Node->getFinallyStmt())) { |
Fariborz Jahanian | 1e7eab4 | 2007-11-07 00:46:42 +0000 | [diff] [blame] | 438 | Indent() << "@finally"; |
| 439 | PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody())); |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 440 | OS << "\n"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 441 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 444 | void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) { |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 447 | void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) { |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 448 | Indent() << "@catch (...) { /* todo */ } \n"; |
| 449 | } |
| 450 | |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 451 | void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 452 | Indent() << "@throw"; |
| 453 | if (Node->getThrowExpr()) { |
| 454 | OS << " "; |
| 455 | PrintExpr(Node->getThrowExpr()); |
| 456 | } |
| 457 | OS << ";\n"; |
| 458 | } |
| 459 | |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 460 | void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) { |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 461 | Indent() << "@synchronized ("; |
| 462 | PrintExpr(Node->getSynchExpr()); |
| 463 | OS << ")"; |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 464 | PrintRawCompoundStmt(Node->getSynchBody()); |
| 465 | OS << "\n"; |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 466 | } |
| 467 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 468 | void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) { |
| 469 | Indent() << "@autoreleasepool"; |
| 470 | PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt())); |
| 471 | OS << "\n"; |
| 472 | } |
| 473 | |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 474 | void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) { |
| 475 | OS << "catch ("; |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 476 | if (Decl *ExDecl = Node->getExceptionDecl()) |
| 477 | PrintRawDecl(ExDecl); |
| 478 | else |
| 479 | OS << "..."; |
| 480 | OS << ") "; |
| 481 | PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock())); |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) { |
| 485 | Indent(); |
| 486 | PrintRawCXXCatchStmt(Node); |
| 487 | OS << "\n"; |
| 488 | } |
| 489 | |
| 490 | void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) { |
| 491 | Indent() << "try "; |
| 492 | PrintRawCompoundStmt(Node->getTryBlock()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) { |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 494 | OS << " "; |
| 495 | PrintRawCXXCatchStmt(Node->getHandler(i)); |
| 496 | } |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 497 | OS << "\n"; |
| 498 | } |
| 499 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 500 | void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) { |
| 501 | Indent() << (Node->getIsCXXTry() ? "try " : "__try "); |
| 502 | PrintRawCompoundStmt(Node->getTryBlock()); |
| 503 | SEHExceptStmt *E = Node->getExceptHandler(); |
| 504 | SEHFinallyStmt *F = Node->getFinallyHandler(); |
| 505 | if(E) |
| 506 | PrintRawSEHExceptHandler(E); |
| 507 | else { |
| 508 | assert(F && "Must have a finally block..."); |
| 509 | PrintRawSEHFinallyStmt(F); |
| 510 | } |
| 511 | OS << "\n"; |
| 512 | } |
| 513 | |
| 514 | void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) { |
| 515 | OS << "__finally "; |
| 516 | PrintRawCompoundStmt(Node->getBlock()); |
| 517 | OS << "\n"; |
| 518 | } |
| 519 | |
| 520 | void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) { |
| 521 | OS << "__except ("; |
| 522 | VisitExpr(Node->getFilterExpr()); |
| 523 | OS << ")\n"; |
| 524 | PrintRawCompoundStmt(Node->getBlock()); |
| 525 | OS << "\n"; |
| 526 | } |
| 527 | |
| 528 | void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) { |
| 529 | Indent(); |
| 530 | PrintRawSEHExceptHandler(Node); |
| 531 | OS << "\n"; |
| 532 | } |
| 533 | |
| 534 | void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) { |
| 535 | Indent(); |
| 536 | PrintRawSEHFinallyStmt(Node); |
| 537 | OS << "\n"; |
| 538 | } |
| 539 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 540 | //===----------------------------------------------------------------------===// |
| 541 | // Expr printing methods. |
| 542 | //===----------------------------------------------------------------------===// |
| 543 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 544 | void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 545 | if (NestedNameSpecifier *Qualifier = Node->getQualifier()) |
| 546 | Qualifier->print(OS, Policy); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 547 | OS << Node->getNameInfo(); |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 548 | if (Node->hasExplicitTemplateArgs()) |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 549 | OS << TemplateSpecializationType::PrintTemplateArgumentList( |
| 550 | Node->getTemplateArgs(), |
| 551 | Node->getNumTemplateArgs(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 552 | Policy); |
Douglas Gregor | 1a49af9 | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 553 | } |
| 554 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 555 | void StmtPrinter::VisitDependentScopeDeclRefExpr( |
| 556 | DependentScopeDeclRefExpr *Node) { |
Axel Naumann | 274f83c | 2011-01-24 15:44:00 +0000 | [diff] [blame] | 557 | if (NestedNameSpecifier *Qualifier = Node->getQualifier()) |
| 558 | Qualifier->print(OS, Policy); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 559 | OS << Node->getNameInfo(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 560 | if (Node->hasExplicitTemplateArgs()) |
| 561 | OS << TemplateSpecializationType::PrintTemplateArgumentList( |
| 562 | Node->getTemplateArgs(), |
| 563 | Node->getNumTemplateArgs(), |
| 564 | Policy); |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 565 | } |
| 566 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 567 | void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) { |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 568 | if (Node->getQualifier()) |
| 569 | Node->getQualifier()->print(OS, Policy); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 570 | OS << Node->getNameInfo(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 571 | if (Node->hasExplicitTemplateArgs()) |
| 572 | OS << TemplateSpecializationType::PrintTemplateArgumentList( |
| 573 | Node->getTemplateArgs(), |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 574 | Node->getNumTemplateArgs(), |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 575 | Policy); |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Steve Naroff | 7779db4 | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 578 | void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { |
Fariborz Jahanian | 232220c | 2007-11-12 22:29:28 +0000 | [diff] [blame] | 579 | if (Node->getBase()) { |
| 580 | PrintExpr(Node->getBase()); |
| 581 | OS << (Node->isArrow() ? "->" : "."); |
| 582 | } |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 583 | OS << *Node->getDecl(); |
Steve Naroff | 7779db4 | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Steve Naroff | ae78407 | 2008-05-30 00:40:33 +0000 | [diff] [blame] | 586 | void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) { |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 587 | if (Node->isSuperReceiver()) |
| 588 | OS << "super."; |
| 589 | else if (Node->getBase()) { |
Steve Naroff | ae78407 | 2008-05-30 00:40:33 +0000 | [diff] [blame] | 590 | PrintExpr(Node->getBase()); |
| 591 | OS << "."; |
| 592 | } |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 593 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 594 | if (Node->isImplicitProperty()) |
| 595 | OS << Node->getImplicitPropertyGetter()->getSelector().getAsString(); |
| 596 | else |
| 597 | OS << Node->getExplicitProperty()->getName(); |
Fariborz Jahanian | 5daf570 | 2008-11-22 18:39:36 +0000 | [diff] [blame] | 598 | } |
| 599 | |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 600 | void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) { |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 601 | switch (Node->getIdentType()) { |
| 602 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 603 | llvm_unreachable("unknown case"); |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 604 | case PredefinedExpr::Func: |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 605 | OS << "__func__"; |
| 606 | break; |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 607 | case PredefinedExpr::Function: |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 608 | OS << "__FUNCTION__"; |
| 609 | break; |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 610 | case PredefinedExpr::PrettyFunction: |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 611 | OS << "__PRETTY_FUNCTION__"; |
| 612 | break; |
| 613 | } |
| 614 | } |
| 615 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 616 | void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) { |
Chris Lattner | b0a721a | 2007-07-13 05:18:11 +0000 | [diff] [blame] | 617 | unsigned value = Node->getValue(); |
Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 618 | |
| 619 | switch (Node->getKind()) { |
| 620 | case CharacterLiteral::Ascii: break; // no prefix. |
| 621 | case CharacterLiteral::Wide: OS << 'L'; break; |
| 622 | case CharacterLiteral::UTF16: OS << 'u'; break; |
| 623 | case CharacterLiteral::UTF32: OS << 'U'; break; |
| 624 | } |
| 625 | |
Chris Lattner | 8bf9f07 | 2007-07-13 23:58:20 +0000 | [diff] [blame] | 626 | switch (value) { |
| 627 | case '\\': |
| 628 | OS << "'\\\\'"; |
| 629 | break; |
| 630 | case '\'': |
| 631 | OS << "'\\''"; |
| 632 | break; |
| 633 | case '\a': |
| 634 | // TODO: K&R: the meaning of '\\a' is different in traditional C |
| 635 | OS << "'\\a'"; |
| 636 | break; |
| 637 | case '\b': |
| 638 | OS << "'\\b'"; |
| 639 | break; |
| 640 | // Nonstandard escape sequence. |
| 641 | /*case '\e': |
| 642 | OS << "'\\e'"; |
| 643 | break;*/ |
| 644 | case '\f': |
| 645 | OS << "'\\f'"; |
| 646 | break; |
| 647 | case '\n': |
| 648 | OS << "'\\n'"; |
| 649 | break; |
| 650 | case '\r': |
| 651 | OS << "'\\r'"; |
| 652 | break; |
| 653 | case '\t': |
| 654 | OS << "'\\t'"; |
| 655 | break; |
| 656 | case '\v': |
| 657 | OS << "'\\v'"; |
| 658 | break; |
| 659 | default: |
Ted Kremenek | 471733d | 2008-02-23 00:52:04 +0000 | [diff] [blame] | 660 | if (value < 256 && isprint(value)) { |
Chris Lattner | 8bf9f07 | 2007-07-13 23:58:20 +0000 | [diff] [blame] | 661 | OS << "'" << (char)value << "'"; |
| 662 | } else if (value < 256) { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 663 | OS << "'\\x" << llvm::format("%x", value) << "'"; |
Chris Lattner | 8bf9f07 | 2007-07-13 23:58:20 +0000 | [diff] [blame] | 664 | } else { |
| 665 | // FIXME what to really do here? |
| 666 | OS << value; |
| 667 | } |
Chris Lattner | b0a721a | 2007-07-13 05:18:11 +0000 | [diff] [blame] | 668 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) { |
| 672 | bool isSigned = Node->getType()->isSignedIntegerType(); |
| 673 | OS << Node->getValue().toString(10, isSigned); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 675 | // Emit suffixes. Integer literals are always a builtin integer type. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 676 | switch (Node->getType()->getAs<BuiltinType>()->getKind()) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 677 | default: llvm_unreachable("Unexpected type for integer literal!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 678 | case BuiltinType::Int: break; // no suffix. |
| 679 | case BuiltinType::UInt: OS << 'U'; break; |
| 680 | case BuiltinType::Long: OS << 'L'; break; |
| 681 | case BuiltinType::ULong: OS << "UL"; break; |
| 682 | case BuiltinType::LongLong: OS << "LL"; break; |
| 683 | case BuiltinType::ULongLong: OS << "ULL"; break; |
| 684 | } |
| 685 | } |
| 686 | void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) { |
Eli Friedman | b390921 | 2011-10-05 20:32:03 +0000 | [diff] [blame] | 687 | llvm::SmallString<16> Str; |
| 688 | Node->getValue().toString(Str); |
| 689 | OS << Str; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 690 | } |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 691 | |
| 692 | void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) { |
| 693 | PrintExpr(Node->getSubExpr()); |
| 694 | OS << "i"; |
| 695 | } |
| 696 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 697 | void StmtPrinter::VisitStringLiteral(StringLiteral *Str) { |
Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 698 | switch (Str->getKind()) { |
| 699 | case StringLiteral::Ascii: break; // no prefix. |
| 700 | case StringLiteral::Wide: OS << 'L'; break; |
| 701 | case StringLiteral::UTF8: OS << "u8"; break; |
| 702 | case StringLiteral::UTF16: OS << 'u'; break; |
| 703 | case StringLiteral::UTF32: OS << 'U'; break; |
| 704 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 705 | OS << '"'; |
Anders Carlsson | ee98ac5 | 2007-10-15 02:50:23 +0000 | [diff] [blame] | 706 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 707 | // FIXME: this doesn't print wstrings right. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 708 | StringRef StrData = Str->getString(); |
| 709 | for (StringRef::iterator I = StrData.begin(), E = StrData.end(); |
Benjamin Kramer | 2f4eaef | 2010-08-17 12:54:38 +0000 | [diff] [blame] | 710 | I != E; ++I) { |
| 711 | unsigned char Char = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | |
Chris Lattner | 9a81c87 | 2009-01-16 19:25:18 +0000 | [diff] [blame] | 713 | switch (Char) { |
| 714 | default: |
| 715 | if (isprint(Char)) |
| 716 | OS << (char)Char; |
| 717 | else // Output anything hard as an octal escape. |
| 718 | OS << '\\' |
| 719 | << (char)('0'+ ((Char >> 6) & 7)) |
| 720 | << (char)('0'+ ((Char >> 3) & 7)) |
| 721 | << (char)('0'+ ((Char >> 0) & 7)); |
| 722 | break; |
| 723 | // Handle some common non-printable cases to make dumps prettier. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 724 | case '\\': OS << "\\\\"; break; |
| 725 | case '"': OS << "\\\""; break; |
| 726 | case '\n': OS << "\\n"; break; |
| 727 | case '\t': OS << "\\t"; break; |
| 728 | case '\a': OS << "\\a"; break; |
| 729 | case '\b': OS << "\\b"; break; |
| 730 | } |
| 731 | } |
| 732 | OS << '"'; |
| 733 | } |
| 734 | void StmtPrinter::VisitParenExpr(ParenExpr *Node) { |
| 735 | OS << "("; |
| 736 | PrintExpr(Node->getSubExpr()); |
| 737 | OS << ")"; |
| 738 | } |
| 739 | void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) { |
Chris Lattner | 296bf19 | 2007-08-23 21:46:40 +0000 | [diff] [blame] | 740 | if (!Node->isPostfix()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 741 | OS << UnaryOperator::getOpcodeStr(Node->getOpcode()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | |
Eli Friedman | 7df71ac | 2009-06-14 22:39:26 +0000 | [diff] [blame] | 743 | // Print a space if this is an "identifier operator" like __real, or if |
| 744 | // it might be concatenated incorrectly like '+'. |
Chris Lattner | 296bf19 | 2007-08-23 21:46:40 +0000 | [diff] [blame] | 745 | switch (Node->getOpcode()) { |
| 746 | default: break; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 747 | case UO_Real: |
| 748 | case UO_Imag: |
| 749 | case UO_Extension: |
Chris Lattner | 296bf19 | 2007-08-23 21:46:40 +0000 | [diff] [blame] | 750 | OS << ' '; |
| 751 | break; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 752 | case UO_Plus: |
| 753 | case UO_Minus: |
Eli Friedman | 7df71ac | 2009-06-14 22:39:26 +0000 | [diff] [blame] | 754 | if (isa<UnaryOperator>(Node->getSubExpr())) |
| 755 | OS << ' '; |
| 756 | break; |
Chris Lattner | 296bf19 | 2007-08-23 21:46:40 +0000 | [diff] [blame] | 757 | } |
| 758 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 759 | PrintExpr(Node->getSubExpr()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 760 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 761 | if (Node->isPostfix()) |
| 762 | OS << UnaryOperator::getOpcodeStr(Node->getOpcode()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 763 | } |
Chris Lattner | 704fe35 | 2007-08-30 17:59:59 +0000 | [diff] [blame] | 764 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 765 | void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) { |
| 766 | OS << "__builtin_offsetof("; |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 767 | OS << Node->getTypeSourceInfo()->getType().getAsString(Policy) << ", "; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 768 | bool PrintedSomething = false; |
| 769 | for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) { |
| 770 | OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i); |
| 771 | if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Array) { |
| 772 | // Array node |
| 773 | OS << "["; |
| 774 | PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex())); |
| 775 | OS << "]"; |
| 776 | PrintedSomething = true; |
| 777 | continue; |
| 778 | } |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 779 | |
| 780 | // Skip implicit base indirections. |
| 781 | if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Base) |
| 782 | continue; |
| 783 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 784 | // Field or identifier node. |
| 785 | IdentifierInfo *Id = ON.getFieldName(); |
| 786 | if (!Id) |
| 787 | continue; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 788 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 789 | if (PrintedSomething) |
| 790 | OS << "."; |
| 791 | else |
| 792 | PrintedSomething = true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 793 | OS << Id->getName(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 794 | } |
| 795 | OS << ")"; |
| 796 | } |
| 797 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 798 | void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){ |
| 799 | switch(Node->getKind()) { |
| 800 | case UETT_SizeOf: |
| 801 | OS << "sizeof"; |
| 802 | break; |
| 803 | case UETT_AlignOf: |
| 804 | OS << "__alignof"; |
| 805 | break; |
| 806 | case UETT_VecStep: |
| 807 | OS << "vec_step"; |
| 808 | break; |
| 809 | } |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 810 | if (Node->isArgumentType()) |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 811 | OS << "(" << Node->getArgumentType().getAsString(Policy) << ")"; |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 812 | else { |
| 813 | OS << " "; |
| 814 | PrintExpr(Node->getArgumentExpr()); |
| 815 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 816 | } |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 817 | |
| 818 | void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) { |
| 819 | OS << "_Generic("; |
| 820 | PrintExpr(Node->getControllingExpr()); |
| 821 | for (unsigned i = 0; i != Node->getNumAssocs(); ++i) { |
| 822 | OS << ", "; |
| 823 | QualType T = Node->getAssocType(i); |
| 824 | if (T.isNull()) |
| 825 | OS << "default"; |
| 826 | else |
| 827 | OS << T.getAsString(Policy); |
| 828 | OS << ": "; |
| 829 | PrintExpr(Node->getAssocExpr(i)); |
| 830 | } |
| 831 | OS << ")"; |
| 832 | } |
| 833 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 834 | void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) { |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 835 | PrintExpr(Node->getLHS()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 836 | OS << "["; |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 837 | PrintExpr(Node->getRHS()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 838 | OS << "]"; |
| 839 | } |
| 840 | |
Peter Collingbourne | d64e237 | 2011-02-08 21:17:54 +0000 | [diff] [blame] | 841 | void StmtPrinter::PrintCallArgs(CallExpr *Call) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 842 | for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) { |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 843 | if (isa<CXXDefaultArgExpr>(Call->getArg(i))) { |
| 844 | // Don't print any defaulted arguments |
| 845 | break; |
| 846 | } |
| 847 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 848 | if (i) OS << ", "; |
| 849 | PrintExpr(Call->getArg(i)); |
| 850 | } |
Peter Collingbourne | d64e237 | 2011-02-08 21:17:54 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | void StmtPrinter::VisitCallExpr(CallExpr *Call) { |
| 854 | PrintExpr(Call->getCallee()); |
| 855 | OS << "("; |
| 856 | PrintCallArgs(Call); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 857 | OS << ")"; |
| 858 | } |
| 859 | void StmtPrinter::VisitMemberExpr(MemberExpr *Node) { |
Douglas Gregor | b3eef68 | 2009-01-08 22:45:41 +0000 | [diff] [blame] | 860 | // FIXME: Suppress printing implicit bases (like "this") |
| 861 | PrintExpr(Node->getBase()); |
Fariborz Jahanian | 97fd83a | 2010-01-11 21:17:32 +0000 | [diff] [blame] | 862 | if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl())) |
| 863 | if (FD->isAnonymousStructOrUnion()) |
| 864 | return; |
Douglas Gregor | b3eef68 | 2009-01-08 22:45:41 +0000 | [diff] [blame] | 865 | OS << (Node->isArrow() ? "->" : "."); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 866 | if (NestedNameSpecifier *Qualifier = Node->getQualifier()) |
| 867 | Qualifier->print(OS, Policy); |
| 868 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 869 | OS << Node->getMemberNameInfo(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 871 | if (Node->hasExplicitTemplateArgs()) |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 872 | OS << TemplateSpecializationType::PrintTemplateArgumentList( |
| 873 | Node->getTemplateArgs(), |
| 874 | Node->getNumTemplateArgs(), |
| 875 | Policy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 876 | } |
Steve Naroff | f242b1b | 2009-07-24 17:54:45 +0000 | [diff] [blame] | 877 | void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) { |
| 878 | PrintExpr(Node->getBase()); |
| 879 | OS << (Node->isArrow() ? "->isa" : ".isa"); |
| 880 | } |
| 881 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 882 | void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) { |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 883 | PrintExpr(Node->getBase()); |
| 884 | OS << "."; |
| 885 | OS << Node->getAccessor().getName(); |
| 886 | } |
Douglas Gregor | 6eec8e8 | 2008-10-28 15:36:24 +0000 | [diff] [blame] | 887 | void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) { |
Fariborz Jahanian | 03e80e4 | 2010-06-30 16:31:08 +0000 | [diff] [blame] | 888 | OS << "(" << Node->getType().getAsString(Policy) << ")"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 889 | PrintExpr(Node->getSubExpr()); |
| 890 | } |
Steve Naroff | aff1edd | 2007-07-19 21:32:11 +0000 | [diff] [blame] | 891 | void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) { |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 892 | OS << "(" << Node->getType().getAsString(Policy) << ")"; |
Steve Naroff | aff1edd | 2007-07-19 21:32:11 +0000 | [diff] [blame] | 893 | PrintExpr(Node->getInitializer()); |
| 894 | } |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 895 | void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) { |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 896 | // No need to print anything, simply forward to the sub expression. |
| 897 | PrintExpr(Node->getSubExpr()); |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 898 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 899 | void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) { |
| 900 | PrintExpr(Node->getLHS()); |
| 901 | OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " "; |
| 902 | PrintExpr(Node->getRHS()); |
| 903 | } |
Chris Lattner | eb14fe8 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 904 | void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) { |
| 905 | PrintExpr(Node->getLHS()); |
| 906 | OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " "; |
| 907 | PrintExpr(Node->getRHS()); |
| 908 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 909 | void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) { |
| 910 | PrintExpr(Node->getCond()); |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 911 | OS << " ? "; |
| 912 | PrintExpr(Node->getLHS()); |
| 913 | OS << " : "; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 914 | PrintExpr(Node->getRHS()); |
| 915 | } |
| 916 | |
| 917 | // GNU extensions. |
| 918 | |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 919 | void |
| 920 | StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) { |
| 921 | PrintExpr(Node->getCommon()); |
| 922 | OS << " ?: "; |
| 923 | PrintExpr(Node->getFalseExpr()); |
| 924 | } |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 925 | void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 926 | OS << "&&" << Node->getLabel()->getName(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 927 | } |
| 928 | |
Chris Lattner | ab18c4c | 2007-07-24 16:58:17 +0000 | [diff] [blame] | 929 | void StmtPrinter::VisitStmtExpr(StmtExpr *E) { |
| 930 | OS << "("; |
| 931 | PrintRawCompoundStmt(E->getSubStmt()); |
| 932 | OS << ")"; |
| 933 | } |
| 934 | |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 935 | void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) { |
| 936 | OS << "__builtin_choose_expr("; |
| 937 | PrintExpr(Node->getCond()); |
Chris Lattner | 94f05e3 | 2007-08-04 00:20:15 +0000 | [diff] [blame] | 938 | OS << ", "; |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 939 | PrintExpr(Node->getLHS()); |
Chris Lattner | 94f05e3 | 2007-08-04 00:20:15 +0000 | [diff] [blame] | 940 | OS << ", "; |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 941 | PrintExpr(Node->getRHS()); |
| 942 | OS << ")"; |
| 943 | } |
Chris Lattner | ab18c4c | 2007-07-24 16:58:17 +0000 | [diff] [blame] | 944 | |
Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 945 | void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) { |
| 946 | OS << "__null"; |
| 947 | } |
| 948 | |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 949 | void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) { |
| 950 | OS << "__builtin_shufflevector("; |
| 951 | for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) { |
| 952 | if (i) OS << ", "; |
| 953 | PrintExpr(Node->getExpr(i)); |
| 954 | } |
| 955 | OS << ")"; |
| 956 | } |
| 957 | |
Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 958 | void StmtPrinter::VisitInitListExpr(InitListExpr* Node) { |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 959 | if (Node->getSyntacticForm()) { |
| 960 | Visit(Node->getSyntacticForm()); |
| 961 | return; |
| 962 | } |
| 963 | |
Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 964 | OS << "{ "; |
| 965 | for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) { |
| 966 | if (i) OS << ", "; |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 967 | if (Node->getInit(i)) |
| 968 | PrintExpr(Node->getInit(i)); |
| 969 | else |
| 970 | OS << "0"; |
Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 971 | } |
| 972 | OS << " }"; |
| 973 | } |
| 974 | |
Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 975 | void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) { |
| 976 | OS << "( "; |
| 977 | for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) { |
| 978 | if (i) OS << ", "; |
| 979 | PrintExpr(Node->getExpr(i)); |
| 980 | } |
| 981 | OS << " )"; |
| 982 | } |
| 983 | |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 984 | void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) { |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 985 | for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(), |
| 986 | DEnd = Node->designators_end(); |
| 987 | D != DEnd; ++D) { |
| 988 | if (D->isFieldDesignator()) { |
| 989 | if (D->getDotLoc().isInvalid()) |
| 990 | OS << D->getFieldName()->getName() << ":"; |
| 991 | else |
| 992 | OS << "." << D->getFieldName()->getName(); |
| 993 | } else { |
| 994 | OS << "["; |
| 995 | if (D->isArrayDesignator()) { |
| 996 | PrintExpr(Node->getArrayIndex(*D)); |
| 997 | } else { |
| 998 | PrintExpr(Node->getArrayRangeStart(*D)); |
| 999 | OS << " ... "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | PrintExpr(Node->getArrayRangeEnd(*D)); |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 1001 | } |
| 1002 | OS << "]"; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | OS << " = "; |
| 1007 | PrintExpr(Node->getInit()); |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 1010 | void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) { |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 1011 | if (Policy.LangOpts.CPlusPlus) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1012 | OS << "/*implicit*/" << Node->getType().getAsString(Policy) << "()"; |
| 1013 | else { |
| 1014 | OS << "/*implicit*/(" << Node->getType().getAsString(Policy) << ")"; |
| 1015 | if (Node->getType()->isRecordType()) |
| 1016 | OS << "{}"; |
| 1017 | else |
| 1018 | OS << 0; |
| 1019 | } |
Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 1022 | void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) { |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 1023 | OS << "__builtin_va_arg("; |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 1024 | PrintExpr(Node->getSubExpr()); |
| 1025 | OS << ", "; |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 1026 | OS << Node->getType().getAsString(Policy); |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 1027 | OS << ")"; |
| 1028 | } |
| 1029 | |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame^] | 1030 | void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) { |
| 1031 | PrintExpr(Node->getSyntacticForm()); |
| 1032 | } |
| 1033 | |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1034 | void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) { |
Eli Friedman | 9e3c20b | 2011-10-11 20:00:47 +0000 | [diff] [blame] | 1035 | const char *Name = 0; |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1036 | switch (Node->getOp()) { |
| 1037 | case AtomicExpr::Load: |
| 1038 | Name = "__atomic_load("; |
| 1039 | break; |
| 1040 | case AtomicExpr::Store: |
| 1041 | Name = "__atomic_store("; |
| 1042 | break; |
| 1043 | case AtomicExpr::CmpXchgStrong: |
| 1044 | Name = "__atomic_compare_exchange_strong("; |
| 1045 | break; |
| 1046 | case AtomicExpr::CmpXchgWeak: |
| 1047 | Name = "__atomic_compare_exchange_weak("; |
| 1048 | break; |
| 1049 | case AtomicExpr::Xchg: |
| 1050 | Name = "__atomic_exchange("; |
| 1051 | break; |
| 1052 | case AtomicExpr::Add: |
| 1053 | Name = "__atomic_fetch_add("; |
| 1054 | break; |
| 1055 | case AtomicExpr::Sub: |
| 1056 | Name = "__atomic_fetch_sub("; |
| 1057 | break; |
| 1058 | case AtomicExpr::And: |
| 1059 | Name = "__atomic_fetch_and("; |
| 1060 | break; |
| 1061 | case AtomicExpr::Or: |
| 1062 | Name = "__atomic_fetch_or("; |
| 1063 | break; |
| 1064 | case AtomicExpr::Xor: |
| 1065 | Name = "__atomic_fetch_xor("; |
| 1066 | break; |
| 1067 | } |
| 1068 | OS << Name; |
| 1069 | PrintExpr(Node->getPtr()); |
| 1070 | OS << ", "; |
| 1071 | if (Node->getOp() != AtomicExpr::Load) { |
| 1072 | PrintExpr(Node->getVal1()); |
| 1073 | OS << ", "; |
| 1074 | } |
| 1075 | if (Node->isCmpXChg()) { |
| 1076 | PrintExpr(Node->getVal2()); |
| 1077 | OS << ", "; |
| 1078 | } |
| 1079 | PrintExpr(Node->getOrder()); |
| 1080 | if (Node->isCmpXChg()) { |
| 1081 | OS << ", "; |
| 1082 | PrintExpr(Node->getOrderFail()); |
| 1083 | } |
| 1084 | OS << ")"; |
| 1085 | } |
| 1086 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1087 | // C++ |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 1088 | void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) { |
| 1089 | const char *OpStrings[NUM_OVERLOADED_OPERATORS] = { |
| 1090 | "", |
| 1091 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 1092 | Spelling, |
| 1093 | #include "clang/Basic/OperatorKinds.def" |
| 1094 | }; |
| 1095 | |
| 1096 | OverloadedOperatorKind Kind = Node->getOperator(); |
| 1097 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 1098 | if (Node->getNumArgs() == 1) { |
| 1099 | OS << OpStrings[Kind] << ' '; |
| 1100 | PrintExpr(Node->getArg(0)); |
| 1101 | } else { |
| 1102 | PrintExpr(Node->getArg(0)); |
| 1103 | OS << ' ' << OpStrings[Kind]; |
| 1104 | } |
| 1105 | } else if (Kind == OO_Call) { |
| 1106 | PrintExpr(Node->getArg(0)); |
| 1107 | OS << '('; |
| 1108 | for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) { |
| 1109 | if (ArgIdx > 1) |
| 1110 | OS << ", "; |
| 1111 | if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx))) |
| 1112 | PrintExpr(Node->getArg(ArgIdx)); |
| 1113 | } |
| 1114 | OS << ')'; |
| 1115 | } else if (Kind == OO_Subscript) { |
| 1116 | PrintExpr(Node->getArg(0)); |
| 1117 | OS << '['; |
| 1118 | PrintExpr(Node->getArg(1)); |
| 1119 | OS << ']'; |
| 1120 | } else if (Node->getNumArgs() == 1) { |
| 1121 | OS << OpStrings[Kind] << ' '; |
| 1122 | PrintExpr(Node->getArg(0)); |
| 1123 | } else if (Node->getNumArgs() == 2) { |
| 1124 | PrintExpr(Node->getArg(0)); |
| 1125 | OS << ' ' << OpStrings[Kind] << ' '; |
| 1126 | PrintExpr(Node->getArg(1)); |
| 1127 | } else { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1128 | llvm_unreachable("unknown overloaded operator"); |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 1129 | } |
| 1130 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1131 | |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 1132 | void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) { |
| 1133 | VisitCallExpr(cast<CallExpr>(Node)); |
| 1134 | } |
| 1135 | |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1136 | void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) { |
| 1137 | PrintExpr(Node->getCallee()); |
| 1138 | OS << "<<<"; |
| 1139 | PrintCallArgs(Node->getConfig()); |
| 1140 | OS << ">>>("; |
| 1141 | PrintCallArgs(Node); |
| 1142 | OS << ")"; |
| 1143 | } |
| 1144 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 1145 | void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) { |
| 1146 | OS << Node->getCastName() << '<'; |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 1147 | OS << Node->getTypeAsWritten().getAsString(Policy) << ">("; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1148 | PrintExpr(Node->getSubExpr()); |
| 1149 | OS << ")"; |
| 1150 | } |
| 1151 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 1152 | void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) { |
| 1153 | VisitCXXNamedCastExpr(Node); |
| 1154 | } |
| 1155 | |
| 1156 | void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) { |
| 1157 | VisitCXXNamedCastExpr(Node); |
| 1158 | } |
| 1159 | |
| 1160 | void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) { |
| 1161 | VisitCXXNamedCastExpr(Node); |
| 1162 | } |
| 1163 | |
| 1164 | void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) { |
| 1165 | VisitCXXNamedCastExpr(Node); |
| 1166 | } |
| 1167 | |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1168 | void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) { |
| 1169 | OS << "typeid("; |
| 1170 | if (Node->isTypeOperand()) { |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 1171 | OS << Node->getTypeOperand().getAsString(Policy); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1172 | } else { |
| 1173 | PrintExpr(Node->getExprOperand()); |
| 1174 | } |
| 1175 | OS << ")"; |
| 1176 | } |
| 1177 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1178 | void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) { |
| 1179 | OS << "__uuidof("; |
| 1180 | if (Node->isTypeOperand()) { |
| 1181 | OS << Node->getTypeOperand().getAsString(Policy); |
| 1182 | } else { |
| 1183 | PrintExpr(Node->getExprOperand()); |
| 1184 | } |
| 1185 | OS << ")"; |
| 1186 | } |
| 1187 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1188 | void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) { |
| 1189 | OS << (Node->getValue() ? "true" : "false"); |
| 1190 | } |
| 1191 | |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 1192 | void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) { |
| 1193 | OS << "nullptr"; |
| 1194 | } |
| 1195 | |
Douglas Gregor | 796da18 | 2008-11-04 14:32:21 +0000 | [diff] [blame] | 1196 | void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) { |
| 1197 | OS << "this"; |
| 1198 | } |
| 1199 | |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1200 | void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) { |
| 1201 | if (Node->getSubExpr() == 0) |
| 1202 | OS << "throw"; |
| 1203 | else { |
| 1204 | OS << "throw "; |
| 1205 | PrintExpr(Node->getSubExpr()); |
| 1206 | } |
| 1207 | } |
| 1208 | |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 1209 | void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) { |
| 1210 | // Nothing to print: we picked up the default argument |
| 1211 | } |
| 1212 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1213 | void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) { |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 1214 | OS << Node->getType().getAsString(Policy); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1215 | OS << "("; |
| 1216 | PrintExpr(Node->getSubExpr()); |
| 1217 | OS << ")"; |
| 1218 | } |
| 1219 | |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 1220 | void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) { |
| 1221 | PrintExpr(Node->getSubExpr()); |
| 1222 | } |
| 1223 | |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 1224 | void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) { |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 1225 | OS << Node->getType().getAsString(Policy); |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 1226 | OS << "("; |
| 1227 | for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | ArgEnd = Node->arg_end(); |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 1229 | Arg != ArgEnd; ++Arg) { |
| 1230 | if (Arg != Node->arg_begin()) |
| 1231 | OS << ", "; |
| 1232 | PrintExpr(*Arg); |
| 1233 | } |
| 1234 | OS << ")"; |
| 1235 | } |
| 1236 | |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 1237 | void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1238 | if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo()) |
| 1239 | OS << TSInfo->getType().getAsString(Policy) << "()"; |
| 1240 | else |
| 1241 | OS << Node->getType().getAsString(Policy) << "()"; |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1244 | void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 1245 | if (E->isGlobalNew()) |
| 1246 | OS << "::"; |
| 1247 | OS << "new "; |
| 1248 | unsigned NumPlace = E->getNumPlacementArgs(); |
| 1249 | if (NumPlace > 0) { |
| 1250 | OS << "("; |
| 1251 | PrintExpr(E->getPlacementArg(0)); |
| 1252 | for (unsigned i = 1; i < NumPlace; ++i) { |
| 1253 | OS << ", "; |
| 1254 | PrintExpr(E->getPlacementArg(i)); |
| 1255 | } |
| 1256 | OS << ") "; |
| 1257 | } |
| 1258 | if (E->isParenTypeId()) |
| 1259 | OS << "("; |
Sebastian Redl | 6fec648 | 2008-12-02 22:08:59 +0000 | [diff] [blame] | 1260 | std::string TypeS; |
| 1261 | if (Expr *Size = E->getArraySize()) { |
| 1262 | llvm::raw_string_ostream s(TypeS); |
Eli Friedman | 6e1a345 | 2009-05-30 05:32:46 +0000 | [diff] [blame] | 1263 | Size->printPretty(s, Context, Helper, Policy); |
Sebastian Redl | 6fec648 | 2008-12-02 22:08:59 +0000 | [diff] [blame] | 1264 | s.flush(); |
| 1265 | TypeS = "[" + TypeS + "]"; |
| 1266 | } |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1267 | E->getAllocatedType().getAsStringInternal(TypeS, Policy); |
Sebastian Redl | 6fec648 | 2008-12-02 22:08:59 +0000 | [diff] [blame] | 1268 | OS << TypeS; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1269 | if (E->isParenTypeId()) |
| 1270 | OS << ")"; |
| 1271 | |
| 1272 | if (E->hasInitializer()) { |
| 1273 | OS << "("; |
| 1274 | unsigned NumCons = E->getNumConstructorArgs(); |
| 1275 | if (NumCons > 0) { |
| 1276 | PrintExpr(E->getConstructorArg(0)); |
| 1277 | for (unsigned i = 1; i < NumCons; ++i) { |
| 1278 | OS << ", "; |
| 1279 | PrintExpr(E->getConstructorArg(i)); |
| 1280 | } |
| 1281 | } |
| 1282 | OS << ")"; |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 1287 | if (E->isGlobalDelete()) |
| 1288 | OS << "::"; |
| 1289 | OS << "delete "; |
| 1290 | if (E->isArrayForm()) |
| 1291 | OS << "[] "; |
| 1292 | PrintExpr(E->getArgument()); |
| 1293 | } |
| 1294 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1295 | void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 1296 | PrintExpr(E->getBase()); |
| 1297 | if (E->isArrow()) |
| 1298 | OS << "->"; |
| 1299 | else |
| 1300 | OS << '.'; |
| 1301 | if (E->getQualifier()) |
| 1302 | E->getQualifier()->print(OS, Policy); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1304 | std::string TypeS; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1305 | if (IdentifierInfo *II = E->getDestroyedTypeIdentifier()) |
| 1306 | OS << II->getName(); |
| 1307 | else |
| 1308 | E->getDestroyedType().getAsStringInternal(TypeS, Policy); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1309 | OS << TypeS; |
| 1310 | } |
| 1311 | |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 1312 | void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | d0fb3ad | 2011-01-24 17:25:03 +0000 | [diff] [blame] | 1313 | for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { |
| 1314 | if (isa<CXXDefaultArgExpr>(E->getArg(i))) { |
| 1315 | // Don't print any defaulted arguments |
| 1316 | break; |
| 1317 | } |
| 1318 | |
| 1319 | if (i) OS << ", "; |
| 1320 | PrintExpr(E->getArg(i)); |
Fariborz Jahanian | c75da51 | 2010-01-13 21:41:11 +0000 | [diff] [blame] | 1321 | } |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 1324 | void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) { |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 1325 | // Just forward to the sub expression. |
| 1326 | PrintExpr(E->getSubExpr()); |
| 1327 | } |
| 1328 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1329 | void |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1330 | StmtPrinter::VisitCXXUnresolvedConstructExpr( |
| 1331 | CXXUnresolvedConstructExpr *Node) { |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 1332 | OS << Node->getTypeAsWritten().getAsString(Policy); |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1333 | OS << "("; |
| 1334 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1335 | ArgEnd = Node->arg_end(); |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1336 | Arg != ArgEnd; ++Arg) { |
| 1337 | if (Arg != Node->arg_begin()) |
| 1338 | OS << ", "; |
| 1339 | PrintExpr(*Arg); |
| 1340 | } |
| 1341 | OS << ")"; |
| 1342 | } |
| 1343 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1344 | void StmtPrinter::VisitCXXDependentScopeMemberExpr( |
| 1345 | CXXDependentScopeMemberExpr *Node) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1346 | if (!Node->isImplicitAccess()) { |
| 1347 | PrintExpr(Node->getBase()); |
| 1348 | OS << (Node->isArrow() ? "->" : "."); |
| 1349 | } |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1350 | if (NestedNameSpecifier *Qualifier = Node->getQualifier()) |
| 1351 | Qualifier->print(OS, Policy); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1352 | else if (Node->hasExplicitTemplateArgs()) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1353 | // FIXME: Track use of "template" keyword explicitly? |
| 1354 | OS << "template "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1355 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1356 | OS << Node->getMemberNameInfo(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1358 | if (Node->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1359 | OS << TemplateSpecializationType::PrintTemplateArgumentList( |
| 1360 | Node->getTemplateArgs(), |
| 1361 | Node->getNumTemplateArgs(), |
| 1362 | Policy); |
| 1363 | } |
Douglas Gregor | 1c0ca59 | 2009-05-22 21:13:27 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1366 | void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1367 | if (!Node->isImplicitAccess()) { |
| 1368 | PrintExpr(Node->getBase()); |
| 1369 | OS << (Node->isArrow() ? "->" : "."); |
| 1370 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1371 | if (NestedNameSpecifier *Qualifier = Node->getQualifier()) |
| 1372 | Qualifier->print(OS, Policy); |
| 1373 | |
| 1374 | // FIXME: this might originally have been written with 'template' |
| 1375 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1376 | OS << Node->getMemberNameInfo(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1377 | |
| 1378 | if (Node->hasExplicitTemplateArgs()) { |
| 1379 | OS << TemplateSpecializationType::PrintTemplateArgumentList( |
| 1380 | Node->getTemplateArgs(), |
| 1381 | Node->getNumTemplateArgs(), |
| 1382 | Policy); |
| 1383 | } |
| 1384 | } |
| 1385 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1386 | static const char *getTypeTraitName(UnaryTypeTrait UTT) { |
| 1387 | switch (UTT) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1388 | case UTT_HasNothrowAssign: return "__has_nothrow_assign"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1389 | case UTT_HasNothrowConstructor: return "__has_nothrow_constructor"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1390 | case UTT_HasNothrowCopy: return "__has_nothrow_copy"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1391 | case UTT_HasTrivialAssign: return "__has_trivial_assign"; |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 1392 | case UTT_HasTrivialDefaultConstructor: return "__has_trivial_constructor"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1393 | case UTT_HasTrivialCopy: return "__has_trivial_copy"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1394 | case UTT_HasTrivialDestructor: return "__has_trivial_destructor"; |
| 1395 | case UTT_HasVirtualDestructor: return "__has_virtual_destructor"; |
| 1396 | case UTT_IsAbstract: return "__is_abstract"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1397 | case UTT_IsArithmetic: return "__is_arithmetic"; |
| 1398 | case UTT_IsArray: return "__is_array"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1399 | case UTT_IsClass: return "__is_class"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1400 | case UTT_IsCompleteType: return "__is_complete_type"; |
| 1401 | case UTT_IsCompound: return "__is_compound"; |
| 1402 | case UTT_IsConst: return "__is_const"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1403 | case UTT_IsEmpty: return "__is_empty"; |
| 1404 | case UTT_IsEnum: return "__is_enum"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1405 | case UTT_IsFloatingPoint: return "__is_floating_point"; |
| 1406 | case UTT_IsFunction: return "__is_function"; |
| 1407 | case UTT_IsFundamental: return "__is_fundamental"; |
| 1408 | case UTT_IsIntegral: return "__is_integral"; |
Chandler Carruth | e194710 | 2011-05-01 07:23:20 +0000 | [diff] [blame] | 1409 | case UTT_IsLiteral: return "__is_literal"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1410 | case UTT_IsLvalueReference: return "__is_lvalue_reference"; |
| 1411 | case UTT_IsMemberFunctionPointer: return "__is_member_function_pointer"; |
| 1412 | case UTT_IsMemberObjectPointer: return "__is_member_object_pointer"; |
| 1413 | case UTT_IsMemberPointer: return "__is_member_pointer"; |
| 1414 | case UTT_IsObject: return "__is_object"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1415 | case UTT_IsPOD: return "__is_pod"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1416 | case UTT_IsPointer: return "__is_pointer"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1417 | case UTT_IsPolymorphic: return "__is_polymorphic"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1418 | case UTT_IsReference: return "__is_reference"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1419 | case UTT_IsRvalueReference: return "__is_rvalue_reference"; |
| 1420 | case UTT_IsScalar: return "__is_scalar"; |
| 1421 | case UTT_IsSigned: return "__is_signed"; |
| 1422 | case UTT_IsStandardLayout: return "__is_standard_layout"; |
| 1423 | case UTT_IsTrivial: return "__is_trivial"; |
Sean Hunt | feb375d | 2011-05-13 00:31:07 +0000 | [diff] [blame] | 1424 | case UTT_IsTriviallyCopyable: return "__is_trivially_copyable"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1425 | case UTT_IsUnion: return "__is_union"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1426 | case UTT_IsUnsigned: return "__is_unsigned"; |
| 1427 | case UTT_IsVoid: return "__is_void"; |
| 1428 | case UTT_IsVolatile: return "__is_volatile"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1429 | } |
Chandler Carruth | e194710 | 2011-05-01 07:23:20 +0000 | [diff] [blame] | 1430 | llvm_unreachable("Type trait not covered by switch statement"); |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | static const char *getTypeTraitName(BinaryTypeTrait BTT) { |
| 1434 | switch (BTT) { |
Francois Pichet | f187237 | 2010-12-08 22:35:30 +0000 | [diff] [blame] | 1435 | case BTT_IsBaseOf: return "__is_base_of"; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1436 | case BTT_IsConvertible: return "__is_convertible"; |
| 1437 | case BTT_IsSame: return "__is_same"; |
Francois Pichet | f187237 | 2010-12-08 22:35:30 +0000 | [diff] [blame] | 1438 | case BTT_TypeCompatible: return "__builtin_types_compatible_p"; |
Douglas Gregor | 9f36113 | 2011-01-27 20:28:01 +0000 | [diff] [blame] | 1439 | case BTT_IsConvertibleTo: return "__is_convertible_to"; |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1440 | } |
Chandler Carruth | a280bc8 | 2011-05-01 07:23:23 +0000 | [diff] [blame] | 1441 | llvm_unreachable("Binary type trait not covered by switch"); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 1444 | static const char *getTypeTraitName(ArrayTypeTrait ATT) { |
| 1445 | switch (ATT) { |
| 1446 | case ATT_ArrayRank: return "__array_rank"; |
| 1447 | case ATT_ArrayExtent: return "__array_extent"; |
| 1448 | } |
Chandler Carruth | a280bc8 | 2011-05-01 07:23:23 +0000 | [diff] [blame] | 1449 | llvm_unreachable("Array type trait not covered by switch"); |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 1452 | static const char *getExpressionTraitName(ExpressionTrait ET) { |
| 1453 | switch (ET) { |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 1454 | case ET_IsLValueExpr: return "__is_lvalue_expr"; |
| 1455 | case ET_IsRValueExpr: return "__is_rvalue_expr"; |
| 1456 | } |
Chandler Carruth | a280bc8 | 2011-05-01 07:23:23 +0000 | [diff] [blame] | 1457 | llvm_unreachable("Expression type trait not covered by switch"); |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1460 | void StmtPrinter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
| 1461 | OS << getTypeTraitName(E->getTrait()) << "(" |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 1462 | << E->getQueriedType().getAsString(Policy) << ")"; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1465 | void StmtPrinter::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 1466 | OS << getTypeTraitName(E->getTrait()) << "(" |
| 1467 | << E->getLhsType().getAsString(Policy) << "," |
| 1468 | << E->getRhsType().getAsString(Policy) << ")"; |
| 1469 | } |
| 1470 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 1471 | void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 1472 | OS << getTypeTraitName(E->getTrait()) << "(" |
| 1473 | << E->getQueriedType().getAsString(Policy) << ")"; |
| 1474 | } |
| 1475 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 1476 | void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 1477 | OS << getExpressionTraitName(E->getTrait()) << "("; |
| 1478 | PrintExpr(E->getQueriedExpression()); |
| 1479 | OS << ")"; |
| 1480 | } |
| 1481 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 1482 | void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 1483 | OS << "noexcept("; |
| 1484 | PrintExpr(E->getOperand()); |
| 1485 | OS << ")"; |
| 1486 | } |
| 1487 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 1488 | void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 1489 | PrintExpr(E->getPattern()); |
| 1490 | OS << "..."; |
| 1491 | } |
| 1492 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 1493 | void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 1494 | OS << "sizeof...(" << E->getPack()->getNameAsString() << ")"; |
| 1495 | } |
| 1496 | |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1497 | void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr( |
| 1498 | SubstNonTypeTemplateParmPackExpr *Node) { |
| 1499 | OS << Node->getParameterPack()->getNameAsString(); |
| 1500 | } |
| 1501 | |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 1502 | void StmtPrinter::VisitSubstNonTypeTemplateParmExpr( |
| 1503 | SubstNonTypeTemplateParmExpr *Node) { |
| 1504 | Visit(Node->getReplacement()); |
| 1505 | } |
| 1506 | |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 1507 | void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){ |
| 1508 | PrintExpr(Node->GetTemporaryExpr()); |
| 1509 | } |
| 1510 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1511 | // Obj-C |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1512 | |
| 1513 | void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) { |
| 1514 | OS << "@"; |
| 1515 | VisitStringLiteral(Node->getString()); |
| 1516 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1517 | |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1518 | void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) { |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 1519 | OS << "@encode(" << Node->getEncodedType().getAsString(Policy) << ')'; |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1522 | void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1523 | OS << "@selector(" << Node->getSelector().getAsString() << ')'; |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1526 | void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1527 | OS << "@protocol(" << *Node->getProtocol() << ')'; |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1530 | void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) { |
| 1531 | OS << "["; |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1532 | switch (Mess->getReceiverKind()) { |
| 1533 | case ObjCMessageExpr::Instance: |
| 1534 | PrintExpr(Mess->getInstanceReceiver()); |
| 1535 | break; |
| 1536 | |
| 1537 | case ObjCMessageExpr::Class: |
| 1538 | OS << Mess->getClassReceiver().getAsString(Policy); |
| 1539 | break; |
| 1540 | |
| 1541 | case ObjCMessageExpr::SuperInstance: |
| 1542 | case ObjCMessageExpr::SuperClass: |
| 1543 | OS << "Super"; |
| 1544 | break; |
| 1545 | } |
| 1546 | |
Ted Kremenek | c29efd8 | 2008-05-02 17:32:38 +0000 | [diff] [blame] | 1547 | OS << ' '; |
Ted Kremenek | 97b7f26 | 2008-04-16 04:30:16 +0000 | [diff] [blame] | 1548 | Selector selector = Mess->getSelector(); |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 1549 | if (selector.isUnarySelector()) { |
Douglas Gregor | 813d834 | 2011-02-18 22:29:55 +0000 | [diff] [blame] | 1550 | OS << selector.getNameForSlot(0); |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 1551 | } else { |
| 1552 | for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) { |
Ted Kremenek | c29efd8 | 2008-05-02 17:32:38 +0000 | [diff] [blame] | 1553 | if (i < selector.getNumArgs()) { |
| 1554 | if (i > 0) OS << ' '; |
| 1555 | if (selector.getIdentifierInfoForSlot(i)) |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1556 | OS << selector.getIdentifierInfoForSlot(i)->getName() << ':'; |
Ted Kremenek | c29efd8 | 2008-05-02 17:32:38 +0000 | [diff] [blame] | 1557 | else |
| 1558 | OS << ":"; |
| 1559 | } |
| 1560 | else OS << ", "; // Handle variadic methods. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1561 | |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 1562 | PrintExpr(Mess->getArg(i)); |
| 1563 | } |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1564 | } |
| 1565 | OS << "]"; |
| 1566 | } |
| 1567 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1568 | void |
| 1569 | StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| 1570 | PrintExpr(E->getSubExpr()); |
| 1571 | } |
| 1572 | |
| 1573 | void |
| 1574 | StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
| 1575 | OS << "(" << E->getBridgeKindName() << E->getType().getAsString(Policy) |
| 1576 | << ")"; |
| 1577 | PrintExpr(E->getSubExpr()); |
| 1578 | } |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 1579 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1580 | void StmtPrinter::VisitBlockExpr(BlockExpr *Node) { |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1581 | BlockDecl *BD = Node->getBlockDecl(); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1582 | OS << "^"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1583 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1584 | const FunctionType *AFT = Node->getFunctionType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1585 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1586 | if (isa<FunctionNoProtoType>(AFT)) { |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1587 | OS << "()"; |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1588 | } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) { |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1589 | OS << '('; |
| 1590 | std::string ParamStr; |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1591 | for (BlockDecl::param_iterator AI = BD->param_begin(), |
| 1592 | E = BD->param_end(); AI != E; ++AI) { |
| 1593 | if (AI != BD->param_begin()) OS << ", "; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1594 | ParamStr = (*AI)->getNameAsString(); |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1595 | (*AI)->getType().getAsStringInternal(ParamStr, Policy); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1596 | OS << ParamStr; |
| 1597 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1598 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1599 | const FunctionProtoType *FT = cast<FunctionProtoType>(AFT); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1600 | if (FT->isVariadic()) { |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1601 | if (!BD->param_empty()) OS << ", "; |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1602 | OS << "..."; |
| 1603 | } |
| 1604 | OS << ')'; |
| 1605 | } |
| 1606 | } |
| 1607 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1608 | void StmtPrinter::VisitBlockDeclRefExpr(BlockDeclRefExpr *Node) { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1609 | OS << *Node->getDecl(); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1610 | } |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 1611 | |
| 1612 | void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {} |
| 1613 | |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 1614 | void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) { |
| 1615 | OS << "__builtin_astype("; |
| 1616 | PrintExpr(Node->getSrcExpr()); |
| 1617 | OS << ", " << Node->getType().getAsString(); |
| 1618 | OS << ")"; |
| 1619 | } |
| 1620 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1621 | //===----------------------------------------------------------------------===// |
| 1622 | // Stmt method implementations |
| 1623 | //===----------------------------------------------------------------------===// |
| 1624 | |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 1625 | void Stmt::dumpPretty(ASTContext& Context) const { |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 1626 | printPretty(llvm::errs(), Context, 0, |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 1627 | PrintingPolicy(Context.getLangOptions())); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1630 | void Stmt::printPretty(raw_ostream &OS, ASTContext& Context, |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 1631 | PrinterHelper* Helper, |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1632 | const PrintingPolicy &Policy, |
| 1633 | unsigned Indentation) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1634 | if (this == 0) { |
| 1635 | OS << "<NULL>"; |
| 1636 | return; |
| 1637 | } |
| 1638 | |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1639 | if (Policy.Dump && &Context) { |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 1640 | dump(OS, Context.getSourceManager()); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1641 | return; |
| 1642 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1643 | |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 1644 | StmtPrinter P(OS, Context, Helper, Policy, Indentation); |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 1645 | P.Visit(const_cast<Stmt*>(this)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1646 | } |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 1647 | |
| 1648 | //===----------------------------------------------------------------------===// |
| 1649 | // PrinterHelper |
| 1650 | //===----------------------------------------------------------------------===// |
| 1651 | |
| 1652 | // Implement virtual destructor. |
Gabor Greif | 8467583 | 2007-09-11 15:32:40 +0000 | [diff] [blame] | 1653 | PrinterHelper::~PrinterHelper() {} |