Stmt.h revision ebcb57a8d298862c65043e88b2429591ab3c58d3
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
42ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
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).
46ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
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
144ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCArrayLiteral; // ctor
145ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCDictionaryLiteral; // ctor
146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ShuffleVectorExpr; // ctor
147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ParenListExpr; // ctor
148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXUnresolvedConstructExpr; // ctor
149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXDependentScopeMemberExpr; // ctor
150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OverloadExpr; // ctor
1514b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr; // ctor
152dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    friend class AtomicExpr; // ctor
1538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1548e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1558e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueKind : 2;
156f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    unsigned ObjectKind : 2;
1578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned TypeDependent : 1;
1588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueDependent : 1;
159561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
162561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  enum { NumExprBits = 16 };
1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
164bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class CharacterLiteralBitfields {
165bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class CharacterLiteral;
166bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
167bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
168bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
169bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
170bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
171bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class FloatingLiteralBitfields {
172bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class FloatingLiteral;
173bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsIEEE : 1; // Distinguishes between PPC128 and IEEE128.
176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsExact : 1;
177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
179bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class UnaryExprOrTypeTraitExprBitfields {
180bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class UnaryExprOrTypeTraitExpr;
181bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
182bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
183bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
184bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsType : 1; // true if operand is a type, false if an expression.
185bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
186bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
187cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  class DeclRefExprBitfields {
188cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class DeclRefExpr;
189cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class ASTStmtReader; // deserialization
190cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned : NumExprBits;
191cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
192cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasQualifier : 1;
193e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    unsigned HasTemplateKWAndArgsInfo : 1;
1943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    unsigned HasFoundDecl : 1;
1957cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    unsigned HadMultipleCandidates : 1;
196cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  };
197cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
1988e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CastExprBitfields {
1998e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CastExpr;
2008e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumExprBits;
2018e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2022bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned Kind : 6;
2032bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned BasePathSize : 32 - 6 - NumExprBits;
2048e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
206cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  class CallExprBitfields {
207cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    friend class CallExpr;
208cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned : NumExprBits;
209cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
210cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned NumPreArgs : 1;
211cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  };
212cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
21380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  class ExprWithCleanupsBitfields {
21480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ExprWithCleanups;
21580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ASTStmtReader; // deserialization
21680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
21780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned : NumExprBits;
21880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
21980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned NumObjects : 32 - NumExprBits;
22080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  };
22180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
2224b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class PseudoObjectExprBitfields {
2234b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr;
2244b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class ASTStmtReader; // deserialization
2254b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2264b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned : NumExprBits;
2274b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2284b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // These don't need to be particularly wide, because they're
2294b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // strictly limited by the forms of expressions we permit.
2304b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned NumSubExprs : 8;
2314b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned ResultIndex : 32 - 8 - NumExprBits;
2324b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
2334b9c2d235fb9449e249d74f48ecfec601650de93John McCall
234f85e193739c953358c865005855253af4f68a497John McCall  class ObjCIndirectCopyRestoreExprBitfields {
235f85e193739c953358c865005855253af4f68a497John McCall    friend class ObjCIndirectCopyRestoreExpr;
236f85e193739c953358c865005855253af4f68a497John McCall    unsigned : NumExprBits;
237f85e193739c953358c865005855253af4f68a497John McCall
238f85e193739c953358c865005855253af4f68a497John McCall    unsigned ShouldCopy : 1;
239f85e193739c953358c865005855253af4f68a497John McCall  };
240f85e193739c953358c865005855253af4f68a497John McCall
24132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  class InitListExprBitfields {
24232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    friend class InitListExpr;
24332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
24432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned : NumExprBits;
24532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
24632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list originally had a GNU array-range
24732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// designator in it. This is a temporary marker used by CodeGen.
24832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned HadArrayRangeDesignator : 1;
24932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
25032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list initializes a std::initializer_list
25132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// object.
25232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned InitializesStdInitializerList : 1;
25332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  };
25432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
2554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  class TypeTraitExprBitfields {
2564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class TypeTraitExpr;
2574ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtReader;
2584ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtWriter;
2594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned : NumExprBits;
2614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
2634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Kind : 8;
2644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief If this expression is not value-dependent, this indicates whether
2664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// the trait evaluated true or false.
2674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Value : 1;
2684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The number of arguments to this type trait.
2704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
2714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  };
2724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  union {
27463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    // FIXME: this is wasteful on 64-bit platforms.
27563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    void *Aligner;
27663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
2778e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBitfields StmtBits;
2788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBitfields CompoundStmtBits;
2798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBitfields ExprBits;
280bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    CharacterLiteralBitfields CharacterLiteralBits;
281bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    FloatingLiteralBitfields FloatingLiteralBits;
282bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
283cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    DeclRefExprBitfields DeclRefExprBits;
2848e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBitfields CastExprBits;
285cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    CallExprBitfields CallExprBits;
28680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    ExprWithCleanupsBitfields ExprWithCleanupsBits;
2874b9c2d235fb9449e249d74f48ecfec601650de93John McCall    PseudoObjectExprBitfields PseudoObjectExprBits;
288f85e193739c953358c865005855253af4f68a497John McCall    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
28932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    InitListExprBitfields InitListExprBits;
2904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeTraitExprBitfields TypeTraitExprBits;
2918e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2928e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
293d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  friend class ASTStmtReader;
2944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
295d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic:
2978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Only allow allocation of Stmts using the allocator in ASTContext
2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // or by doing a placement new.
2998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext& C,
300f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor                     unsigned alignment = 8) throw() {
3018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return ::operator new(bytes, C, alignment);
3028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
3031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext* C,
305f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor                     unsigned alignment = 8) throw() {
3068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return ::operator new(bytes, *C, alignment);
3078189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, void* mem) throw() {
3108189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return mem;
3118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
312e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
313fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext&, unsigned) throw() { }
314fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext*, unsigned) throw() { }
315e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor  void operator delete(void*, std::size_t) throw() { }
316fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, void*) throw() { }
317e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
318025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic:
319025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief A placeholder type used to construct an empty shell of a
320025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// type, that will be filled in later (e.g., by some
321025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// de-serialization).
322025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  struct EmptyShell { };
323025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
32402892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate:
32502892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  /// \brief Whether statistic collection is enabled.
32602892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static bool StatisticsEnabled;
32702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar
3289c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected:
329025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Construct an empty statement.
3308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  explicit Stmt(StmtClass SC, EmptyShell) {
3318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
33202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
333025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  }
334025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt(StmtClass SC) {
3378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
33802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
341ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  StmtClass getStmtClass() const {
3428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    return static_cast<StmtClass>(StmtBits.sClass);
343b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor  }
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStmtClassName() const;
3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
346b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// SourceLocation tokens are not useful in isolation - they are low level
347b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// value objects created/interpreted by SourceManager. We assume AST
348b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// clients will have a pointer to the respective SourceManager.
34963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
35063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
351311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  SourceLocation getLocStart() const { return getSourceRange().getBegin(); }
352311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  SourceLocation getLocEnd() const { return getSourceRange().getEnd(); }
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // global temp stats (until we have a per-module visitor)
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void addStmtClass(const StmtClass s);
35602892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static void EnableStatistics();
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void PrintStats();
3586000dace22f110d8768476989313e9d981d690d0Chris Lattner
3596000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dump - This does a local dump of the specified AST fragment.  It dumps the
3606000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// specified node and a few nodes underneath it, but not the whole subtree.
3616000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// This is useful in a debugger.
362f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump() const;
363f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
3648cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS, SourceManager &SM) const;
3656000dace22f110d8768476989313e9d981d690d0Chris Lattner
3666000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpAll - This does a dump of the specified AST fragment and all subtrees.
3676000dace22f110d8768476989313e9d981d690d0Chris Lattner  void dumpAll() const;
368e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  void dumpAll(SourceManager &SM) const;
3696000dace22f110d8768476989313e9d981d690d0Chris Lattner
3706000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
3716000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// back to its original source language syntax.
37248d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman  void dumpPretty(ASTContext& Context) const;
3738cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
374e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
37548d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman                   unsigned Indentation = 0) const {
37648d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman    printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation);
37748d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman  }
3788cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, ASTContext &Context,
3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                   PrinterHelper *Helper,
380e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
381d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                   unsigned Indentation = 0) const;
3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
383d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
384d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
385d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  void viewAST() const;
3861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3877e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// Skip past any implicit AST nodes which might surround this
3887e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
3897e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  Stmt *IgnoreImplicit();
3907e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
391a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  const Stmt *stripLabelLikeStatements() const;
392a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  Stmt *stripLabelLikeStatements() {
393a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth    return const_cast<Stmt*>(
394a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
395a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  }
396a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth
3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Implement isa<T> support.
3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *) { return true; }
3991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
400d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
401d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  contain implicit control-flow in the order their subexpressions
402d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  are evaluated.  This predicate returns true if this statement has
403d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  such implicit control-flow.  Such statements are also specially handled
404d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  within CFGs.
405d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  bool hasImplicitControlFlow() const;
406d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek
40763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// Child Iterators: All subclasses must implement 'children'
40863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// to permit easy iteration over the substatements/subexpessions of an
40963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// AST node.  This permits easy iteration over all nodes in the AST.
4109caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef StmtIterator       child_iterator;
4119caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef ConstStmtIterator  const_child_iterator;
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef StmtRange          child_range;
41463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef ConstStmtRange     const_child_range;
4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_range children() const {
41863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return const_cast<Stmt*>(this)->children();
41977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_begin() { return children().first; }
42263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_end() { return children().second; }
42363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
42463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_begin() const { return children().first; }
42563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_end() const { return children().second; }
42641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
42741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Produce a unique representation of the given statement.
42841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief ID once the profiling operation is complete, will contain
43041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// the unique representation of the given statement.
43141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Context the AST context in which the statement resides
43341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Canonical whether the profile should be based on the canonical
43541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// representation of this statement (e.g., where non-type template
4361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// parameters are identified by index/level rather than their
43741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// declaration pointers) or the exact representation of the statement as
43841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// written in the source.
4394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
440b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth               bool Canonical) const;
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions
4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration.
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt {
4499653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor  DeclGroupRef DG;
45081c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation StartLoc, EndLoc;
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
4548ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
4558ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek                                    StartLoc(startLoc), EndLoc(endLoc) {}
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  /// \brief Build an empty declaration statement.
45884f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
45984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4607e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  /// isSingleDecl - This method returns true if this DeclStmt refers
461fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner  /// to a single Decl.
4627e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  bool isSingleDecl() const {
463fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner    return DG.isSingleDecl();
4648ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  }
4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4667e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
4671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Decl *getSingleDecl() { return DG.getSingleDecl(); }
4681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
469e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  const DeclGroupRef getDeclGroup() const { return DG; }
470e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  DeclGroupRef getDeclGroup() { return DG; }
47184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
472b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
47381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
47484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setStartLoc(SourceLocation L) { StartLoc = L; }
47581c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
47684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setEndLoc(SourceLocation L) { EndLoc = L; }
47784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4788ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  SourceRange getSourceRange() const {
47981c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner    return SourceRange(StartLoc, EndLoc);
48081c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  }
4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DeclStmtClass;
4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclStmt *) { return true; }
4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48714f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek  // Iterators over subexpressions.
48863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
48963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(child_iterator(DG.begin(), DG.end()),
49063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       child_iterator(DG.end(), DG.end()));
49163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4930632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::iterator decl_iterator;
4940632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::const_iterator const_decl_iterator;
4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4968ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_begin() { return DG.begin(); }
4978ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_end() { return DG.end(); }
4988ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_begin() const { return DG.begin(); }
4998ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_end() const { return DG.end(); }
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3.
5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt {
5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation SemiLoc;
50644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
507e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  /// \brief True if the null statement was preceded by an empty macro, e.g:
50844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @code
50944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   #define CALL(x)
51044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   CALL(0);
51144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @endcode
512e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool HasLeadingEmptyMacro;
5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
514e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
515e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis    : Stmt(NullStmtClass), SemiLoc(L),
516e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
518025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty null statement.
519e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
520e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(false) { }
521025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getSemiLoc() const { return SemiLoc; }
523025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
524b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
525e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
52644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
52763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(SemiLoc); }
5281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == NullStmtClass;
5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const NullStmt *) { return true; }
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
53544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
53644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtReader;
53744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtWriter;
5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }.
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt {
5438189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  Stmt** Body;
544b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation LBracLoc, RBracLoc;
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5468e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned NumStmts,
5478e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall               SourceLocation LB, SourceLocation RB)
5488e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) {
5498e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = NumStmts;
550654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis    assert(CompoundStmtBits.NumStmts == NumStmts &&
551654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis           "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
5528e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
553026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (NumStmts == 0) {
554026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      Body = 0;
555026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return;
556026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    }
5571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
558026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Body = new (C) Stmt*[NumStmts];
5598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    memcpy(Body, StmtStart, NumStmts * sizeof(*Body));
5601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
561025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
562025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  // \brief Build an empty compound statement.
563025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CompoundStmt(EmptyShell Empty)
5648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    : Stmt(CompoundStmtClass, Empty), Body(0) {
5658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = 0;
5668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
567025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
568025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
5691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
5718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned size() const { return CompoundStmtBits.NumStmts; }
572025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5738189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt** body_iterator;
5748189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  body_iterator body_begin() { return Body; }
5758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  body_iterator body_end() { return Body + size(); }
5768e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
577ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setLastStmt(Stmt *S) {
5798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    assert(!body_empty() && "setLastStmt");
5808e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Body[size()-1] = S;
5818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5838189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt* const * const_body_iterator;
5848189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_body_iterator body_begin() const { return Body; }
5858e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const_body_iterator body_end() const { return Body + size(); }
5868e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
5878189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek
5888189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
5898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rbegin() {
5908189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_end());
5918189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rend() {
5938189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_begin());
5948189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5954ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<const_body_iterator>
5978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek          const_reverse_body_iterator;
5984ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rbegin() const {
6008189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_end());
6018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6038189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rend() const {
6048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_begin());
6058189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(LBracLoc, RBracLoc);
609b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
611cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getLBracLoc() const { return LBracLoc; }
612025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
613cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getRBracLoc() const { return RBracLoc; }
614025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundStmtClass;
6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundStmt *) { return true; }
6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6218297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
62263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
62363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
62463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
625ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6268ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  const_child_range children() const {
6278ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
6288ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  }
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
631c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt,
632c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt {
633103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected:
634c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // A pointer to the following CaseStmt or DefaultStmt class,
635c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // used by SwitchStmt.
636c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *NextSwitchCase;
637103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek
638d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
6391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
640c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic:
641c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
642c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
643c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
644c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
645c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
646d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek
64763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  Stmt *getSubStmt();
648702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  const Stmt *getSubStmt() const {
649702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner    return const_cast<SwitchCase*>(this)->getSubStmt();
650702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  }
651b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
65263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(); }
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass ||
65663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall           T->getStmtClass() == DefaultStmtClass;
657c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
658c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  static bool classof(const SwitchCase *) { return true; }
659c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson};
660c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
661c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase {
6620a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor  enum { LHS, RHS, SUBSTMT, END_EXPR };
6631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
664d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek                             // GNU "case 1 ... 4" extension
665b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation CaseLoc;
666dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation EllipsisLoc;
667dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
669dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
6701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation ellipsisLoc, SourceLocation colonLoc)
671d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    : SwitchCase(CaseStmtClass) {
67224e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner    SubExprs[SUBSTMT] = 0;
673d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
674d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
675b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    CaseLoc = caseLoc;
676dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    EllipsisLoc = ellipsisLoc;
677dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc = colonLoc;
678d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  }
679025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
680025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty switch case statement.
681025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { }
682025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
683764a7ce5217f9569e100a3445f47496ee82daf86Chris Lattner  SourceLocation getCaseLoc() const { return CaseLoc; }
684025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCaseLoc(SourceLocation L) { CaseLoc = L; }
685dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
686dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
687dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
688dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
689025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
690d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
691d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
692d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
693025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getLHS() const {
6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
69651b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const {
6981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
69951b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
70051b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
70220dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
70320dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
70420dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
70763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
7083fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    // Handle deeply nested case statements with iteration instead of recursion.
7093fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    const CaseStmt *CS = this;
71091ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
7113fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner      CS = CS2;
7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
714b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass;
7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CaseStmt *) { return true; }
7191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
720d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
72163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
72263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
72363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
726c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase {
727d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt* SubStmt;
7286c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation DefaultLoc;
729dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
732dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL),
733dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc(CL) {}
734025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
735025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty default statement.
736025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { }
737025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
738d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubStmt; }
73951b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubStmt; }
740025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSubStmt(Stmt *S) { SubStmt = S; }
741025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
7426c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation getDefaultLoc() const { return DefaultLoc; }
743025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setDefaultLoc(SourceLocation L) { DefaultLoc = L; }
744dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
745dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
74763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DefaultLoc, SubStmt->getLocEnd());
749b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DefaultStmtClass;
7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DefaultStmt *) { return true; }
7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
755d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
75663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
759ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
760ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement.  For example:
761ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///    foo: return;
762ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///
7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt {
764ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *TheDecl;
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *SubStmt;
766b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IdentLoc;
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
768ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
769ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
7708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
7711de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
7721de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  // \brief Build an empty label statement.
7731de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
7741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getIdentLoc() const { return IdentLoc; }
776ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getDecl() const { return TheDecl; }
777ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setDecl(LabelDecl *D) { TheDecl = D; }
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *getSubStmt() { return SubStmt; }
7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Stmt *getSubStmt() const { return SubStmt; }
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setSubStmt(Stmt *SS) { SubStmt = SS; }
783b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
78463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
7851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(IdentLoc, SubStmt->getLocEnd());
7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
78763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
78863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == LabelStmtClass;
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const LabelStmt *) { return true; }
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else.
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt {
79943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, THEN, ELSE, END_EXPR };
8008297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
8018cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor
802b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IfLoc;
803d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation ElseLoc;
804ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
80744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
808ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
809025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty if/then/else statement
810025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
811025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
8128cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \brief Retrieve the variable declared in this "if" statement, if any.
8138cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///
8148cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// In the following example, "x" is the condition variable.
8158cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \code
8168cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// if (int x = foo()) {
8178cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///   printf("x is %d", x);
8188cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// }
8198cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \endcode
82043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
82143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
822ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
823d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this IfStmt has a condition variable, return the faux DeclStmt
824d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
825d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
826d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
827d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
828ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8298297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
830025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
8318297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getThen() const { return SubExprs[THEN]; }
8321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setThen(Stmt *S) { SubExprs[THEN] = S; }
8338297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getElse() const { return SubExprs[ELSE]; }
834025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8368297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
8378297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getThen() { return SubExprs[THEN]; }
8388297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getElse() { return SubExprs[ELSE]; }
839b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
840025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getIfLoc() const { return IfLoc; }
841025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setIfLoc(SourceLocation L) { IfLoc = L; }
842d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation getElseLoc() const { return ElseLoc; }
843d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  void setElseLoc(SourceLocation L) { ElseLoc = L; }
844025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
84563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
846b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    if (SubExprs[ELSE])
847b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
848b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    else
849b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
850b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators over subexpressions.  The iterators will include iterating
85363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // over the initialization expression referenced by the condition variable.
85463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
85563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
85663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
85763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IfStmtClass;
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IfStmt *) { return true; }
8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt.
8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt {
86743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
8681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
869c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // This points to a linked list of case and default statements.
870c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *FirstCase;
8719dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  SourceLocation SwitchLoc;
8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
873559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// If the SwitchStmt is a switch on an enum value, this records whether
874559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// all the enum values were covered by CaseStmts.  This value is meant to
875559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// be a hint for possible clients.
876559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  unsigned AllEnumCasesCovered : 1;
877559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
87943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
8801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
881025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build a empty switch statement.
882025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
883025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
884d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \brief Retrieve the variable declared in this "switch" statement, if any.
885d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///
886d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// In the following example, "x" is the condition variable.
887d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \code
888d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// switch (int x = foo()) {
889d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   case 0: break;
890d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   // ...
891d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// }
892d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \endcode
89343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
89443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
895ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
896d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
897d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
898d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
899d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
900d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
901d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor
9028297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
9038297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
904c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
905c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9068297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
907025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
9088297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
909025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
910c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getSwitchCaseList() { return FirstCase; }
9111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
91243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Set the case list for this switch statement.
91343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
91443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// The caller is responsible for incrementing the retain counts on
91543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// all of the SwitchCase statements in this list.
916025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
917025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
918025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getSwitchLoc() const { return SwitchLoc; }
919025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
920c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setBody(Stmt *S, SourceLocation SL) {
9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[BODY] = S;
9239dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    SwitchLoc = SL;
9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
925c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void addSwitchCase(SwitchCase *SC) {
926ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!SC->getNextSwitchCase()
927ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           && "case/default already added to a switch");
928c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    SC->setNextSwitchCase(FirstCase);
929c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson    FirstCase = SC;
930c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
931559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
932559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
933559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// switch over an enum value then all cases have been explicitly covered.
934559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  void setAllEnumCasesCovered() {
935559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    AllEnumCasesCovered = 1;
936559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
937559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
938559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
939559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// have been explicitly covered.
940559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  bool isAllEnumCasesCovered() const {
941559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    return (bool) AllEnumCasesCovered;
942559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
943559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
94463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
9469dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  }
94763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators
94863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
94963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
95063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
95163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
9521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SwitchStmtClass;
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const SwitchStmt *) { return true; }
9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt.
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt {
96243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
9638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
964b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation WhileLoc;
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
966ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
96743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor            SourceLocation WL);
9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
969d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty while statement.
970d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
971d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
9725656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \brief Retrieve the variable declared in this "while" statement, if any.
9735656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///
9745656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// In the following example, "x" is the condition variable.
9755656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \code
9765656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// while (int x = random()) {
9775656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///   // ...
9785656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// }
9795656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \endcode
98043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
98143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
9825656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
983d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this WhileStmt has a condition variable, return the faux DeclStmt
984d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
985d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
986d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
987d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
988d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
9898297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
9908297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
991d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
9928297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
9938297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
994d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
995d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
996d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
997d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
998b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
99963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
1001b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == WhileStmtClass;
10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const WhileStmt *) { return true; }
10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10078297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
100863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
100963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
101063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt.
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt {
1016c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor  enum { BODY, COND, END_EXPR };
10178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1018b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation DoLoc;
10199f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation WhileLoc;
1020989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
10219f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor
10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1023989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1024989135901c750af61ef012b6b0a0368be415bc46Chris Lattner         SourceLocation RP)
1025989135901c750af61ef012b6b0a0368be415bc46Chris Lattner    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
10268297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
10278297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[BODY] = body;
10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
102967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
103067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty do-while statement.
103167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10338297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10348297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
103567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10368297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Stmt *getBody() const { return SubExprs[BODY]; }
103867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
103967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
104067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getDoLoc() const { return DoLoc; }
104167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setDoLoc(SourceLocation L) { DoLoc = L; }
10429f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
10439f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1044b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1045989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
1046989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1047989135901c750af61ef012b6b0a0368be415bc46Chris Lattner
104863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
10491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DoLoc, RParenLoc);
1050b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DoStmtClass;
10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DoStmt *) { return true; }
10558297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
10568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
105763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
105863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
105963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not
10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source.
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt {
106843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
10698297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1070b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation ForLoc;
10715831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation LParenLoc, RParenLoc;
10725831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor
10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1074ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
107543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty for statement.
107867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
107967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
10808297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getInit() { return SubExprs[INIT]; }
1081ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
108299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \brief Retrieve the variable declared in this "for" statement, if any.
108399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///
108499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// In the following example, "y" is the condition variable.
108599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \code
108699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// for (int x = random(); int y = mangle(x); ++x) {
108799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///   // ...
108899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// }
108999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \endcode
109043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
109143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
1092ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1093d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this ForStmt has a condition variable, return the faux DeclStmt
1094d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1095d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1096d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1097d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1098d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
10998297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
11008297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11018297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
11028297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11038297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getInit() const { return SubExprs[INIT]; }
11048297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
11058297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11068297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1107b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
110867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInit(Stmt *S) { SubExprs[INIT] = S; }
110967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
111067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
111167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
111267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
111367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getForLoc() const { return ForLoc; }
111467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setForLoc(SourceLocation L) { ForLoc = L; }
11155831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
11165831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
11175831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11185831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
111967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
112063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
11211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
1122b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ForStmtClass;
11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ForStmt *) { return true; }
11271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11288297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
112963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
113063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
113163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto.
11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt {
1137ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
1138507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation GotoLoc;
113961f62165220e75694fe333179c78815e2e48d71fTed Kremenek  SourceLocation LabelLoc;
11405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1141ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
114261f62165220e75694fe333179c78815e2e48d71fTed Kremenek    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11441de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Build an empty goto statement.
11451de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
11461de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1147ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
1148ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *D) { Label = D; }
11491de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
11501de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getGotoLoc() const { return GotoLoc; }
11511de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
11521de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
11531de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1154b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
115563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(GotoLoc, LabelLoc);
1157507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GotoStmtClass;
11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const GotoStmt *) { return true; }
11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
116463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto.
11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt {
1170ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation GotoLoc;
11715f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation StarLoc;
11721060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Target;
11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
11755f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor                   Expr *target)
11765f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
11775f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor      Target((Stmt*)target) {}
11787d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
11797d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty indirect goto statement.
11801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IndirectGotoStmt(EmptyShell Empty)
11817d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Stmt(IndirectGotoStmtClass, Empty) { }
11821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1183ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1184ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation getGotoLoc() const { return GotoLoc; }
11855f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  void setStarLoc(SourceLocation L) { StarLoc = L; }
11865f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation getStarLoc() const { return StarLoc; }
11871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
118895c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
118995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
11907d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1191b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
119295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// getConstantTarget - Returns the fixed target of this indirect
119395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// goto, if one exists.
1194ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getConstantTarget();
1195ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  const LabelDecl *getConstantTarget() const {
119695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
119795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  }
119895c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall
119963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
1200ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner    return SourceRange(GotoLoc, Target->getLocEnd());
1201ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  }
12021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IndirectGotoStmtClass;
12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IndirectGotoStmt *) { return true; }
12071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12088297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
120963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Target, &Target+1); }
12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue.
12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt {
1216507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation ContinueLoc;
12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1218507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1220d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty continue statement.
1221d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1222d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1223d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getContinueLoc() const { return ContinueLoc; }
1224d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1225d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
122663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ContinueLoc);
1228507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
1229861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor
12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ContinueStmtClass;
12325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ContinueStmt *) { return true; }
12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12358297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
123663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break.
12405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt {
1242507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation BreakLoc;
12435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1244507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1246025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty break statement.
1247025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1248025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1249025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getBreakLoc() const { return BreakLoc; }
1250025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1251025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
125263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(BreakLoc); }
1253b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BreakStmtClass;
12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BreakStmt *) { return true; }
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
126063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1264c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression:
1265c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return;
1266c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return 4;
1267c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///
1268c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to
1269c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to
1270c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void.  We explicitly model this in the AST, which means you can't
1271c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument.
12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt {
12741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *RetExpr;
1275507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation RetLoc;
12765077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *NRVOCandidate;
1277ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12795077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL)
128025a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
12815077c3876beeaed32280af88244e8050078619a8Douglas Gregor
12825077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
12835077c3876beeaed32280af88244e8050078619a8Douglas Gregor    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
12845077c3876beeaed32280af88244e8050078619a8Douglas Gregor      NRVOCandidate(NRVOCandidate) {}
12850de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
12860de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  /// \brief Build an empty return expression.
12870de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
12880de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
12891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getRetValue() const;
12901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getRetValue();
12910de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
12920de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
12930de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  SourceLocation getReturnLoc() const { return RetLoc; }
12940de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1295b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
12965077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// \brief Retrieve the variable that might be used for the named return
12975077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// value optimization.
12985077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ///
12995077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// The optimization itself can only be performed if the variable is
13005077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// also marked as an NRVO object.
13015077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
13025077c3876beeaed32280af88244e8050078619a8Douglas Gregor  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1303ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
130463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ReturnStmtClass;
13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReturnStmt *) { return true; }
13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
131263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
131363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
131463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range();
131563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1318fe795956194141c91ae555985c9b930595bff43fChris Lattner/// AsmStmt - This represents a GNU inline-assembly statement extension.
1319fe795956194141c91ae555985c9b930595bff43fChris Lattner///
1320fe795956194141c91ae555985c9b930595bff43fChris Lattnerclass AsmStmt : public Stmt {
1321fe795956194141c91ae555985c9b930595bff43fChris Lattner  SourceLocation AsmLoc, RParenLoc;
13226a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  StringLiteral *AsmStr;
1323b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1324dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson  bool IsSimple;
132539c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson  bool IsVolatile;
13263b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump  bool MSAsm;
13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1328b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  unsigned NumOutputs;
1329b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  unsigned NumInputs;
1330966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  unsigned NumClobbers;
13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1332966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  // FIXME: If we wanted to, we could allocate all of these in one big array.
1333966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  IdentifierInfo **Names;
1334966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Constraints;
1335966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  Stmt **Exprs;
1336966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Clobbers;
1337ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1338fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic:
1339ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile,
1340966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson          bool msasm, unsigned numoutputs, unsigned numinputs,
1341ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson          IdentifierInfo **names, StringLiteral **constraints,
1342db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner          Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
1343db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner          StringLiteral **clobbers, SourceLocation rparenloc);
1344b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1345cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  /// \brief Build an empty inline-assembly statement.
1346ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty),
1347966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    Names(0), Constraints(0), Exprs(0), Clobbers(0) { }
1348cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1349cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getAsmLoc() const { return AsmLoc; }
1350cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1351cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1352cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1353cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
135439c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson  bool isVolatile() const { return IsVolatile; }
1355cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setVolatile(bool V) { IsVolatile = V; }
1356dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson  bool isSimple() const { return IsSimple; }
13576ffe643322949dd776285a6df60d3578f3918be4Chris Lattner  void setSimple(bool V) { IsSimple = V; }
13583b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump  bool isMSAsm() const { return MSAsm; }
13593b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump  void setMSAsm(bool V) { MSAsm = V; }
1360dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson
1361458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  //===--- Asm String Analysis ---===//
1362458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1363458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  const StringLiteral *getAsmString() const { return AsmStr; }
1364458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  StringLiteral *getAsmString() { return AsmStr; }
1365cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmString(StringLiteral *E) { AsmStr = E; }
1366cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1367458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AsmStringPiece - this is part of a decomposed asm string specification
1368458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// (for use with the AnalyzeAsmString function below).  An asm string is
1369458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// considered to be a concatenation of these parts.
1370458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  class AsmStringPiece {
1371458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1372458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    enum Kind {
1373458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1374458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Operand  // Operand reference, with optional modifier %c4.
1375458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    };
1376458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  private:
1377458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    Kind MyKind;
1378458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    std::string Str;
1379458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned OperandNo;
1380458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1381458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1382458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(unsigned OpNo, char Modifier)
1383458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      : MyKind(Operand), Str(), OperandNo(OpNo) {
1384458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Str += Modifier;
1385458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1387458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isString() const { return MyKind == String; }
1388458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isOperand() const { return MyKind == Operand; }
13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1390458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    const std::string &getString() const {
1391458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isString());
1392458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str;
1393458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1394458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1395458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned getOperandNo() const {
1396458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1397458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return OperandNo;
1398458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1400458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// getModifier - Get the modifier for this operand, if present.  This
1401458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// returns '\0' if there was no modifier.
1402458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    char getModifier() const {
1403458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1404458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str[0];
1405458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1406458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  };
14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1408458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1409458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// it into pieces.  If the asm string is erroneous, emit errors and return
1410458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// true, otherwise return false.  This handles canonicalization and
1411458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
14121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1413686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1414fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner                            ASTContext &C, unsigned &DiagOffs) const;
14151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1417b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Output operands ---===//
1418b327793860737d1c103a73aeda8057dd628a101dChris Lattner
1419b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  unsigned getNumOutputs() const { return NumOutputs; }
1420ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
1421ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1422ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Names[i];
1423ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1424ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
1425686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputName(unsigned i) const {
1426ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    if (IdentifierInfo *II = getOutputIdentifier(i))
1427ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson      return II->getName();
1428ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1429686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    return StringRef();
1430ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  }
1431ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson
1432b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// getOutputConstraint - Return the constraint string for the specified
1433b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// output operand.  All output constraints are known to be non-empty (either
1434b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// '=' or '+').
1435686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputConstraint(unsigned i) const;
14361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1437b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1438ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i];
1439ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1440b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1441b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return Constraints[i];
1442b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1444ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getOutputExpr(unsigned i);
14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1446b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getOutputExpr(unsigned i) const {
1447b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return const_cast<AsmStmt*>(this)->getOutputExpr(i);
1448b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1450b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// isOutputPlusConstraint - Return true if the specified output constraint
1451b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// is a "+" constraint (which is both an input and an output) or false if it
1452b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// is an "=" constraint (just an output).
1453b327793860737d1c103a73aeda8057dd628a101dChris Lattner  bool isOutputPlusConstraint(unsigned i) const {
1454b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return getOutputConstraint(i)[0] == '+';
1455b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
145785759278332404e96d4bb89d0e976e46158cd026Chris Lattner  /// getNumPlusOperands - Return the number of output operands that have a "+"
145885759278332404e96d4bb89d0e976e46158cd026Chris Lattner  /// constraint.
145985759278332404e96d4bb89d0e976e46158cd026Chris Lattner  unsigned getNumPlusOperands() const;
14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1461b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Input operands ---===//
14621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumInputs() const { return NumInputs; }
14641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1465ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  IdentifierInfo *getInputIdentifier(unsigned i) const {
1466ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Names[i + NumOutputs];
1467ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
14681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1469686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputName(unsigned i) const {
1470ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    if (IdentifierInfo *II = getInputIdentifier(i))
1471ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson      return II->getName();
1472ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson
1473686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    return StringRef();
1474ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  }
1475ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson
1476b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// getInputConstraint - Return the specified input constraint.  Unlike output
1477b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// constraints, these can be empty.
1478686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputConstraint(unsigned i) const;
14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1480b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1481ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1482ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1483b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getInputConstraintLiteral(unsigned i) {
1484ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1485ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
14861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1487ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getInputExpr(unsigned i);
1488935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner  void setInputExpr(unsigned i, Expr *E);
1489ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1490b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getInputExpr(unsigned i) const {
1491b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return const_cast<AsmStmt*>(this)->getInputExpr(i);
1492b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
1493cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1494acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson  void setOutputsAndInputsAndClobbers(ASTContext &C,
1495ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                      IdentifierInfo **Names,
1496fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Constraints,
1497fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      Stmt **Exprs,
1498fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumOutputs,
1499ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      unsigned NumInputs,
1500fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Clobbers,
1501fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumClobbers);
1502cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
150310ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  //===--- Other ---===//
15041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
150510ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// getNamedOperand - Given a symbolic operand reference like %[foo],
150610ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// translate this into a numeric value needed to reference the same operand.
150710ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// This returns -1 if the operand name is invalid.
1508686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  int getNamedOperand(StringRef SymbolicName) const;
150910ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner
1510966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  unsigned getNumClobbers() const { return NumClobbers; }
1511b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  StringLiteral *getClobber(unsigned i) { return Clobbers[i]; }
1512d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson  const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; }
1513cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
151463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
1515fe795956194141c91ae555985c9b930595bff43fChris Lattner    return SourceRange(AsmLoc, RParenLoc);
1516fe795956194141c91ae555985c9b930595bff43fChris Lattner  }
15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1518fe795956194141c91ae555985c9b930595bff43fChris Lattner  static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;}
1519fe795956194141c91ae555985c9b930595bff43fChris Lattner  static bool classof(const AsmStmt *) { return true; }
15201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1521ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek  // Input expr iterators.
15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1523ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ExprIterator inputs_iterator;
1524ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ConstExprIterator const_inputs_iterator;
15251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1526ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  inputs_iterator begin_inputs() {
1527966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1528ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
15291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1530ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  inputs_iterator end_inputs() {
1531966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs + NumInputs;
1532ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1534ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  const_inputs_iterator begin_inputs() const {
1535966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1536ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
15371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1538ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  const_inputs_iterator end_inputs() const {
1539966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs + NumInputs;
1540d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1542ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek  // Output expr iterators.
15431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1544ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ExprIterator outputs_iterator;
1545ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ConstExprIterator const_outputs_iterator;
15461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1547d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  outputs_iterator begin_outputs() {
1548966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0];
1549d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
1550d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  outputs_iterator end_outputs() {
1551966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1552d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1554d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  const_outputs_iterator begin_outputs() const {
1555966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0];
1556d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
1557d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  const_outputs_iterator end_outputs() const {
1558966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1559d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
15601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
156163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
156263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
156363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
1564fe795956194141c91ae555985c9b930595bff43fChris Lattner};
156578492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek
156628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt {
156728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
156828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
156928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
157028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { FILTER_EXPR, BLOCK };
157128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
157228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt(SourceLocation Loc,
157328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Expr *FilterExpr,
157428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Stmt *Block);
157528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
15767110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
15777110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
15787110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
15797110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
158028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
158128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHExceptStmt* Create(ASTContext &C,
158228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation ExceptLoc,
158328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Expr *FilterExpr,
158428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Block);
158528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceRange getSourceRange() const {
158628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getExceptLoc(), getEndLoc());
158728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
158828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
158928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getExceptLoc() const { return Loc; }
159028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
159128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1592ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getFilterExpr() const {
1593ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1594ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1595ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1596ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt *getBlock() const {
1597ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return llvm::cast<CompoundStmt>(Children[BLOCK]);
1598ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
159928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
160028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
160128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
160228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
160328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
160428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
160528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHExceptStmtClass;
160628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
160728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
160828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHExceptStmt *) { return true; }
160928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
161028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
161128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
161228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt {
161328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
161428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Block;
161528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
161628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt(SourceLocation Loc,
161728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                 Stmt *Block);
161828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
16197110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
16207110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
16217110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
16227110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
162328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
162428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHFinallyStmt* Create(ASTContext &C,
162528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                SourceLocation FinallyLoc,
162628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                Stmt *Block);
162728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
162828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceRange getSourceRange() const {
162928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getFinallyLoc(), getEndLoc());
163028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
163128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
163228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getFinallyLoc() const { return Loc; }
163328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
163428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
163528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); }
163628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
163728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
163828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(&Block,&Block+1);
163928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
164028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
164128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
164228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHFinallyStmtClass;
164328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
164428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
164528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHFinallyStmt *) { return true; }
164628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
164728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
164828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
164928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt {
165028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool            IsCXXTry;
165128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  TryLoc;
165228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
165328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
165428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { TRY = 0, HANDLER = 1 };
165528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
165628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
165728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             SourceLocation TryLoc,
165828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *TryBlock,
165928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *Handler);
166028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
16617110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
16627110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
16637110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
16647110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
166528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
166628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHTryStmt* Create(ASTContext &C,
166728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            bool isCXXTry,
166828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            SourceLocation TryLoc,
166928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *TryBlock,
167028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *Handler);
167128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
167228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceRange getSourceRange() const {
167328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getTryLoc(), getEndLoc());
167428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
167528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
167628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getTryLoc() const { return TryLoc; }
167728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
167828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
167928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool getIsCXXTry() const { return IsCXXTry; }
1680ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1681ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt* getTryBlock() const {
1682ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return llvm::cast<CompoundStmt>(Children[TRY]);
1683ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1684ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
168528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt *getHandler() const { return Children[HANDLER]; }
168628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
168728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Returns 0 if not defined
168828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt  *getExceptHandler() const;
168928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt *getFinallyHandler() const;
169028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
169128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
169228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
169328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
169428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
169528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
169628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHTryStmtClass;
169728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
169828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
169928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHTryStmt *) { return true; }
170028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
1701ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
17035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1705