StmtDumper.cpp revision 28ad063b279378b19cb0704f977429df366a151e
16000dace22f110d8768476989313e9d981d690d0Chris Lattner//===--- StmtDumper.cpp - Dumping implementation for Stmt ASTs ------------===//
26000dace22f110d8768476989313e9d981d690d0Chris Lattner//
36000dace22f110d8768476989313e9d981d690d0Chris Lattner//                     The LLVM Compiler Infrastructure
46000dace22f110d8768476989313e9d981d690d0Chris Lattner//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
76000dace22f110d8768476989313e9d981d690d0Chris Lattner//
86000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
96000dace22f110d8768476989313e9d981d690d0Chris Lattner//
106000dace22f110d8768476989313e9d981d690d0Chris Lattner// This file implements the Stmt::dump/Stmt::print methods, which dump out the
116000dace22f110d8768476989313e9d981d690d0Chris Lattner// AST in a form that exposes type details and other fields.
126000dace22f110d8768476989313e9d981d690d0Chris Lattner//
136000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
146000dace22f110d8768476989313e9d981d690d0Chris Lattner
156000dace22f110d8768476989313e9d981d690d0Chris Lattner#include "clang/AST/StmtVisitor.h"
1691d1d7a448bbde955e15ec39aa368958673450bfTed Kremenek#include "clang/AST/DeclObjC.h"
172a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor#include "clang/AST/DeclCXX.h"
18d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h"
19e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner#include "clang/Basic/SourceManager.h"
20806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar#include "llvm/Support/raw_ostream.h"
216000dace22f110d8768476989313e9d981d690d0Chris Lattnerusing namespace clang;
226000dace22f110d8768476989313e9d981d690d0Chris Lattner
236000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
246000dace22f110d8768476989313e9d981d690d0Chris Lattner// StmtDumper Visitor
256000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
266000dace22f110d8768476989313e9d981d690d0Chris Lattner
276000dace22f110d8768476989313e9d981d690d0Chris Lattnernamespace  {
28770b4a8834670e9427d3ce5a1a8472eb86f45fd2Benjamin Kramer  class StmtDumper : public StmtVisitor<StmtDumper> {
29e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner    SourceManager *SM;
305f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner    raw_ostream &OS;
316000dace22f110d8768476989313e9d981d690d0Chris Lattner    unsigned IndentLevel;
321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
336000dace22f110d8768476989313e9d981d690d0Chris Lattner    /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump
346000dace22f110d8768476989313e9d981d690d0Chris Lattner    /// the first few levels of an AST.  This keeps track of how many ast levels
356000dace22f110d8768476989313e9d981d690d0Chris Lattner    /// are left.
366000dace22f110d8768476989313e9d981d690d0Chris Lattner    unsigned MaxDepth;
371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner    /// LastLocFilename/LastLocLine - Keep track of the last location we print
39e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner    /// out so that we can print out deltas from then on out.
40e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner    const char *LastLocFilename;
41e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner    unsigned LastLocLine;
42d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
436000dace22f110d8768476989313e9d981d690d0Chris Lattner  public:
445f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner    StmtDumper(SourceManager *sm, raw_ostream &os, unsigned maxDepth)
45806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar      : SM(sm), OS(os), IndentLevel(0-1), MaxDepth(maxDepth) {
46e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner      LastLocFilename = "";
47e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner      LastLocLine = ~0U;
48e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner    }
491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50f9e0581818f5daf7d6f467a72aeba266c086d61dChris Lattner    void DumpSubTree(Stmt *S) {
516000dace22f110d8768476989313e9d981d690d0Chris Lattner      // Prune the recursion if not using dump all.
526000dace22f110d8768476989313e9d981d690d0Chris Lattner      if (MaxDepth == 0) return;
531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54f9e0581818f5daf7d6f467a72aeba266c086d61dChris Lattner      ++IndentLevel;
556000dace22f110d8768476989313e9d981d690d0Chris Lattner      if (S) {
565399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek        if (DeclStmt* DS = dyn_cast<DeclStmt>(S))
575399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek          VisitDeclStmt(DS);
581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        else {
595399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek          Visit(S);
601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
615399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek          // Print out children.
627502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall          Stmt::child_range CI = S->children();
637502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall          if (CI) {
647502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall            while (CI) {
65806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar              OS << '\n';
665399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek              DumpSubTree(*CI++);
675399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek            }
68b393879e292faa61bb4a2853bad4412daf0158e6Chris Lattner          }
69b393879e292faa61bb4a2853bad4412daf0158e6Chris Lattner        }
70a46325e7b9c07adcfcf25566ba6ccce033a63e61Chris Lattner        OS << ')';
716000dace22f110d8768476989313e9d981d690d0Chris Lattner      } else {
726000dace22f110d8768476989313e9d981d690d0Chris Lattner        Indent();
73806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar        OS << "<<<NULL>>>";
746000dace22f110d8768476989313e9d981d690d0Chris Lattner      }
75f9e0581818f5daf7d6f467a72aeba266c086d61dChris Lattner      --IndentLevel;
766000dace22f110d8768476989313e9d981d690d0Chris Lattner    }
771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
78f9e0581818f5daf7d6f467a72aeba266c086d61dChris Lattner    void DumpDeclarator(Decl *D);
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
806000dace22f110d8768476989313e9d981d690d0Chris Lattner    void Indent() const {
816000dace22f110d8768476989313e9d981d690d0Chris Lattner      for (int i = 0, e = IndentLevel; i < e; ++i)
82806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar        OS << "  ";
836000dace22f110d8768476989313e9d981d690d0Chris Lattner    }
841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
859dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    void DumpType(QualType T) {
8649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall      SplitQualType T_split = T.split();
8749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall      OS << "'" << QualType::getAsString(T_split) << "'";
88fd8f7da224ef188f799256a6bc37c463ba0071edChris Lattner
8961366e9cd41a6dbde4e66416dac21269c8ac1d94Douglas Gregor      if (!T.isNull()) {
900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        // If the type is sugared, also dump a (shallow) desugared type.
9149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall        SplitQualType D_split = T.getSplitDesugaredType();
9249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall        if (T_split != D_split)
9349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall          OS << ":'" << QualType::getAsString(D_split) << "'";
94bad37858aef8910195a9c75f2892a09a032424b7Chris Lattner      }
95fd8f7da224ef188f799256a6bc37c463ba0071edChris Lattner    }
966b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    void DumpDeclRef(Decl *node);
979dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    void DumpStmt(const Stmt *Node) {
986000dace22f110d8768476989313e9d981d690d0Chris Lattner      Indent();
99806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar      OS << "(" << Node->getStmtClassName()
100806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar         << " " << (void*)Node;
1019dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff      DumpSourceRange(Node);
1026000dace22f110d8768476989313e9d981d690d0Chris Lattner    }
103f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    void DumpValueKind(ExprValueKind K) {
104f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      switch (K) {
105f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      case VK_RValue: break;
106f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      case VK_LValue: OS << " lvalue"; break;
107f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      case VK_XValue: OS << " xvalue"; break;
108f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      }
109f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    }
110f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    void DumpObjectKind(ExprObjectKind K) {
111f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      switch (K) {
112f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      case OK_Ordinary: break;
113f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      case OK_BitField: OS << " bitfield"; break;
114f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      case OK_ObjCProperty: OS << " objcproperty"; break;
115ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      case OK_ObjCSubscript: OS << " objcsubscript"; break;
116f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      case OK_VectorComponent: OS << " vectorcomponent"; break;
117f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      }
118f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    }
1199dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    void DumpExpr(const Expr *Node) {
1206000dace22f110d8768476989313e9d981d690d0Chris Lattner      DumpStmt(Node);
121806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar      OS << ' ';
122fd8f7da224ef188f799256a6bc37c463ba0071edChris Lattner      DumpType(Node->getType());
123f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      DumpValueKind(Node->getValueKind());
124f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      DumpObjectKind(Node->getObjectKind());
1256000dace22f110d8768476989313e9d981d690d0Chris Lattner    }
1269dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    void DumpSourceRange(const Stmt *Node);
127e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner    void DumpLocation(SourceLocation Loc);
1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12917a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    // Stmts.
130c5598cbc4c3f2fb515af7f142f78ff630bdb5c01Chris Lattner    void VisitStmt(Stmt *Node);
1315399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek    void VisitDeclStmt(DeclStmt *Node);
13217a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitLabelStmt(LabelStmt *Node);
13317a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitGotoStmt(GotoStmt *Node);
1341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13517a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    // Exprs
13617a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitExpr(Expr *Node);
13727a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    void VisitCastExpr(CastExpr *Node);
13817a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitDeclRefExpr(DeclRefExpr *Node);
139d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner    void VisitPredefinedExpr(PredefinedExpr *Node);
14017a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitCharacterLiteral(CharacterLiteral *Node);
14117a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitIntegerLiteral(IntegerLiteral *Node);
14217a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitFloatingLiteral(FloatingLiteral *Node);
14317a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitStringLiteral(StringLiteral *Str);
14417a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitUnaryOperator(UnaryOperator *Node);
145f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node);
14617a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitMemberExpr(MemberExpr *Node);
147213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman    void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
14817a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitBinaryOperator(BinaryOperator *Node);
14917a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
15017a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitAddrLabelExpr(AddrLabelExpr *Node);
1516b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    void VisitBlockExpr(BlockExpr *Node);
1524b9c2d235fb9449e249d74f48ecfec601650de93John McCall    void VisitOpaqueValueExpr(OpaqueValueExpr *Node);
15317a1a72e70dcbd6257dde644c790a3013113174fChris Lattner
15417a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    // C++
15549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
15617a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
157cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor    void VisitCXXThisExpr(CXXThisExpr *Node);
15849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
1590eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson    void VisitCXXConstructExpr(CXXConstructExpr *Node);
1600eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson    void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node);
1614765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    void VisitExprWithCleanups(ExprWithCleanups *Node);
1629d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall    void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node);
1630eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson    void DumpCXXTemporary(CXXTemporary *Temporary);
1641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16517a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    // ObjC
1668f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    void VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node);
16717a1a72e70dcbd6257dde644c790a3013113174fChris Lattner    void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
168b3d914b91429477f4bf0436408b1656bd099b32aTed Kremenek    void VisitObjCMessageExpr(ObjCMessageExpr* Node);
16936faaddccf519231a3facd26495e895ba5a28776Argyrios Kyrtzidis    void VisitObjCBoxedExpr(ObjCBoxedExpr* Node);
170b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian    void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
171390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian    void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
1727f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar    void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
173ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    void VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node);
1743c64d9eaa092ac65c39e381f4a49689cf994d666Steve Naroff    void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
175ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    void VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node);
1766000dace22f110d8768476989313e9d981d690d0Chris Lattner  };
1776000dace22f110d8768476989313e9d981d690d0Chris Lattner}
1786000dace22f110d8768476989313e9d981d690d0Chris Lattner
1796000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
180e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner//  Utilities
181e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner//===----------------------------------------------------------------------===//
182e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner
183e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattnervoid StmtDumper::DumpLocation(SourceLocation Loc) {
184df7c17a8d02fe09a3466786bae3e40fc3252687aChris Lattner  SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
1851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
186e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  // The general format we print out is filename:line:col, but we drop pieces
187e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  // that haven't changed since the last loc printed.
188b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
189b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner
190cb7b1e17b63967317ab5cc55682168cf0380519aDouglas Gregor  if (PLoc.isInvalid()) {
191cb7b1e17b63967317ab5cc55682168cf0380519aDouglas Gregor    OS << "<invalid sloc>";
192cb7b1e17b63967317ab5cc55682168cf0380519aDouglas Gregor    return;
193cb7b1e17b63967317ab5cc55682168cf0380519aDouglas Gregor  }
194cb7b1e17b63967317ab5cc55682168cf0380519aDouglas Gregor
195b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
196806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << PLoc.getFilename() << ':' << PLoc.getLine()
197806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar       << ':' << PLoc.getColumn();
198b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner    LastLocFilename = PLoc.getFilename();
199b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner    LastLocLine = PLoc.getLine();
200b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  } else if (PLoc.getLine() != LastLocLine) {
201806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << "line" << ':' << PLoc.getLine()
202806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar       << ':' << PLoc.getColumn();
203b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner    LastLocLine = PLoc.getLine();
204e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  } else {
205806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << "col" << ':' << PLoc.getColumn();
206e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  }
207e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner}
208e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner
2099dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroffvoid StmtDumper::DumpSourceRange(const Stmt *Node) {
210e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  // Can't translate locations if a SourceManager isn't available.
211e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  if (SM == 0) return;
2121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
213e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  // TODO: If the parent expression is available, we can print a delta vs its
214e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  // location.
215e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  SourceRange R = Node->getSourceRange();
2161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
217806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " <";
218311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  DumpLocation(R.getBegin());
219311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  if (R.getBegin() != R.getEnd()) {
220806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << ", ";
221311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner    DumpLocation(R.getEnd());
222e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  }
223806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << ">";
2241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
225e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  // <t2.c:123:421[blah], t2.c:412:321>
226e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner
227e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner}
228e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner
229e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner
230e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner//===----------------------------------------------------------------------===//
2316000dace22f110d8768476989313e9d981d690d0Chris Lattner//  Stmt printing methods.
2326000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
2336000dace22f110d8768476989313e9d981d690d0Chris Lattner
2346000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitStmt(Stmt *Node) {
23517a1a72e70dcbd6257dde644c790a3013113174fChris Lattner  DumpStmt(Node);
2366000dace22f110d8768476989313e9d981d690d0Chris Lattner}
2376000dace22f110d8768476989313e9d981d690d0Chris Lattner
238f9e0581818f5daf7d6f467a72aeba266c086d61dChris Lattnervoid StmtDumper::DumpDeclarator(Decl *D) {
2396000dace22f110d8768476989313e9d981d690d0Chris Lattner  // FIXME: Need to complete/beautify this... this code simply shows the
2406000dace22f110d8768476989313e9d981d690d0Chris Lattner  // nodes are where they need to be.
2416000dace22f110d8768476989313e9d981d690d0Chris Lattner  if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
242806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << "\"typedef " << localType->getUnderlyingType().getAsString()
243b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer       << ' ' << *localType << '"';
244162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  } else if (TypeAliasDecl *localType = dyn_cast<TypeAliasDecl>(D)) {
245b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer    OS << "\"using " << *localType << " = "
246162e1c1b487352434552147967c3dd296ebee2f7Richard Smith       << localType->getUnderlyingType().getAsString() << '"';
2476000dace22f110d8768476989313e9d981d690d0Chris Lattner  } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
248806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << "\"";
2496000dace22f110d8768476989313e9d981d690d0Chris Lattner    // Emit storage class for vardecls.
2506000dace22f110d8768476989313e9d981d690d0Chris Lattner    if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
251d931b086984257de68868a64a235c2b4b34003fbJohn McCall      if (V->getStorageClass() != SC_None)
252806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar        OS << VarDecl::getStorageClassSpecifierString(V->getStorageClass())
253806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar           << " ";
2546000dace22f110d8768476989313e9d981d690d0Chris Lattner    }
2551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25639f34e97d6a468f0a7dfa5664c61217cffc65b74Chris Lattner    std::string Name = VD->getNameAsString();
2571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    VD->getType().getAsStringInternal(Name,
2584e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie                          PrintingPolicy(VD->getASTContext().getLangOpts()));
259806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << Name;
2601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2616000dace22f110d8768476989313e9d981d690d0Chris Lattner    // If this is a vardecl with an initializer, emit it.
2626000dace22f110d8768476989313e9d981d690d0Chris Lattner    if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
2636000dace22f110d8768476989313e9d981d690d0Chris Lattner      if (V->getInit()) {
264806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar        OS << " =\n";
265f9e0581818f5daf7d6f467a72aeba266c086d61dChris Lattner        DumpSubTree(V->getInit());
2666000dace22f110d8768476989313e9d981d690d0Chris Lattner      }
2676000dace22f110d8768476989313e9d981d690d0Chris Lattner    }
268806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << '"';
2699219928c7a036b65d7801a02c4de3a8283ed3124Steve Naroff  } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
2709219928c7a036b65d7801a02c4de3a8283ed3124Steve Naroff    // print a free standing tag decl (e.g. "struct x;").
2719219928c7a036b65d7801a02c4de3a8283ed3124Steve Naroff    const char *tagname;
2729219928c7a036b65d7801a02c4de3a8283ed3124Steve Naroff    if (const IdentifierInfo *II = TD->getIdentifier())
273e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar      tagname = II->getNameStart();
2749219928c7a036b65d7801a02c4de3a8283ed3124Steve Naroff    else
2759219928c7a036b65d7801a02c4de3a8283ed3124Steve Naroff      tagname = "<anonymous>";
276806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << '"' << TD->getKindName() << ' ' << tagname << ";\"";
2779219928c7a036b65d7801a02c4de3a8283ed3124Steve Naroff    // FIXME: print tag bodies.
2782a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor  } else if (UsingDirectiveDecl *UD = dyn_cast<UsingDirectiveDecl>(D)) {
2792a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor    // print using-directive decl (e.g. "using namespace x;")
2802a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor    const char *ns;
2812a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor    if (const IdentifierInfo *II = UD->getNominatedNamespace()->getIdentifier())
282e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar      ns = II->getNameStart();
2832a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor    else
2842a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor      ns = "<anonymous>";
285806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << '"' << UD->getDeclKindName() << ns << ";\"";
2860ca43595e9e8dcf62a2ab6f5c7f4666bfb230b6aSebastian Redl  } else if (UsingDecl *UD = dyn_cast<UsingDecl>(D)) {
2870ca43595e9e8dcf62a2ab6f5c7f4666bfb230b6aSebastian Redl    // print using decl (e.g. "using std::string;")
2880ca43595e9e8dcf62a2ab6f5c7f4666bfb230b6aSebastian Redl    const char *tn = UD->isTypeName() ? "typename " : "";
2890ca43595e9e8dcf62a2ab6f5c7f4666bfb230b6aSebastian Redl    OS << '"' << UD->getDeclKindName() << tn;
290dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor    UD->getQualifier()->print(OS,
2914e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie                        PrintingPolicy(UD->getASTContext().getLangOpts()));
2920ca43595e9e8dcf62a2ab6f5c7f4666bfb230b6aSebastian Redl    OS << ";\"";
2934ae493cccbfbf122ec6ebac0e330232c22fa8489Chris Lattner  } else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) {
294a59d20b135bfde058a5a69045bab5ec4e2553f74Benjamin Kramer    OS << "label " << *LD;
29528ac87e1a22ee15f284643d9007640d25b1aab5bPeter Collingbourne  } else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) {
29628ac87e1a22ee15f284643d9007640d25b1aab5bPeter Collingbourne    OS << "\"static_assert(\n";
29728ac87e1a22ee15f284643d9007640d25b1aab5bPeter Collingbourne    DumpSubTree(SAD->getAssertExpr());
29828ac87e1a22ee15f284643d9007640d25b1aab5bPeter Collingbourne    OS << ",\n";
29928ac87e1a22ee15f284643d9007640d25b1aab5bPeter Collingbourne    DumpSubTree(SAD->getMessage());
30028ac87e1a22ee15f284643d9007640d25b1aab5bPeter Collingbourne    OS << ");\"";
3016000dace22f110d8768476989313e9d981d690d0Chris Lattner  } else {
302b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Unexpected decl");
3036000dace22f110d8768476989313e9d981d690d0Chris Lattner  }
3046000dace22f110d8768476989313e9d981d690d0Chris Lattner}
3056000dace22f110d8768476989313e9d981d690d0Chris Lattner
3065399ce26f27e6d093417a3882e38da8738a78fefTed Kremenekvoid StmtDumper::VisitDeclStmt(DeclStmt *Node) {
3075399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek  DumpStmt(Node);
308806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << "\n";
30904a72b77da736734c925d673834888a081f5ebc5Ted Kremenek  for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
31004a72b77da736734c925d673834888a081f5ebc5Ted Kremenek       DI != DE; ++DI) {
3114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    Decl* D = *DI;
3125399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek    ++IndentLevel;
3135399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek    Indent();
314806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << (void*) D << " ";
3155399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek    DumpDeclarator(D);
316f279725f9772a8644957049971001f655b9041c9Chris Lattner    if (DI+1 != DE)
317806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar      OS << "\n";
3185399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek    --IndentLevel;
3195399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek  }
3205399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek}
3215399ce26f27e6d093417a3882e38da8738a78fefTed Kremenek
3226000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitLabelStmt(LabelStmt *Node) {
3236000dace22f110d8768476989313e9d981d690d0Chris Lattner  DumpStmt(Node);
324806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " '" << Node->getName() << "'";
3256000dace22f110d8768476989313e9d981d690d0Chris Lattner}
3266000dace22f110d8768476989313e9d981d690d0Chris Lattner
3276000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitGotoStmt(GotoStmt *Node) {
3286000dace22f110d8768476989313e9d981d690d0Chris Lattner  DumpStmt(Node);
329806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " '" << Node->getLabel()->getName()
330806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar     << "':" << (void*)Node->getLabel();
3316000dace22f110d8768476989313e9d981d690d0Chris Lattner}
3326000dace22f110d8768476989313e9d981d690d0Chris Lattner
3336000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
3346000dace22f110d8768476989313e9d981d690d0Chris Lattner//  Expr printing methods.
3356000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
3366000dace22f110d8768476989313e9d981d690d0Chris Lattner
3376000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitExpr(Expr *Node) {
3386000dace22f110d8768476989313e9d981d690d0Chris Lattner  DumpExpr(Node);
3396000dace22f110d8768476989313e9d981d690d0Chris Lattner}
3406000dace22f110d8768476989313e9d981d690d0Chris Lattner
3415f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnerstatic void DumpBasePath(raw_ostream &OS, CastExpr *Node) {
342f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  if (Node->path_empty())
3435cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    return;
3445cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson
3455cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  OS << " (";
3465cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  bool First = true;
347f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  for (CastExpr::path_iterator
348f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall         I = Node->path_begin(), E = Node->path_end(); I != E; ++I) {
3495cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    const CXXBaseSpecifier *Base = *I;
3505cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    if (!First)
3515cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson      OS << " -> ";
3525cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson
3535cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    const CXXRecordDecl *RD =
3545cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
3555cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson
3565cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    if (Base->isVirtual())
3575cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson      OS << "virtual ";
3585cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    OS << RD->getName();
3595cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    First = false;
3605cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  }
3615cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson
3625cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  OS << ')';
3635cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson}
3645cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson
36527a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlssonvoid StmtDumper::VisitCastExpr(CastExpr *Node) {
36627a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson  DumpExpr(Node);
3675cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  OS << " <" << Node->getCastKindName();
3685cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  DumpBasePath(OS, Node);
3695cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  OS << ">";
37027a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson}
37127a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson
3726000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
3736000dace22f110d8768476989313e9d981d690d0Chris Lattner  DumpExpr(Node);
374eb641f9995e761004a0b1ac0c9e917a424a66032Ted Kremenek
375806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " ";
3766b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  DumpDeclRef(Node->getDecl());
3773aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  if (Node->getDecl() != Node->getFoundDecl()) {
3783aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    OS << " (";
3793aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    DumpDeclRef(Node->getFoundDecl());
3803aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    OS << ")";
3813aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  }
3826b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall}
3836b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall
3846b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCallvoid StmtDumper::DumpDeclRef(Decl *d) {
3856b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  OS << d->getDeclKindName() << ' ' << (void*) d;
3866b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall
3876b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  if (NamedDecl *nd = dyn_cast<NamedDecl>(d)) {
3886b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    OS << " '";
3896b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    nd->getDeclName().printName(OS);
3906b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    OS << "'";
391eb641f9995e761004a0b1ac0c9e917a424a66032Ted Kremenek  }
3921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3936b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  if (ValueDecl *vd = dyn_cast<ValueDecl>(d)) {
3946b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    OS << ' '; DumpType(vd->getType());
3956b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  }
3966000dace22f110d8768476989313e9d981d690d0Chris Lattner}
3976000dace22f110d8768476989313e9d981d690d0Chris Lattner
3989d5f35e1124bbaa4a8944f7409478d45cb839de5John McCallvoid StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
3999d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall  DumpExpr(Node);
4009d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall  OS << " (";
4019d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall  if (!Node->requiresADL()) OS << "no ";
402900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer  OS << "ADL) = '" << Node->getName() << '\'';
4039d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall
4049d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall  UnresolvedLookupExpr::decls_iterator
4059d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall    I = Node->decls_begin(), E = Node->decls_end();
4069d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall  if (I == E) OS << " empty";
4079d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall  for (; I != E; ++I)
4089d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall    OS << " " << (void*) *I;
4099d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall}
4109d5f35e1124bbaa4a8944f7409478d45cb839de5John McCall
4113c64d9eaa092ac65c39e381f4a49689cf994d666Steve Naroffvoid StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
412466c2e3af049964f3a573917bd04d6b6ce1d121dSteve Naroff  DumpExpr(Node);
4133c64d9eaa092ac65c39e381f4a49689cf994d666Steve Naroff
414806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << Node->getDecl()->getDeclKindName()
415b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer     << "Decl='" << *Node->getDecl()
416806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar     << "' " << (void*)Node->getDecl();
417218543b10e81ea2269ef6ae34d2d8ddbdec54dbeSteve Naroff  if (Node->isFreeIvar())
418806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << " isFreeIvar";
4193c64d9eaa092ac65c39e381f4a49689cf994d666Steve Naroff}
4203c64d9eaa092ac65c39e381f4a49689cf994d666Steve Naroff
421d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnervoid StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
4226000dace22f110d8768476989313e9d981d690d0Chris Lattner  DumpExpr(Node);
4236000dace22f110d8768476989313e9d981d690d0Chris Lattner  switch (Node->getIdentType()) {
424b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  default: llvm_unreachable("unknown case");
425806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  case PredefinedExpr::Func:           OS <<  " __func__"; break;
426806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  case PredefinedExpr::Function:       OS <<  " __FUNCTION__"; break;
42728ad063b279378b19cb0704f977429df366a151eNico Weber  case PredefinedExpr::LFunction:       OS <<  " L__FUNCTION__"; break;
428806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  case PredefinedExpr::PrettyFunction: OS <<  " __PRETTY_FUNCTION__";break;
4296000dace22f110d8768476989313e9d981d690d0Chris Lattner  }
4306000dace22f110d8768476989313e9d981d690d0Chris Lattner}
4316000dace22f110d8768476989313e9d981d690d0Chris Lattner
4326000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
433a0df31ac1f09a3cf2f08c5c3a134376640dc7893Chris Lattner  DumpExpr(Node);
43449cf8847ef4d9caebdd162d2a5d7d055333d8b5cRichard Trieu  OS << " " << Node->getValue();
4356000dace22f110d8768476989313e9d981d690d0Chris Lattner}
4366000dace22f110d8768476989313e9d981d690d0Chris Lattner
4376000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
4386000dace22f110d8768476989313e9d981d690d0Chris Lattner  DumpExpr(Node);
4396000dace22f110d8768476989313e9d981d690d0Chris Lattner
4406000dace22f110d8768476989313e9d981d690d0Chris Lattner  bool isSigned = Node->getType()->isSignedIntegerType();
441806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << Node->getValue().toString(10, isSigned);
4426000dace22f110d8768476989313e9d981d690d0Chris Lattner}
4436000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
4446000dace22f110d8768476989313e9d981d690d0Chris Lattner  DumpExpr(Node);
445806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << Node->getValueAsApproximateDouble();
4466000dace22f110d8768476989313e9d981d690d0Chris Lattner}
4475d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
4486000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitStringLiteral(StringLiteral *Str) {
449a0df31ac1f09a3cf2f08c5c3a134376640dc7893Chris Lattner  DumpExpr(Str);
450806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " ";
4518ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu  Str->outputString(OS);
4526000dace22f110d8768476989313e9d981d690d0Chris Lattner}
45317a1a72e70dcbd6257dde644c790a3013113174fChris Lattner
4546000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
45513cb21f55d80052d99ef8d54d44939b8e98f8de5Chris Lattner  DumpExpr(Node);
456806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
457806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar     << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
4586000dace22f110d8768476989313e9d981d690d0Chris Lattner}
459f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbournevoid StmtDumper::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
46013cb21f55d80052d99ef8d54d44939b8e98f8de5Chris Lattner  DumpExpr(Node);
461f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  switch(Node->getKind()) {
462f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  case UETT_SizeOf:
463f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    OS << " sizeof ";
464f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    break;
465f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  case UETT_AlignOf:
466f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    OS << " __alignof ";
467f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    break;
468f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  case UETT_VecStep:
469f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    OS << " vec_step ";
470f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    break;
471f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  }
4720518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  if (Node->isArgumentType())
4730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    DumpType(Node->getArgumentType());
4746000dace22f110d8768476989313e9d981d690d0Chris Lattner}
47513cb21f55d80052d99ef8d54d44939b8e98f8de5Chris Lattner
4766000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitMemberExpr(MemberExpr *Node) {
47713cb21f55d80052d99ef8d54d44939b8e98f8de5Chris Lattner  DumpExpr(Node);
478806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << (Node->isArrow() ? "->" : ".")
479b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer     << *Node->getMemberDecl() << ' '
480806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar     << (void*)Node->getMemberDecl();
4816000dace22f110d8768476989313e9d981d690d0Chris Lattner}
482213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanvoid StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
48313cb21f55d80052d99ef8d54d44939b8e98f8de5Chris Lattner  DumpExpr(Node);
484806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << Node->getAccessor().getNameStart();
4856000dace22f110d8768476989313e9d981d690d0Chris Lattner}
4866000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
4876000dace22f110d8768476989313e9d981d690d0Chris Lattner  DumpExpr(Node);
488806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
489eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner}
490eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattnervoid StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
491eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner  DumpExpr(Node);
492806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
493806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar     << "' ComputeLHSTy=";
494ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  DumpType(Node->getComputationLHSType());
495806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " ComputeResultTy=";
496ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  DumpType(Node->getComputationResultType());
4976000dace22f110d8768476989313e9d981d690d0Chris Lattner}
4986000dace22f110d8768476989313e9d981d690d0Chris Lattner
4996b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCallvoid StmtDumper::VisitBlockExpr(BlockExpr *Node) {
5006b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  DumpExpr(Node);
5016b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall
5026b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  BlockDecl *block = Node->getBlockDecl();
50389da8cf16b671845660711d3dd4174a809ca6ccaJohn McCall  OS << " decl=" << block;
50489da8cf16b671845660711d3dd4174a809ca6ccaJohn McCall
50589da8cf16b671845660711d3dd4174a809ca6ccaJohn McCall  IndentLevel++;
5066b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  if (block->capturesCXXThis()) {
5076b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    OS << '\n'; Indent(); OS << "(capture this)";
5086b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  }
5096b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  for (BlockDecl::capture_iterator
5106b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall         i = block->capture_begin(), e = block->capture_end(); i != e; ++i) {
5116b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    OS << '\n';
5126b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    Indent();
5136b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    OS << "(capture ";
5146b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    if (i->isByRef()) OS << "byref ";
5156b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    if (i->isNested()) OS << "nested ";
516ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor    if (i->getVariable())
517ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor      DumpDeclRef(i->getVariable());
5186b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    if (i->hasCopyExpr()) DumpSubTree(i->getCopyExpr());
5196b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    OS << ")";
5206b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  }
5216b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  IndentLevel--;
5226b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall
52389da8cf16b671845660711d3dd4174a809ca6ccaJohn McCall  OS << '\n';
5246b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  DumpSubTree(block->getBody());
5256b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall}
5266b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall
5274b9c2d235fb9449e249d74f48ecfec601650de93John McCallvoid StmtDumper::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
5284b9c2d235fb9449e249d74f48ecfec601650de93John McCall  DumpExpr(Node);
5294b9c2d235fb9449e249d74f48ecfec601650de93John McCall
5304b9c2d235fb9449e249d74f48ecfec601650de93John McCall  if (Expr *Source = Node->getSourceExpr()) {
5314b9c2d235fb9449e249d74f48ecfec601650de93John McCall    OS << '\n';
5324b9c2d235fb9449e249d74f48ecfec601650de93John McCall    DumpSubTree(Source);
5334b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
5344b9c2d235fb9449e249d74f48ecfec601650de93John McCall}
5354b9c2d235fb9449e249d74f48ecfec601650de93John McCall
5366000dace22f110d8768476989313e9d981d690d0Chris Lattner// GNU extensions.
5376000dace22f110d8768476989313e9d981d690d0Chris Lattner
5386000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
53913cb21f55d80052d99ef8d54d44939b8e98f8de5Chris Lattner  DumpExpr(Node);
540806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << Node->getLabel()->getName()
541806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar     << " " << (void*)Node->getLabel();
5426000dace22f110d8768476989313e9d981d690d0Chris Lattner}
5436000dace22f110d8768476989313e9d981d690d0Chris Lattner
544f9e0581818f5daf7d6f467a72aeba266c086d61dChris Lattner//===----------------------------------------------------------------------===//
545f9e0581818f5daf7d6f467a72aeba266c086d61dChris Lattner// C++ Expressions
546f9e0581818f5daf7d6f467a72aeba266c086d61dChris Lattner//===----------------------------------------------------------------------===//
5476000dace22f110d8768476989313e9d981d690d0Chris Lattner
54849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorvoid StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
54913cb21f55d80052d99ef8d54d44939b8e98f8de5Chris Lattner  DumpExpr(Node);
550806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << Node->getCastName()
551806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar     << "<" << Node->getTypeAsWritten().getAsString() << ">"
5525cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson     << " <" << Node->getCastKindName();
5535cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  DumpBasePath(OS, Node);
5545cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  OS << ">";
5556000dace22f110d8768476989313e9d981d690d0Chris Lattner}
5566000dace22f110d8768476989313e9d981d690d0Chris Lattner
5576000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
55813cb21f55d80052d99ef8d54d44939b8e98f8de5Chris Lattner  DumpExpr(Node);
559806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << (Node->getValue() ? "true" : "false");
5606000dace22f110d8768476989313e9d981d690d0Chris Lattner}
5616000dace22f110d8768476989313e9d981d690d0Chris Lattner
562cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregorvoid StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
563cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor  DumpExpr(Node);
564806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " this";
565cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor}
566cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor
56749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorvoid StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
56849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  DumpExpr(Node);
569cc2fca2ba2716293204901b8d2393428b965f12aEli Friedman  OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
570cc2fca2ba2716293204901b8d2393428b965f12aEli Friedman     << " <" << Node->getCastKindName() << ">";
57149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}
57249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
5730eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlssonvoid StmtDumper::VisitCXXConstructExpr(CXXConstructExpr *Node) {
5740eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson  DumpExpr(Node);
575d4bbdfebe9bd13defa977a934bf73fc2ce3b2817John McCall  CXXConstructorDecl *Ctor = Node->getConstructor();
576d4bbdfebe9bd13defa977a934bf73fc2ce3b2817John McCall  DumpType(Ctor->getType());
5770eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson  if (Node->isElidable())
578806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << " elidable";
579f8cf0b028c7a5b632c3a711813cd44a9d9642537John McCall  if (Node->requiresZeroInitialization())
580f8cf0b028c7a5b632c3a711813cd44a9d9642537John McCall    OS << " zeroing";
5810eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson}
5820eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson
5830eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlssonvoid StmtDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
5840eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson  DumpExpr(Node);
585806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " ";
5860eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson  DumpCXXTemporary(Node->getTemporary());
5870eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson}
5880eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson
5894765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallvoid StmtDumper::VisitExprWithCleanups(ExprWithCleanups *Node) {
5900eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson  DumpExpr(Node);
5910eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson  ++IndentLevel;
59280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) {
593806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar    OS << "\n";
5940eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson    Indent();
59580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    OS << "(cleanup ";
59680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    DumpDeclRef(Node->getObject(i));
59780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    OS << ")";
5980eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson  }
5990eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson  --IndentLevel;
6000eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson}
6010eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson
6020eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlssonvoid StmtDumper::DumpCXXTemporary(CXXTemporary *Temporary) {
603806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << "(CXXTemporary " << (void *)Temporary << ")";
6040eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson}
6050eca1b609a2a272b6af1a3ead48186c8a15ae9b4Anders Carlsson
6065508518a2702b00be3b15a26d772bde968972f54Anders Carlsson//===----------------------------------------------------------------------===//
6075508518a2702b00be3b15a26d772bde968972f54Anders Carlsson// Obj-C Expressions
6085508518a2702b00be3b15a26d772bde968972f54Anders Carlsson//===----------------------------------------------------------------------===//
6095508518a2702b00be3b15a26d772bde968972f54Anders Carlsson
610b3d914b91429477f4bf0436408b1656bd099b32aTed Kremenekvoid StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
611b3d914b91429477f4bf0436408b1656bd099b32aTed Kremenek  DumpExpr(Node);
612806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " selector=" << Node->getSelector().getAsString();
61304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  switch (Node->getReceiverKind()) {
61404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case ObjCMessageExpr::Instance:
61504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
61604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
61704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case ObjCMessageExpr::Class:
61804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    OS << " class=";
61904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    DumpType(Node->getClassReceiver());
62004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
62104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
62204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case ObjCMessageExpr::SuperInstance:
62304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    OS << " super (instance)";
62404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
62504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
62604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case ObjCMessageExpr::SuperClass:
62704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    OS << " super (class)";
62804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
62904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  }
630b3d914b91429477f4bf0436408b1656bd099b32aTed Kremenek}
631b3d914b91429477f4bf0436408b1656bd099b32aTed Kremenek
63236faaddccf519231a3facd26495e895ba5a28776Argyrios Kyrtzidisvoid StmtDumper::VisitObjCBoxedExpr(ObjCBoxedExpr* Node) {
63336faaddccf519231a3facd26495e895ba5a28776Argyrios Kyrtzidis  DumpExpr(Node);
63436faaddccf519231a3facd26495e895ba5a28776Argyrios Kyrtzidis  OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
63536faaddccf519231a3facd26495e895ba5a28776Argyrios Kyrtzidis}
63636faaddccf519231a3facd26495e895ba5a28776Argyrios Kyrtzidis
6378f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregorvoid StmtDumper::VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node) {
6388f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  DumpStmt(Node);
639c00d8e18ad3d903acfeb5d05163ce90713066a3fDouglas Gregor  if (VarDecl *CatchParam = Node->getCatchParamDecl()) {
6408f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    OS << " catch parm = ";
6418f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    DumpDeclarator(CatchParam);
6428f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  } else {
6438f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    OS << " catch all";
6448f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  }
6458f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor}
6468f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor
647f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlssonvoid StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
648f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson  DumpExpr(Node);
649806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " ";
650f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson  DumpType(Node->getEncodedType());
651f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson}
652f9bcf01f82dfd2688f81e57bcc6300c9b13c51a6Anders Carlsson
653b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanianvoid StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
654b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  DumpExpr(Node);
6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
656806c12e64ccbf7a259aa49dfe929724b4853baaeDaniel Dunbar  OS << " " << Node->getSelector().getAsString();
657b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian}
658b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
659390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanianvoid StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
660390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  DumpExpr(Node);
6611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
662b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer  OS << ' ' <<* Node->getProtocol();
663390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian}
6647f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar
6657f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbarvoid StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
6667f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  DumpExpr(Node);
66712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (Node->isImplicitProperty()) {
66899130e5a02e93282cb393d2cba0d3dffc10abc01Fariborz Jahanian    OS << " Kind=MethodRef Getter=\"";
66999130e5a02e93282cb393d2cba0d3dffc10abc01Fariborz Jahanian    if (Node->getImplicitPropertyGetter())
67099130e5a02e93282cb393d2cba0d3dffc10abc01Fariborz Jahanian      OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
67199130e5a02e93282cb393d2cba0d3dffc10abc01Fariborz Jahanian    else
67299130e5a02e93282cb393d2cba0d3dffc10abc01Fariborz Jahanian      OS << "(null)";
67399130e5a02e93282cb393d2cba0d3dffc10abc01Fariborz Jahanian
67499130e5a02e93282cb393d2cba0d3dffc10abc01Fariborz Jahanian    OS << "\" Setter=\"";
67512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
67612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall      OS << Setter->getSelector().getAsString();
67712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    else
67812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall      OS << "(null)";
67912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    OS << "\"";
68012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  } else {
681b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer    OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
68212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  }
6831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6848ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian  if (Node->isSuperReceiver())
6858ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian    OS << " super";
686b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis
687b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis  OS << " Messaging=";
688b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis  if (Node->isMessagingGetter() && Node->isMessagingSetter())
689b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis    OS << "Getter&Setter";
690b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis  else if (Node->isMessagingGetter())
691b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis    OS << "Getter";
692b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis  else if (Node->isMessagingSetter())
693b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis    OS << "Setter";
694cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor}
695cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor
696ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekvoid StmtDumper::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
697ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  DumpExpr(Node);
698ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (Node->isArraySubscriptRefExpr())
699ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    OS << " Kind=ArraySubscript GetterForArray=\"";
700ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  else
701ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    OS << " Kind=DictionarySubscript GetterForDictionary=\"";
702ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (Node->getAtIndexMethodDecl())
703ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
704ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  else
705ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    OS << "(null)";
706ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
707ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (Node->isArraySubscriptRefExpr())
708ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    OS << "\" SetterForArray=\"";
709ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  else
710ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    OS << "\" SetterForDictionary=\"";
711ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (Node->setAtIndexMethodDecl())
712ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
713ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  else
714ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    OS << "(null)";
715ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
716ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
717ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekvoid StmtDumper::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
718ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  DumpExpr(Node);
719ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
720ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
721ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
7226000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
7236000dace22f110d8768476989313e9d981d690d0Chris Lattner// Stmt method implementations
7246000dace22f110d8768476989313e9d981d690d0Chris Lattner//===----------------------------------------------------------------------===//
7256000dace22f110d8768476989313e9d981d690d0Chris Lattner
7266000dace22f110d8768476989313e9d981d690d0Chris Lattner/// dump - This does a local dump of the specified AST fragment.  It dumps the
7276000dace22f110d8768476989313e9d981d690d0Chris Lattner/// specified node and a few nodes underneath it, but not the whole subtree.
7286000dace22f110d8768476989313e9d981d690d0Chris Lattner/// This is useful in a debugger.
729e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattnervoid Stmt::dump(SourceManager &SM) const {
7309668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis  dump(llvm::errs(), SM);
7319668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis}
7329668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis
7335f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
7349668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis  StmtDumper P(&SM, OS, 4);
735b393879e292faa61bb4a2853bad4412daf0158e6Chris Lattner  P.DumpSubTree(const_cast<Stmt*>(this));
7369668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis  OS << "\n";
7370c727a35718556866a978f64ac549d9798735f08Chris Lattner}
7380c727a35718556866a978f64ac549d9798735f08Chris Lattner
7390c727a35718556866a978f64ac549d9798735f08Chris Lattner/// dump - This does a local dump of the specified AST fragment.  It dumps the
7400c727a35718556866a978f64ac549d9798735f08Chris Lattner/// specified node and a few nodes underneath it, but not the whole subtree.
7410c727a35718556866a978f64ac549d9798735f08Chris Lattner/// This is useful in a debugger.
7426000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid Stmt::dump() const {
7439668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis  StmtDumper P(0, llvm::errs(), 4);
744b393879e292faa61bb4a2853bad4412daf0158e6Chris Lattner  P.DumpSubTree(const_cast<Stmt*>(this));
7459668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis  llvm::errs() << "\n";
7460c727a35718556866a978f64ac549d9798735f08Chris Lattner}
7470c727a35718556866a978f64ac549d9798735f08Chris Lattner
7480c727a35718556866a978f64ac549d9798735f08Chris Lattner/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
749e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattnervoid Stmt::dumpAll(SourceManager &SM) const {
7509668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis  StmtDumper P(&SM, llvm::errs(), ~0U);
751b393879e292faa61bb4a2853bad4412daf0158e6Chris Lattner  P.DumpSubTree(const_cast<Stmt*>(this));
7529668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis  llvm::errs() << "\n";
7536000dace22f110d8768476989313e9d981d690d0Chris Lattner}
7546000dace22f110d8768476989313e9d981d690d0Chris Lattner
7556000dace22f110d8768476989313e9d981d690d0Chris Lattner/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
7566000dace22f110d8768476989313e9d981d690d0Chris Lattnervoid Stmt::dumpAll() const {
7579668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis  StmtDumper P(0, llvm::errs(), ~0U);
758b393879e292faa61bb4a2853bad4412daf0158e6Chris Lattner  P.DumpSubTree(const_cast<Stmt*>(this));
7599668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis  llvm::errs() << "\n";
7606000dace22f110d8768476989313e9d981d690d0Chris Lattner}
761