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