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