Stmt.h revision 4b9c2d235fb9449e249d74f48ecfec601650de93
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Stmt interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_STMT_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_STMT_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
179594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "clang/Basic/LLVM.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/SourceLocation.h"
19d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h"
209caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h"
218ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek#include "clang/AST/DeclGroup.h"
228189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek#include "clang/AST/ASTContext.h"
239594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "llvm/Support/raw_ostream.h"
249594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "llvm/ADT/SmallVector.h"
256e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string>
267573098b83e780d1c5bea13b384b610d8f155676Steve Naroff
2741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm {
2841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  class FoldingSetNodeID;
2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor}
3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
32e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  class ASTContext;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
357ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff  class ParmVarDecl;
364b07b2968f87f3cd5a3d8c76145f1cbfd718d42dSebastian Redl  class QualType;
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class IdentifierInfo;
380c727a35718556866a978f64ac549d9798735f08Chris Lattner  class SourceManager;
396a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  class StringLiteral;
406c36be5b383875b490684bcf439d6d427298c1afChris Lattner  class SwitchStmt;
411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //===----------------------------------------------------------------------===//
43ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  // ExprIterator - Iterators for iterating over Stmt* arrays that contain
44ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
45ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  references to children (to be compatible with StmtIterator).
46ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //===----------------------------------------------------------------------===//
471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Stmt;
49ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Expr;
501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ExprIterator {
52ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Stmt** I;
53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator(Stmt** i) : I(i) {}
551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExprIterator() : I(0) {}
56ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator& operator++() { ++I; return *this; }
57ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator-(size_t i) { return I-i; }
58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator+(size_t i) { return I+i; }
59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator[](size_t idx);
60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    // FIXME: Verify that this will correctly return a signed distance.
61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ExprIterator& R) const { return I - R.I; }
62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator*() const;
63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator->() const;
64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ExprIterator& R) const { return I == R.I; }
65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ExprIterator& R) const { return I != R.I; }
66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ExprIterator& R) const { return I > R.I; }
67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ExprIterator& R) const { return I >= R.I; }
68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  };
691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ConstExprIterator {
711705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    const Stmt * const *I;
72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
731705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator(const Stmt * const *i) : I(i) {}
741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ConstExprIterator() : I(0) {}
75ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ConstExprIterator& operator++() { ++I; return *this; }
761705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator+(size_t i) const { return I+i; }
771705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator-(size_t i) const { return I-i; }
78ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator[](size_t idx) const;
79ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ConstExprIterator& R) const { return I - R.I; }
80ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator*() const;
81ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator->() const;
82ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ConstExprIterator& R) const { return I == R.I; }
83ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ConstExprIterator& R) const { return I != R.I; }
84ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ConstExprIterator& R) const { return I > R.I; }
85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  };
871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements.
90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement.
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt {
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum StmtClass {
97f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor    NoStmtClass = 0,
98f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class,
997381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \
1009a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
1017381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
1029a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
1037381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT)
1044bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
1058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1078189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Make vanilla 'new' and 'delete' illegal for Stmts.
1088189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected:
1098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes) throw() {
110b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
1118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void operator delete(void* data) throw() {
113b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
1148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1168e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class StmtBitfields {
1178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Stmt;
1188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    /// \brief The statement class.
1208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned sClass : 8;
1218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  enum { NumStmtBits = 8 };
1238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CompoundStmtBitfields {
1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CompoundStmt;
1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned NumStmts : 32 - NumStmtBits;
1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class ExprBitfields {
1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Expr;
1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DeclRefExpr; // computeDependence
1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class InitListExpr; // ctor
1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DesignatedInitExpr; // ctor
136d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor    friend class BlockDeclRefExpr; // ctor
137bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ASTStmtReader; // deserialization
138bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXNewExpr; // ctor
139bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class DependentScopeDeclRefExpr; // ctor
140bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXConstructExpr; // ctor
141bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CallExpr; // ctor
142bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OffsetOfExpr; // ctor
143bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ObjCMessageExpr; // ctor
144bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ShuffleVectorExpr; // ctor
145bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ParenListExpr; // ctor
146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXUnresolvedConstructExpr; // ctor
147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXDependentScopeMemberExpr; // ctor
148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OverloadExpr; // ctor
1494b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr; // ctor
150dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    friend class AtomicExpr; // ctor
1518e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1528e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueKind : 2;
154f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    unsigned ObjectKind : 2;
1558e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned TypeDependent : 1;
1568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueDependent : 1;
157561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
160561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  enum { NumExprBits = 16 };
1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
162cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  class DeclRefExprBitfields {
163cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class DeclRefExpr;
164cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class ASTStmtReader; // deserialization
165cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned : NumExprBits;
166cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
167cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasQualifier : 1;
168cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasExplicitTemplateArgs : 1;
1693aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    unsigned HasFoundDecl : 1;
1707cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    unsigned HadMultipleCandidates : 1;
171cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  };
172cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
1738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CastExprBitfields {
1748e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CastExpr;
1758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumExprBits;
1768e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1772bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned Kind : 6;
1782bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned BasePathSize : 32 - 6 - NumExprBits;
1798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1808e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
181cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  class CallExprBitfields {
182cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    friend class CallExpr;
183cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned : NumExprBits;
184cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
185cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned NumPreArgs : 1;
186cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  };
187cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
1884b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class PseudoObjectExprBitfields {
1894b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr;
1904b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class ASTStmtReader; // deserialization
1914b9c2d235fb9449e249d74f48ecfec601650de93John McCall
1924b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned : NumExprBits;
1934b9c2d235fb9449e249d74f48ecfec601650de93John McCall
1944b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // These don't need to be particularly wide, because they're
1954b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // strictly limited by the forms of expressions we permit.
1964b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned NumSubExprs : 8;
1974b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned ResultIndex : 32 - 8 - NumExprBits;
1984b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
1994b9c2d235fb9449e249d74f48ecfec601650de93John McCall
200f85e193739c953358c865005855253af4f68a497John McCall  class ObjCIndirectCopyRestoreExprBitfields {
201f85e193739c953358c865005855253af4f68a497John McCall    friend class ObjCIndirectCopyRestoreExpr;
202f85e193739c953358c865005855253af4f68a497John McCall    unsigned : NumExprBits;
203f85e193739c953358c865005855253af4f68a497John McCall
204f85e193739c953358c865005855253af4f68a497John McCall    unsigned ShouldCopy : 1;
205f85e193739c953358c865005855253af4f68a497John McCall  };
206f85e193739c953358c865005855253af4f68a497John McCall
2078e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  union {
20863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    // FIXME: this is wasteful on 64-bit platforms.
20963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    void *Aligner;
21063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
2118e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBitfields StmtBits;
2128e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBitfields CompoundStmtBits;
2138e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBitfields ExprBits;
214cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    DeclRefExprBitfields DeclRefExprBits;
2158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBitfields CastExprBits;
216cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    CallExprBitfields CallExprBits;
2174b9c2d235fb9449e249d74f48ecfec601650de93John McCall    PseudoObjectExprBitfields PseudoObjectExprBits;
218f85e193739c953358c865005855253af4f68a497John McCall    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
2198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
221d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  friend class ASTStmtReader;
222d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2238189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic:
2248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Only allow allocation of Stmts using the allocator in ASTContext
2251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // or by doing a placement new.
2268189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext& C,
227f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor                     unsigned alignment = 8) throw() {
2288189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return ::operator new(bytes, C, alignment);
2298189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
2301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2318189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext* C,
232f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor                     unsigned alignment = 8) throw() {
2338189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return ::operator new(bytes, *C, alignment);
2348189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2368189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, void* mem) throw() {
2378189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return mem;
2388189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
239e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
240fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext&, unsigned) throw() { }
241fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext*, unsigned) throw() { }
242e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor  void operator delete(void*, std::size_t) throw() { }
243fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, void*) throw() { }
244e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
245025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic:
246025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief A placeholder type used to construct an empty shell of a
247025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// type, that will be filled in later (e.g., by some
248025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// de-serialization).
249025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  struct EmptyShell { };
250025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
2519c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected:
252025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Construct an empty statement.
2538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  explicit Stmt(StmtClass SC, EmptyShell) {
2548e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
255025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor    if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
256025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  }
257025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt(StmtClass SC) {
2608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
264c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  StmtClass getStmtClass() const {
2658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    return static_cast<StmtClass>(StmtBits.sClass);
266b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor  }
2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStmtClassName() const;
2681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
269b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// SourceLocation tokens are not useful in isolation - they are low level
270b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// value objects created/interpreted by SourceManager. We assume AST
271b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// clients will have a pointer to the respective SourceManager.
27263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
27363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
274311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  SourceLocation getLocStart() const { return getSourceRange().getBegin(); }
275311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  SourceLocation getLocEnd() const { return getSourceRange().getEnd(); }
2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // global temp stats (until we have a per-module visitor)
2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void addStmtClass(const StmtClass s);
2792024f4d4b0d57616f79ea742fa782d633d414462Kovarththanan Rajaratnam  static bool CollectingStats(bool Enable = false);
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void PrintStats();
2816000dace22f110d8768476989313e9d981d690d0Chris Lattner
2826000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dump - This does a local dump of the specified AST fragment.  It dumps the
2836000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// specified node and a few nodes underneath it, but not the whole subtree.
2846000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// This is useful in a debugger.
2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void dump() const;
286e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  void dump(SourceManager &SM) const;
2878cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS, SourceManager &SM) const;
2886000dace22f110d8768476989313e9d981d690d0Chris Lattner
2896000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpAll - This does a dump of the specified AST fragment and all subtrees.
2906000dace22f110d8768476989313e9d981d690d0Chris Lattner  void dumpAll() const;
291e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  void dumpAll(SourceManager &SM) const;
2926000dace22f110d8768476989313e9d981d690d0Chris Lattner
2936000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
2946000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// back to its original source language syntax.
29548d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman  void dumpPretty(ASTContext& Context) const;
2968cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
297e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
29848d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman                   unsigned Indentation = 0) const {
29948d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman    printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation);
30048d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman  }
3018cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, ASTContext &Context,
3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                   PrinterHelper *Helper,
303e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
304d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                   unsigned Indentation = 0) const;
3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
306d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
307d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
308d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  void viewAST() const;
3091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3107e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// Skip past any implicit AST nodes which might surround this
3117e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
3127e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  Stmt *IgnoreImplicit();
3137e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
314a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  const Stmt *stripLabelLikeStatements() const;
315a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  Stmt *stripLabelLikeStatements() {
316a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth    return const_cast<Stmt*>(
317a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
318a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  }
319a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Implement isa<T> support.
3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *) { return true; }
3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
323d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
324d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  contain implicit control-flow in the order their subexpressions
325d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  are evaluated.  This predicate returns true if this statement has
326d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  such implicit control-flow.  Such statements are also specially handled
327d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  within CFGs.
328d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  bool hasImplicitControlFlow() const;
329d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek
33063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// Child Iterators: All subclasses must implement 'children'
33163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// to permit easy iteration over the substatements/subexpessions of an
33263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// AST node.  This permits easy iteration over all nodes in the AST.
3339caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef StmtIterator       child_iterator;
3349caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef ConstStmtIterator  const_child_iterator;
3351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef StmtRange          child_range;
33763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef ConstStmtRange     const_child_range;
3381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
34063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_range children() const {
34163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return const_cast<Stmt*>(this)->children();
34277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_begin() { return children().first; }
34563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_end() { return children().second; }
34663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
34763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_begin() const { return children().first; }
34863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_end() const { return children().second; }
34941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
35041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Produce a unique representation of the given statement.
35141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
35241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief ID once the profiling operation is complete, will contain
35341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// the unique representation of the given statement.
35441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
35541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Context the AST context in which the statement resides
35641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
35741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Canonical whether the profile should be based on the canonical
35841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// representation of this statement (e.g., where non-type template
3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// parameters are identified by index/level rather than their
36041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// declaration pointers) or the exact representation of the statement as
36141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// written in the source.
3624ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
363b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth               bool Canonical) const;
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions
3681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration.
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt {
3729653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor  DeclGroupRef DG;
37381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation StartLoc, EndLoc;
3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
3778ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
3788ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek                                    StartLoc(startLoc), EndLoc(endLoc) {}
3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  /// \brief Build an empty declaration statement.
38184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
38284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
3837e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  /// isSingleDecl - This method returns true if this DeclStmt refers
384fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner  /// to a single Decl.
3857e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  bool isSingleDecl() const {
386fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner    return DG.isSingleDecl();
3878ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  }
3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3897e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Decl *getSingleDecl() { return DG.getSingleDecl(); }
3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
392e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  const DeclGroupRef getDeclGroup() const { return DG; }
393e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  DeclGroupRef getDeclGroup() { return DG; }
39484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
395b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
39681c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
39784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setStartLoc(SourceLocation L) { StartLoc = L; }
39881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
39984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setEndLoc(SourceLocation L) { EndLoc = L; }
40084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4018ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  SourceRange getSourceRange() const {
40281c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner    return SourceRange(StartLoc, EndLoc);
40381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  }
4041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DeclStmtClass;
4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclStmt *) { return true; }
4091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41014f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek  // Iterators over subexpressions.
41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
41263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(child_iterator(DG.begin(), DG.end()),
41363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       child_iterator(DG.end(), DG.end()));
41463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4160632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::iterator decl_iterator;
4170632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::const_iterator const_decl_iterator;
4181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4198ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_begin() { return DG.begin(); }
4208ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_end() { return DG.end(); }
4218ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_begin() const { return DG.begin(); }
4228ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_end() const { return DG.end(); }
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3.
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt {
4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation SemiLoc;
42944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
430e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  /// \brief True if the null statement was preceded by an empty macro, e.g:
43144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @code
43244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   #define CALL(x)
43344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   CALL(0);
43444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @endcode
435e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool HasLeadingEmptyMacro;
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
437e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
438e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis    : Stmt(NullStmtClass), SemiLoc(L),
439e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
441025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty null statement.
442e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
443e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(false) { }
444025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getSemiLoc() const { return SemiLoc; }
446025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
447b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
448e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
44944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
45063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(SemiLoc); }
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == NullStmtClass;
4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const NullStmt *) { return true; }
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
45844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
45944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtReader;
46044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtWriter;
4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }.
4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt {
4668189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  Stmt** Body;
467b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation LBracLoc, RBracLoc;
4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned NumStmts,
4708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall               SourceLocation LB, SourceLocation RB)
4718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) {
4728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = NumStmts;
473654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis    assert(CompoundStmtBits.NumStmts == NumStmts &&
474654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis           "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
4758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
476026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (NumStmts == 0) {
477026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      Body = 0;
478026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return;
479026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    }
4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
481026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Body = new (C) Stmt*[NumStmts];
4828e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    memcpy(Body, StmtStart, NumStmts * sizeof(*Body));
4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
484025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
485025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  // \brief Build an empty compound statement.
486025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CompoundStmt(EmptyShell Empty)
4878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    : Stmt(CompoundStmtClass, Empty), Body(0) {
4888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = 0;
4898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
490025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
491025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
4948e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned size() const { return CompoundStmtBits.NumStmts; }
495025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
4968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt** body_iterator;
4978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  body_iterator body_begin() { return Body; }
4988e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  body_iterator body_end() { return Body + size(); }
4998e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
500e946fc833d8592aa2890bfd9839f1ad839b3d284Fariborz Jahanian
5018e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setLastStmt(Stmt *S) {
5028e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    assert(!body_empty() && "setLastStmt");
5038e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Body[size()-1] = S;
5048e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt* const * const_body_iterator;
5078189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_body_iterator body_begin() const { return Body; }
5088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const_body_iterator body_end() const { return Body + size(); }
5098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
5108189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek
5118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
5128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rbegin() {
5138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_end());
5148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rend() {
5168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_begin());
5178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5184ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5198189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<const_body_iterator>
5208189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek          const_reverse_body_iterator;
5214ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5228189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rbegin() const {
5238189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_end());
5248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5268189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rend() const {
5278189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_begin());
5288189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
5311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(LBracLoc, RBracLoc);
532b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
534cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getLBracLoc() const { return LBracLoc; }
535025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
536cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getRBracLoc() const { return RBracLoc; }
537025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundStmtClass;
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundStmt *) { return true; }
5431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5448297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
54563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
54663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
54763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
5488ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek
5498ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  const_child_range children() const {
5508ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
5518ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  }
5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
554c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt,
555c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt {
556103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected:
557c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // A pointer to the following CaseStmt or DefaultStmt class,
558c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // used by SwitchStmt.
559c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *NextSwitchCase;
560103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek
561d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
5621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
563c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic:
564c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
565c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
566c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
567c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
568c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
569d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek
57063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  Stmt *getSubStmt();
571702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  const Stmt *getSubStmt() const {
572702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner    return const_cast<SwitchCase*>(this)->getSubStmt();
573702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  }
574b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
57563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(); }
5761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass ||
57963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall           T->getStmtClass() == DefaultStmtClass;
580c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
581c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  static bool classof(const SwitchCase *) { return true; }
582c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson};
583c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
584c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase {
5850a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor  enum { LHS, RHS, SUBSTMT, END_EXPR };
5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
587d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek                             // GNU "case 1 ... 4" extension
588b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation CaseLoc;
589dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation EllipsisLoc;
590dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
592dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation ellipsisLoc, SourceLocation colonLoc)
594d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    : SwitchCase(CaseStmtClass) {
59524e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner    SubExprs[SUBSTMT] = 0;
596d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
597d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
598b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    CaseLoc = caseLoc;
599dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    EllipsisLoc = ellipsisLoc;
600dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc = colonLoc;
601d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  }
602025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
603025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty switch case statement.
604025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { }
605025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
606764a7ce5217f9569e100a3445f47496ee82daf86Chris Lattner  SourceLocation getCaseLoc() const { return CaseLoc; }
607025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCaseLoc(SourceLocation L) { CaseLoc = L; }
608dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
609dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
610dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
611dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
612025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
613d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
614d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
615d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
616025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getLHS() const {
6181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
61951b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const {
6211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
62251b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
62351b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
62520dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
62620dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
62720dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
6313fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    // Handle deeply nested case statements with iteration instead of recursion.
6323fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    const CaseStmt *CS = this;
63391ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
6343fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner      CS = CS2;
6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
637b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
6381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass;
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CaseStmt *) { return true; }
6421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
643d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
64463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
64563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
64663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
649c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase {
650d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt* SubStmt;
6516c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation DefaultLoc;
652dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
655dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL),
656dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc(CL) {}
657025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
658025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty default statement.
659025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { }
660025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
661d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubStmt; }
66251b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubStmt; }
663025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSubStmt(Stmt *S) { SubStmt = S; }
664025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
6656c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation getDefaultLoc() const { return DefaultLoc; }
666025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setDefaultLoc(SourceLocation L) { DefaultLoc = L; }
667dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
668dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
67063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DefaultLoc, SubStmt->getLocEnd());
672b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
6731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DefaultStmtClass;
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DefaultStmt *) { return true; }
6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
678d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
67963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
682ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner
683ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement.  For example:
684ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///    foo: return;
685ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt {
687ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *TheDecl;
6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *SubStmt;
689b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IdentLoc;
6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
691ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
692ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
6938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
6941de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
6951de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  // \brief Build an empty label statement.
6961de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getIdentLoc() const { return IdentLoc; }
699ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getDecl() const { return TheDecl; }
700ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setDecl(LabelDecl *D) { TheDecl = D; }
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *getSubStmt() { return SubStmt; }
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Stmt *getSubStmt() const { return SubStmt; }
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setSubStmt(Stmt *SS) { SubStmt = SS; }
706b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
70763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(IdentLoc, SubStmt->getLocEnd());
7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
71063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
71163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == LabelStmtClass;
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const LabelStmt *) { return true; }
7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else.
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt {
72243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, THEN, ELSE, END_EXPR };
7238297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
7248cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor
725b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IfLoc;
726d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation ElseLoc;
72744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
72943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
73044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
73143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor
732025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty if/then/else statement
733025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
734025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
7358cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \brief Retrieve the variable declared in this "if" statement, if any.
7368cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///
7378cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// In the following example, "x" is the condition variable.
7388cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \code
7398cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// if (int x = foo()) {
7408cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///   printf("x is %d", x);
7418cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// }
7428cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \endcode
74343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
74443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
745c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
746d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this IfStmt has a condition variable, return the faux DeclStmt
747d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
748d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
749d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
750d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
751d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
7528297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
753025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
7548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getThen() const { return SubExprs[THEN]; }
7551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setThen(Stmt *S) { SubExprs[THEN] = S; }
7568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getElse() const { return SubExprs[ELSE]; }
757025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
7608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getThen() { return SubExprs[THEN]; }
7618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getElse() { return SubExprs[ELSE]; }
762b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
763025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getIfLoc() const { return IfLoc; }
764025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setIfLoc(SourceLocation L) { IfLoc = L; }
765d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation getElseLoc() const { return ElseLoc; }
766d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  void setElseLoc(SourceLocation L) { ElseLoc = L; }
767025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
76863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
769b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    if (SubExprs[ELSE])
770b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
771b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    else
772b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
773b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
7741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators over subexpressions.  The iterators will include iterating
77663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // over the initialization expression referenced by the condition variable.
77763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
77863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
77963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
78063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
7811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IfStmtClass;
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IfStmt *) { return true; }
7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt.
7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt {
79043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
792c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // This points to a linked list of case and default statements.
793c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *FirstCase;
7949dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  SourceLocation SwitchLoc;
7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
796559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// If the SwitchStmt is a switch on an enum value, this records whether
797559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// all the enum values were covered by CaseStmts.  This value is meant to
798559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// be a hint for possible clients.
799559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  unsigned AllEnumCasesCovered : 1;
800559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
80243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
8031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
804025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build a empty switch statement.
805025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
806025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
807d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \brief Retrieve the variable declared in this "switch" statement, if any.
808d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///
809d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// In the following example, "x" is the condition variable.
810d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \code
811d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// switch (int x = foo()) {
812d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   case 0: break;
813d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   // ...
814d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// }
815d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \endcode
81643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
81743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
818d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
819d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
820d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
821d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
822d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
823d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
824d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor
8258297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
8268297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
827c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
828c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
8298297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
830025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
8318297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
832025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
833c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getSwitchCaseList() { return FirstCase; }
8341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Set the case list for this switch statement.
83643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
83743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// The caller is responsible for incrementing the retain counts on
83843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// all of the SwitchCase statements in this list.
839025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
840025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
841025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getSwitchLoc() const { return SwitchLoc; }
842025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
843c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
8441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setBody(Stmt *S, SourceLocation SL) {
8451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[BODY] = S;
8469dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    SwitchLoc = SL;
8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
848c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void addSwitchCase(SwitchCase *SC) {
849c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    assert(!SC->getNextSwitchCase() && "case/default already added to a switch");
850c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    SC->setNextSwitchCase(FirstCase);
851c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson    FirstCase = SC;
852c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
853559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
854559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
855559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// switch over an enum value then all cases have been explicitly covered.
856559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  void setAllEnumCasesCovered() {
857559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    AllEnumCasesCovered = 1;
858559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
859559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
860559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
861559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// have been explicitly covered.
862559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  bool isAllEnumCasesCovered() const {
863559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    return (bool) AllEnumCasesCovered;
864559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
865559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
86663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
8671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
8689dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  }
86963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators
87063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
87163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
87263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
87363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
8741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SwitchStmtClass;
8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const SwitchStmt *) { return true; }
8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt.
8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt {
88443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
8858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
886b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation WhileLoc;
8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
88843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
88943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor            SourceLocation WL);
8901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
891d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty while statement.
892d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
893d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
8945656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \brief Retrieve the variable declared in this "while" statement, if any.
8955656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///
8965656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// In the following example, "x" is the condition variable.
8975656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \code
8985656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// while (int x = random()) {
8995656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///   // ...
9005656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// }
9015656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \endcode
90243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
90343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
9045656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
905d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this WhileStmt has a condition variable, return the faux DeclStmt
906d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
907d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
908d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
909d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
910d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
9118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
9128297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
913d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
9148297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
9158297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
916d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
917d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
918d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
919d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
920b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
92163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
923b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == WhileStmtClass;
9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const WhileStmt *) { return true; }
9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9298297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
93063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
93163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
93263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt.
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt {
938c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor  enum { BODY, COND, END_EXPR };
9398297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
940b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation DoLoc;
9419f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation WhileLoc;
942989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
9439f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor
9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
945989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
946989135901c750af61ef012b6b0a0368be415bc46Chris Lattner         SourceLocation RP)
947989135901c750af61ef012b6b0a0368be415bc46Chris Lattner    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
9488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
9498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[BODY] = body;
9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
95167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
95267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty do-while statement.
95367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
9541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9558297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
9568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
95767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
9588297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Stmt *getBody() const { return SubExprs[BODY]; }
96067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
96167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
96267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getDoLoc() const { return DoLoc; }
96367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setDoLoc(SourceLocation L) { DoLoc = L; }
9649f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
9659f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
966b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
967989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
968989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
969989135901c750af61ef012b6b0a0368be415bc46Chris Lattner
97063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
9711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DoLoc, RParenLoc);
972b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DoStmtClass;
9755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DoStmt *) { return true; }
9778297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
9788297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
97963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
98063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
98163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not
9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source.
9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt {
99043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
9918297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
992b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation ForLoc;
9935831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation LParenLoc, RParenLoc;
9945831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
99643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
99743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty for statement.
100067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
100167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
10028297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getInit() { return SubExprs[INIT]; }
1003c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
100499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \brief Retrieve the variable declared in this "for" statement, if any.
100599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///
100699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// In the following example, "y" is the condition variable.
100799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \code
100899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// for (int x = random(); int y = mangle(x); ++x) {
100999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///   // ...
101099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// }
101199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \endcode
101243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
101343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
1014c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1015d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this ForStmt has a condition variable, return the faux DeclStmt
1016d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1017d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1018d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1019d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1020d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
10218297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10228297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
10238297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10248297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
10258297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getInit() const { return SubExprs[INIT]; }
10268297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
10278297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
10288297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1029b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
103067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInit(Stmt *S) { SubExprs[INIT] = S; }
103167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
103267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
103367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
103467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
103567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getForLoc() const { return ForLoc; }
103667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setForLoc(SourceLocation L) { ForLoc = L; }
10375831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
10385831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
10395831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
10405831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
104167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
104263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
1044b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ForStmtClass;
10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ForStmt *) { return true; }
10491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
105163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
105263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
105363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto.
10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt {
1059ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
1060507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation GotoLoc;
106161f62165220e75694fe333179c78815e2e48d71fTed Kremenek  SourceLocation LabelLoc;
10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1063ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
106461f62165220e75694fe333179c78815e2e48d71fTed Kremenek    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10661de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Build an empty goto statement.
10671de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
10681de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1069ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
1070ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *D) { Label = D; }
10711de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
10721de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getGotoLoc() const { return GotoLoc; }
10731de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
10741de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
10751de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1076b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
107763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(GotoLoc, LabelLoc);
1079507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GotoStmtClass;
10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const GotoStmt *) { return true; }
10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
108663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto.
10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt {
1092ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation GotoLoc;
10935f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation StarLoc;
10941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Target;
10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
10975f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor                   Expr *target)
10985f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
10995f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor      Target((Stmt*)target) {}
11007d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
11017d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty indirect goto statement.
11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IndirectGotoStmt(EmptyShell Empty)
11037d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Stmt(IndirectGotoStmtClass, Empty) { }
11041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1105ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1106ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation getGotoLoc() const { return GotoLoc; }
11075f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  void setStarLoc(SourceLocation L) { StarLoc = L; }
11085f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation getStarLoc() const { return StarLoc; }
11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
111095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
111195c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
11127d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1113b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
111495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// getConstantTarget - Returns the fixed target of this indirect
111595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// goto, if one exists.
1116ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getConstantTarget();
1117ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  const LabelDecl *getConstantTarget() const {
111895c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
111995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  }
112095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall
112163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
1122ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner    return SourceRange(GotoLoc, Target->getLocEnd());
1123ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  }
11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IndirectGotoStmtClass;
11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IndirectGotoStmt *) { return true; }
11291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11308297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
113163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Target, &Target+1); }
11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue.
11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt {
1138507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation ContinueLoc;
11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1140507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1142d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty continue statement.
1143d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1144d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1145d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getContinueLoc() const { return ContinueLoc; }
1146d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1147d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
114863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
11491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ContinueLoc);
1150507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
1151861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor
11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ContinueStmtClass;
11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ContinueStmt *) { return true; }
11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
115863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break.
11625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt {
1164507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation BreakLoc;
11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1166507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1168025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty break statement.
1169025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1170025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1171025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getBreakLoc() const { return BreakLoc; }
1172025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1173025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
117463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(BreakLoc); }
1175b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
11761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BreakStmtClass;
11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BreakStmt *) { return true; }
11801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
118263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1186c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression:
1187c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return;
1188c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return 4;
1189c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///
1190c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to
1191c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to
1192c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void.  We explicitly model this in the AST, which means you can't
1193c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument.
11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt {
11961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *RetExpr;
1197507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation RetLoc;
11985077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *NRVOCandidate;
11995077c3876beeaed32280af88244e8050078619a8Douglas Gregor
12005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12015077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL)
120225a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
12035077c3876beeaed32280af88244e8050078619a8Douglas Gregor
12045077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
12055077c3876beeaed32280af88244e8050078619a8Douglas Gregor    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
12065077c3876beeaed32280af88244e8050078619a8Douglas Gregor      NRVOCandidate(NRVOCandidate) {}
12070de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
12080de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  /// \brief Build an empty return expression.
12090de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
12100de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
12111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getRetValue() const;
12121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getRetValue();
12130de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
12140de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
12150de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  SourceLocation getReturnLoc() const { return RetLoc; }
12160de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1217b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
12185077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// \brief Retrieve the variable that might be used for the named return
12195077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// value optimization.
12205077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ///
12215077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// The optimization itself can only be performed if the variable is
12225077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// also marked as an NRVO object.
12235077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
12245077c3876beeaed32280af88244e8050078619a8Douglas Gregor  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
12255077c3876beeaed32280af88244e8050078619a8Douglas Gregor
122663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ReturnStmtClass;
12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReturnStmt *) { return true; }
12321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12338297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
123463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
123563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
123663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range();
123763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1240fe795956194141c91ae555985c9b930595bff43fChris Lattner/// AsmStmt - This represents a GNU inline-assembly statement extension.
1241fe795956194141c91ae555985c9b930595bff43fChris Lattner///
1242fe795956194141c91ae555985c9b930595bff43fChris Lattnerclass AsmStmt : public Stmt {
1243fe795956194141c91ae555985c9b930595bff43fChris Lattner  SourceLocation AsmLoc, RParenLoc;
12446a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  StringLiteral *AsmStr;
1245b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1246dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson  bool IsSimple;
124739c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson  bool IsVolatile;
12483b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump  bool MSAsm;
12491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1250b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  unsigned NumOutputs;
1251b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  unsigned NumInputs;
1252966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  unsigned NumClobbers;
12531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1254966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  // FIXME: If we wanted to, we could allocate all of these in one big array.
1255966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  IdentifierInfo **Names;
1256966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Constraints;
1257966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  Stmt **Exprs;
1258966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Clobbers;
1259c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1260fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic:
1261c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile,
1262966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson          bool msasm, unsigned numoutputs, unsigned numinputs,
1263ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson          IdentifierInfo **names, StringLiteral **constraints,
1264db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner          Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
1265db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner          StringLiteral **clobbers, SourceLocation rparenloc);
1266b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1267cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  /// \brief Build an empty inline-assembly statement.
1268c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty),
1269966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    Names(0), Constraints(0), Exprs(0), Clobbers(0) { }
1270cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1271cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getAsmLoc() const { return AsmLoc; }
1272cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1273cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1274cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1275cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
127639c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson  bool isVolatile() const { return IsVolatile; }
1277cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setVolatile(bool V) { IsVolatile = V; }
1278dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson  bool isSimple() const { return IsSimple; }
12796ffe643322949dd776285a6df60d3578f3918be4Chris Lattner  void setSimple(bool V) { IsSimple = V; }
12803b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump  bool isMSAsm() const { return MSAsm; }
12813b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump  void setMSAsm(bool V) { MSAsm = V; }
1282dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson
1283458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  //===--- Asm String Analysis ---===//
1284458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1285458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  const StringLiteral *getAsmString() const { return AsmStr; }
1286458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  StringLiteral *getAsmString() { return AsmStr; }
1287cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmString(StringLiteral *E) { AsmStr = E; }
1288cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1289458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AsmStringPiece - this is part of a decomposed asm string specification
1290458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// (for use with the AnalyzeAsmString function below).  An asm string is
1291458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// considered to be a concatenation of these parts.
1292458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  class AsmStringPiece {
1293458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1294458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    enum Kind {
1295458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1296458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Operand  // Operand reference, with optional modifier %c4.
1297458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    };
1298458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  private:
1299458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    Kind MyKind;
1300458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    std::string Str;
1301458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned OperandNo;
1302458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1303458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1304458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(unsigned OpNo, char Modifier)
1305458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      : MyKind(Operand), Str(), OperandNo(OpNo) {
1306458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Str += Modifier;
1307458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1309458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isString() const { return MyKind == String; }
1310458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isOperand() const { return MyKind == Operand; }
13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1312458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    const std::string &getString() const {
1313458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isString());
1314458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str;
1315458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1316458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1317458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned getOperandNo() const {
1318458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1319458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return OperandNo;
1320458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1322458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// getModifier - Get the modifier for this operand, if present.  This
1323458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// returns '\0' if there was no modifier.
1324458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    char getModifier() const {
1325458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1326458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str[0];
1327458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1328458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  };
13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1330458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1331458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// it into pieces.  If the asm string is erroneous, emit errors and return
1332458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// true, otherwise return false.  This handles canonicalization and
1333458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
13341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1335686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1336fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner                            ASTContext &C, unsigned &DiagOffs) const;
13371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1339b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Output operands ---===//
1340b327793860737d1c103a73aeda8057dd628a101dChris Lattner
1341b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  unsigned getNumOutputs() const { return NumOutputs; }
1342ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
1343ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1344ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Names[i];
1345ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1346ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
1347686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputName(unsigned i) const {
1348ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    if (IdentifierInfo *II = getOutputIdentifier(i))
1349ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson      return II->getName();
1350c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1351686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    return StringRef();
1352ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  }
1353ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson
1354b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// getOutputConstraint - Return the constraint string for the specified
1355b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// output operand.  All output constraints are known to be non-empty (either
1356b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// '=' or '+').
1357686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputConstraint(unsigned i) const;
13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1359b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1360ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i];
1361ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1362b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1363b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return Constraints[i];
1364b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1366ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getOutputExpr(unsigned i);
13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1368b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getOutputExpr(unsigned i) const {
1369b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return const_cast<AsmStmt*>(this)->getOutputExpr(i);
1370b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
13711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1372b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// isOutputPlusConstraint - Return true if the specified output constraint
1373b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// is a "+" constraint (which is both an input and an output) or false if it
1374b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// is an "=" constraint (just an output).
1375b327793860737d1c103a73aeda8057dd628a101dChris Lattner  bool isOutputPlusConstraint(unsigned i) const {
1376b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return getOutputConstraint(i)[0] == '+';
1377b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
137985759278332404e96d4bb89d0e976e46158cd026Chris Lattner  /// getNumPlusOperands - Return the number of output operands that have a "+"
138085759278332404e96d4bb89d0e976e46158cd026Chris Lattner  /// constraint.
138185759278332404e96d4bb89d0e976e46158cd026Chris Lattner  unsigned getNumPlusOperands() const;
13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1383b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Input operands ---===//
13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumInputs() const { return NumInputs; }
13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1387ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  IdentifierInfo *getInputIdentifier(unsigned i) const {
1388ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Names[i + NumOutputs];
1389ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
13901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1391686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputName(unsigned i) const {
1392ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    if (IdentifierInfo *II = getInputIdentifier(i))
1393ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson      return II->getName();
1394ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson
1395686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    return StringRef();
1396ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  }
1397ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson
1398b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// getInputConstraint - Return the specified input constraint.  Unlike output
1399b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// constraints, these can be empty.
1400686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputConstraint(unsigned i) const;
14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1402b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1403ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1404ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1405b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getInputConstraintLiteral(unsigned i) {
1406ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1407ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1409ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getInputExpr(unsigned i);
1410935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner  void setInputExpr(unsigned i, Expr *E);
1411935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner
1412b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getInputExpr(unsigned i) const {
1413b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return const_cast<AsmStmt*>(this)->getInputExpr(i);
1414b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
1415cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1416acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson  void setOutputsAndInputsAndClobbers(ASTContext &C,
1417ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                      IdentifierInfo **Names,
1418fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Constraints,
1419fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      Stmt **Exprs,
1420fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumOutputs,
1421c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                      unsigned NumInputs,
1422fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Clobbers,
1423fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumClobbers);
1424cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
142510ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  //===--- Other ---===//
14261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
142710ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// getNamedOperand - Given a symbolic operand reference like %[foo],
142810ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// translate this into a numeric value needed to reference the same operand.
142910ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// This returns -1 if the operand name is invalid.
1430686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  int getNamedOperand(StringRef SymbolicName) const;
143110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner
1432966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  unsigned getNumClobbers() const { return NumClobbers; }
1433b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  StringLiteral *getClobber(unsigned i) { return Clobbers[i]; }
1434d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson  const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; }
1435cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
143663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
1437fe795956194141c91ae555985c9b930595bff43fChris Lattner    return SourceRange(AsmLoc, RParenLoc);
1438fe795956194141c91ae555985c9b930595bff43fChris Lattner  }
14391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1440fe795956194141c91ae555985c9b930595bff43fChris Lattner  static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;}
1441fe795956194141c91ae555985c9b930595bff43fChris Lattner  static bool classof(const AsmStmt *) { return true; }
14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1443ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek  // Input expr iterators.
14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1445ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ExprIterator inputs_iterator;
1446ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ConstExprIterator const_inputs_iterator;
14471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1448ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  inputs_iterator begin_inputs() {
1449966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1450ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
14511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1452ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  inputs_iterator end_inputs() {
1453966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs + NumInputs;
1454ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
14551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1456ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  const_inputs_iterator begin_inputs() const {
1457966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1458ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
14591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1460ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  const_inputs_iterator end_inputs() const {
1461966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs + NumInputs;
1462d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
14631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1464ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek  // Output expr iterators.
14651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1466ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ExprIterator outputs_iterator;
1467ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ConstExprIterator const_outputs_iterator;
14681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1469d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  outputs_iterator begin_outputs() {
1470966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0];
1471d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
1472d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  outputs_iterator end_outputs() {
1473966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1474d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
14751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1476d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  const_outputs_iterator begin_outputs() const {
1477966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0];
1478d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
1479d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  const_outputs_iterator end_outputs() const {
1480966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1481d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
148363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
148463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
148563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
1486fe795956194141c91ae555985c9b930595bff43fChris Lattner};
148778492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek
148828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt {
148928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
149028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
149128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
149228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { FILTER_EXPR, BLOCK };
149328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
149428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt(SourceLocation Loc,
149528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Expr *FilterExpr,
149628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Stmt *Block);
149728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
14987110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
14997110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
15007110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
15017110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
150228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
150328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHExceptStmt* Create(ASTContext &C,
150428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation ExceptLoc,
150528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Expr *FilterExpr,
150628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Block);
150728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceRange getSourceRange() const {
150828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getExceptLoc(), getEndLoc());
150928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
151028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
151128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getExceptLoc() const { return Loc; }
151228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
151328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
151428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Expr *getFilterExpr() const { return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); }
151528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Children[BLOCK]); }
151628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
151728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
151828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
151928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
152028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
152128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
152228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHExceptStmtClass;
152328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
152428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
152528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHExceptStmt *) { return true; }
152628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
152728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
152828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
152928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt {
153028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
153128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Block;
153228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
153328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt(SourceLocation Loc,
153428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                 Stmt *Block);
153528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
15367110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
15377110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
15387110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
15397110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
154028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
154128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHFinallyStmt* Create(ASTContext &C,
154228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                SourceLocation FinallyLoc,
154328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                Stmt *Block);
154428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
154528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceRange getSourceRange() const {
154628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getFinallyLoc(), getEndLoc());
154728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
154828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
154928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getFinallyLoc() const { return Loc; }
155028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
155128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
155228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); }
155328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
155428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
155528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(&Block,&Block+1);
155628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
155728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
155828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
155928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHFinallyStmtClass;
156028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
156128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
156228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHFinallyStmt *) { return true; }
156328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
156428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
156528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
156628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt {
156728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool            IsCXXTry;
156828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  TryLoc;
156928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
157028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
157128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { TRY = 0, HANDLER = 1 };
157228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
157328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
157428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             SourceLocation TryLoc,
157528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *TryBlock,
157628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *Handler);
157728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
15787110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
15797110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
15807110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
15817110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
158228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
158328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHTryStmt* Create(ASTContext &C,
158428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            bool isCXXTry,
158528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            SourceLocation TryLoc,
158628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *TryBlock,
158728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *Handler);
158828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
158928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceRange getSourceRange() const {
159028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getTryLoc(), getEndLoc());
159128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
159228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
159328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getTryLoc() const { return TryLoc; }
159428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
159528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
159628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool getIsCXXTry() const { return IsCXXTry; }
159728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  CompoundStmt* getTryBlock() const { return llvm::cast<CompoundStmt>(Children[TRY]); }
159828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt *getHandler() const { return Children[HANDLER]; }
159928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
160028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Returns 0 if not defined
160128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt  *getExceptHandler() const;
160228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt *getFinallyHandler() const;
160328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
160428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
160528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
160628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
160728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
160828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
160928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHTryStmtClass;
161028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
161128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
161228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHTryStmt *) { return true; }
161328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
1614ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor
16155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
16165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1618