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" |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 17 | #include "clang/Basic/SourceManager.h" |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Compiler.h" |
| 19 | #include <cstdio> |
| 20 | using namespace clang; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // StmtDumper Visitor |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | namespace { |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 27 | class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor<StmtDumper> { |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 28 | SourceManager *SM; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 29 | FILE *F; |
| 30 | unsigned IndentLevel; |
| 31 | |
| 32 | /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump |
| 33 | /// the first few levels of an AST. This keeps track of how many ast levels |
| 34 | /// are left. |
| 35 | unsigned MaxDepth; |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 36 | |
| 37 | /// LastLocFilename/LastLocLine - Keep track of the last location we print |
| 38 | /// out so that we can print out deltas from then on out. |
| 39 | const char *LastLocFilename; |
| 40 | unsigned LastLocLine; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 41 | public: |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 42 | StmtDumper(SourceManager *sm, FILE *f, unsigned maxDepth) |
| 43 | : SM(sm), F(f), IndentLevel(0-1), MaxDepth(maxDepth) { |
| 44 | LastLocFilename = ""; |
| 45 | LastLocLine = ~0U; |
| 46 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 47 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 48 | void DumpSubTree(Stmt *S) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 49 | // Prune the recursion if not using dump all. |
| 50 | if (MaxDepth == 0) return; |
| 51 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 52 | ++IndentLevel; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 53 | if (S) { |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 54 | if (DeclStmt* DS = dyn_cast<DeclStmt>(S)) |
| 55 | VisitDeclStmt(DS); |
| 56 | else { |
| 57 | Visit(S); |
| 58 | |
| 59 | // Print out children. |
| 60 | Stmt::child_iterator CI = S->child_begin(), CE = S->child_end(); |
| 61 | if (CI != CE) { |
| 62 | while (CI != CE) { |
| 63 | fprintf(F, "\n"); |
| 64 | DumpSubTree(*CI++); |
| 65 | } |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 66 | } |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 67 | fprintf(F, ")"); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 68 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 69 | } else { |
| 70 | Indent(); |
Chris Lattner | 4a70adb | 2007-08-26 03:53:29 +0000 | [diff] [blame] | 71 | fprintf(F, "<<<NULL>>>"); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 72 | } |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 73 | --IndentLevel; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 76 | void DumpDeclarator(Decl *D); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 77 | |
| 78 | void Indent() const { |
| 79 | for (int i = 0, e = IndentLevel; i < e; ++i) |
| 80 | fprintf(F, " "); |
| 81 | } |
| 82 | |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 83 | void DumpType(QualType T) { |
Chris Lattner | fd8f7da | 2007-08-09 00:36:22 +0000 | [diff] [blame] | 84 | fprintf(F, "'%s'", T.getAsString().c_str()); |
| 85 | |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 86 | if (!T.isNull()) { |
| 87 | // If the type is directly a typedef, strip off typedefness to give at |
| 88 | // least one level of concreteness. |
| 89 | if (TypedefType *TDT = dyn_cast<TypedefType>(T)) { |
| 90 | QualType Simplified = |
| 91 | TDT->LookThroughTypedefs().getQualifiedType(T.getCVRQualifiers()); |
| 92 | fprintf(F, ":'%s'", Simplified.getAsString().c_str()); |
| 93 | } |
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 | } |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 96 | void DumpStmt(const Stmt *Node) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 97 | Indent(); |
| 98 | fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node); |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 99 | DumpSourceRange(Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 100 | } |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 101 | void DumpExpr(const Expr *Node) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 102 | DumpStmt(Node); |
Chris Lattner | fd8f7da | 2007-08-09 00:36:22 +0000 | [diff] [blame] | 103 | fprintf(F, " "); |
| 104 | DumpType(Node->getType()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 105 | } |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 106 | void DumpSourceRange(const Stmt *Node); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 107 | void DumpLocation(SourceLocation Loc); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 108 | |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 109 | // Stmts. |
Chris Lattner | c5598cb | 2007-08-21 04:04:25 +0000 | [diff] [blame] | 110 | void VisitStmt(Stmt *Node); |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 111 | void VisitDeclStmt(DeclStmt *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 112 | void VisitLabelStmt(LabelStmt *Node); |
| 113 | void VisitGotoStmt(GotoStmt *Node); |
| 114 | |
| 115 | // Exprs |
| 116 | void VisitExpr(Expr *Node); |
| 117 | void VisitDeclRefExpr(DeclRefExpr *Node); |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 118 | void VisitPredefinedExpr(PredefinedExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 119 | void VisitCharacterLiteral(CharacterLiteral *Node); |
| 120 | void VisitIntegerLiteral(IntegerLiteral *Node); |
| 121 | void VisitFloatingLiteral(FloatingLiteral *Node); |
| 122 | void VisitStringLiteral(StringLiteral *Str); |
| 123 | void VisitUnaryOperator(UnaryOperator *Node); |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 124 | void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 125 | void VisitMemberExpr(MemberExpr *Node); |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 126 | void VisitExtVectorElementExpr(ExtVectorElementExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 127 | void VisitBinaryOperator(BinaryOperator *Node); |
| 128 | void VisitCompoundAssignOperator(CompoundAssignOperator *Node); |
| 129 | void VisitAddrLabelExpr(AddrLabelExpr *Node); |
| 130 | void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node); |
| 131 | |
| 132 | // C++ |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 133 | void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node); |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 134 | void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node); |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 135 | void VisitCXXThisExpr(CXXThisExpr *Node); |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 136 | void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node); |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 137 | |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 138 | // ObjC |
| 139 | void VisitObjCEncodeExpr(ObjCEncodeExpr *Node); |
Ted Kremenek | b3d914b | 2008-02-29 22:04:05 +0000 | [diff] [blame] | 140 | void VisitObjCMessageExpr(ObjCMessageExpr* Node); |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 141 | void VisitObjCSelectorExpr(ObjCSelectorExpr *Node); |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 142 | void VisitObjCProtocolExpr(ObjCProtocolExpr *Node); |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 143 | void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node); |
Fariborz Jahanian | 5daf570 | 2008-11-22 18:39:36 +0000 | [diff] [blame] | 144 | void VisitObjCKVCRefExpr(ObjCKVCRefExpr *Node); |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 145 | void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node); |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 146 | void VisitObjCSuperExpr(ObjCSuperExpr *Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 147 | }; |
| 148 | } |
| 149 | |
| 150 | //===----------------------------------------------------------------------===// |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 151 | // Utilities |
| 152 | //===----------------------------------------------------------------------===// |
| 153 | |
| 154 | void StmtDumper::DumpLocation(SourceLocation Loc) { |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 155 | SourceLocation SpellingLoc = SM->getSpellingLoc(Loc); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 156 | |
| 157 | // The general format we print out is filename:line:col, but we drop pieces |
| 158 | // that haven't changed since the last loc printed. |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 159 | const char *Filename = SM->getSourceName(SpellingLoc); |
| 160 | unsigned LineNo = SM->getLineNumber(SpellingLoc); |
| 161 | unsigned ColNo = SM->getColumnNumber(SpellingLoc); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 162 | if (strcmp(Filename, LastLocFilename) != 0) { |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 163 | fprintf(stderr, "%s:%u:%u", Filename, LineNo, ColNo); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 164 | LastLocFilename = Filename; |
| 165 | LastLocLine = LineNo; |
| 166 | } else if (LineNo != LastLocLine) { |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 167 | fprintf(stderr, "line:%u:%u", LineNo, ColNo); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 168 | LastLocLine = LineNo; |
| 169 | } else { |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 170 | fprintf(stderr, "col:%u", ColNo); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 174 | void StmtDumper::DumpSourceRange(const Stmt *Node) { |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 175 | // Can't translate locations if a SourceManager isn't available. |
| 176 | if (SM == 0) return; |
| 177 | |
| 178 | // TODO: If the parent expression is available, we can print a delta vs its |
| 179 | // location. |
| 180 | SourceRange R = Node->getSourceRange(); |
| 181 | |
| 182 | fprintf(stderr, " <"); |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 183 | DumpLocation(R.getBegin()); |
| 184 | if (R.getBegin() != R.getEnd()) { |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 185 | fprintf(stderr, ", "); |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 186 | DumpLocation(R.getEnd()); |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 187 | } |
| 188 | fprintf(stderr, ">"); |
| 189 | |
| 190 | // <t2.c:123:421[blah], t2.c:412:321> |
| 191 | |
| 192 | } |
| 193 | |
| 194 | |
| 195 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 196 | // Stmt printing methods. |
| 197 | //===----------------------------------------------------------------------===// |
| 198 | |
| 199 | void StmtDumper::VisitStmt(Stmt *Node) { |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 200 | DumpStmt(Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 203 | void StmtDumper::DumpDeclarator(Decl *D) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 204 | // FIXME: Need to complete/beautify this... this code simply shows the |
| 205 | // nodes are where they need to be. |
| 206 | if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) { |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 207 | fprintf(F, "\"typedef %s %s\"", |
| 208 | localType->getUnderlyingType().getAsString().c_str(), |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 209 | localType->getNameAsString().c_str()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 210 | } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 211 | fprintf(F, "\""); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 212 | // Emit storage class for vardecls. |
| 213 | if (VarDecl *V = dyn_cast<VarDecl>(VD)) { |
| 214 | switch (V->getStorageClass()) { |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 215 | default: assert(0 && "Unknown storage class!"); |
| 216 | case VarDecl::None: break; |
| 217 | case VarDecl::Extern: fprintf(F, "extern "); break; |
| 218 | case VarDecl::Static: fprintf(F, "static "); break; |
| 219 | case VarDecl::Auto: fprintf(F, "auto "); break; |
| 220 | case VarDecl::Register: fprintf(F, "register "); break; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 224 | std::string Name = VD->getNameAsString(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 225 | VD->getType().getAsStringInternal(Name); |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 226 | fprintf(F, "%s", Name.c_str()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 227 | |
| 228 | // If this is a vardecl with an initializer, emit it. |
| 229 | if (VarDecl *V = dyn_cast<VarDecl>(VD)) { |
| 230 | if (V->getInit()) { |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 231 | fprintf(F, " =\n"); |
| 232 | DumpSubTree(V->getInit()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 235 | fprintf(F, "\""); |
Steve Naroff | 9219928 | 2007-11-17 21:37:36 +0000 | [diff] [blame] | 236 | } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 237 | // print a free standing tag decl (e.g. "struct x;"). |
| 238 | const char *tagname; |
| 239 | if (const IdentifierInfo *II = TD->getIdentifier()) |
| 240 | tagname = II->getName(); |
| 241 | else |
| 242 | tagname = "<anonymous>"; |
| 243 | fprintf(F, "\"%s %s;\"", TD->getKindName(), tagname); |
| 244 | // FIXME: print tag bodies. |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 245 | } else { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 246 | assert(0 && "Unexpected decl"); |
| 247 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 250 | void StmtDumper::VisitDeclStmt(DeclStmt *Node) { |
| 251 | DumpStmt(Node); |
| 252 | fprintf(F,"\n"); |
Ted Kremenek | 04a72b7 | 2008-10-06 18:38:35 +0000 | [diff] [blame] | 253 | for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end(); |
| 254 | DI != DE; ++DI) { |
| 255 | ScopedDecl* D = *DI; |
Ted Kremenek | 5399ce2 | 2007-12-12 06:59:42 +0000 | [diff] [blame] | 256 | ++IndentLevel; |
| 257 | Indent(); |
| 258 | fprintf(F, "%p ", (void*) D); |
| 259 | DumpDeclarator(D); |
| 260 | if (D->getNextDeclarator()) |
| 261 | fprintf(F,"\n"); |
| 262 | --IndentLevel; |
| 263 | } |
| 264 | } |
| 265 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 266 | void StmtDumper::VisitLabelStmt(LabelStmt *Node) { |
| 267 | DumpStmt(Node); |
Chris Lattner | 3cb640b | 2008-07-26 19:24:43 +0000 | [diff] [blame] | 268 | fprintf(F, " '%s'", Node->getName()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 271 | void StmtDumper::VisitGotoStmt(GotoStmt *Node) { |
| 272 | DumpStmt(Node); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 273 | fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 276 | //===----------------------------------------------------------------------===// |
| 277 | // Expr printing methods. |
| 278 | //===----------------------------------------------------------------------===// |
| 279 | |
| 280 | void StmtDumper::VisitExpr(Expr *Node) { |
| 281 | DumpExpr(Node); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) { |
| 285 | DumpExpr(Node); |
Ted Kremenek | eb641f9 | 2007-09-10 17:32:55 +0000 | [diff] [blame] | 286 | |
| 287 | fprintf(F, " "); |
| 288 | switch (Node->getDecl()->getKind()) { |
| 289 | case Decl::Function: fprintf(F,"FunctionDecl"); break; |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 290 | case Decl::Var: fprintf(F,"Var"); break; |
Chris Lattner | aa9fc46 | 2007-10-08 21:37:32 +0000 | [diff] [blame] | 291 | case Decl::ParmVar: fprintf(F,"ParmVar"); break; |
Ted Kremenek | eb641f9 | 2007-09-10 17:32:55 +0000 | [diff] [blame] | 292 | case Decl::EnumConstant: fprintf(F,"EnumConstant"); break; |
| 293 | case Decl::Typedef: fprintf(F,"Typedef"); break; |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 294 | case Decl::Record: fprintf(F,"Record"); break; |
Ted Kremenek | eb641f9 | 2007-09-10 17:32:55 +0000 | [diff] [blame] | 295 | case Decl::Enum: fprintf(F,"Enum"); break; |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 296 | case Decl::CXXRecord: fprintf(F,"CXXRecord"); break; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 297 | case Decl::ObjCInterface: fprintf(F,"ObjCInterface"); break; |
| 298 | case Decl::ObjCClass: fprintf(F,"ObjCClass"); break; |
Ted Kremenek | eb641f9 | 2007-09-10 17:32:55 +0000 | [diff] [blame] | 299 | default: fprintf(F,"Decl"); break; |
| 300 | } |
| 301 | |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 302 | fprintf(F, "='%s' %p", Node->getDecl()->getNameAsString().c_str(), |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 303 | (void*)Node->getDecl()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 306 | void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { |
Steve Naroff | 466c2e3 | 2008-05-23 00:59:14 +0000 | [diff] [blame] | 307 | DumpExpr(Node); |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 308 | |
Steve Naroff | 466c2e3 | 2008-05-23 00:59:14 +0000 | [diff] [blame] | 309 | fprintf(F, " %sDecl='%s' %p", Node->getDecl()->getDeclKindName(), |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 310 | Node->getDecl()->getNameAsString().c_str(), (void*)Node->getDecl()); |
Steve Naroff | 218543b | 2008-05-23 22:01:24 +0000 | [diff] [blame] | 311 | if (Node->isFreeIvar()) |
| 312 | fprintf(F, " isFreeIvar"); |
Steve Naroff | 3c64d9e | 2008-03-12 13:19:12 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 315 | void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) { |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 316 | DumpExpr(Node); |
| 317 | switch (Node->getIdentType()) { |
Chris Lattner | 0d17f6f | 2008-06-21 18:04:54 +0000 | [diff] [blame] | 318 | default: assert(0 && "unknown case"); |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 319 | case PredefinedExpr::Func: fprintf(F, " __func__"); break; |
| 320 | case PredefinedExpr::Function: fprintf(F, " __FUNCTION__"); break; |
| 321 | case PredefinedExpr::PrettyFunction: fprintf(F, " __PRETTY_FUNCTION__");break; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) { |
Chris Lattner | a0df31a | 2007-08-09 01:04:32 +0000 | [diff] [blame] | 326 | DumpExpr(Node); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 327 | fprintf(F, " %d", Node->getValue()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) { |
| 331 | DumpExpr(Node); |
| 332 | |
| 333 | bool isSigned = Node->getType()->isSignedIntegerType(); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 334 | fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 335 | } |
| 336 | void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) { |
| 337 | DumpExpr(Node); |
Chris Lattner | da8249e | 2008-06-07 22:13:43 +0000 | [diff] [blame] | 338 | fprintf(F, " %f", Node->getValueAsApproximateDouble()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 339 | } |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 340 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 341 | void StmtDumper::VisitStringLiteral(StringLiteral *Str) { |
Chris Lattner | a0df31a | 2007-08-09 01:04:32 +0000 | [diff] [blame] | 342 | DumpExpr(Str); |
| 343 | // FIXME: this doesn't print wstrings right. |
Chris Lattner | 5fc6107 | 2007-08-09 17:14:24 +0000 | [diff] [blame] | 344 | fprintf(F, " %s\"", Str->isWide() ? "L" : ""); |
Chris Lattner | a0df31a | 2007-08-09 01:04:32 +0000 | [diff] [blame] | 345 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 346 | for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) { |
Chris Lattner | 5fc6107 | 2007-08-09 17:14:24 +0000 | [diff] [blame] | 347 | switch (char C = Str->getStrData()[i]) { |
| 348 | default: |
| 349 | if (isprint(C)) |
| 350 | fputc(C, F); |
| 351 | else |
| 352 | fprintf(F, "\\%03o", C); |
| 353 | break; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 354 | // Handle some common ones to make dumps prettier. |
Chris Lattner | 5fc6107 | 2007-08-09 17:14:24 +0000 | [diff] [blame] | 355 | case '\\': fprintf(F, "\\\\"); break; |
| 356 | case '"': fprintf(F, "\\\""); break; |
| 357 | case '\n': fprintf(F, "\\n"); break; |
| 358 | case '\t': fprintf(F, "\\t"); break; |
| 359 | case '\a': fprintf(F, "\\a"); break; |
| 360 | case '\b': fprintf(F, "\\b"); break; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 361 | } |
| 362 | } |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 363 | fprintf(F, "\""); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 364 | } |
Chris Lattner | 17a1a72 | 2007-08-30 01:00:35 +0000 | [diff] [blame] | 365 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 366 | void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 367 | DumpExpr(Node); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 368 | fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix", |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 369 | UnaryOperator::getOpcodeStr(Node->getOpcode())); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 370 | } |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 371 | void StmtDumper::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 372 | DumpExpr(Node); |
| 373 | fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof"); |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 374 | if (Node->isArgumentType()) |
| 375 | DumpType(Node->getArgumentType()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 376 | } |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 377 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 378 | void StmtDumper::VisitMemberExpr(MemberExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 379 | DumpExpr(Node); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 380 | fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".", |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 381 | Node->getMemberDecl()->getNameAsString().c_str(), |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 382 | (void*)Node->getMemberDecl()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 383 | } |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 384 | void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 385 | DumpExpr(Node); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 386 | fprintf(F, " %s", Node->getAccessor().getName()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 387 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 388 | void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) { |
| 389 | DumpExpr(Node); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 390 | fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode())); |
Chris Lattner | eb14fe8 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 391 | } |
| 392 | void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) { |
| 393 | DumpExpr(Node); |
| 394 | fprintf(F, " '%s' ComputeTy=", |
| 395 | BinaryOperator::getOpcodeStr(Node->getOpcode())); |
| 396 | DumpType(Node->getComputationType()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 397 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 398 | |
| 399 | // GNU extensions. |
| 400 | |
| 401 | void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 402 | DumpExpr(Node); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 403 | fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 406 | void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 407 | DumpExpr(Node); |
| 408 | fprintf(F, " "); |
| 409 | DumpType(Node->getArgType1()); |
| 410 | fprintf(F, " "); |
| 411 | DumpType(Node->getArgType2()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Chris Lattner | f9e0581 | 2007-08-09 18:03:18 +0000 | [diff] [blame] | 414 | //===----------------------------------------------------------------------===// |
| 415 | // C++ Expressions |
| 416 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 417 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 418 | void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 419 | DumpExpr(Node); |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 420 | fprintf(F, " %s<%s>", Node->getCastName(), |
| 421 | Node->getTypeAsWritten().getAsString().c_str()); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) { |
Chris Lattner | 13cb21f | 2007-08-09 17:35:30 +0000 | [diff] [blame] | 425 | DumpExpr(Node); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 426 | fprintf(F, " %s", Node->getValue() ? "true" : "false"); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 429 | void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) { |
| 430 | DumpExpr(Node); |
| 431 | fprintf(F, " this"); |
| 432 | } |
| 433 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 434 | void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) { |
| 435 | DumpExpr(Node); |
| 436 | fprintf(F, " functional cast to %s", |
| 437 | Node->getTypeAsWritten().getAsString().c_str()); |
| 438 | } |
| 439 | |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 440 | //===----------------------------------------------------------------------===// |
| 441 | // Obj-C Expressions |
| 442 | //===----------------------------------------------------------------------===// |
| 443 | |
Ted Kremenek | b3d914b | 2008-02-29 22:04:05 +0000 | [diff] [blame] | 444 | void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) { |
| 445 | DumpExpr(Node); |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 446 | fprintf(F, " selector=%s", Node->getSelector().getAsString().c_str()); |
Ted Kremenek | ea958e57 | 2008-05-01 17:26:20 +0000 | [diff] [blame] | 447 | IdentifierInfo* clsName = Node->getClassName(); |
| 448 | if (clsName) fprintf(F, " class=%s", clsName->getName()); |
Ted Kremenek | b3d914b | 2008-02-29 22:04:05 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 451 | void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) { |
| 452 | DumpExpr(Node); |
| 453 | |
| 454 | fprintf(F, " "); |
| 455 | DumpType(Node->getEncodedType()); |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 458 | void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) { |
| 459 | DumpExpr(Node); |
| 460 | |
| 461 | fprintf(F, " "); |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 462 | fprintf(F, "%s", Node->getSelector().getAsString().c_str()); |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 465 | void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) { |
| 466 | DumpExpr(Node); |
| 467 | |
| 468 | fprintf(F, " "); |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 469 | fprintf(F, "%s", Node->getProtocol()->getNameAsString().c_str()); |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 470 | } |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 471 | |
| 472 | void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) { |
| 473 | DumpExpr(Node); |
Daniel Dunbar | e66f4e3 | 2008-09-03 00:27:26 +0000 | [diff] [blame] | 474 | |
Fariborz Jahanian | 5daf570 | 2008-11-22 18:39:36 +0000 | [diff] [blame] | 475 | fprintf(F, " Kind=PropertyRef Property=\"%s\"", |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 476 | Node->getProperty()->getNameAsString().c_str()); |
Fariborz Jahanian | 5daf570 | 2008-11-22 18:39:36 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | void StmtDumper::VisitObjCKVCRefExpr(ObjCKVCRefExpr *Node) { |
| 480 | DumpExpr(Node); |
| 481 | |
| 482 | ObjCMethodDecl *Getter = Node->getGetterMethod(); |
| 483 | ObjCMethodDecl *Setter = Node->getSetterMethod(); |
| 484 | fprintf(F, " Kind=MethodRef Getter=\"%s\" Setter=\"%s\"", |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 485 | Getter->getSelector().getAsString().c_str(), |
| 486 | Setter ? Setter->getSelector().getAsString().c_str() : "(null)"); |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Douglas Gregor | cd9b46e | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 489 | void StmtDumper::VisitObjCSuperExpr(ObjCSuperExpr *Node) { |
| 490 | DumpExpr(Node); |
| 491 | fprintf(F, " super"); |
| 492 | } |
| 493 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 494 | //===----------------------------------------------------------------------===// |
| 495 | // Stmt method implementations |
| 496 | //===----------------------------------------------------------------------===// |
| 497 | |
| 498 | /// dump - This does a local dump of the specified AST fragment. It dumps the |
| 499 | /// specified node and a few nodes underneath it, but not the whole subtree. |
| 500 | /// This is useful in a debugger. |
Chris Lattner | e300c87 | 2007-08-30 06:17:34 +0000 | [diff] [blame] | 501 | void Stmt::dump(SourceManager &SM) const { |
Chris Lattner | 0c727a3 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 502 | StmtDumper P(&SM, stderr, 4); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 503 | P.DumpSubTree(const_cast<Stmt*>(this)); |
Chris Lattner | 0c727a3 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 504 | fprintf(stderr, "\n"); |
| 505 | } |
| 506 | |
| 507 | /// dump - This does a local dump of the specified AST fragment. It dumps the |
| 508 | /// specified node and a few nodes underneath it, but not the whole subtree. |
| 509 | /// This is useful in a debugger. |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 510 | void Stmt::dump() const { |
Chris Lattner | 0c727a3 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 511 | StmtDumper P(0, stderr, 4); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 512 | P.DumpSubTree(const_cast<Stmt*>(this)); |
Chris Lattner | 0c727a3 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 513 | fprintf(stderr, "\n"); |
| 514 | } |
| 515 | |
| 516 | /// 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] | 517 | void Stmt::dumpAll(SourceManager &SM) const { |
Chris Lattner | 0c727a3 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 518 | StmtDumper P(&SM, stderr, ~0U); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 519 | P.DumpSubTree(const_cast<Stmt*>(this)); |
Chris Lattner | ee41ce5 | 2007-08-10 21:51:12 +0000 | [diff] [blame] | 520 | fprintf(stderr, "\n"); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /// dumpAll - This does a dump of the specified AST fragment and all subtrees. |
| 524 | void Stmt::dumpAll() const { |
Chris Lattner | 0c727a3 | 2007-08-30 00:40:08 +0000 | [diff] [blame] | 525 | StmtDumper P(0, stderr, ~0U); |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 526 | P.DumpSubTree(const_cast<Stmt*>(this)); |
Chris Lattner | ee41ce5 | 2007-08-10 21:51:12 +0000 | [diff] [blame] | 527 | fprintf(stderr, "\n"); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 528 | } |