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" |
Ted Kremenek | 91d1d7a | 2007-10-17 18:36:42 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclObjC.h" |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 17 | #include "clang/AST/PrettyPrinter.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Compiler.h" |
Ted Kremenek | 51221ec | 2007-11-26 22:50:46 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Streams.h" |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Format.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | // StmtPrinter Visitor |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
| 27 | namespace { |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 28 | class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor<StmtPrinter> { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 29 | llvm::raw_ostream &OS; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 30 | unsigned IndentLevel; |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 31 | clang::PrinterHelper* Helper; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | public: |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 33 | StmtPrinter(llvm::raw_ostream &os, PrinterHelper* helper) : |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 34 | OS(os), IndentLevel(0), Helper(helper) {} |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 35 | |
| 36 | void PrintStmt(Stmt *S, int SubIndent = 1) { |
| 37 | IndentLevel += SubIndent; |
| 38 | if (S && isa<Expr>(S)) { |
| 39 | // If this is an expr used in a stmt context, indent and newline it. |
| 40 | Indent(); |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 41 | Visit(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 42 | OS << ";\n"; |
| 43 | } else if (S) { |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 44 | Visit(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 45 | } else { |
| 46 | Indent() << "<<<NULL STATEMENT>>>\n"; |
| 47 | } |
| 48 | IndentLevel -= SubIndent; |
| 49 | } |
| 50 | |
| 51 | void PrintRawCompoundStmt(CompoundStmt *S); |
| 52 | void PrintRawDecl(Decl *D); |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 53 | void PrintRawDeclStmt(DeclStmt *S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 54 | void PrintRawIfStmt(IfStmt *If); |
| 55 | |
| 56 | void PrintExpr(Expr *E) { |
| 57 | if (E) |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 58 | Visit(E); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 59 | else |
| 60 | OS << "<null expr>"; |
| 61 | } |
| 62 | |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 63 | llvm::raw_ostream &Indent(int Delta = 0) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 64 | for (int i = 0, e = IndentLevel+Delta; i < e; ++i) |
| 65 | OS << " "; |
| 66 | return OS; |
| 67 | } |
| 68 | |
Chris Lattner | 704fe35 | 2007-08-30 17:59:59 +0000 | [diff] [blame] | 69 | bool PrintOffsetOfDesignator(Expr *E); |
| 70 | void VisitUnaryOffsetOf(UnaryOperator *Node); |
| 71 | |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 72 | void Visit(Stmt* S) { |
| 73 | if (Helper && Helper->handledStmt(S,OS)) |
| 74 | return; |
| 75 | else StmtVisitor<StmtPrinter>::Visit(S); |
| 76 | } |
| 77 | |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 78 | void VisitStmt(Stmt *Node); |
Douglas Gregor | f2cad86 | 2008-11-14 12:46:07 +0000 | [diff] [blame] | 79 | #define STMT(CLASS, PARENT) \ |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 80 | void Visit##CLASS(CLASS *Node); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 81 | #include "clang/AST/StmtNodes.def" |
| 82 | }; |
| 83 | } |
| 84 | |
| 85 | //===----------------------------------------------------------------------===// |
| 86 | // Stmt printing methods. |
| 87 | //===----------------------------------------------------------------------===// |
| 88 | |
| 89 | void StmtPrinter::VisitStmt(Stmt *Node) { |
| 90 | Indent() << "<<unknown stmt type>>\n"; |
| 91 | } |
| 92 | |
| 93 | /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and |
| 94 | /// with no newline after the }. |
| 95 | void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) { |
| 96 | OS << "{\n"; |
| 97 | for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end(); |
| 98 | I != E; ++I) |
| 99 | PrintStmt(*I); |
| 100 | |
| 101 | Indent() << "}"; |
| 102 | } |
| 103 | |
| 104 | void StmtPrinter::PrintRawDecl(Decl *D) { |
| 105 | // FIXME: Need to complete/beautify this... this code simply shows the |
| 106 | // nodes are where they need to be. |
| 107 | if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) { |
| 108 | OS << "typedef " << localType->getUnderlyingType().getAsString(); |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 109 | OS << " " << localType->getNameAsString(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 110 | } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 111 | // Emit storage class for vardecls. |
| 112 | if (VarDecl *V = dyn_cast<VarDecl>(VD)) { |
| 113 | switch (V->getStorageClass()) { |
| 114 | default: assert(0 && "Unknown storage class!"); |
| 115 | case VarDecl::None: break; |
| 116 | case VarDecl::Extern: OS << "extern "; break; |
| 117 | case VarDecl::Static: OS << "static "; break; |
| 118 | case VarDecl::Auto: OS << "auto "; break; |
| 119 | case VarDecl::Register: OS << "register "; break; |
| 120 | } |
| 121 | } |
| 122 | |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 123 | std::string Name = VD->getNameAsString(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 124 | VD->getType().getAsStringInternal(Name); |
| 125 | OS << Name; |
| 126 | |
Chris Lattner | 24c3990 | 2007-07-12 00:36:32 +0000 | [diff] [blame] | 127 | // If this is a vardecl with an initializer, emit it. |
| 128 | if (VarDecl *V = dyn_cast<VarDecl>(VD)) { |
| 129 | if (V->getInit()) { |
| 130 | OS << " = "; |
| 131 | PrintExpr(V->getInit()); |
| 132 | } |
| 133 | } |
Steve Naroff | 91578f3 | 2007-11-17 21:21:01 +0000 | [diff] [blame] | 134 | } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 135 | // print a free standing tag decl (e.g. "struct x;"). |
| 136 | OS << TD->getKindName(); |
| 137 | OS << " "; |
| 138 | if (const IdentifierInfo *II = TD->getIdentifier()) |
| 139 | OS << II->getName(); |
| 140 | else |
| 141 | OS << "<anonymous>"; |
| 142 | // FIXME: print tag bodies. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 143 | } else { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 144 | assert(0 && "Unexpected decl"); |
| 145 | } |
| 146 | } |
| 147 | |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 148 | void StmtPrinter::PrintRawDeclStmt(DeclStmt *S) { |
| 149 | bool isFirst = false; |
| 150 | |
| 151 | for (DeclStmt::decl_iterator I = S->decl_begin(), E = S->decl_end(); |
| 152 | I != E; ++I) { |
| 153 | |
| 154 | if (!isFirst) OS << ", "; |
| 155 | else isFirst = false; |
| 156 | |
| 157 | PrintRawDecl(*I); |
| 158 | } |
| 159 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 160 | |
| 161 | void StmtPrinter::VisitNullStmt(NullStmt *Node) { |
| 162 | Indent() << ";\n"; |
| 163 | } |
| 164 | |
| 165 | void StmtPrinter::VisitDeclStmt(DeclStmt *Node) { |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 166 | for (DeclStmt::decl_iterator I = Node->decl_begin(), E = Node->decl_end(); |
| 167 | I!=E; ++I) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 168 | Indent(); |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 169 | PrintRawDecl(*I); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 170 | OS << ";\n"; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) { |
| 175 | Indent(); |
| 176 | PrintRawCompoundStmt(Node); |
| 177 | OS << "\n"; |
| 178 | } |
| 179 | |
| 180 | void StmtPrinter::VisitCaseStmt(CaseStmt *Node) { |
| 181 | Indent(-1) << "case "; |
| 182 | PrintExpr(Node->getLHS()); |
| 183 | if (Node->getRHS()) { |
| 184 | OS << " ... "; |
| 185 | PrintExpr(Node->getRHS()); |
| 186 | } |
| 187 | OS << ":\n"; |
| 188 | |
| 189 | PrintStmt(Node->getSubStmt(), 0); |
| 190 | } |
| 191 | |
| 192 | void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) { |
| 193 | Indent(-1) << "default:\n"; |
| 194 | PrintStmt(Node->getSubStmt(), 0); |
| 195 | } |
| 196 | |
| 197 | void StmtPrinter::VisitLabelStmt(LabelStmt *Node) { |
| 198 | Indent(-1) << Node->getName() << ":\n"; |
| 199 | PrintStmt(Node->getSubStmt(), 0); |
| 200 | } |
| 201 | |
| 202 | void StmtPrinter::PrintRawIfStmt(IfStmt *If) { |
| 203 | OS << "if "; |
| 204 | PrintExpr(If->getCond()); |
| 205 | |
| 206 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) { |
| 207 | OS << ' '; |
| 208 | PrintRawCompoundStmt(CS); |
| 209 | OS << (If->getElse() ? ' ' : '\n'); |
| 210 | } else { |
| 211 | OS << '\n'; |
| 212 | PrintStmt(If->getThen()); |
| 213 | if (If->getElse()) Indent(); |
| 214 | } |
| 215 | |
| 216 | if (Stmt *Else = If->getElse()) { |
| 217 | OS << "else"; |
| 218 | |
| 219 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) { |
| 220 | OS << ' '; |
| 221 | PrintRawCompoundStmt(CS); |
| 222 | OS << '\n'; |
| 223 | } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) { |
| 224 | OS << ' '; |
| 225 | PrintRawIfStmt(ElseIf); |
| 226 | } else { |
| 227 | OS << '\n'; |
| 228 | PrintStmt(If->getElse()); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void StmtPrinter::VisitIfStmt(IfStmt *If) { |
| 234 | Indent(); |
| 235 | PrintRawIfStmt(If); |
| 236 | } |
| 237 | |
| 238 | void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) { |
| 239 | Indent() << "switch ("; |
| 240 | PrintExpr(Node->getCond()); |
| 241 | OS << ")"; |
| 242 | |
| 243 | // Pretty print compoundstmt bodies (very common). |
| 244 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) { |
| 245 | OS << " "; |
| 246 | PrintRawCompoundStmt(CS); |
| 247 | OS << "\n"; |
| 248 | } else { |
| 249 | OS << "\n"; |
| 250 | PrintStmt(Node->getBody()); |
| 251 | } |
| 252 | } |
| 253 | |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 254 | void StmtPrinter::VisitSwitchCase(SwitchCase*) { |
| 255 | assert(0 && "SwitchCase is an abstract class"); |
| 256 | } |
| 257 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 258 | void StmtPrinter::VisitWhileStmt(WhileStmt *Node) { |
| 259 | Indent() << "while ("; |
| 260 | PrintExpr(Node->getCond()); |
| 261 | OS << ")\n"; |
| 262 | PrintStmt(Node->getBody()); |
| 263 | } |
| 264 | |
| 265 | void StmtPrinter::VisitDoStmt(DoStmt *Node) { |
Chris Lattner | 8bdcc47 | 2007-09-15 21:49:37 +0000 | [diff] [blame] | 266 | Indent() << "do "; |
| 267 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) { |
| 268 | PrintRawCompoundStmt(CS); |
| 269 | OS << " "; |
| 270 | } else { |
| 271 | OS << "\n"; |
| 272 | PrintStmt(Node->getBody()); |
| 273 | Indent(); |
| 274 | } |
| 275 | |
| 276 | OS << "while "; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 277 | PrintExpr(Node->getCond()); |
| 278 | OS << ";\n"; |
| 279 | } |
| 280 | |
| 281 | void StmtPrinter::VisitForStmt(ForStmt *Node) { |
| 282 | Indent() << "for ("; |
| 283 | if (Node->getInit()) { |
| 284 | if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit())) |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 285 | PrintRawDeclStmt(DS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 286 | else |
| 287 | PrintExpr(cast<Expr>(Node->getInit())); |
| 288 | } |
Chris Lattner | 8bdcc47 | 2007-09-15 21:49:37 +0000 | [diff] [blame] | 289 | OS << ";"; |
| 290 | if (Node->getCond()) { |
| 291 | OS << " "; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 292 | PrintExpr(Node->getCond()); |
Chris Lattner | 8bdcc47 | 2007-09-15 21:49:37 +0000 | [diff] [blame] | 293 | } |
| 294 | OS << ";"; |
| 295 | if (Node->getInc()) { |
| 296 | OS << " "; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 297 | PrintExpr(Node->getInc()); |
Chris Lattner | 8bdcc47 | 2007-09-15 21:49:37 +0000 | [diff] [blame] | 298 | } |
| 299 | OS << ") "; |
| 300 | |
| 301 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) { |
| 302 | PrintRawCompoundStmt(CS); |
| 303 | OS << "\n"; |
| 304 | } else { |
| 305 | OS << "\n"; |
| 306 | PrintStmt(Node->getBody()); |
| 307 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 310 | void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) { |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 311 | Indent() << "for ("; |
| 312 | if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement())) |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 313 | PrintRawDeclStmt(DS); |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 314 | else |
| 315 | PrintExpr(cast<Expr>(Node->getElement())); |
| 316 | OS << " in "; |
| 317 | PrintExpr(Node->getCollection()); |
| 318 | OS << ") "; |
| 319 | |
| 320 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) { |
| 321 | PrintRawCompoundStmt(CS); |
| 322 | OS << "\n"; |
| 323 | } else { |
| 324 | OS << "\n"; |
| 325 | PrintStmt(Node->getBody()); |
| 326 | } |
| 327 | } |
| 328 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 329 | void StmtPrinter::VisitGotoStmt(GotoStmt *Node) { |
| 330 | Indent() << "goto " << Node->getLabel()->getName() << ";\n"; |
| 331 | } |
| 332 | |
| 333 | void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) { |
| 334 | Indent() << "goto *"; |
| 335 | PrintExpr(Node->getTarget()); |
| 336 | OS << ";\n"; |
| 337 | } |
| 338 | |
| 339 | void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) { |
| 340 | Indent() << "continue;\n"; |
| 341 | } |
| 342 | |
| 343 | void StmtPrinter::VisitBreakStmt(BreakStmt *Node) { |
| 344 | Indent() << "break;\n"; |
| 345 | } |
| 346 | |
| 347 | |
| 348 | void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) { |
| 349 | Indent() << "return"; |
| 350 | if (Node->getRetValue()) { |
| 351 | OS << " "; |
| 352 | PrintExpr(Node->getRetValue()); |
| 353 | } |
| 354 | OS << ";\n"; |
| 355 | } |
| 356 | |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 357 | |
| 358 | void StmtPrinter::VisitAsmStmt(AsmStmt *Node) { |
Anders Carlsson | 39c47b5 | 2007-11-23 23:12:25 +0000 | [diff] [blame] | 359 | Indent() << "asm "; |
| 360 | |
| 361 | if (Node->isVolatile()) |
| 362 | OS << "volatile "; |
| 363 | |
| 364 | OS << "("; |
Anders Carlsson | 6a0ef4b | 2007-11-20 19:21:03 +0000 | [diff] [blame] | 365 | VisitStringLiteral(Node->getAsmString()); |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 366 | |
| 367 | // Outputs |
| 368 | if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 || |
| 369 | Node->getNumClobbers() != 0) |
| 370 | OS << " : "; |
| 371 | |
| 372 | for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) { |
| 373 | if (i != 0) |
| 374 | OS << ", "; |
| 375 | |
| 376 | if (!Node->getOutputName(i).empty()) { |
| 377 | OS << '['; |
| 378 | OS << Node->getOutputName(i); |
| 379 | OS << "] "; |
| 380 | } |
| 381 | |
| 382 | VisitStringLiteral(Node->getOutputConstraint(i)); |
| 383 | OS << " "; |
| 384 | Visit(Node->getOutputExpr(i)); |
| 385 | } |
| 386 | |
| 387 | // Inputs |
| 388 | if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0) |
| 389 | OS << " : "; |
| 390 | |
| 391 | for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) { |
| 392 | if (i != 0) |
| 393 | OS << ", "; |
| 394 | |
| 395 | if (!Node->getInputName(i).empty()) { |
| 396 | OS << '['; |
| 397 | OS << Node->getInputName(i); |
| 398 | OS << "] "; |
| 399 | } |
| 400 | |
| 401 | VisitStringLiteral(Node->getInputConstraint(i)); |
| 402 | OS << " "; |
| 403 | Visit(Node->getInputExpr(i)); |
| 404 | } |
| 405 | |
| 406 | // Clobbers |
| 407 | if (Node->getNumClobbers() != 0) |
| 408 | OS << " : "; |
| 409 | |
| 410 | for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) { |
| 411 | if (i != 0) |
| 412 | OS << ", "; |
| 413 | |
| 414 | VisitStringLiteral(Node->getClobber(i)); |
| 415 | } |
| 416 | |
Anders Carlsson | 6a0ef4b | 2007-11-20 19:21:03 +0000 | [diff] [blame] | 417 | OS << ");\n"; |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 420 | void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) { |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 421 | Indent() << "@try"; |
| 422 | if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) { |
| 423 | PrintRawCompoundStmt(TS); |
| 424 | OS << "\n"; |
| 425 | } |
| 426 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 427 | for (ObjCAtCatchStmt *catchStmt = |
| 428 | static_cast<ObjCAtCatchStmt *>(Node->getCatchStmts()); |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 429 | catchStmt; |
| 430 | catchStmt = |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 431 | static_cast<ObjCAtCatchStmt *>(catchStmt->getNextCatchStmt())) { |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 432 | Indent() << "@catch("; |
| 433 | if (catchStmt->getCatchParamStmt()) { |
| 434 | if (DeclStmt *DS = dyn_cast<DeclStmt>(catchStmt->getCatchParamStmt())) |
Ted Kremenek | ecd64c5 | 2008-10-06 18:39:36 +0000 | [diff] [blame] | 435 | PrintRawDeclStmt(DS); |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 436 | } |
| 437 | OS << ")"; |
| 438 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) |
| 439 | { |
| 440 | PrintRawCompoundStmt(CS); |
| 441 | OS << "\n"; |
| 442 | } |
| 443 | } |
| 444 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 445 | if (ObjCAtFinallyStmt *FS =static_cast<ObjCAtFinallyStmt *>( |
Fariborz Jahanian | 1e7eab4 | 2007-11-07 00:46:42 +0000 | [diff] [blame] | 446 | Node->getFinallyStmt())) { |
| 447 | Indent() << "@finally"; |
| 448 | PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody())); |
Fariborz Jahanian | 7794cb8 | 2007-11-02 18:16:07 +0000 | [diff] [blame] | 449 | OS << "\n"; |
| 450 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 453 | void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) { |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 456 | void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) { |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 457 | Indent() << "@catch (...) { /* todo */ } \n"; |
| 458 | } |
| 459 | |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 460 | void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 461 | Indent() << "@throw"; |
| 462 | if (Node->getThrowExpr()) { |
| 463 | OS << " "; |
| 464 | PrintExpr(Node->getThrowExpr()); |
| 465 | } |
| 466 | OS << ";\n"; |
| 467 | } |
| 468 | |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 469 | void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) { |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 470 | Indent() << "@synchronized ("; |
| 471 | PrintExpr(Node->getSynchExpr()); |
| 472 | OS << ")"; |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 473 | PrintRawCompoundStmt(Node->getSynchBody()); |
| 474 | OS << "\n"; |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 477 | //===----------------------------------------------------------------------===// |
| 478 | // Expr printing methods. |
| 479 | //===----------------------------------------------------------------------===// |
| 480 | |
| 481 | void StmtPrinter::VisitExpr(Expr *Node) { |
| 482 | OS << "<<unknown expr type>>"; |
| 483 | } |
| 484 | |
| 485 | void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 486 | OS << Node->getDecl()->getNameAsString(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Steve Naroff | 7779db4 | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 489 | void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { |
Fariborz Jahanian | 232220c | 2007-11-12 22:29:28 +0000 | [diff] [blame] | 490 | if (Node->getBase()) { |
| 491 | PrintExpr(Node->getBase()); |
| 492 | OS << (Node->isArrow() ? "->" : "."); |
| 493 | } |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 494 | OS << Node->getDecl()->getNameAsString(); |
Steve Naroff | 7779db4 | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Steve Naroff | ae78407 | 2008-05-30 00:40:33 +0000 | [diff] [blame] | 497 | void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) { |
| 498 | if (Node->getBase()) { |
| 499 | PrintExpr(Node->getBase()); |
| 500 | OS << "."; |
| 501 | } |
Steve Naroff | c77a636 | 2008-12-04 16:24:46 +0000 | [diff] [blame] | 502 | OS << Node->getProperty()->getNameAsCString(); |
Steve Naroff | ae78407 | 2008-05-30 00:40:33 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Fariborz Jahanian | 5daf570 | 2008-11-22 18:39:36 +0000 | [diff] [blame] | 505 | void StmtPrinter::VisitObjCKVCRefExpr(ObjCKVCRefExpr *Node) { |
| 506 | if (Node->getBase()) { |
| 507 | PrintExpr(Node->getBase()); |
| 508 | OS << "."; |
| 509 | } |
| 510 | // FIXME: Setter/Getter names |
| 511 | } |
| 512 | |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 513 | void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) { |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 514 | switch (Node->getIdentType()) { |
| 515 | default: |
| 516 | assert(0 && "unknown case"); |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 517 | case PredefinedExpr::Func: |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 518 | OS << "__func__"; |
| 519 | break; |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 520 | case PredefinedExpr::Function: |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 521 | OS << "__FUNCTION__"; |
| 522 | break; |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 523 | case PredefinedExpr::PrettyFunction: |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 524 | OS << "__PRETTY_FUNCTION__"; |
| 525 | break; |
| 526 | } |
| 527 | } |
| 528 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 529 | void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) { |
Chris Lattner | b0a721a | 2007-07-13 05:18:11 +0000 | [diff] [blame] | 530 | unsigned value = Node->getValue(); |
Chris Lattner | c250aae | 2008-06-07 22:35:38 +0000 | [diff] [blame] | 531 | if (Node->isWide()) |
| 532 | OS << "L"; |
Chris Lattner | 8bf9f07 | 2007-07-13 23:58:20 +0000 | [diff] [blame] | 533 | switch (value) { |
| 534 | case '\\': |
| 535 | OS << "'\\\\'"; |
| 536 | break; |
| 537 | case '\'': |
| 538 | OS << "'\\''"; |
| 539 | break; |
| 540 | case '\a': |
| 541 | // TODO: K&R: the meaning of '\\a' is different in traditional C |
| 542 | OS << "'\\a'"; |
| 543 | break; |
| 544 | case '\b': |
| 545 | OS << "'\\b'"; |
| 546 | break; |
| 547 | // Nonstandard escape sequence. |
| 548 | /*case '\e': |
| 549 | OS << "'\\e'"; |
| 550 | break;*/ |
| 551 | case '\f': |
| 552 | OS << "'\\f'"; |
| 553 | break; |
| 554 | case '\n': |
| 555 | OS << "'\\n'"; |
| 556 | break; |
| 557 | case '\r': |
| 558 | OS << "'\\r'"; |
| 559 | break; |
| 560 | case '\t': |
| 561 | OS << "'\\t'"; |
| 562 | break; |
| 563 | case '\v': |
| 564 | OS << "'\\v'"; |
| 565 | break; |
| 566 | default: |
Ted Kremenek | 471733d | 2008-02-23 00:52:04 +0000 | [diff] [blame] | 567 | if (value < 256 && isprint(value)) { |
Chris Lattner | 8bf9f07 | 2007-07-13 23:58:20 +0000 | [diff] [blame] | 568 | OS << "'" << (char)value << "'"; |
| 569 | } else if (value < 256) { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 570 | OS << "'\\x" << llvm::format("%x", value) << "'"; |
Chris Lattner | 8bf9f07 | 2007-07-13 23:58:20 +0000 | [diff] [blame] | 571 | } else { |
| 572 | // FIXME what to really do here? |
| 573 | OS << value; |
| 574 | } |
Chris Lattner | b0a721a | 2007-07-13 05:18:11 +0000 | [diff] [blame] | 575 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) { |
| 579 | bool isSigned = Node->getType()->isSignedIntegerType(); |
| 580 | OS << Node->getValue().toString(10, isSigned); |
| 581 | |
| 582 | // Emit suffixes. Integer literals are always a builtin integer type. |
Chris Lattner | b77792e | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 583 | switch (Node->getType()->getAsBuiltinType()->getKind()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 584 | default: assert(0 && "Unexpected type for integer literal!"); |
| 585 | case BuiltinType::Int: break; // no suffix. |
| 586 | case BuiltinType::UInt: OS << 'U'; break; |
| 587 | case BuiltinType::Long: OS << 'L'; break; |
| 588 | case BuiltinType::ULong: OS << "UL"; break; |
| 589 | case BuiltinType::LongLong: OS << "LL"; break; |
| 590 | case BuiltinType::ULongLong: OS << "ULL"; break; |
| 591 | } |
| 592 | } |
| 593 | void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) { |
Chris Lattner | 86e499d | 2007-08-01 00:23:58 +0000 | [diff] [blame] | 594 | // FIXME: print value more precisely. |
Chris Lattner | da8249e | 2008-06-07 22:13:43 +0000 | [diff] [blame] | 595 | OS << Node->getValueAsApproximateDouble(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 596 | } |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 597 | |
| 598 | void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) { |
| 599 | PrintExpr(Node->getSubExpr()); |
| 600 | OS << "i"; |
| 601 | } |
| 602 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 603 | void StmtPrinter::VisitStringLiteral(StringLiteral *Str) { |
| 604 | if (Str->isWide()) OS << 'L'; |
| 605 | OS << '"'; |
Anders Carlsson | ee98ac5 | 2007-10-15 02:50:23 +0000 | [diff] [blame] | 606 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 607 | // FIXME: this doesn't print wstrings right. |
| 608 | for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) { |
| 609 | switch (Str->getStrData()[i]) { |
| 610 | default: OS << Str->getStrData()[i]; break; |
| 611 | // Handle some common ones to make dumps prettier. |
| 612 | case '\\': OS << "\\\\"; break; |
| 613 | case '"': OS << "\\\""; break; |
| 614 | case '\n': OS << "\\n"; break; |
| 615 | case '\t': OS << "\\t"; break; |
| 616 | case '\a': OS << "\\a"; break; |
| 617 | case '\b': OS << "\\b"; break; |
| 618 | } |
| 619 | } |
| 620 | OS << '"'; |
| 621 | } |
| 622 | void StmtPrinter::VisitParenExpr(ParenExpr *Node) { |
| 623 | OS << "("; |
| 624 | PrintExpr(Node->getSubExpr()); |
| 625 | OS << ")"; |
| 626 | } |
| 627 | void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) { |
Chris Lattner | 296bf19 | 2007-08-23 21:46:40 +0000 | [diff] [blame] | 628 | if (!Node->isPostfix()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 629 | OS << UnaryOperator::getOpcodeStr(Node->getOpcode()); |
Chris Lattner | 296bf19 | 2007-08-23 21:46:40 +0000 | [diff] [blame] | 630 | |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 631 | // Print a space if this is an "identifier operator" like __real. |
Chris Lattner | 296bf19 | 2007-08-23 21:46:40 +0000 | [diff] [blame] | 632 | switch (Node->getOpcode()) { |
| 633 | default: break; |
Chris Lattner | 296bf19 | 2007-08-23 21:46:40 +0000 | [diff] [blame] | 634 | case UnaryOperator::Real: |
| 635 | case UnaryOperator::Imag: |
| 636 | case UnaryOperator::Extension: |
| 637 | OS << ' '; |
| 638 | break; |
| 639 | } |
| 640 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 641 | PrintExpr(Node->getSubExpr()); |
| 642 | |
| 643 | if (Node->isPostfix()) |
| 644 | OS << UnaryOperator::getOpcodeStr(Node->getOpcode()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 645 | } |
Chris Lattner | 704fe35 | 2007-08-30 17:59:59 +0000 | [diff] [blame] | 646 | |
| 647 | bool StmtPrinter::PrintOffsetOfDesignator(Expr *E) { |
| 648 | if (isa<CompoundLiteralExpr>(E)) { |
| 649 | // Base case, print the type and comma. |
| 650 | OS << E->getType().getAsString() << ", "; |
| 651 | return true; |
| 652 | } else if (ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 653 | PrintOffsetOfDesignator(ASE->getLHS()); |
| 654 | OS << "["; |
| 655 | PrintExpr(ASE->getRHS()); |
| 656 | OS << "]"; |
| 657 | return false; |
| 658 | } else { |
| 659 | MemberExpr *ME = cast<MemberExpr>(E); |
| 660 | bool IsFirst = PrintOffsetOfDesignator(ME->getBase()); |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 661 | OS << (IsFirst ? "" : ".") << ME->getMemberDecl()->getNameAsString(); |
Chris Lattner | 704fe35 | 2007-08-30 17:59:59 +0000 | [diff] [blame] | 662 | return false; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | void StmtPrinter::VisitUnaryOffsetOf(UnaryOperator *Node) { |
| 667 | OS << "__builtin_offsetof("; |
| 668 | PrintOffsetOfDesignator(Node->getSubExpr()); |
| 669 | OS << ")"; |
| 670 | } |
| 671 | |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 672 | void StmtPrinter::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node) { |
| 673 | OS << (Node->isSizeOf() ? "sizeof" : "__alignof"); |
| 674 | if (Node->isArgumentType()) |
| 675 | OS << "(" << Node->getArgumentType().getAsString() << ")"; |
| 676 | else { |
| 677 | OS << " "; |
| 678 | PrintExpr(Node->getArgumentExpr()); |
| 679 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 680 | } |
| 681 | void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) { |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 682 | PrintExpr(Node->getLHS()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 683 | OS << "["; |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 684 | PrintExpr(Node->getRHS()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 685 | OS << "]"; |
| 686 | } |
| 687 | |
| 688 | void StmtPrinter::VisitCallExpr(CallExpr *Call) { |
| 689 | PrintExpr(Call->getCallee()); |
| 690 | OS << "("; |
| 691 | for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) { |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 692 | if (isa<CXXDefaultArgExpr>(Call->getArg(i))) { |
| 693 | // Don't print any defaulted arguments |
| 694 | break; |
| 695 | } |
| 696 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 697 | if (i) OS << ", "; |
| 698 | PrintExpr(Call->getArg(i)); |
| 699 | } |
| 700 | OS << ")"; |
| 701 | } |
| 702 | void StmtPrinter::VisitMemberExpr(MemberExpr *Node) { |
| 703 | PrintExpr(Node->getBase()); |
| 704 | OS << (Node->isArrow() ? "->" : "."); |
Douglas Gregor | 86f1940 | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 705 | OS << Node->getMemberDecl()->getNameAsString(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 706 | } |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 707 | void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) { |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 708 | PrintExpr(Node->getBase()); |
| 709 | OS << "."; |
| 710 | OS << Node->getAccessor().getName(); |
| 711 | } |
Argyrios Kyrtzidis | 0835a3c | 2008-08-18 23:01:59 +0000 | [diff] [blame] | 712 | void StmtPrinter::VisitCastExpr(CastExpr *) { |
| 713 | assert(0 && "CastExpr is an abstract class"); |
| 714 | } |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 715 | void StmtPrinter::VisitExplicitCastExpr(ExplicitCastExpr *) { |
| 716 | assert(0 && "ExplicitCastExpr is an abstract class"); |
| 717 | } |
Douglas Gregor | 6eec8e8 | 2008-10-28 15:36:24 +0000 | [diff] [blame] | 718 | void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) { |
Chris Lattner | 26dc7b3 | 2007-07-15 23:54:50 +0000 | [diff] [blame] | 719 | OS << "(" << Node->getType().getAsString() << ")"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 720 | PrintExpr(Node->getSubExpr()); |
| 721 | } |
Steve Naroff | aff1edd | 2007-07-19 21:32:11 +0000 | [diff] [blame] | 722 | void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) { |
| 723 | OS << "(" << Node->getType().getAsString() << ")"; |
| 724 | PrintExpr(Node->getInitializer()); |
| 725 | } |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 726 | void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) { |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 727 | // No need to print anything, simply forward to the sub expression. |
| 728 | PrintExpr(Node->getSubExpr()); |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 729 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 730 | void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) { |
| 731 | PrintExpr(Node->getLHS()); |
| 732 | OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " "; |
| 733 | PrintExpr(Node->getRHS()); |
| 734 | } |
Chris Lattner | eb14fe8 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 735 | void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) { |
| 736 | PrintExpr(Node->getLHS()); |
| 737 | OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " "; |
| 738 | PrintExpr(Node->getRHS()); |
| 739 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 740 | void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) { |
| 741 | PrintExpr(Node->getCond()); |
Ted Kremenek | 8e911c4 | 2007-11-26 18:27:54 +0000 | [diff] [blame] | 742 | |
| 743 | if (Node->getLHS()) { |
| 744 | OS << " ? "; |
| 745 | PrintExpr(Node->getLHS()); |
| 746 | OS << " : "; |
| 747 | } |
| 748 | else { // Handle GCC extention where LHS can be NULL. |
| 749 | OS << " ?: "; |
| 750 | } |
| 751 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 752 | PrintExpr(Node->getRHS()); |
| 753 | } |
| 754 | |
| 755 | // GNU extensions. |
| 756 | |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 757 | void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 758 | OS << "&&" << Node->getLabel()->getName(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Chris Lattner | ab18c4c | 2007-07-24 16:58:17 +0000 | [diff] [blame] | 761 | void StmtPrinter::VisitStmtExpr(StmtExpr *E) { |
| 762 | OS << "("; |
| 763 | PrintRawCompoundStmt(E->getSubStmt()); |
| 764 | OS << ")"; |
| 765 | } |
| 766 | |
Steve Naroff | d34e915 | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 767 | void StmtPrinter::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) { |
| 768 | OS << "__builtin_types_compatible_p("; |
| 769 | OS << Node->getArgType1().getAsString() << ","; |
| 770 | OS << Node->getArgType2().getAsString() << ")"; |
| 771 | } |
| 772 | |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 773 | void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) { |
| 774 | OS << "__builtin_choose_expr("; |
| 775 | PrintExpr(Node->getCond()); |
Chris Lattner | 94f05e3 | 2007-08-04 00:20:15 +0000 | [diff] [blame] | 776 | OS << ", "; |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 777 | PrintExpr(Node->getLHS()); |
Chris Lattner | 94f05e3 | 2007-08-04 00:20:15 +0000 | [diff] [blame] | 778 | OS << ", "; |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 779 | PrintExpr(Node->getRHS()); |
| 780 | OS << ")"; |
| 781 | } |
Chris Lattner | ab18c4c | 2007-07-24 16:58:17 +0000 | [diff] [blame] | 782 | |
Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 783 | void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) { |
| 784 | OS << "__null"; |
| 785 | } |
| 786 | |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 787 | void StmtPrinter::VisitOverloadExpr(OverloadExpr *Node) { |
| 788 | OS << "__builtin_overload("; |
Nate Begeman | 67295d0 | 2008-01-30 20:50:20 +0000 | [diff] [blame] | 789 | for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) { |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 790 | if (i) OS << ", "; |
Nate Begeman | 67295d0 | 2008-01-30 20:50:20 +0000 | [diff] [blame] | 791 | PrintExpr(Node->getExpr(i)); |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 792 | } |
| 793 | OS << ")"; |
| 794 | } |
| 795 | |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 796 | void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) { |
| 797 | OS << "__builtin_shufflevector("; |
| 798 | for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) { |
| 799 | if (i) OS << ", "; |
| 800 | PrintExpr(Node->getExpr(i)); |
| 801 | } |
| 802 | OS << ")"; |
| 803 | } |
| 804 | |
Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 805 | void StmtPrinter::VisitInitListExpr(InitListExpr* Node) { |
| 806 | OS << "{ "; |
| 807 | for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) { |
| 808 | if (i) OS << ", "; |
| 809 | PrintExpr(Node->getInit(i)); |
| 810 | } |
| 811 | OS << " }"; |
| 812 | } |
| 813 | |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 814 | void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) { |
| 815 | OS << "va_arg("; |
| 816 | PrintExpr(Node->getSubExpr()); |
| 817 | OS << ", "; |
| 818 | OS << Node->getType().getAsString(); |
| 819 | OS << ")"; |
| 820 | } |
| 821 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 822 | // C++ |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 823 | void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) { |
| 824 | const char *OpStrings[NUM_OVERLOADED_OPERATORS] = { |
| 825 | "", |
| 826 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 827 | Spelling, |
| 828 | #include "clang/Basic/OperatorKinds.def" |
| 829 | }; |
| 830 | |
| 831 | OverloadedOperatorKind Kind = Node->getOperator(); |
| 832 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 833 | if (Node->getNumArgs() == 1) { |
| 834 | OS << OpStrings[Kind] << ' '; |
| 835 | PrintExpr(Node->getArg(0)); |
| 836 | } else { |
| 837 | PrintExpr(Node->getArg(0)); |
| 838 | OS << ' ' << OpStrings[Kind]; |
| 839 | } |
| 840 | } else if (Kind == OO_Call) { |
| 841 | PrintExpr(Node->getArg(0)); |
| 842 | OS << '('; |
| 843 | for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) { |
| 844 | if (ArgIdx > 1) |
| 845 | OS << ", "; |
| 846 | if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx))) |
| 847 | PrintExpr(Node->getArg(ArgIdx)); |
| 848 | } |
| 849 | OS << ')'; |
| 850 | } else if (Kind == OO_Subscript) { |
| 851 | PrintExpr(Node->getArg(0)); |
| 852 | OS << '['; |
| 853 | PrintExpr(Node->getArg(1)); |
| 854 | OS << ']'; |
| 855 | } else if (Node->getNumArgs() == 1) { |
| 856 | OS << OpStrings[Kind] << ' '; |
| 857 | PrintExpr(Node->getArg(0)); |
| 858 | } else if (Node->getNumArgs() == 2) { |
| 859 | PrintExpr(Node->getArg(0)); |
| 860 | OS << ' ' << OpStrings[Kind] << ' '; |
| 861 | PrintExpr(Node->getArg(1)); |
| 862 | } else { |
| 863 | assert(false && "unknown overloaded operator"); |
| 864 | } |
| 865 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 866 | |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame^] | 867 | void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) { |
| 868 | VisitCallExpr(cast<CallExpr>(Node)); |
| 869 | } |
| 870 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 871 | void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) { |
| 872 | OS << Node->getCastName() << '<'; |
| 873 | OS << Node->getTypeAsWritten().getAsString() << ">("; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 874 | PrintExpr(Node->getSubExpr()); |
| 875 | OS << ")"; |
| 876 | } |
| 877 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 878 | void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) { |
| 879 | VisitCXXNamedCastExpr(Node); |
| 880 | } |
| 881 | |
| 882 | void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) { |
| 883 | VisitCXXNamedCastExpr(Node); |
| 884 | } |
| 885 | |
| 886 | void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) { |
| 887 | VisitCXXNamedCastExpr(Node); |
| 888 | } |
| 889 | |
| 890 | void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) { |
| 891 | VisitCXXNamedCastExpr(Node); |
| 892 | } |
| 893 | |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 894 | void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) { |
| 895 | OS << "typeid("; |
| 896 | if (Node->isTypeOperand()) { |
| 897 | OS << Node->getTypeOperand().getAsString(); |
| 898 | } else { |
| 899 | PrintExpr(Node->getExprOperand()); |
| 900 | } |
| 901 | OS << ")"; |
| 902 | } |
| 903 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 904 | void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) { |
| 905 | OS << (Node->getValue() ? "true" : "false"); |
| 906 | } |
| 907 | |
Douglas Gregor | 796da18 | 2008-11-04 14:32:21 +0000 | [diff] [blame] | 908 | void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) { |
| 909 | OS << "this"; |
| 910 | } |
| 911 | |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 912 | void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) { |
| 913 | if (Node->getSubExpr() == 0) |
| 914 | OS << "throw"; |
| 915 | else { |
| 916 | OS << "throw "; |
| 917 | PrintExpr(Node->getSubExpr()); |
| 918 | } |
| 919 | } |
| 920 | |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 921 | void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) { |
| 922 | // Nothing to print: we picked up the default argument |
| 923 | } |
| 924 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 925 | void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) { |
| 926 | OS << Node->getType().getAsString(); |
| 927 | OS << "("; |
| 928 | PrintExpr(Node->getSubExpr()); |
| 929 | OS << ")"; |
| 930 | } |
| 931 | |
| 932 | void StmtPrinter::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *Node) { |
| 933 | OS << Node->getType().getAsString() << "()"; |
| 934 | } |
| 935 | |
Argyrios Kyrtzidis | 9e922b1 | 2008-09-09 23:47:53 +0000 | [diff] [blame] | 936 | void |
| 937 | StmtPrinter::VisitCXXConditionDeclExpr(CXXConditionDeclExpr *E) { |
| 938 | PrintRawDecl(E->getVarDecl()); |
| 939 | } |
| 940 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 941 | void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 942 | if (E->isGlobalNew()) |
| 943 | OS << "::"; |
| 944 | OS << "new "; |
| 945 | unsigned NumPlace = E->getNumPlacementArgs(); |
| 946 | if (NumPlace > 0) { |
| 947 | OS << "("; |
| 948 | PrintExpr(E->getPlacementArg(0)); |
| 949 | for (unsigned i = 1; i < NumPlace; ++i) { |
| 950 | OS << ", "; |
| 951 | PrintExpr(E->getPlacementArg(i)); |
| 952 | } |
| 953 | OS << ") "; |
| 954 | } |
| 955 | if (E->isParenTypeId()) |
| 956 | OS << "("; |
Sebastian Redl | 6fec648 | 2008-12-02 22:08:59 +0000 | [diff] [blame] | 957 | std::string TypeS; |
| 958 | if (Expr *Size = E->getArraySize()) { |
| 959 | llvm::raw_string_ostream s(TypeS); |
| 960 | Size->printPretty(s); |
| 961 | s.flush(); |
| 962 | TypeS = "[" + TypeS + "]"; |
| 963 | } |
| 964 | E->getAllocatedType().getAsStringInternal(TypeS); |
| 965 | OS << TypeS; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 966 | if (E->isParenTypeId()) |
| 967 | OS << ")"; |
| 968 | |
| 969 | if (E->hasInitializer()) { |
| 970 | OS << "("; |
| 971 | unsigned NumCons = E->getNumConstructorArgs(); |
| 972 | if (NumCons > 0) { |
| 973 | PrintExpr(E->getConstructorArg(0)); |
| 974 | for (unsigned i = 1; i < NumCons; ++i) { |
| 975 | OS << ", "; |
| 976 | PrintExpr(E->getConstructorArg(i)); |
| 977 | } |
| 978 | } |
| 979 | OS << ")"; |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 984 | if (E->isGlobalDelete()) |
| 985 | OS << "::"; |
| 986 | OS << "delete "; |
| 987 | if (E->isArrayForm()) |
| 988 | OS << "[] "; |
| 989 | PrintExpr(E->getArgument()); |
| 990 | } |
| 991 | |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 992 | void StmtPrinter::VisitCXXDependentNameExpr(CXXDependentNameExpr *E) { |
| 993 | OS << E->getName()->getName(); |
| 994 | } |
| 995 | |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 996 | // Obj-C |
| 997 | |
| 998 | void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) { |
| 999 | OS << "@"; |
| 1000 | VisitStringLiteral(Node->getString()); |
| 1001 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1002 | |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1003 | void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1004 | OS << "@encode(" << Node->getEncodedType().getAsString() << ')'; |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1007 | void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1008 | OS << "@selector(" << Node->getSelector().getAsString() << ')'; |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1011 | void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1012 | OS << "@protocol(" << Node->getProtocol()->getNameAsString() << ')'; |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1015 | void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) { |
| 1016 | OS << "["; |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 1017 | Expr *receiver = Mess->getReceiver(); |
| 1018 | if (receiver) PrintExpr(receiver); |
| 1019 | else OS << Mess->getClassName()->getName(); |
Ted Kremenek | c29efd8 | 2008-05-02 17:32:38 +0000 | [diff] [blame] | 1020 | OS << ' '; |
Ted Kremenek | 97b7f26 | 2008-04-16 04:30:16 +0000 | [diff] [blame] | 1021 | Selector selector = Mess->getSelector(); |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 1022 | if (selector.isUnarySelector()) { |
Ted Kremenek | c29efd8 | 2008-05-02 17:32:38 +0000 | [diff] [blame] | 1023 | OS << selector.getIdentifierInfoForSlot(0)->getName(); |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 1024 | } else { |
| 1025 | for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) { |
Ted Kremenek | c29efd8 | 2008-05-02 17:32:38 +0000 | [diff] [blame] | 1026 | if (i < selector.getNumArgs()) { |
| 1027 | if (i > 0) OS << ' '; |
| 1028 | if (selector.getIdentifierInfoForSlot(i)) |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1029 | OS << selector.getIdentifierInfoForSlot(i)->getName() << ':'; |
Ted Kremenek | c29efd8 | 2008-05-02 17:32:38 +0000 | [diff] [blame] | 1030 | else |
| 1031 | OS << ":"; |
| 1032 | } |
| 1033 | else OS << ", "; // Handle variadic methods. |
| 1034 | |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 1035 | PrintExpr(Mess->getArg(i)); |
| 1036 | } |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1037 | } |
| 1038 | OS << "]"; |
| 1039 | } |
| 1040 | |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 1041 | void StmtPrinter::VisitObjCSuperExpr(ObjCSuperExpr *) { |
| 1042 | OS << "super"; |
| 1043 | } |
| 1044 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1045 | void StmtPrinter::VisitBlockExpr(BlockExpr *Node) { |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1046 | BlockDecl *BD = Node->getBlockDecl(); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1047 | OS << "^"; |
| 1048 | |
| 1049 | const FunctionType *AFT = Node->getFunctionType(); |
| 1050 | |
| 1051 | if (isa<FunctionTypeNoProto>(AFT)) { |
| 1052 | OS << "()"; |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1053 | } else if (!BD->param_empty() || cast<FunctionTypeProto>(AFT)->isVariadic()) { |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1054 | OS << '('; |
| 1055 | std::string ParamStr; |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1056 | for (BlockDecl::param_iterator AI = BD->param_begin(), |
| 1057 | E = BD->param_end(); AI != E; ++AI) { |
| 1058 | if (AI != BD->param_begin()) OS << ", "; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1059 | ParamStr = (*AI)->getNameAsString(); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1060 | (*AI)->getType().getAsStringInternal(ParamStr); |
| 1061 | OS << ParamStr; |
| 1062 | } |
| 1063 | |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1064 | const FunctionTypeProto *FT = cast<FunctionTypeProto>(AFT); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1065 | if (FT->isVariadic()) { |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1066 | if (!BD->param_empty()) OS << ", "; |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1067 | OS << "..."; |
| 1068 | } |
| 1069 | OS << ')'; |
| 1070 | } |
| 1071 | } |
| 1072 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1073 | void StmtPrinter::VisitBlockDeclRefExpr(BlockDeclRefExpr *Node) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1074 | OS << Node->getDecl()->getNameAsString(); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1075 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1076 | //===----------------------------------------------------------------------===// |
| 1077 | // Stmt method implementations |
| 1078 | //===----------------------------------------------------------------------===// |
| 1079 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1080 | void Stmt::dumpPretty() const { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1081 | printPretty(llvm::errs()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1084 | void Stmt::printPretty(llvm::raw_ostream &OS, PrinterHelper* Helper) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1085 | if (this == 0) { |
| 1086 | OS << "<NULL>"; |
| 1087 | return; |
| 1088 | } |
| 1089 | |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 1090 | StmtPrinter P(OS, Helper); |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 1091 | P.Visit(const_cast<Stmt*>(this)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1092 | } |
Ted Kremenek | 42a509f | 2007-08-31 21:30:12 +0000 | [diff] [blame] | 1093 | |
| 1094 | //===----------------------------------------------------------------------===// |
| 1095 | // PrinterHelper |
| 1096 | //===----------------------------------------------------------------------===// |
| 1097 | |
| 1098 | // Implement virtual destructor. |
Gabor Greif | 8467583 | 2007-09-11 15:32:40 +0000 | [diff] [blame] | 1099 | PrinterHelper::~PrinterHelper() {} |