Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1 | //===--- StmtDumper.cpp - Dumping 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. |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Stmt::dump/Stmt::print methods, which dump out the |
| 11 | // AST in a form that exposes type details and other fields. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/AST/StmtVisitor.h" |
Ted Kremenek | 91d1d7a | 2007-10-17 18:36:42 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 18 | #include "clang/AST/PrettyPrinter.h" |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 19 | #include "clang/Basic/SourceManager.h" |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | // StmtDumper Visitor |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
| 27 | namespace { |
Benjamin Kramer | 770b4a8 | 2009-11-28 19:03:38 +0000 | [diff] [blame] | 28 | class StmtDumper : public StmtVisitor<StmtDumper> { |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 29 | SourceManager *SM; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 30 | raw_ostream &OS; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 31 | unsigned IndentLevel; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 32 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 33 | /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump |
| 34 | /// the first few levels of an AST. This keeps track of how many ast levels |
| 35 | /// are left. |
| 36 | unsigned MaxDepth; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 37 | |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 38 | /// LastLocFilename/LastLocLine - Keep track of the last location we print |
| 39 | /// out so that we can print out deltas from then on out. |
| 40 | const char *LastLocFilename; |
| 41 | unsigned LastLocLine; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 42 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 43 | public: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 44 | StmtDumper(SourceManager *sm, raw_ostream &os, unsigned maxDepth) |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 45 | : SM(sm), OS(os), IndentLevel(0-1), MaxDepth(maxDepth) { |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 46 | LastLocFilename = ""; |
| 47 | LastLocLine = ~0U; |
| 48 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 49 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 50 | void DumpSubTree(Stmt *S) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 51 | // Prune the recursion if not using dump all. |
| 52 | if (MaxDepth == 0) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 54 | ++IndentLevel; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 55 | if (S) { |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 56 | if (DeclStmt* DS = dyn_cast<DeclStmt>(S)) |
| 57 | VisitDeclStmt(DS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 58 | else { |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 59 | Visit(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 60 | |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 61 | // Print out children. |
John McCall | 7502c1d | 2011-02-13 04:07:26 +0000 | [diff] [blame] | 62 | Stmt::child_range CI = S->children(); |
| 63 | if (CI) { |
| 64 | while (CI) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 65 | OS << '\n'; |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 66 | DumpSubTree(*CI++); |
| 67 | } |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 68 | } |
| 69 | } |
Chris Lattner | a46325e | 2010-05-25 17:56:43 +0000 | [diff] [blame] | 70 | OS << ')'; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 71 | } else { |
| 72 | Indent(); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 73 | OS << "<<<NULL>>>"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 74 | } |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 75 | --IndentLevel; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 76 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 77 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 78 | void DumpDeclarator(Decl *D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 79 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 80 | void Indent() const { |
| 81 | for (int i = 0, e = IndentLevel; i < e; ++i) |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 82 | OS << " "; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 83 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 85 | void DumpType(QualType T) { |
John McCall | 49f4e1c | 2010-12-10 11:01:00 +0000 | [diff] [blame] | 86 | SplitQualType T_split = T.split(); |
| 87 | OS << "'" << QualType::getAsString(T_split) << "'"; |
Chris Lattner | fd8f7da | 2007-08-09 00:36:22 +0000 | [diff] [blame] | 88 | |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 89 | if (!T.isNull()) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 90 | // If the type is sugared, also dump a (shallow) desugared type. |
John McCall | 49f4e1c | 2010-12-10 11:01:00 +0000 | [diff] [blame] | 91 | SplitQualType D_split = T.getSplitDesugaredType(); |
| 92 | if (T_split != D_split) |
| 93 | OS << ":'" << QualType::getAsString(D_split) << "'"; |
Chris Lattner | bad3785 | 2008-04-02 05:06:23 +0000 | [diff] [blame] | 94 | } |
Chris Lattner | fd8f7da | 2007-08-09 00:36:22 +0000 | [diff] [blame] | 95 | } |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 96 | void DumpDeclRef(Decl *node); |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 97 | void DumpStmt(const Stmt *Node) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 98 | Indent(); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 99 | OS << "(" << Node->getStmtClassName() |
| 100 | << " " << (void*)Node; |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 101 | DumpSourceRange(Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 102 | } |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 103 | void DumpValueKind(ExprValueKind K) { |
| 104 | switch (K) { |
| 105 | case VK_RValue: break; |
| 106 | case VK_LValue: OS << " lvalue"; break; |
| 107 | case VK_XValue: OS << " xvalue"; break; |
| 108 | } |
| 109 | } |
| 110 | void DumpObjectKind(ExprObjectKind K) { |
| 111 | switch (K) { |
| 112 | case OK_Ordinary: break; |
| 113 | case OK_BitField: OS << " bitfield"; break; |
| 114 | case OK_ObjCProperty: OS << " objcproperty"; break; |
| 115 | case OK_VectorComponent: OS << " vectorcomponent"; break; |
| 116 | } |
| 117 | } |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 118 | void DumpExpr(const Expr *Node) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 119 | DumpStmt(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 120 | OS << ' '; |
Chris Lattner | fd8f7da | 2007-08-09 00:36:22 +0000 | [diff] [blame] | 121 | DumpType(Node->getType()); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 122 | DumpValueKind(Node->getValueKind()); |
| 123 | DumpObjectKind(Node->getObjectKind()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 124 | } |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 125 | void DumpSourceRange(const Stmt *Node); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 126 | void DumpLocation(SourceLocation Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 127 | |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 128 | // Stmts. |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 129 | void VisitStmt(Stmt *Node); |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 130 | void VisitDeclStmt(DeclStmt *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 131 | void VisitLabelStmt(LabelStmt *Node); |
| 132 | void VisitGotoStmt(GotoStmt *Node); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 133 | |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 134 | // Exprs |
| 135 | void VisitExpr(Expr *Node); |
Anders Carlsson | 27a5b9b | 2009-08-22 23:33:40 +0000 | [diff] [blame] | 136 | void VisitCastExpr(CastExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 137 | void VisitDeclRefExpr(DeclRefExpr *Node); |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 138 | void VisitPredefinedExpr(PredefinedExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 139 | void VisitCharacterLiteral(CharacterLiteral *Node); |
| 140 | void VisitIntegerLiteral(IntegerLiteral *Node); |
| 141 | void VisitFloatingLiteral(FloatingLiteral *Node); |
| 142 | void VisitStringLiteral(StringLiteral *Str); |
| 143 | void VisitUnaryOperator(UnaryOperator *Node); |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 144 | void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 145 | void VisitMemberExpr(MemberExpr *Node); |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 146 | void VisitExtVectorElementExpr(ExtVectorElementExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 147 | void VisitBinaryOperator(BinaryOperator *Node); |
| 148 | void VisitCompoundAssignOperator(CompoundAssignOperator *Node); |
| 149 | void VisitAddrLabelExpr(AddrLabelExpr *Node); |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 150 | void VisitBlockExpr(BlockExpr *Node); |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 151 | void VisitOpaqueValueExpr(OpaqueValueExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 152 | |
| 153 | // C++ |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 154 | void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 155 | void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node); |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 156 | void VisitCXXThisExpr(CXXThisExpr *Node); |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 157 | void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node); |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 158 | void VisitCXXConstructExpr(CXXConstructExpr *Node); |
| 159 | void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node); |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 160 | void VisitExprWithCleanups(ExprWithCleanups *Node); |
John McCall | 9d5f35e | 2009-12-11 21:50:11 +0000 | [diff] [blame] | 161 | void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node); |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 162 | void DumpCXXTemporary(CXXTemporary *Temporary); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 164 | // ObjC |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 165 | void VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 166 | void VisitObjCEncodeExpr(ObjCEncodeExpr *Node); |
Ted Kremenek | b3d914b | 2008-02-29 22:04:05 +0000 | [diff] [blame] | 167 | void VisitObjCMessageExpr(ObjCMessageExpr* Node); |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 168 | void VisitObjCSelectorExpr(ObjCSelectorExpr *Node); |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 169 | void VisitObjCProtocolExpr(ObjCProtocolExpr *Node); |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 170 | void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node); |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 171 | void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 172 | }; |
| 173 | } |
| 174 | |
| 175 | //===----------------------------------------------------------------------===// |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 176 | // Utilities |
| 177 | //===----------------------------------------------------------------------===// |
| 178 | |
| 179 | void StmtDumper::DumpLocation(SourceLocation Loc) { |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 180 | SourceLocation SpellingLoc = SM->getSpellingLoc(Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 182 | // The general format we print out is filename:line:col, but we drop pieces |
| 183 | // that haven't changed since the last loc printed. |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 184 | PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc); |
| 185 | |
Douglas Gregor | cb7b1e1 | 2010-11-12 07:15:47 +0000 | [diff] [blame] | 186 | if (PLoc.isInvalid()) { |
| 187 | OS << "<invalid sloc>"; |
| 188 | return; |
| 189 | } |
| 190 | |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 191 | if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 192 | OS << PLoc.getFilename() << ':' << PLoc.getLine() |
| 193 | << ':' << PLoc.getColumn(); |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 194 | LastLocFilename = PLoc.getFilename(); |
| 195 | LastLocLine = PLoc.getLine(); |
| 196 | } else if (PLoc.getLine() != LastLocLine) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 197 | OS << "line" << ':' << PLoc.getLine() |
| 198 | << ':' << PLoc.getColumn(); |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 199 | LastLocLine = PLoc.getLine(); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 200 | } else { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 201 | OS << "col" << ':' << PLoc.getColumn(); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 205 | void StmtDumper::DumpSourceRange(const Stmt *Node) { |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 206 | // Can't translate locations if a SourceManager isn't available. |
| 207 | if (SM == 0) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 208 | |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 209 | // TODO: If the parent expression is available, we can print a delta vs its |
| 210 | // location. |
| 211 | SourceRange R = Node->getSourceRange(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 212 | |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 213 | OS << " <"; |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 214 | DumpLocation(R.getBegin()); |
| 215 | if (R.getBegin() != R.getEnd()) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 216 | OS << ", "; |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 217 | DumpLocation(R.getEnd()); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 218 | } |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 219 | OS << ">"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 220 | |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 221 | // <t2.c:123:421[blah], t2.c:412:321> |
| 222 | |
| 223 | } |
| 224 | |
| 225 | |
| 226 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 227 | // Stmt printing methods. |
| 228 | //===----------------------------------------------------------------------===// |
| 229 | |
| 230 | void StmtDumper::VisitStmt(Stmt *Node) { |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 231 | DumpStmt(Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 234 | void StmtDumper::DumpDeclarator(Decl *D) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 235 | // FIXME: Need to complete/beautify this... this code simply shows the |
| 236 | // nodes are where they need to be. |
| 237 | if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 238 | OS << "\"typedef " << localType->getUnderlyingType().getAsString() |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 239 | << ' ' << *localType << '"'; |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 240 | } else if (TypeAliasDecl *localType = dyn_cast<TypeAliasDecl>(D)) { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 241 | OS << "\"using " << *localType << " = " |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 242 | << localType->getUnderlyingType().getAsString() << '"'; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 243 | } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 244 | OS << "\""; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 245 | // Emit storage class for vardecls. |
| 246 | if (VarDecl *V = dyn_cast<VarDecl>(VD)) { |
John McCall | d931b08 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 247 | if (V->getStorageClass() != SC_None) |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 248 | OS << VarDecl::getStorageClassSpecifierString(V->getStorageClass()) |
| 249 | << " "; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 251 | |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 252 | std::string Name = VD->getNameAsString(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 253 | VD->getType().getAsStringInternal(Name, |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 254 | PrintingPolicy(VD->getASTContext().getLangOptions())); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 255 | OS << Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 256 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 257 | // If this is a vardecl with an initializer, emit it. |
| 258 | if (VarDecl *V = dyn_cast<VarDecl>(VD)) { |
| 259 | if (V->getInit()) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 260 | OS << " =\n"; |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 261 | DumpSubTree(V->getInit()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 264 | OS << '"'; |
Steve Naroff | 9219928 | 2007-11-17 21:37:36 +0000 | [diff] [blame] | 265 | } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 266 | // print a free standing tag decl (e.g. "struct x;"). |
| 267 | const char *tagname; |
| 268 | if (const IdentifierInfo *II = TD->getIdentifier()) |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 269 | tagname = II->getNameStart(); |
Steve Naroff | 9219928 | 2007-11-17 21:37:36 +0000 | [diff] [blame] | 270 | else |
| 271 | tagname = "<anonymous>"; |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 272 | OS << '"' << TD->getKindName() << ' ' << tagname << ";\""; |
Steve Naroff | 9219928 | 2007-11-17 21:37:36 +0000 | [diff] [blame] | 273 | // FIXME: print tag bodies. |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 274 | } else if (UsingDirectiveDecl *UD = dyn_cast<UsingDirectiveDecl>(D)) { |
| 275 | // print using-directive decl (e.g. "using namespace x;") |
| 276 | const char *ns; |
| 277 | if (const IdentifierInfo *II = UD->getNominatedNamespace()->getIdentifier()) |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 278 | ns = II->getNameStart(); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 279 | else |
| 280 | ns = "<anonymous>"; |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 281 | OS << '"' << UD->getDeclKindName() << ns << ";\""; |
Sebastian Redl | 0ca4359 | 2010-05-04 10:20:17 +0000 | [diff] [blame] | 282 | } else if (UsingDecl *UD = dyn_cast<UsingDecl>(D)) { |
| 283 | // print using decl (e.g. "using std::string;") |
| 284 | const char *tn = UD->isTypeName() ? "typename " : ""; |
| 285 | OS << '"' << UD->getDeclKindName() << tn; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 286 | UD->getQualifier()->print(OS, |
| 287 | PrintingPolicy(UD->getASTContext().getLangOptions())); |
Sebastian Redl | 0ca4359 | 2010-05-04 10:20:17 +0000 | [diff] [blame] | 288 | OS << ";\""; |
Chris Lattner | 4ae493c | 2011-02-18 02:08:43 +0000 | [diff] [blame] | 289 | } else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) { |
| 290 | OS << "label " << LD->getNameAsString(); |
Peter Collingbourne | 28ac87e | 2011-03-16 18:37:27 +0000 | [diff] [blame] | 291 | } else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) { |
| 292 | OS << "\"static_assert(\n"; |
| 293 | DumpSubTree(SAD->getAssertExpr()); |
| 294 | OS << ",\n"; |
| 295 | DumpSubTree(SAD->getMessage()); |
| 296 | OS << ");\""; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 297 | } else { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 298 | llvm_unreachable("Unexpected decl"); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 299 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 302 | void StmtDumper::VisitDeclStmt(DeclStmt *Node) { |
| 303 | DumpStmt(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 304 | OS << "\n"; |
Ted Kremenek | 04a72b7 | 2008-10-06 18:38:35 +0000 | [diff] [blame] | 305 | for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end(); |
| 306 | DI != DE; ++DI) { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 307 | Decl* D = *DI; |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 308 | ++IndentLevel; |
| 309 | Indent(); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 310 | OS << (void*) D << " "; |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 311 | DumpDeclarator(D); |
Chris Lattner | f279725 | 2009-03-29 16:04:50 +0000 | [diff] [blame] | 312 | if (DI+1 != DE) |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 313 | OS << "\n"; |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 314 | --IndentLevel; |
| 315 | } |
| 316 | } |
| 317 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 318 | void StmtDumper::VisitLabelStmt(LabelStmt *Node) { |
| 319 | DumpStmt(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 320 | OS << " '" << Node->getName() << "'"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 323 | void StmtDumper::VisitGotoStmt(GotoStmt *Node) { |
| 324 | DumpStmt(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 325 | OS << " '" << Node->getLabel()->getName() |
| 326 | << "':" << (void*)Node->getLabel(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 329 | //===----------------------------------------------------------------------===// |
| 330 | // Expr printing methods. |
| 331 | //===----------------------------------------------------------------------===// |
| 332 | |
| 333 | void StmtDumper::VisitExpr(Expr *Node) { |
| 334 | DumpExpr(Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 337 | static void DumpBasePath(raw_ostream &OS, CastExpr *Node) { |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 338 | if (Node->path_empty()) |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 339 | return; |
| 340 | |
| 341 | OS << " ("; |
| 342 | bool First = true; |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 343 | for (CastExpr::path_iterator |
| 344 | I = Node->path_begin(), E = Node->path_end(); I != E; ++I) { |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 345 | const CXXBaseSpecifier *Base = *I; |
| 346 | if (!First) |
| 347 | OS << " -> "; |
| 348 | |
| 349 | const CXXRecordDecl *RD = |
| 350 | cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); |
| 351 | |
| 352 | if (Base->isVirtual()) |
| 353 | OS << "virtual "; |
| 354 | OS << RD->getName(); |
| 355 | First = false; |
| 356 | } |
| 357 | |
| 358 | OS << ')'; |
| 359 | } |
| 360 | |
Anders Carlsson | 27a5b9b | 2009-08-22 23:33:40 +0000 | [diff] [blame] | 361 | void StmtDumper::VisitCastExpr(CastExpr *Node) { |
| 362 | DumpExpr(Node); |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 363 | OS << " <" << Node->getCastKindName(); |
| 364 | DumpBasePath(OS, Node); |
| 365 | OS << ">"; |
Anders Carlsson | 27a5b9b | 2009-08-22 23:33:40 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 368 | void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) { |
| 369 | DumpExpr(Node); |
Ted Kremenek | eb641f9 | 2007-09-10 17:32:55 +0000 | [diff] [blame] | 370 | |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 371 | OS << " "; |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 372 | DumpDeclRef(Node->getDecl()); |
Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 373 | if (Node->getDecl() != Node->getFoundDecl()) { |
| 374 | OS << " ("; |
| 375 | DumpDeclRef(Node->getFoundDecl()); |
| 376 | OS << ")"; |
| 377 | } |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | void StmtDumper::DumpDeclRef(Decl *d) { |
| 381 | OS << d->getDeclKindName() << ' ' << (void*) d; |
| 382 | |
| 383 | if (NamedDecl *nd = dyn_cast<NamedDecl>(d)) { |
| 384 | OS << " '"; |
| 385 | nd->getDeclName().printName(OS); |
| 386 | OS << "'"; |
Ted Kremenek | eb641f9 | 2007-09-10 17:32:55 +0000 | [diff] [blame] | 387 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 389 | if (ValueDecl *vd = dyn_cast<ValueDecl>(d)) { |
| 390 | OS << ' '; DumpType(vd->getType()); |
| 391 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 392 | } |
| 393 | |
John McCall | 9d5f35e | 2009-12-11 21:50:11 +0000 | [diff] [blame] | 394 | void StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) { |
| 395 | DumpExpr(Node); |
| 396 | OS << " ("; |
| 397 | if (!Node->requiresADL()) OS << "no "; |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 398 | OS << "ADL) = '" << Node->getName() << '\''; |
John McCall | 9d5f35e | 2009-12-11 21:50:11 +0000 | [diff] [blame] | 399 | |
| 400 | UnresolvedLookupExpr::decls_iterator |
| 401 | I = Node->decls_begin(), E = Node->decls_end(); |
| 402 | if (I == E) OS << " empty"; |
| 403 | for (; I != E; ++I) |
| 404 | OS << " " << (void*) *I; |
| 405 | } |
| 406 | |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 407 | void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { |
Steve Naroff | 466c2e3 | 2008-05-23 00:59:14 +0000 | [diff] [blame] | 408 | DumpExpr(Node); |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 409 | |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 410 | OS << " " << Node->getDecl()->getDeclKindName() |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 411 | << "Decl='" << *Node->getDecl() |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 412 | << "' " << (void*)Node->getDecl(); |
Steve Naroff | 218543b | 2008-05-23 22:01:24 +0000 | [diff] [blame] | 413 | if (Node->isFreeIvar()) |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 414 | OS << " isFreeIvar"; |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 417 | void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 418 | DumpExpr(Node); |
| 419 | switch (Node->getIdentType()) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 420 | default: llvm_unreachable("unknown case"); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 421 | case PredefinedExpr::Func: OS << " __func__"; break; |
| 422 | case PredefinedExpr::Function: OS << " __FUNCTION__"; break; |
| 423 | case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
| 427 | void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) { |
Chris Lattner | a0df31a | 2007-08-09 01:04:32 +0000 | [diff] [blame] | 428 | DumpExpr(Node); |
Richard Trieu | 49cf884 | 2011-11-03 23:56:23 +0000 | [diff] [blame] | 429 | OS << " " << Node->getValue(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) { |
| 433 | DumpExpr(Node); |
| 434 | |
| 435 | bool isSigned = Node->getType()->isSignedIntegerType(); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 436 | OS << " " << Node->getValue().toString(10, isSigned); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 437 | } |
| 438 | void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) { |
| 439 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 440 | OS << " " << Node->getValueAsApproximateDouble(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 441 | } |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 442 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 443 | void StmtDumper::VisitStringLiteral(StringLiteral *Str) { |
Chris Lattner | a0df31a | 2007-08-09 01:04:32 +0000 | [diff] [blame] | 444 | DumpExpr(Str); |
| 445 | // FIXME: this doesn't print wstrings right. |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 446 | OS << " "; |
Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 447 | switch (Str->getKind()) { |
| 448 | case StringLiteral::Ascii: break; // No prefix |
| 449 | case StringLiteral::Wide: OS << 'L'; break; |
| 450 | case StringLiteral::UTF8: OS << "u8"; break; |
| 451 | case StringLiteral::UTF16: OS << 'u'; break; |
| 452 | case StringLiteral::UTF32: OS << 'U'; break; |
| 453 | } |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 454 | OS << '"'; |
Benjamin Kramer | 2f4eaef | 2010-08-17 12:54:38 +0000 | [diff] [blame] | 455 | OS.write_escaped(Str->getString()); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 456 | OS << '"'; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 457 | } |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 458 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 459 | void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 460 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 461 | OS << " " << (Node->isPostfix() ? "postfix" : "prefix") |
| 462 | << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 463 | } |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 464 | void StmtDumper::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 465 | DumpExpr(Node); |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 466 | switch(Node->getKind()) { |
| 467 | case UETT_SizeOf: |
| 468 | OS << " sizeof "; |
| 469 | break; |
| 470 | case UETT_AlignOf: |
| 471 | OS << " __alignof "; |
| 472 | break; |
| 473 | case UETT_VecStep: |
| 474 | OS << " vec_step "; |
| 475 | break; |
| 476 | } |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 477 | if (Node->isArgumentType()) |
| 478 | DumpType(Node->getArgumentType()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 479 | } |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 480 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 481 | void StmtDumper::VisitMemberExpr(MemberExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 482 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 483 | OS << " " << (Node->isArrow() ? "->" : ".") |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 484 | << *Node->getMemberDecl() << ' ' |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 485 | << (void*)Node->getMemberDecl(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 486 | } |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 487 | void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 488 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 489 | OS << " " << Node->getAccessor().getNameStart(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 490 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 491 | void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) { |
| 492 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 493 | OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'"; |
Chris Lattner | eb14fe8 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 494 | } |
| 495 | void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) { |
| 496 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 497 | OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) |
| 498 | << "' ComputeLHSTy="; |
Eli Friedman | ab3a852 | 2009-03-28 01:22:36 +0000 | [diff] [blame] | 499 | DumpType(Node->getComputationLHSType()); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 500 | OS << " ComputeResultTy="; |
Eli Friedman | ab3a852 | 2009-03-28 01:22:36 +0000 | [diff] [blame] | 501 | DumpType(Node->getComputationResultType()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 502 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 503 | |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 504 | void StmtDumper::VisitBlockExpr(BlockExpr *Node) { |
| 505 | DumpExpr(Node); |
| 506 | |
| 507 | IndentLevel++; |
| 508 | BlockDecl *block = Node->getBlockDecl(); |
| 509 | if (block->capturesCXXThis()) { |
| 510 | OS << '\n'; Indent(); OS << "(capture this)"; |
| 511 | } |
| 512 | for (BlockDecl::capture_iterator |
| 513 | i = block->capture_begin(), e = block->capture_end(); i != e; ++i) { |
| 514 | OS << '\n'; |
| 515 | Indent(); |
| 516 | OS << "(capture "; |
| 517 | if (i->isByRef()) OS << "byref "; |
| 518 | if (i->isNested()) OS << "nested "; |
| 519 | DumpDeclRef(i->getVariable()); |
| 520 | if (i->hasCopyExpr()) DumpSubTree(i->getCopyExpr()); |
| 521 | OS << ")"; |
| 522 | } |
| 523 | IndentLevel--; |
| 524 | |
| 525 | DumpSubTree(block->getBody()); |
| 526 | } |
| 527 | |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 528 | void StmtDumper::VisitOpaqueValueExpr(OpaqueValueExpr *Node) { |
| 529 | DumpExpr(Node); |
| 530 | |
| 531 | if (Expr *Source = Node->getSourceExpr()) { |
| 532 | OS << '\n'; |
| 533 | DumpSubTree(Source); |
| 534 | } |
| 535 | } |
| 536 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 537 | // GNU extensions. |
| 538 | |
| 539 | void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 540 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 541 | OS << " " << Node->getLabel()->getName() |
| 542 | << " " << (void*)Node->getLabel(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 545 | //===----------------------------------------------------------------------===// |
| 546 | // C++ Expressions |
| 547 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 548 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 549 | void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 550 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 551 | OS << " " << Node->getCastName() |
| 552 | << "<" << Node->getTypeAsWritten().getAsString() << ">" |
Anders Carlsson | 5cf86ba | 2010-04-24 19:06:50 +0000 | [diff] [blame] | 553 | << " <" << Node->getCastKindName(); |
| 554 | DumpBasePath(OS, Node); |
| 555 | OS << ">"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 559 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 560 | OS << " " << (Node->getValue() ? "true" : "false"); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 563 | void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) { |
| 564 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 565 | OS << " this"; |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 568 | void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) { |
| 569 | DumpExpr(Node); |
Eli Friedman | cc2fca2 | 2011-09-02 17:38:59 +0000 | [diff] [blame] | 570 | OS << " functional cast to " << Node->getTypeAsWritten().getAsString() |
| 571 | << " <" << Node->getCastKindName() << ">"; |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 574 | void StmtDumper::VisitCXXConstructExpr(CXXConstructExpr *Node) { |
| 575 | DumpExpr(Node); |
John McCall | d4bbdfe | 2010-02-02 19:03:45 +0000 | [diff] [blame] | 576 | CXXConstructorDecl *Ctor = Node->getConstructor(); |
| 577 | DumpType(Ctor->getType()); |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 578 | if (Node->isElidable()) |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 579 | OS << " elidable"; |
John McCall | f8cf0b0 | 2010-08-07 06:38:55 +0000 | [diff] [blame] | 580 | if (Node->requiresZeroInitialization()) |
| 581 | OS << " zeroing"; |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | void StmtDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) { |
| 585 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 586 | OS << " "; |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 587 | DumpCXXTemporary(Node->getTemporary()); |
| 588 | } |
| 589 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 590 | void StmtDumper::VisitExprWithCleanups(ExprWithCleanups *Node) { |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 591 | DumpExpr(Node); |
| 592 | ++IndentLevel; |
John McCall | 80ee6e8 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 593 | for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 594 | OS << "\n"; |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 595 | Indent(); |
John McCall | 80ee6e8 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 596 | OS << "(cleanup "; |
| 597 | DumpDeclRef(Node->getObject(i)); |
| 598 | OS << ")"; |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 599 | } |
| 600 | --IndentLevel; |
| 601 | } |
| 602 | |
| 603 | void StmtDumper::DumpCXXTemporary(CXXTemporary *Temporary) { |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 604 | OS << "(CXXTemporary " << (void *)Temporary << ")"; |
Anders Carlsson | 0eca1b6 | 2009-08-12 00:21:52 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 607 | //===----------------------------------------------------------------------===// |
| 608 | // Obj-C Expressions |
| 609 | //===----------------------------------------------------------------------===// |
| 610 | |
Ted Kremenek | b3d914b | 2008-02-29 22:04:05 +0000 | [diff] [blame] | 611 | void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) { |
| 612 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 613 | OS << " selector=" << Node->getSelector().getAsString(); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 614 | switch (Node->getReceiverKind()) { |
| 615 | case ObjCMessageExpr::Instance: |
| 616 | break; |
| 617 | |
| 618 | case ObjCMessageExpr::Class: |
| 619 | OS << " class="; |
| 620 | DumpType(Node->getClassReceiver()); |
| 621 | break; |
| 622 | |
| 623 | case ObjCMessageExpr::SuperInstance: |
| 624 | OS << " super (instance)"; |
| 625 | break; |
| 626 | |
| 627 | case ObjCMessageExpr::SuperClass: |
| 628 | OS << " super (class)"; |
| 629 | break; |
| 630 | } |
Ted Kremenek | b3d914b | 2008-02-29 22:04:05 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 633 | void StmtDumper::VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node) { |
| 634 | DumpStmt(Node); |
Douglas Gregor | c00d8e1 | 2010-04-26 16:46:50 +0000 | [diff] [blame] | 635 | if (VarDecl *CatchParam = Node->getCatchParamDecl()) { |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 636 | OS << " catch parm = "; |
| 637 | DumpDeclarator(CatchParam); |
| 638 | } else { |
| 639 | OS << " catch all"; |
| 640 | } |
| 641 | } |
| 642 | |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 643 | void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) { |
| 644 | DumpExpr(Node); |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 645 | OS << " "; |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 646 | DumpType(Node->getEncodedType()); |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 649 | void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) { |
| 650 | DumpExpr(Node); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 651 | |
Daniel Dunbar | 806c12e | 2009-12-03 09:13:13 +0000 | [diff] [blame] | 652 | OS << " " << Node->getSelector().getAsString(); |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 655 | void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) { |
| 656 | DumpExpr(Node); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 658 | OS << ' ' <<* Node->getProtocol(); |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 659 | } |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 660 | |
| 661 | void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) { |
| 662 | DumpExpr(Node); |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 663 | if (Node->isImplicitProperty()) { |
Fariborz Jahanian | 99130e5 | 2010-12-22 19:46:35 +0000 | [diff] [blame] | 664 | OS << " Kind=MethodRef Getter=\""; |
| 665 | if (Node->getImplicitPropertyGetter()) |
| 666 | OS << Node->getImplicitPropertyGetter()->getSelector().getAsString(); |
| 667 | else |
| 668 | OS << "(null)"; |
| 669 | |
| 670 | OS << "\" Setter=\""; |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 671 | if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter()) |
| 672 | OS << Setter->getSelector().getAsString(); |
| 673 | else |
| 674 | OS << "(null)"; |
| 675 | OS << "\""; |
| 676 | } else { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 677 | OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"'; |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 678 | } |
Fariborz Jahanian | 5daf570 | 2008-11-22 18:39:36 +0000 | [diff] [blame] | 679 | |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 680 | if (Node->isSuperReceiver()) |
| 681 | OS << " super"; |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 684 | //===----------------------------------------------------------------------===// |
| 685 | // Stmt method implementations |
| 686 | //===----------------------------------------------------------------------===// |
| 687 | |
| 688 | /// dump - This does a local dump of the specified AST fragment. It dumps the |
| 689 | /// specified node and a few nodes underneath it, but not the whole subtree. |
| 690 | /// This is useful in a debugger. |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 691 | void Stmt::dump(SourceManager &SM) const { |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 692 | dump(llvm::errs(), SM); |
| 693 | } |
| 694 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 695 | void Stmt::dump(raw_ostream &OS, SourceManager &SM) const { |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 696 | StmtDumper P(&SM, OS, 4); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 697 | P.DumpSubTree(const_cast<Stmt*>(this)); |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 698 | OS << "\n"; |
Chris Lattner | 0c727a3 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /// dump - This does a local dump of the specified AST fragment. It dumps the |
| 702 | /// specified node and a few nodes underneath it, but not the whole subtree. |
| 703 | /// This is useful in a debugger. |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 704 | void Stmt::dump() const { |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 705 | StmtDumper P(0, llvm::errs(), 4); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 706 | P.DumpSubTree(const_cast<Stmt*>(this)); |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 707 | llvm::errs() << "\n"; |
Chris Lattner | 0c727a3 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /// dumpAll - This does a dump of the specified AST fragment and all subtrees. |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 711 | void Stmt::dumpAll(SourceManager &SM) const { |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 712 | StmtDumper P(&SM, llvm::errs(), ~0U); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 713 | P.DumpSubTree(const_cast<Stmt*>(this)); |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 714 | llvm::errs() << "\n"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | /// dumpAll - This does a dump of the specified AST fragment and all subtrees. |
| 718 | void Stmt::dumpAll() const { |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 719 | StmtDumper P(0, llvm::errs(), ~0U); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 720 | P.DumpSubTree(const_cast<Stmt*>(this)); |
Argyrios Kyrtzidis | 9668033 | 2010-08-09 10:54:31 +0000 | [diff] [blame] | 721 | llvm::errs() << "\n"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 722 | } |