]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/AST/StmtPrinter.cpp
Merge ACPICA 20101013.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / AST / StmtPrinter.cpp
1 //===--- StmtPrinter.cpp - Printing 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::dumpPretty/Stmt::printPretty methods, which
11 // pretty print the AST back out to C code.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "clang/AST/StmtVisitor.h"
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/PrettyPrinter.h"
19 #include "llvm/Support/Format.h"
20 #include "clang/AST/Expr.h"
21 using namespace clang;
22
23 //===----------------------------------------------------------------------===//
24 // StmtPrinter Visitor
25 //===----------------------------------------------------------------------===//
26
27 namespace  {
28   class StmtPrinter : public StmtVisitor<StmtPrinter> {
29     llvm::raw_ostream &OS;
30     ASTContext &Context;
31     unsigned IndentLevel;
32     clang::PrinterHelper* Helper;
33     PrintingPolicy Policy;
34
35   public:
36     StmtPrinter(llvm::raw_ostream &os, ASTContext &C, PrinterHelper* helper,
37                 const PrintingPolicy &Policy,
38                 unsigned Indentation = 0)
39       : OS(os), Context(C), IndentLevel(Indentation), Helper(helper),
40         Policy(Policy) {}
41
42     void PrintStmt(Stmt *S) {
43       PrintStmt(S, Policy.Indentation);
44     }
45
46     void PrintStmt(Stmt *S, int SubIndent) {
47       IndentLevel += SubIndent;
48       if (S && isa<Expr>(S)) {
49         // If this is an expr used in a stmt context, indent and newline it.
50         Indent();
51         Visit(S);
52         OS << ";\n";
53       } else if (S) {
54         Visit(S);
55       } else {
56         Indent() << "<<<NULL STATEMENT>>>\n";
57       }
58       IndentLevel -= SubIndent;
59     }
60
61     void PrintRawCompoundStmt(CompoundStmt *S);
62     void PrintRawDecl(Decl *D);
63     void PrintRawDeclStmt(DeclStmt *S);
64     void PrintRawIfStmt(IfStmt *If);
65     void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
66
67     void PrintExpr(Expr *E) {
68       if (E)
69         Visit(E);
70       else
71         OS << "<null expr>";
72     }
73
74     llvm::raw_ostream &Indent(int Delta = 0) {
75       for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
76         OS << "  ";
77       return OS;
78     }
79
80     void Visit(Stmt* S) {
81       if (Helper && Helper->handledStmt(S,OS))
82           return;
83       else StmtVisitor<StmtPrinter>::Visit(S);
84     }
85     
86     void VisitStmt(Stmt *Node) ATTRIBUTE_UNUSED {
87       Indent() << "<<unknown stmt type>>\n";
88     }
89     void VisitExpr(Expr *Node) ATTRIBUTE_UNUSED {
90       OS << "<<unknown expr type>>";
91     }
92     void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
93
94 #define ABSTRACT_STMT(CLASS)
95 #define STMT(CLASS, PARENT) \
96     void Visit##CLASS(CLASS *Node);
97 #include "clang/AST/StmtNodes.inc"
98   };
99 }
100
101 //===----------------------------------------------------------------------===//
102 //  Stmt printing methods.
103 //===----------------------------------------------------------------------===//
104
105 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
106 /// with no newline after the }.
107 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
108   OS << "{\n";
109   for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
110        I != E; ++I)
111     PrintStmt(*I);
112
113   Indent() << "}";
114 }
115
116 void StmtPrinter::PrintRawDecl(Decl *D) {
117   D->print(OS, Policy, IndentLevel);
118 }
119
120 void StmtPrinter::PrintRawDeclStmt(DeclStmt *S) {
121   DeclStmt::decl_iterator Begin = S->decl_begin(), End = S->decl_end();
122   llvm::SmallVector<Decl*, 2> Decls;
123   for ( ; Begin != End; ++Begin)
124     Decls.push_back(*Begin);
125
126   Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
127 }
128
129 void StmtPrinter::VisitNullStmt(NullStmt *Node) {
130   Indent() << ";\n";
131 }
132
133 void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
134   Indent();
135   PrintRawDeclStmt(Node);
136   OS << ";\n";
137 }
138
139 void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
140   Indent();
141   PrintRawCompoundStmt(Node);
142   OS << "\n";
143 }
144
145 void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
146   Indent(-1) << "case ";
147   PrintExpr(Node->getLHS());
148   if (Node->getRHS()) {
149     OS << " ... ";
150     PrintExpr(Node->getRHS());
151   }
152   OS << ":\n";
153
154   PrintStmt(Node->getSubStmt(), 0);
155 }
156
157 void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
158   Indent(-1) << "default:\n";
159   PrintStmt(Node->getSubStmt(), 0);
160 }
161
162 void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
163   Indent(-1) << Node->getName() << ":\n";
164   PrintStmt(Node->getSubStmt(), 0);
165 }
166
167 void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
168   OS << "if (";
169   PrintExpr(If->getCond());
170   OS << ')';
171
172   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
173     OS << ' ';
174     PrintRawCompoundStmt(CS);
175     OS << (If->getElse() ? ' ' : '\n');
176   } else {
177     OS << '\n';
178     PrintStmt(If->getThen());
179     if (If->getElse()) Indent();
180   }
181
182   if (Stmt *Else = If->getElse()) {
183     OS << "else";
184
185     if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
186       OS << ' ';
187       PrintRawCompoundStmt(CS);
188       OS << '\n';
189     } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
190       OS << ' ';
191       PrintRawIfStmt(ElseIf);
192     } else {
193       OS << '\n';
194       PrintStmt(If->getElse());
195     }
196   }
197 }
198
199 void StmtPrinter::VisitIfStmt(IfStmt *If) {
200   Indent();
201   PrintRawIfStmt(If);
202 }
203
204 void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
205   Indent() << "switch (";
206   PrintExpr(Node->getCond());
207   OS << ")";
208
209   // Pretty print compoundstmt bodies (very common).
210   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
211     OS << " ";
212     PrintRawCompoundStmt(CS);
213     OS << "\n";
214   } else {
215     OS << "\n";
216     PrintStmt(Node->getBody());
217   }
218 }
219
220 void StmtPrinter::VisitSwitchCase(SwitchCase*) {
221   assert(0 && "SwitchCase is an abstract class");
222 }
223
224 void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
225   Indent() << "while (";
226   PrintExpr(Node->getCond());
227   OS << ")\n";
228   PrintStmt(Node->getBody());
229 }
230
231 void StmtPrinter::VisitDoStmt(DoStmt *Node) {
232   Indent() << "do ";
233   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
234     PrintRawCompoundStmt(CS);
235     OS << " ";
236   } else {
237     OS << "\n";
238     PrintStmt(Node->getBody());
239     Indent();
240   }
241
242   OS << "while (";
243   PrintExpr(Node->getCond());
244   OS << ");\n";
245 }
246
247 void StmtPrinter::VisitForStmt(ForStmt *Node) {
248   Indent() << "for (";
249   if (Node->getInit()) {
250     if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
251       PrintRawDeclStmt(DS);
252     else
253       PrintExpr(cast<Expr>(Node->getInit()));
254   }
255   OS << ";";
256   if (Node->getCond()) {
257     OS << " ";
258     PrintExpr(Node->getCond());
259   }
260   OS << ";";
261   if (Node->getInc()) {
262     OS << " ";
263     PrintExpr(Node->getInc());
264   }
265   OS << ") ";
266
267   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
268     PrintRawCompoundStmt(CS);
269     OS << "\n";
270   } else {
271     OS << "\n";
272     PrintStmt(Node->getBody());
273   }
274 }
275
276 void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
277   Indent() << "for (";
278   if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
279     PrintRawDeclStmt(DS);
280   else
281     PrintExpr(cast<Expr>(Node->getElement()));
282   OS << " in ";
283   PrintExpr(Node->getCollection());
284   OS << ") ";
285
286   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
287     PrintRawCompoundStmt(CS);
288     OS << "\n";
289   } else {
290     OS << "\n";
291     PrintStmt(Node->getBody());
292   }
293 }
294
295 void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
296   Indent() << "goto " << Node->getLabel()->getName() << ";\n";
297 }
298
299 void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
300   Indent() << "goto *";
301   PrintExpr(Node->getTarget());
302   OS << ";\n";
303 }
304
305 void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
306   Indent() << "continue;\n";
307 }
308
309 void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
310   Indent() << "break;\n";
311 }
312
313
314 void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
315   Indent() << "return";
316   if (Node->getRetValue()) {
317     OS << " ";
318     PrintExpr(Node->getRetValue());
319   }
320   OS << ";\n";
321 }
322
323
324 void StmtPrinter::VisitAsmStmt(AsmStmt *Node) {
325   Indent() << "asm ";
326
327   if (Node->isVolatile())
328     OS << "volatile ";
329
330   OS << "(";
331   VisitStringLiteral(Node->getAsmString());
332
333   // Outputs
334   if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
335       Node->getNumClobbers() != 0)
336     OS << " : ";
337
338   for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
339     if (i != 0)
340       OS << ", ";
341
342     if (!Node->getOutputName(i).empty()) {
343       OS << '[';
344       OS << Node->getOutputName(i);
345       OS << "] ";
346     }
347
348     VisitStringLiteral(Node->getOutputConstraintLiteral(i));
349     OS << " ";
350     Visit(Node->getOutputExpr(i));
351   }
352
353   // Inputs
354   if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
355     OS << " : ";
356
357   for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
358     if (i != 0)
359       OS << ", ";
360
361     if (!Node->getInputName(i).empty()) {
362       OS << '[';
363       OS << Node->getInputName(i);
364       OS << "] ";
365     }
366
367     VisitStringLiteral(Node->getInputConstraintLiteral(i));
368     OS << " ";
369     Visit(Node->getInputExpr(i));
370   }
371
372   // Clobbers
373   if (Node->getNumClobbers() != 0)
374     OS << " : ";
375
376   for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
377     if (i != 0)
378       OS << ", ";
379
380     VisitStringLiteral(Node->getClobber(i));
381   }
382
383   OS << ");\n";
384 }
385
386 void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
387   Indent() << "@try";
388   if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
389     PrintRawCompoundStmt(TS);
390     OS << "\n";
391   }
392
393   for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
394     ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
395     Indent() << "@catch(";
396     if (catchStmt->getCatchParamDecl()) {
397       if (Decl *DS = catchStmt->getCatchParamDecl())
398         PrintRawDecl(DS);
399     }
400     OS << ")";
401     if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
402       PrintRawCompoundStmt(CS);
403       OS << "\n";
404     }
405   }
406
407   if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
408         Node->getFinallyStmt())) {
409     Indent() << "@finally";
410     PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
411     OS << "\n";
412   }
413 }
414
415 void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
416 }
417
418 void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
419   Indent() << "@catch (...) { /* todo */ } \n";
420 }
421
422 void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
423   Indent() << "@throw";
424   if (Node->getThrowExpr()) {
425     OS << " ";
426     PrintExpr(Node->getThrowExpr());
427   }
428   OS << ";\n";
429 }
430
431 void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
432   Indent() << "@synchronized (";
433   PrintExpr(Node->getSynchExpr());
434   OS << ")";
435   PrintRawCompoundStmt(Node->getSynchBody());
436   OS << "\n";
437 }
438
439 void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
440   OS << "catch (";
441   if (Decl *ExDecl = Node->getExceptionDecl())
442     PrintRawDecl(ExDecl);
443   else
444     OS << "...";
445   OS << ") ";
446   PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
447 }
448
449 void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
450   Indent();
451   PrintRawCXXCatchStmt(Node);
452   OS << "\n";
453 }
454
455 void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
456   Indent() << "try ";
457   PrintRawCompoundStmt(Node->getTryBlock());
458   for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
459     OS << " ";
460     PrintRawCXXCatchStmt(Node->getHandler(i));
461   }
462   OS << "\n";
463 }
464
465 //===----------------------------------------------------------------------===//
466 //  Expr printing methods.
467 //===----------------------------------------------------------------------===//
468
469 void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
470   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
471     Qualifier->print(OS, Policy);
472   OS << Node->getNameInfo();
473   if (Node->hasExplicitTemplateArgs())
474     OS << TemplateSpecializationType::PrintTemplateArgumentList(
475                                                     Node->getTemplateArgs(),
476                                                     Node->getNumTemplateArgs(),
477                                                     Policy);  
478 }
479
480 void StmtPrinter::VisitDependentScopeDeclRefExpr(
481                                            DependentScopeDeclRefExpr *Node) {
482   Node->getQualifier()->print(OS, Policy);
483   OS << Node->getNameInfo();
484   if (Node->hasExplicitTemplateArgs())
485     OS << TemplateSpecializationType::PrintTemplateArgumentList(
486                                                    Node->getTemplateArgs(),
487                                                    Node->getNumTemplateArgs(),
488                                                    Policy);
489 }
490
491 void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
492   if (Node->getQualifier())
493     Node->getQualifier()->print(OS, Policy);
494   OS << Node->getNameInfo();
495   if (Node->hasExplicitTemplateArgs())
496     OS << TemplateSpecializationType::PrintTemplateArgumentList(
497                                                    Node->getTemplateArgs(),
498                                                    Node->getNumTemplateArgs(),
499                                                    Policy);
500 }
501
502 void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
503   if (Node->getBase()) {
504     PrintExpr(Node->getBase());
505     OS << (Node->isArrow() ? "->" : ".");
506   }
507   OS << Node->getDecl();
508 }
509
510 void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
511   if (Node->getBase()) {
512     PrintExpr(Node->getBase());
513     OS << ".";
514   }
515   OS << Node->getProperty()->getName();
516 }
517
518 void StmtPrinter::VisitObjCImplicitSetterGetterRefExpr(
519                                         ObjCImplicitSetterGetterRefExpr *Node) {
520   if (Node->getBase()) {
521     PrintExpr(Node->getBase());
522     OS << ".";
523   }
524   if (Node->getGetterMethod())
525     OS << Node->getGetterMethod();
526
527 }
528
529 void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
530   switch (Node->getIdentType()) {
531     default:
532       assert(0 && "unknown case");
533     case PredefinedExpr::Func:
534       OS << "__func__";
535       break;
536     case PredefinedExpr::Function:
537       OS << "__FUNCTION__";
538       break;
539     case PredefinedExpr::PrettyFunction:
540       OS << "__PRETTY_FUNCTION__";
541       break;
542   }
543 }
544
545 void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
546   unsigned value = Node->getValue();
547   if (Node->isWide())
548     OS << "L";
549   switch (value) {
550   case '\\':
551     OS << "'\\\\'";
552     break;
553   case '\'':
554     OS << "'\\''";
555     break;
556   case '\a':
557     // TODO: K&R: the meaning of '\\a' is different in traditional C
558     OS << "'\\a'";
559     break;
560   case '\b':
561     OS << "'\\b'";
562     break;
563   // Nonstandard escape sequence.
564   /*case '\e':
565     OS << "'\\e'";
566     break;*/
567   case '\f':
568     OS << "'\\f'";
569     break;
570   case '\n':
571     OS << "'\\n'";
572     break;
573   case '\r':
574     OS << "'\\r'";
575     break;
576   case '\t':
577     OS << "'\\t'";
578     break;
579   case '\v':
580     OS << "'\\v'";
581     break;
582   default:
583     if (value < 256 && isprint(value)) {
584       OS << "'" << (char)value << "'";
585     } else if (value < 256) {
586       OS << "'\\x" << llvm::format("%x", value) << "'";
587     } else {
588       // FIXME what to really do here?
589       OS << value;
590     }
591   }
592 }
593
594 void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
595   bool isSigned = Node->getType()->isSignedIntegerType();
596   OS << Node->getValue().toString(10, isSigned);
597
598   // Emit suffixes.  Integer literals are always a builtin integer type.
599   switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
600   default: assert(0 && "Unexpected type for integer literal!");
601   case BuiltinType::Int:       break; // no suffix.
602   case BuiltinType::UInt:      OS << 'U'; break;
603   case BuiltinType::Long:      OS << 'L'; break;
604   case BuiltinType::ULong:     OS << "UL"; break;
605   case BuiltinType::LongLong:  OS << "LL"; break;
606   case BuiltinType::ULongLong: OS << "ULL"; break;
607   }
608 }
609 void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
610   // FIXME: print value more precisely.
611   OS << Node->getValueAsApproximateDouble();
612 }
613
614 void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
615   PrintExpr(Node->getSubExpr());
616   OS << "i";
617 }
618
619 void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
620   if (Str->isWide()) OS << 'L';
621   OS << '"';
622
623   // FIXME: this doesn't print wstrings right.
624   llvm::StringRef StrData = Str->getString();
625   for (llvm::StringRef::iterator I = StrData.begin(), E = StrData.end(); 
626                                                              I != E; ++I) {
627     unsigned char Char = *I;
628
629     switch (Char) {
630     default:
631       if (isprint(Char))
632         OS << (char)Char;
633       else  // Output anything hard as an octal escape.
634         OS << '\\'
635         << (char)('0'+ ((Char >> 6) & 7))
636         << (char)('0'+ ((Char >> 3) & 7))
637         << (char)('0'+ ((Char >> 0) & 7));
638       break;
639     // Handle some common non-printable cases to make dumps prettier.
640     case '\\': OS << "\\\\"; break;
641     case '"': OS << "\\\""; break;
642     case '\n': OS << "\\n"; break;
643     case '\t': OS << "\\t"; break;
644     case '\a': OS << "\\a"; break;
645     case '\b': OS << "\\b"; break;
646     }
647   }
648   OS << '"';
649 }
650 void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
651   OS << "(";
652   PrintExpr(Node->getSubExpr());
653   OS << ")";
654 }
655 void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
656   if (!Node->isPostfix()) {
657     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
658
659     // Print a space if this is an "identifier operator" like __real, or if
660     // it might be concatenated incorrectly like '+'.
661     switch (Node->getOpcode()) {
662     default: break;
663     case UO_Real:
664     case UO_Imag:
665     case UO_Extension:
666       OS << ' ';
667       break;
668     case UO_Plus:
669     case UO_Minus:
670       if (isa<UnaryOperator>(Node->getSubExpr()))
671         OS << ' ';
672       break;
673     }
674   }
675   PrintExpr(Node->getSubExpr());
676
677   if (Node->isPostfix())
678     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
679 }
680
681 void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
682   OS << "__builtin_offsetof(";
683   OS << Node->getTypeSourceInfo()->getType().getAsString(Policy) << ", ";
684   bool PrintedSomething = false;
685   for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
686     OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i);
687     if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Array) {
688       // Array node
689       OS << "[";
690       PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
691       OS << "]";
692       PrintedSomething = true;
693       continue;
694     }
695
696     // Skip implicit base indirections.
697     if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Base)
698       continue;
699
700     // Field or identifier node.
701     IdentifierInfo *Id = ON.getFieldName();
702     if (!Id)
703       continue;
704     
705     if (PrintedSomething)
706       OS << ".";
707     else
708       PrintedSomething = true;
709     OS << Id->getName();    
710   }
711   OS << ")";
712 }
713
714 void StmtPrinter::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node) {
715   OS << (Node->isSizeOf() ? "sizeof" : "__alignof");
716   if (Node->isArgumentType())
717     OS << "(" << Node->getArgumentType().getAsString(Policy) << ")";
718   else {
719     OS << " ";
720     PrintExpr(Node->getArgumentExpr());
721   }
722 }
723 void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
724   PrintExpr(Node->getLHS());
725   OS << "[";
726   PrintExpr(Node->getRHS());
727   OS << "]";
728 }
729
730 void StmtPrinter::VisitCallExpr(CallExpr *Call) {
731   PrintExpr(Call->getCallee());
732   OS << "(";
733   for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
734     if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
735       // Don't print any defaulted arguments
736       break;
737     }
738
739     if (i) OS << ", ";
740     PrintExpr(Call->getArg(i));
741   }
742   OS << ")";
743 }
744 void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
745   // FIXME: Suppress printing implicit bases (like "this")
746   PrintExpr(Node->getBase());
747   if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
748     if (FD->isAnonymousStructOrUnion())
749       return;
750   OS << (Node->isArrow() ? "->" : ".");
751   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
752     Qualifier->print(OS, Policy);
753
754   OS << Node->getMemberNameInfo();
755
756   if (Node->hasExplicitTemplateArgs())
757     OS << TemplateSpecializationType::PrintTemplateArgumentList(
758                                                     Node->getTemplateArgs(),
759                                                     Node->getNumTemplateArgs(),
760                                                                 Policy);
761 }
762 void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
763   PrintExpr(Node->getBase());
764   OS << (Node->isArrow() ? "->isa" : ".isa");
765 }
766
767 void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
768   PrintExpr(Node->getBase());
769   OS << ".";
770   OS << Node->getAccessor().getName();
771 }
772 void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
773   OS << "(" << Node->getType().getAsString(Policy) << ")";
774   PrintExpr(Node->getSubExpr());
775 }
776 void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
777   OS << "(" << Node->getType().getAsString(Policy) << ")";
778   PrintExpr(Node->getInitializer());
779 }
780 void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
781   // No need to print anything, simply forward to the sub expression.
782   PrintExpr(Node->getSubExpr());
783 }
784 void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
785   PrintExpr(Node->getLHS());
786   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
787   PrintExpr(Node->getRHS());
788 }
789 void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
790   PrintExpr(Node->getLHS());
791   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
792   PrintExpr(Node->getRHS());
793 }
794 void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
795   PrintExpr(Node->getCond());
796
797   if (Node->getLHS()) {
798     OS << " ? ";
799     PrintExpr(Node->getLHS());
800     OS << " : ";
801   }
802   else { // Handle GCC extension where LHS can be NULL.
803     OS << " ?: ";
804   }
805
806   PrintExpr(Node->getRHS());
807 }
808
809 // GNU extensions.
810
811 void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
812   OS << "&&" << Node->getLabel()->getName();
813 }
814
815 void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
816   OS << "(";
817   PrintRawCompoundStmt(E->getSubStmt());
818   OS << ")";
819 }
820
821 void StmtPrinter::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
822   OS << "__builtin_types_compatible_p(";
823   OS << Node->getArgType1().getAsString(Policy) << ",";
824   OS << Node->getArgType2().getAsString(Policy) << ")";
825 }
826
827 void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
828   OS << "__builtin_choose_expr(";
829   PrintExpr(Node->getCond());
830   OS << ", ";
831   PrintExpr(Node->getLHS());
832   OS << ", ";
833   PrintExpr(Node->getRHS());
834   OS << ")";
835 }
836
837 void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
838   OS << "__null";
839 }
840
841 void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
842   OS << "__builtin_shufflevector(";
843   for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
844     if (i) OS << ", ";
845     PrintExpr(Node->getExpr(i));
846   }
847   OS << ")";
848 }
849
850 void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
851   if (Node->getSyntacticForm()) {
852     Visit(Node->getSyntacticForm());
853     return;
854   }
855
856   OS << "{ ";
857   for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
858     if (i) OS << ", ";
859     if (Node->getInit(i))
860       PrintExpr(Node->getInit(i));
861     else
862       OS << "0";
863   }
864   OS << " }";
865 }
866
867 void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
868   OS << "( ";
869   for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
870     if (i) OS << ", ";
871     PrintExpr(Node->getExpr(i));
872   }
873   OS << " )";
874 }
875
876 void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
877   for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
878                       DEnd = Node->designators_end();
879        D != DEnd; ++D) {
880     if (D->isFieldDesignator()) {
881       if (D->getDotLoc().isInvalid())
882         OS << D->getFieldName()->getName() << ":";
883       else
884         OS << "." << D->getFieldName()->getName();
885     } else {
886       OS << "[";
887       if (D->isArrayDesignator()) {
888         PrintExpr(Node->getArrayIndex(*D));
889       } else {
890         PrintExpr(Node->getArrayRangeStart(*D));
891         OS << " ... ";
892         PrintExpr(Node->getArrayRangeEnd(*D));
893       }
894       OS << "]";
895     }
896   }
897
898   OS << " = ";
899   PrintExpr(Node->getInit());
900 }
901
902 void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
903   if (Policy.LangOpts.CPlusPlus)
904     OS << "/*implicit*/" << Node->getType().getAsString(Policy) << "()";
905   else {
906     OS << "/*implicit*/(" << Node->getType().getAsString(Policy) << ")";
907     if (Node->getType()->isRecordType())
908       OS << "{}";
909     else
910       OS << 0;
911   }
912 }
913
914 void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
915   OS << "__builtin_va_arg(";
916   PrintExpr(Node->getSubExpr());
917   OS << ", ";
918   OS << Node->getType().getAsString(Policy);
919   OS << ")";
920 }
921
922 // C++
923 void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
924   const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
925     "",
926 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
927     Spelling,
928 #include "clang/Basic/OperatorKinds.def"
929   };
930
931   OverloadedOperatorKind Kind = Node->getOperator();
932   if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
933     if (Node->getNumArgs() == 1) {
934       OS << OpStrings[Kind] << ' ';
935       PrintExpr(Node->getArg(0));
936     } else {
937       PrintExpr(Node->getArg(0));
938       OS << ' ' << OpStrings[Kind];
939     }
940   } else if (Kind == OO_Call) {
941     PrintExpr(Node->getArg(0));
942     OS << '(';
943     for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
944       if (ArgIdx > 1)
945         OS << ", ";
946       if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
947         PrintExpr(Node->getArg(ArgIdx));
948     }
949     OS << ')';
950   } else if (Kind == OO_Subscript) {
951     PrintExpr(Node->getArg(0));
952     OS << '[';
953     PrintExpr(Node->getArg(1));
954     OS << ']';
955   } else if (Node->getNumArgs() == 1) {
956     OS << OpStrings[Kind] << ' ';
957     PrintExpr(Node->getArg(0));
958   } else if (Node->getNumArgs() == 2) {
959     PrintExpr(Node->getArg(0));
960     OS << ' ' << OpStrings[Kind] << ' ';
961     PrintExpr(Node->getArg(1));
962   } else {
963     assert(false && "unknown overloaded operator");
964   }
965 }
966
967 void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
968   VisitCallExpr(cast<CallExpr>(Node));
969 }
970
971 void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
972   OS << Node->getCastName() << '<';
973   OS << Node->getTypeAsWritten().getAsString(Policy) << ">(";
974   PrintExpr(Node->getSubExpr());
975   OS << ")";
976 }
977
978 void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
979   VisitCXXNamedCastExpr(Node);
980 }
981
982 void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
983   VisitCXXNamedCastExpr(Node);
984 }
985
986 void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
987   VisitCXXNamedCastExpr(Node);
988 }
989
990 void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
991   VisitCXXNamedCastExpr(Node);
992 }
993
994 void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
995   OS << "typeid(";
996   if (Node->isTypeOperand()) {
997     OS << Node->getTypeOperand().getAsString(Policy);
998   } else {
999     PrintExpr(Node->getExprOperand());
1000   }
1001   OS << ")";
1002 }
1003
1004 void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
1005   OS << (Node->getValue() ? "true" : "false");
1006 }
1007
1008 void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1009   OS << "nullptr";
1010 }
1011
1012 void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1013   OS << "this";
1014 }
1015
1016 void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
1017   if (Node->getSubExpr() == 0)
1018     OS << "throw";
1019   else {
1020     OS << "throw ";
1021     PrintExpr(Node->getSubExpr());
1022   }
1023 }
1024
1025 void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
1026   // Nothing to print: we picked up the default argument
1027 }
1028
1029 void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
1030   OS << Node->getType().getAsString(Policy);
1031   OS << "(";
1032   PrintExpr(Node->getSubExpr());
1033   OS << ")";
1034 }
1035
1036 void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1037   PrintExpr(Node->getSubExpr());
1038 }
1039
1040 void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
1041   OS << Node->getType().getAsString(Policy);
1042   OS << "(";
1043   for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
1044                                          ArgEnd = Node->arg_end();
1045        Arg != ArgEnd; ++Arg) {
1046     if (Arg != Node->arg_begin())
1047       OS << ", ";
1048     PrintExpr(*Arg);
1049   }
1050   OS << ")";
1051 }
1052
1053 void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
1054   OS << Node->getType().getAsString(Policy) << "()";
1055 }
1056
1057 void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
1058   if (E->isGlobalNew())
1059     OS << "::";
1060   OS << "new ";
1061   unsigned NumPlace = E->getNumPlacementArgs();
1062   if (NumPlace > 0) {
1063     OS << "(";
1064     PrintExpr(E->getPlacementArg(0));
1065     for (unsigned i = 1; i < NumPlace; ++i) {
1066       OS << ", ";
1067       PrintExpr(E->getPlacementArg(i));
1068     }
1069     OS << ") ";
1070   }
1071   if (E->isParenTypeId())
1072     OS << "(";
1073   std::string TypeS;
1074   if (Expr *Size = E->getArraySize()) {
1075     llvm::raw_string_ostream s(TypeS);
1076     Size->printPretty(s, Context, Helper, Policy);
1077     s.flush();
1078     TypeS = "[" + TypeS + "]";
1079   }
1080   E->getAllocatedType().getAsStringInternal(TypeS, Policy);
1081   OS << TypeS;
1082   if (E->isParenTypeId())
1083     OS << ")";
1084
1085   if (E->hasInitializer()) {
1086     OS << "(";
1087     unsigned NumCons = E->getNumConstructorArgs();
1088     if (NumCons > 0) {
1089       PrintExpr(E->getConstructorArg(0));
1090       for (unsigned i = 1; i < NumCons; ++i) {
1091         OS << ", ";
1092         PrintExpr(E->getConstructorArg(i));
1093       }
1094     }
1095     OS << ")";
1096   }
1097 }
1098
1099 void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1100   if (E->isGlobalDelete())
1101     OS << "::";
1102   OS << "delete ";
1103   if (E->isArrayForm())
1104     OS << "[] ";
1105   PrintExpr(E->getArgument());
1106 }
1107
1108 void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1109   PrintExpr(E->getBase());
1110   if (E->isArrow())
1111     OS << "->";
1112   else
1113     OS << '.';
1114   if (E->getQualifier())
1115     E->getQualifier()->print(OS, Policy);
1116
1117   std::string TypeS;
1118   if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
1119     OS << II->getName();
1120   else
1121     E->getDestroyedType().getAsStringInternal(TypeS, Policy);
1122   OS << TypeS;
1123 }
1124
1125 void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1126   // FIXME. For now we just print a trivial constructor call expression,
1127   // constructing its first argument object.
1128   if (E->getNumArgs() == 1) {
1129     CXXConstructorDecl *CD = E->getConstructor();
1130     if (CD->isTrivial())
1131       PrintExpr(E->getArg(0));
1132   }
1133   // Nothing to print.
1134 }
1135
1136 void StmtPrinter::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
1137   // Just forward to the sub expression.
1138   PrintExpr(E->getSubExpr());
1139 }
1140
1141 void
1142 StmtPrinter::VisitCXXUnresolvedConstructExpr(
1143                                            CXXUnresolvedConstructExpr *Node) {
1144   OS << Node->getTypeAsWritten().getAsString(Policy);
1145   OS << "(";
1146   for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
1147                                              ArgEnd = Node->arg_end();
1148        Arg != ArgEnd; ++Arg) {
1149     if (Arg != Node->arg_begin())
1150       OS << ", ";
1151     PrintExpr(*Arg);
1152   }
1153   OS << ")";
1154 }
1155
1156 void StmtPrinter::VisitCXXDependentScopeMemberExpr(
1157                                          CXXDependentScopeMemberExpr *Node) {
1158   if (!Node->isImplicitAccess()) {
1159     PrintExpr(Node->getBase());
1160     OS << (Node->isArrow() ? "->" : ".");
1161   }
1162   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1163     Qualifier->print(OS, Policy);
1164   else if (Node->hasExplicitTemplateArgs())
1165     // FIXME: Track use of "template" keyword explicitly?
1166     OS << "template ";
1167
1168   OS << Node->getMemberNameInfo();
1169
1170   if (Node->hasExplicitTemplateArgs()) {
1171     OS << TemplateSpecializationType::PrintTemplateArgumentList(
1172                                                     Node->getTemplateArgs(),
1173                                                     Node->getNumTemplateArgs(),
1174                                                     Policy);
1175   }
1176 }
1177
1178 void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
1179   if (!Node->isImplicitAccess()) {
1180     PrintExpr(Node->getBase());
1181     OS << (Node->isArrow() ? "->" : ".");
1182   }
1183   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1184     Qualifier->print(OS, Policy);
1185
1186   // FIXME: this might originally have been written with 'template'
1187
1188   OS << Node->getMemberNameInfo();
1189
1190   if (Node->hasExplicitTemplateArgs()) {
1191     OS << TemplateSpecializationType::PrintTemplateArgumentList(
1192                                                     Node->getTemplateArgs(),
1193                                                     Node->getNumTemplateArgs(),
1194                                                     Policy);
1195   }
1196 }
1197
1198 static const char *getTypeTraitName(UnaryTypeTrait UTT) {
1199   switch (UTT) {
1200   default: assert(false && "Unknown type trait");
1201   case UTT_HasNothrowAssign:      return "__has_nothrow_assign";
1202   case UTT_HasNothrowCopy:        return "__has_nothrow_copy";
1203   case UTT_HasNothrowConstructor: return "__has_nothrow_constructor";
1204   case UTT_HasTrivialAssign:      return "__has_trivial_assign";
1205   case UTT_HasTrivialCopy:        return "__has_trivial_copy";
1206   case UTT_HasTrivialConstructor: return "__has_trivial_constructor";
1207   case UTT_HasTrivialDestructor:  return "__has_trivial_destructor";
1208   case UTT_HasVirtualDestructor:  return "__has_virtual_destructor";
1209   case UTT_IsAbstract:            return "__is_abstract";
1210   case UTT_IsClass:               return "__is_class";
1211   case UTT_IsEmpty:               return "__is_empty";
1212   case UTT_IsEnum:                return "__is_enum";
1213   case UTT_IsPOD:                 return "__is_pod";
1214   case UTT_IsPolymorphic:         return "__is_polymorphic";
1215   case UTT_IsUnion:               return "__is_union";
1216   }
1217 }
1218
1219 void StmtPrinter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
1220   OS << getTypeTraitName(E->getTrait()) << "("
1221      << E->getQueriedType().getAsString(Policy) << ")";
1222 }
1223
1224 // Obj-C
1225
1226 void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
1227   OS << "@";
1228   VisitStringLiteral(Node->getString());
1229 }
1230
1231 void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
1232   OS << "@encode(" << Node->getEncodedType().getAsString(Policy) << ')';
1233 }
1234
1235 void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
1236   OS << "@selector(" << Node->getSelector().getAsString() << ')';
1237 }
1238
1239 void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
1240   OS << "@protocol(" << Node->getProtocol() << ')';
1241 }
1242
1243 void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
1244   OS << "[";
1245   switch (Mess->getReceiverKind()) {
1246   case ObjCMessageExpr::Instance:
1247     PrintExpr(Mess->getInstanceReceiver());
1248     break;
1249
1250   case ObjCMessageExpr::Class:
1251     OS << Mess->getClassReceiver().getAsString(Policy);
1252     break;
1253
1254   case ObjCMessageExpr::SuperInstance:
1255   case ObjCMessageExpr::SuperClass:
1256     OS << "Super";
1257     break;
1258   }
1259
1260   OS << ' ';
1261   Selector selector = Mess->getSelector();
1262   if (selector.isUnarySelector()) {
1263     OS << selector.getIdentifierInfoForSlot(0)->getName();
1264   } else {
1265     for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
1266       if (i < selector.getNumArgs()) {
1267         if (i > 0) OS << ' ';
1268         if (selector.getIdentifierInfoForSlot(i))
1269           OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
1270         else
1271            OS << ":";
1272       }
1273       else OS << ", "; // Handle variadic methods.
1274
1275       PrintExpr(Mess->getArg(i));
1276     }
1277   }
1278   OS << "]";
1279 }
1280
1281 void StmtPrinter::VisitObjCSuperExpr(ObjCSuperExpr *) {
1282   OS << "super";
1283 }
1284
1285 void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
1286   BlockDecl *BD = Node->getBlockDecl();
1287   OS << "^";
1288
1289   const FunctionType *AFT = Node->getFunctionType();
1290
1291   if (isa<FunctionNoProtoType>(AFT)) {
1292     OS << "()";
1293   } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
1294     OS << '(';
1295     std::string ParamStr;
1296     for (BlockDecl::param_iterator AI = BD->param_begin(),
1297          E = BD->param_end(); AI != E; ++AI) {
1298       if (AI != BD->param_begin()) OS << ", ";
1299       ParamStr = (*AI)->getNameAsString();
1300       (*AI)->getType().getAsStringInternal(ParamStr, Policy);
1301       OS << ParamStr;
1302     }
1303
1304     const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
1305     if (FT->isVariadic()) {
1306       if (!BD->param_empty()) OS << ", ";
1307       OS << "...";
1308     }
1309     OS << ')';
1310   }
1311 }
1312
1313 void StmtPrinter::VisitBlockDeclRefExpr(BlockDeclRefExpr *Node) {
1314   OS << Node->getDecl();
1315 }
1316 //===----------------------------------------------------------------------===//
1317 // Stmt method implementations
1318 //===----------------------------------------------------------------------===//
1319
1320 void Stmt::dumpPretty(ASTContext& Context) const {
1321   printPretty(llvm::errs(), Context, 0,
1322               PrintingPolicy(Context.getLangOptions()));
1323 }
1324
1325 void Stmt::printPretty(llvm::raw_ostream &OS, ASTContext& Context,
1326                        PrinterHelper* Helper,
1327                        const PrintingPolicy &Policy,
1328                        unsigned Indentation) const {
1329   if (this == 0) {
1330     OS << "<NULL>";
1331     return;
1332   }
1333
1334   if (Policy.Dump && &Context) {
1335     dump(OS, Context.getSourceManager());
1336     return;
1337   }
1338
1339   StmtPrinter P(OS, Context, Helper, Policy, Indentation);
1340   P.Visit(const_cast<Stmt*>(this));
1341 }
1342
1343 //===----------------------------------------------------------------------===//
1344 // PrinterHelper
1345 //===----------------------------------------------------------------------===//
1346
1347 // Implement virtual destructor.
1348 PrinterHelper::~PrinterHelper() {}