Stmt.h revision 05ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1
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
172fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/DeclGroup.h"
189caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h"
199fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan#include "clang/Basic/CapturedStmt.h"
202fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/IdentifierTable.h"
212fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/LLVM.h"
222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/SourceLocation.h"
232fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "llvm/ADT/ArrayRef.h"
243a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir#include "llvm/ADT/PointerIntPair.h"
25aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
26a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer#include "llvm/Support/ErrorHandling.h"
276e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string>
287573098b83e780d1c5bea13b384b610d8f155676Steve Naroff
2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm {
3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  class FoldingSetNodeID;
3141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor}
3241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
34e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  class ASTContext;
352fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Attr;
366afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  class CapturedDecl;
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
382fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Expr;
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class IdentifierInfo;
40478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class LabelDecl;
412fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class ParmVarDecl;
42a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class PrinterHelper;
43a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  struct PrintingPolicy;
442fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class QualType;
45051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  class RecordDecl;
460c727a35718556866a978f64ac549d9798735f08Chris Lattner  class SourceManager;
476a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  class StringLiteral;
486c36be5b383875b490684bcf439d6d427298c1afChris Lattner  class SwitchStmt;
49a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class Token;
50478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class VarDecl;
511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  // ExprIterator - Iterators for iterating over Stmt* arrays that contain
54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  references to children (to be compatible with StmtIterator).
56ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Stmt;
59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Expr;
601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ExprIterator {
62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Stmt** I;
63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator(Stmt** i) : I(i) {}
651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExprIterator() : I(0) {}
66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator& operator++() { ++I; return *this; }
67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator-(size_t i) { return I-i; }
68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator+(size_t i) { return I+i; }
69ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator[](size_t idx);
70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    // FIXME: Verify that this will correctly return a signed distance.
71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ExprIterator& R) const { return I - R.I; }
72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator*() const;
73ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator->() const;
74ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ExprIterator& R) const { return I == R.I; }
75ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ExprIterator& R) const { return I != R.I; }
76ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ExprIterator& R) const { return I > R.I; }
77ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ExprIterator& R) const { return I >= R.I; }
78ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  };
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ConstExprIterator {
811705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    const Stmt * const *I;
82ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
831705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator(const Stmt * const *i) : I(i) {}
841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ConstExprIterator() : I(0) {}
85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ConstExprIterator& operator++() { ++I; return *this; }
861705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator+(size_t i) const { return I+i; }
871705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator-(size_t i) const { return I-i; }
88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator[](size_t idx) const;
89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ConstExprIterator& R) const { return I - R.I; }
90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator*() const;
91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator->() const;
92ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ConstExprIterator& R) const { return I == R.I; }
93ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ConstExprIterator& R) const { return I != R.I; }
94ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ConstExprIterator& R) const { return I > R.I; }
95ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  };
971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
99ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements.
100ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement.
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt {
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum StmtClass {
107f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor    NoStmtClass = 0,
108f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class,
1097381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \
1109a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
1117381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
1129a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
1137381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT)
1144bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
1158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Make vanilla 'new' and 'delete' illegal for Stmts.
1188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected:
1198189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes) throw() {
120b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
1218189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1228189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void operator delete(void* data) throw() {
123b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
1248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class StmtBitfields {
1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Stmt;
1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    /// \brief The statement class.
1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned sClass : 8;
1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  enum { NumStmtBits = 8 };
1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CompoundStmtBitfields {
1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CompoundStmt;
1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned NumStmts : 32 - NumStmtBits;
1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class ExprBitfields {
1428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Expr;
1438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DeclRefExpr; // computeDependence
1448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class InitListExpr; // ctor
1458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DesignatedInitExpr; // ctor
146d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor    friend class BlockDeclRefExpr; // ctor
147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ASTStmtReader; // deserialization
148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXNewExpr; // ctor
149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class DependentScopeDeclRefExpr; // ctor
150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXConstructExpr; // ctor
151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CallExpr; // ctor
152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OffsetOfExpr; // ctor
153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ObjCMessageExpr; // ctor
154ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCArrayLiteral; // ctor
155ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCDictionaryLiteral; // ctor
156bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ShuffleVectorExpr; // ctor
157bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ParenListExpr; // ctor
158bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXUnresolvedConstructExpr; // ctor
159bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXDependentScopeMemberExpr; // ctor
160bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OverloadExpr; // ctor
1614b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr; // ctor
162dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    friend class AtomicExpr; // ctor
1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueKind : 2;
166f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    unsigned ObjectKind : 2;
1678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned TypeDependent : 1;
1688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueDependent : 1;
169561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
170d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
172561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  enum { NumExprBits = 16 };
1738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class CharacterLiteralBitfields {
175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class CharacterLiteral;
176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
179bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
180bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
1819ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover  enum APFloatSemantics {
1829ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEhalf,
1839ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEsingle,
1849ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEdouble,
1859ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    x87DoubleExtended,
1869ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEquad,
1879ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    PPCDoubleDouble
1889ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover  };
1899ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover
190bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class FloatingLiteralBitfields {
191bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class FloatingLiteral;
192bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
193bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
1949ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    unsigned Semantics : 3; // Provides semantics for APFloat construction
195bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsExact : 1;
196bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
197bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
198bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class UnaryExprOrTypeTraitExprBitfields {
199bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class UnaryExprOrTypeTraitExpr;
200bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
201bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
202bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
203bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsType : 1; // true if operand is a type, false if an expression.
204bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
205bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
206cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  class DeclRefExprBitfields {
207cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class DeclRefExpr;
208cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class ASTStmtReader; // deserialization
209cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned : NumExprBits;
210cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
211cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasQualifier : 1;
212e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    unsigned HasTemplateKWAndArgsInfo : 1;
2133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    unsigned HasFoundDecl : 1;
2147cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    unsigned HadMultipleCandidates : 1;
215f4b88a45902af1802a1cb42ba48b1c474474f228John McCall    unsigned RefersToEnclosingLocal : 1;
216cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  };
217cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
2188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CastExprBitfields {
2198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CastExpr;
2208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumExprBits;
2218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2222bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned Kind : 6;
2232bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned BasePathSize : 32 - 6 - NumExprBits;
2248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
226cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  class CallExprBitfields {
227cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    friend class CallExpr;
228cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned : NumExprBits;
229cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
230cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned NumPreArgs : 1;
231cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  };
232cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
23380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  class ExprWithCleanupsBitfields {
23480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ExprWithCleanups;
23580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ASTStmtReader; // deserialization
23680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
23780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned : NumExprBits;
23880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
23980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned NumObjects : 32 - NumExprBits;
24080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  };
24180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
2424b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class PseudoObjectExprBitfields {
2434b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr;
2444b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class ASTStmtReader; // deserialization
2454b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2464b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned : NumExprBits;
2474b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2484b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // These don't need to be particularly wide, because they're
2494b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // strictly limited by the forms of expressions we permit.
2504b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned NumSubExprs : 8;
2514b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned ResultIndex : 32 - 8 - NumExprBits;
2524b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
2534b9c2d235fb9449e249d74f48ecfec601650de93John McCall
254f85e193739c953358c865005855253af4f68a497John McCall  class ObjCIndirectCopyRestoreExprBitfields {
255f85e193739c953358c865005855253af4f68a497John McCall    friend class ObjCIndirectCopyRestoreExpr;
256f85e193739c953358c865005855253af4f68a497John McCall    unsigned : NumExprBits;
257f85e193739c953358c865005855253af4f68a497John McCall
258f85e193739c953358c865005855253af4f68a497John McCall    unsigned ShouldCopy : 1;
259f85e193739c953358c865005855253af4f68a497John McCall  };
260f85e193739c953358c865005855253af4f68a497John McCall
26132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  class InitListExprBitfields {
26232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    friend class InitListExpr;
26332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned : NumExprBits;
26532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list originally had a GNU array-range
26732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// designator in it. This is a temporary marker used by CodeGen.
26832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned HadArrayRangeDesignator : 1;
26932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  };
27032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
2714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  class TypeTraitExprBitfields {
2724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class TypeTraitExpr;
2734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtReader;
2744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtWriter;
2754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned : NumExprBits;
2774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
2794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Kind : 8;
2804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief If this expression is not value-dependent, this indicates whether
2824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// the trait evaluated true or false.
2834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Value : 1;
2844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The number of arguments to this type trait.
2864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
2874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  };
288211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith
2898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  union {
29063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    // FIXME: this is wasteful on 64-bit platforms.
29163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    void *Aligner;
29263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
2938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBitfields StmtBits;
2948e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBitfields CompoundStmtBits;
2958e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBitfields ExprBits;
296bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    CharacterLiteralBitfields CharacterLiteralBits;
297bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    FloatingLiteralBitfields FloatingLiteralBits;
298bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
299cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    DeclRefExprBitfields DeclRefExprBits;
3008e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBitfields CastExprBits;
301cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    CallExprBitfields CallExprBits;
30280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    ExprWithCleanupsBitfields ExprWithCleanupsBits;
3034b9c2d235fb9449e249d74f48ecfec601650de93John McCall    PseudoObjectExprBitfields PseudoObjectExprBits;
304f85e193739c953358c865005855253af4f68a497John McCall    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
30532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    InitListExprBitfields InitListExprBits;
3064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeTraitExprBitfields TypeTraitExprBits;
3078e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
3088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
309d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  friend class ASTStmtReader;
3104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
311d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
3128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic:
3138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Only allow allocation of Stmts using the allocator in ASTContext
3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // or by doing a placement new.
31505ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper  void* operator new(size_t bytes, const ASTContext& C,
3162fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer                     unsigned alignment = 8) throw();
3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31805ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper  void* operator new(size_t bytes, const ASTContext* C,
3192fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer                     unsigned alignment = 8) throw();
3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3218189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, void* mem) throw() {
3228189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return mem;
3238189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
324e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
32505ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper  void operator delete(void*, const ASTContext&, unsigned) throw() { }
32605ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper  void operator delete(void*, const ASTContext*, unsigned) throw() { }
32705ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper  void operator delete(void*, size_t) throw() { }
328fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, void*) throw() { }
329e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
330025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic:
331025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief A placeholder type used to construct an empty shell of a
332025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// type, that will be filled in later (e.g., by some
333025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// de-serialization).
334025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  struct EmptyShell { };
335025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
33602892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate:
33702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  /// \brief Whether statistic collection is enabled.
33802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static bool StatisticsEnabled;
33902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar
3409c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected:
341025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Construct an empty statement.
3428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  explicit Stmt(StmtClass SC, EmptyShell) {
3438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
34402892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
345025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  }
346025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3488e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt(StmtClass SC) {
3498e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
35002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
353ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  StmtClass getStmtClass() const {
3548e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    return static_cast<StmtClass>(StmtBits.sClass);
355b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor  }
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStmtClassName() const;
3571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
358b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// SourceLocation tokens are not useful in isolation - they are low level
359b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// value objects created/interpreted by SourceManager. We assume AST
360b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// clients will have a pointer to the respective SourceManager.
361aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
362aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
363aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // global temp stats (until we have a per-module visitor)
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void addStmtClass(const StmtClass s);
36702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static void EnableStatistics();
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void PrintStats();
3696000dace22f110d8768476989313e9d981d690d0Chris Lattner
37095f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \brief Dumps the specified AST fragment and all subtrees to
37195f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \c llvm::errs().
372f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump() const;
373f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
3748cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS, SourceManager &SM) const;
3756000dace22f110d8768476989313e9d981d690d0Chris Lattner
3767ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu  /// dumpColor - same as dump(), but forces color highlighting.
3777ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu  LLVM_ATTRIBUTE_USED void dumpColor() const;
3787ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu
3796000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
3806000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// back to its original source language syntax.
381d1420c6fa788669e49f21e184927c7833881e399Richard Smith  void dumpPretty(ASTContext &Context) const;
3828cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
383e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
384d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                   unsigned Indentation = 0) const;
3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
386d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
387d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
388d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  void viewAST() const;
3891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3907e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// Skip past any implicit AST nodes which might surround this
3917e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
3927e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  Stmt *IgnoreImplicit();
3937e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
394a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  const Stmt *stripLabelLikeStatements() const;
395a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  Stmt *stripLabelLikeStatements() {
396a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth    return const_cast<Stmt*>(
397a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
398a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  }
399a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth
40063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// Child Iterators: All subclasses must implement 'children'
40163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// to permit easy iteration over the substatements/subexpessions of an
40263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// AST node.  This permits easy iteration over all nodes in the AST.
4039caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef StmtIterator       child_iterator;
4049caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef ConstStmtIterator  const_child_iterator;
4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef StmtRange          child_range;
40763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef ConstStmtRange     const_child_range;
4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
41063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_range children() const {
41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return const_cast<Stmt*>(this)->children();
41277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
4131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_begin() { return children().first; }
41563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_end() { return children().second; }
41663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_begin() const { return children().first; }
41863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_end() const { return children().second; }
41941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
42041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Produce a unique representation of the given statement.
42141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42270517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param ID once the profiling operation is complete, will contain
42341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// the unique representation of the given statement.
42441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42570517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Context the AST context in which the statement resides
42641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42770517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Canonical whether the profile should be based on the canonical
42841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// representation of this statement (e.g., where non-type template
4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// parameters are identified by index/level rather than their
43041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// declaration pointers) or the exact representation of the statement as
43141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// written in the source.
4324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
433b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth               bool Canonical) const;
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions
4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration.
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt {
4429653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor  DeclGroupRef DG;
44381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation StartLoc, EndLoc;
4441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
4478ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
4488ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek                                    StartLoc(startLoc), EndLoc(endLoc) {}
4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  /// \brief Build an empty declaration statement.
45184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
45284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4537e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  /// isSingleDecl - This method returns true if this DeclStmt refers
454fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner  /// to a single Decl.
4557e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  bool isSingleDecl() const {
456fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner    return DG.isSingleDecl();
4578ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  }
4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4597e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Decl *getSingleDecl() { return DG.getSingleDecl(); }
4611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
462e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  const DeclGroupRef getDeclGroup() const { return DG; }
463e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  DeclGroupRef getDeclGroup() { return DG; }
46484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
465b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
46681c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
46784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setStartLoc(SourceLocation L) { StartLoc = L; }
46881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
46984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setEndLoc(SourceLocation L) { EndLoc = L; }
47084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
47165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
47265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DeclStmtClass;
4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47814f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek  // Iterators over subexpressions.
47963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
48063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(child_iterator(DG.begin(), DG.end()),
48163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       child_iterator(DG.end(), DG.end()));
48263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4840632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::iterator decl_iterator;
4850632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::const_iterator const_decl_iterator;
4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4878ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_begin() { return DG.begin(); }
4888ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_end() { return DG.end(); }
4898ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_begin() const { return DG.begin(); }
4908ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_end() const { return DG.end(); }
491fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose
492fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
493fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rbegin() {
494fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_end());
495fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
496fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rend() {
497fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_begin());
498fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3.
5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt {
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation SemiLoc;
50544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
506e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  /// \brief True if the null statement was preceded by an empty macro, e.g:
50744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @code
50844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   #define CALL(x)
50944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   CALL(0);
51044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @endcode
511e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool HasLeadingEmptyMacro;
5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
513e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
514e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis    : Stmt(NullStmtClass), SemiLoc(L),
515e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
517025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty null statement.
518e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
519e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(false) { }
520025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getSemiLoc() const { return SemiLoc; }
522025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
523b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
524e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
52544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
52665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
52765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
5281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == NullStmtClass;
5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
53444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
53544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtReader;
53644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtWriter;
5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }.
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt {
5428189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  Stmt** Body;
543b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation LBracLoc, RBracLoc;
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
545d36aa359e2f45cd22c7366a015ad94de08044dbbNico Weber  CompoundStmt(ASTContext &C, ArrayRef<Stmt*> Stmts,
5463a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer               SourceLocation LB, SourceLocation RB);
5473a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer
5483a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  // \brief Build an empty compound statment with a location.
5493a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  explicit CompoundStmt(SourceLocation Loc)
5503a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) {
5513a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    CompoundStmtBits.NumStmts = 0;
5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
553025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
554025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  // \brief Build an empty compound statement.
555025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CompoundStmt(EmptyShell Empty)
5568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    : Stmt(CompoundStmtClass, Empty), Body(0) {
5578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = 0;
5588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
559025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
560025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
5611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
5638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned size() const { return CompoundStmtBits.NumStmts; }
564025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5658189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt** body_iterator;
5668189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  body_iterator body_begin() { return Body; }
5678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  body_iterator body_end() { return Body + size(); }
5688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
569ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setLastStmt(Stmt *S) {
5718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    assert(!body_empty() && "setLastStmt");
5728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Body[size()-1] = S;
5738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5758189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt* const * const_body_iterator;
5768189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_body_iterator body_begin() const { return Body; }
5778e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const_body_iterator body_end() const { return Body + size(); }
5788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
5798189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek
5808189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
5818189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rbegin() {
5828189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_end());
5838189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5848189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rend() {
5858189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_begin());
5868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5874ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5888189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<const_body_iterator>
5898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek          const_reverse_body_iterator;
5904ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5918189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rbegin() const {
5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_end());
5938189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rend() const {
5968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_begin());
5978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
60065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
6011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
602cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getLBracLoc() const { return LBracLoc; }
603025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
604cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getRBracLoc() const { return RBracLoc; }
605025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundStmtClass;
6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
61263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
61363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
61463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
615ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6168ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  const_child_range children() const {
6178ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
6188ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  }
6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
621c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt,
622c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt {
623103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected:
624c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // A pointer to the following CaseStmt or DefaultStmt class,
625c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // used by SwitchStmt.
626c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *NextSwitchCase;
62781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation KeywordLoc;
62881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation ColonLoc;
62981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis
63081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
63181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {}
632103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek
63381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SwitchCase(StmtClass SC, EmptyShell)
63481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : Stmt(SC), NextSwitchCase(0) {}
6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
636c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic:
637c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
638c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
639c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
640c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
641c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
642d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek
64381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getKeywordLoc() const { return KeywordLoc; }
64481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
64581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getColonLoc() const { return ColonLoc; }
64681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setColonLoc(SourceLocation L) { ColonLoc = L; }
64781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis
64863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  Stmt *getSubStmt();
649702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  const Stmt *getSubStmt() const {
650702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner    return const_cast<SwitchCase*>(this)->getSubStmt();
651702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  }
652b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
65381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
65481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocEnd() const LLVM_READONLY;
6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass ||
65863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall           T->getStmtClass() == DefaultStmtClass;
659c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
660c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson};
661c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
662c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase {
6630a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor  enum { LHS, RHS, SUBSTMT, END_EXPR };
6641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
665d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek                             // GNU "case 1 ... 4" extension
666dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation EllipsisLoc;
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
668dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation ellipsisLoc, SourceLocation colonLoc)
67081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
67124e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner    SubExprs[SUBSTMT] = 0;
672d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
673d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
674dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    EllipsisLoc = ellipsisLoc;
675d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  }
676025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
677025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty switch case statement.
67881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
679025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
68081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getCaseLoc() const { return KeywordLoc; }
68181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
682dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
683dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
684dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
685dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
686025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
687d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
688d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
689d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
690025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getLHS() const {
6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
69351b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const {
6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
69651b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
69751b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
69920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
70020dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
70120dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
7021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
70381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
70465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
7053fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    // Handle deeply nested case statements with iteration instead of recursion.
7063fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    const CaseStmt *CS = this;
70791ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
7083fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner      CS = CS2;
7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return CS->getSubStmt()->getLocEnd();
711b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
71265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass;
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
717d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
71863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
71963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
72063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
723c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase {
724d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt* SubStmt;
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
72781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
728025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
729025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty default statement.
73081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  explicit DefaultStmt(EmptyShell Empty)
73181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : SwitchCase(DefaultStmtClass, Empty) { }
732025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
733d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubStmt; }
73451b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubStmt; }
735025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSubStmt(Stmt *S) { SubStmt = S; }
736025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
73781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getDefaultLoc() const { return KeywordLoc; }
73881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
739dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
740dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
74281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
74365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
74465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DefaultStmtClass;
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
749d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
75063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
75381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidisinline SourceLocation SwitchCase::getLocEnd() const {
75481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
75581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    return CS->getLocEnd();
75681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  return cast<DefaultStmt>(this)->getLocEnd();
75781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis}
758ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
759ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement.  For example:
760ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///    foo: return;
761ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt {
763ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *TheDecl;
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *SubStmt;
765b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IdentLoc;
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
767ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
768ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
7698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
7701de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
7711de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  // \brief Build an empty label statement.
7721de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getIdentLoc() const { return IdentLoc; }
775ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getDecl() const { return TheDecl; }
776ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setDecl(LabelDecl *D) { TheDecl = D; }
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *getSubStmt() { return SubStmt; }
7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Stmt *getSubStmt() const { return SubStmt; }
7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setSubStmt(Stmt *SS) { SubStmt = SS; }
782b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
78365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
78465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
78565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
78663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
78763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
7881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == LabelStmtClass;
7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
794534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement.
795534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
796534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example:
797534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///   [[omp::for(...)]] for (...) { ... }
798534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
799534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt {
800534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *SubStmt;
801534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation AttrLoc;
8024990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  unsigned NumAttrs;
8034990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  const Attr *Attrs[1];
804534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
805534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  friend class ASTStmtReader;
806534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8074990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
8084990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
8094990890fc9428f98bef90ba349203a648c592778Alexander Kornienko      NumAttrs(Attrs.size()) {
8104990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*));
811534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
812534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8134990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
8144990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
8154990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memset(Attrs, 0, NumAttrs * sizeof(Attr*));
816534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
817534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8184990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic:
8194990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *Create(ASTContext &C, SourceLocation Loc,
8204990890fc9428f98bef90ba349203a648c592778Alexander Kornienko                                ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
8214990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  // \brief Build an empty attributed statement.
8224990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs);
8234990890fc9428f98bef90ba349203a648c592778Alexander Kornienko
824534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation getAttrLoc() const { return AttrLoc; }
8254990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  ArrayRef<const Attr*> getAttrs() const {
8264990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    return ArrayRef<const Attr*>(Attrs, NumAttrs);
8274990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  }
828534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *getSubStmt() { return SubStmt; }
829534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  const Stmt *getSubStmt() const { return SubStmt; }
830534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
83165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
83265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
83365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
834534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
835534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
836534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  static bool classof(const Stmt *T) {
837534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return T->getStmtClass() == AttributedStmtClass;
838534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
839534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith};
840534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
841534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else.
8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt {
84543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, THEN, ELSE, END_EXPR };
8468297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
8478cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor
848b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IfLoc;
849d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation ElseLoc;
850ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
852ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
85344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
854ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
855025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty if/then/else statement
856025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
857025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
8588cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \brief Retrieve the variable declared in this "if" statement, if any.
8598cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///
8608cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// In the following example, "x" is the condition variable.
8618cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \code
8628cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// if (int x = foo()) {
8638cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///   printf("x is %d", x);
8648cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// }
8658cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \endcode
86643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
86743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
868ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
869d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this IfStmt has a condition variable, return the faux DeclStmt
870d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
871d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
872d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
873d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
874ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
876025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
8778297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getThen() const { return SubExprs[THEN]; }
8781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setThen(Stmt *S) { SubExprs[THEN] = S; }
8798297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getElse() const { return SubExprs[ELSE]; }
880025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8828297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
8838297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getThen() { return SubExprs[THEN]; }
8848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getElse() { return SubExprs[ELSE]; }
885b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
886025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getIfLoc() const { return IfLoc; }
887025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setIfLoc(SourceLocation L) { IfLoc = L; }
888d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation getElseLoc() const { return ElseLoc; }
889d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  void setElseLoc(SourceLocation L) { ElseLoc = L; }
890025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
89165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
89265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
893b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    if (SubExprs[ELSE])
89465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return SubExprs[ELSE]->getLocEnd();
895b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    else
89665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return SubExprs[THEN]->getLocEnd();
897b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
89963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators over subexpressions.  The iterators will include iterating
90063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // over the initialization expression referenced by the condition variable.
90163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
90263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
90363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
90463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
9051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IfStmtClass;
9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt.
9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt {
91343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
915c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // This points to a linked list of case and default statements.
916c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *FirstCase;
9179dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  SourceLocation SwitchLoc;
9181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
919559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// If the SwitchStmt is a switch on an enum value, this records whether
920559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// all the enum values were covered by CaseStmts.  This value is meant to
921559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// be a hint for possible clients.
922559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  unsigned AllEnumCasesCovered : 1;
923559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
92543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
927025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build a empty switch statement.
928025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
929025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
930d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \brief Retrieve the variable declared in this "switch" statement, if any.
931d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///
932d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// In the following example, "x" is the condition variable.
933d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \code
934d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// switch (int x = foo()) {
935d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   case 0: break;
936d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   // ...
937d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// }
938d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \endcode
93943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
94043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
941ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
942d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
943d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
944d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
945d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
946d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
947d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor
9488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
9498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
950c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
951c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9528297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
953025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
9548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
955025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
956c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getSwitchCaseList() { return FirstCase; }
9571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
95843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Set the case list for this switch statement.
959025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
960025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
961025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getSwitchLoc() const { return SwitchLoc; }
962025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
963c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setBody(Stmt *S, SourceLocation SL) {
9651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[BODY] = S;
9669dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    SwitchLoc = SL;
9671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
968c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void addSwitchCase(SwitchCase *SC) {
969ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!SC->getNextSwitchCase()
970ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           && "case/default already added to a switch");
971c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    SC->setNextSwitchCase(FirstCase);
972c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson    FirstCase = SC;
973c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
974559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
975559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
976559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// switch over an enum value then all cases have been explicitly covered.
977559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  void setAllEnumCasesCovered() {
978559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    AllEnumCasesCovered = 1;
979559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
980559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
981559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
982559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// have been explicitly covered.
983559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  bool isAllEnumCasesCovered() const {
984559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    return (bool) AllEnumCasesCovered;
985559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
986559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
98765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
98865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
98965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
9909dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  }
99165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
99263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators
99363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
99463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
99563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
99663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SwitchStmtClass;
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt.
10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt {
100643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
10078297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1008b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation WhileLoc;
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1010ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
101143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor            SourceLocation WL);
10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1013d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty while statement.
1014d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1015d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
10165656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \brief Retrieve the variable declared in this "while" statement, if any.
10175656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///
10185656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// In the following example, "x" is the condition variable.
10195656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \code
10205656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// while (int x = random()) {
10215656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///   // ...
10225656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// }
10235656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \endcode
102443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
102543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
10265656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
1027d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1028d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1029d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1030d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1031d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1032d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
10338297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10348297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1035d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10368297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10378297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1038d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1039d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1040d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
1041d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1042b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
104365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
104465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
104565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
1046b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
104765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == WhileStmtClass;
10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10528297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
105363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
105463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
105563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt.
10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt {
1061c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor  enum { BODY, COND, END_EXPR };
10628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1063b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation DoLoc;
10649f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation WhileLoc;
1065989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
10669f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1068989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1069989135901c750af61ef012b6b0a0368be415bc46Chris Lattner         SourceLocation RP)
1070989135901c750af61ef012b6b0a0368be415bc46Chris Lattner    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
10718297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
10728297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[BODY] = body;
10731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
107467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
107567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty do-while statement.
107667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10788297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10798297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
108067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Stmt *getBody() const { return SubExprs[BODY]; }
108367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
108467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
108567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getDoLoc() const { return DoLoc; }
108667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setDoLoc(SourceLocation L) { DoLoc = L; }
10879f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
10889f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1089b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1090989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
1091989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1092989135901c750af61ef012b6b0a0368be415bc46Chris Lattner
109365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
109465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
109565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
10961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DoStmtClass;
10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10998297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11008297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
110163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
110263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
110363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not
11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source.
11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt {
111243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
11138297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1114b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation ForLoc;
11155831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation LParenLoc, RParenLoc;
11165831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor
11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1118ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
111943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
112167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty for statement.
112267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
112367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
11248297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getInit() { return SubExprs[INIT]; }
1125ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
112699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \brief Retrieve the variable declared in this "for" statement, if any.
112799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///
112899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// In the following example, "y" is the condition variable.
112999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \code
113099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// for (int x = random(); int y = mangle(x); ++x) {
113199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///   // ...
113299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// }
113399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \endcode
113443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
113543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
1136ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1137d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this ForStmt has a condition variable, return the faux DeclStmt
1138d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1139d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1140d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1141d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1142d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
11438297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
11448297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11458297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
11468297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11478297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getInit() const { return SubExprs[INIT]; }
11488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
11498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1151b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
115267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInit(Stmt *S) { SubExprs[INIT] = S; }
115367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
115467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
115567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
115667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
115767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getForLoc() const { return ForLoc; }
115867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setForLoc(SourceLocation L) { ForLoc = L; }
11595831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
11605831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
11615831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11625831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
116367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
116465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
116565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
116665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
1167b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
116865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
11691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ForStmtClass;
11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11738297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
117463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
117563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
117663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto.
11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt {
1182ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
1183507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation GotoLoc;
118461f62165220e75694fe333179c78815e2e48d71fTed Kremenek  SourceLocation LabelLoc;
11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1186ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
118761f62165220e75694fe333179c78815e2e48d71fTed Kremenek    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11891de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Build an empty goto statement.
11901de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
11911de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1192ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
1193ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *D) { Label = D; }
11941de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
11951de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getGotoLoc() const { return GotoLoc; }
11961de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
11971de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
11981de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1199b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
120065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
120165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
120265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GotoStmtClass;
12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12078297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
120863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto.
12125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt {
1214ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation GotoLoc;
12155f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation StarLoc;
12161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Target;
12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
12195f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor                   Expr *target)
12205f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
12215f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor      Target((Stmt*)target) {}
12227d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
12237d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty indirect goto statement.
12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IndirectGotoStmt(EmptyShell Empty)
12257d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Stmt(IndirectGotoStmtClass, Empty) { }
12261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1227ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1228ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation getGotoLoc() const { return GotoLoc; }
12295f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  void setStarLoc(SourceLocation L) { StarLoc = L; }
12305f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation getStarLoc() const { return StarLoc; }
12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
123295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
123395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
12347d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1235b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
123695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// getConstantTarget - Returns the fixed target of this indirect
123795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// goto, if one exists.
1238ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getConstantTarget();
1239ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  const LabelDecl *getConstantTarget() const {
124095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
124195c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  }
124295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall
124365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
124465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IndirectGotoStmtClass;
12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
125163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Target, &Target+1); }
12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue.
12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt {
1258507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation ContinueLoc;
12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1260507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
12611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1262d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty continue statement.
1263d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1264d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1265d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getContinueLoc() const { return ContinueLoc; }
1266d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1267d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
126865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
126965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1270861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor
12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ContinueStmtClass;
12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
127663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break.
12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt {
1282507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation BreakLoc;
12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1284507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
12851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1286025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty break statement.
1287025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1288025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1289025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getBreakLoc() const { return BreakLoc; }
1290025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1291025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
129265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
129365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1294b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
12951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BreakStmtClass;
12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12998297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
130063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1304c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression:
1305c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return;
1306c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return 4;
1307c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///
1308c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to
1309c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to
1310c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void.  We explicitly model this in the AST, which means you can't
1311c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument.
13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt {
13141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *RetExpr;
1315507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation RetLoc;
13165077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *NRVOCandidate;
1317ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13195077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL)
132025a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
13215077c3876beeaed32280af88244e8050078619a8Douglas Gregor
13225077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
13235077c3876beeaed32280af88244e8050078619a8Douglas Gregor    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
13245077c3876beeaed32280af88244e8050078619a8Douglas Gregor      NRVOCandidate(NRVOCandidate) {}
13250de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13260de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  /// \brief Build an empty return expression.
13270de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
13280de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getRetValue() const;
13301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getRetValue();
13310de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
13320de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13330de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  SourceLocation getReturnLoc() const { return RetLoc; }
13340de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1335b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13365077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// \brief Retrieve the variable that might be used for the named return
13375077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// value optimization.
13385077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ///
13395077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// The optimization itself can only be performed if the variable is
13405077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// also marked as an NRVO object.
13415077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
13425077c3876beeaed32280af88244e8050078619a8Douglas Gregor  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1343ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
134465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
134565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
134665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return RetExpr ? RetExpr->getLocEnd() : RetLoc;
134765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ReturnStmtClass;
13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
135463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
135563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
135663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range();
135763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1360728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1361728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier///
1362728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass AsmStmt : public Stmt {
1363728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierprotected:
1364066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation AsmLoc;
136512b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief True if the assembly statement does not have any input or output
136612b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// operands.
1367728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsSimple;
136812b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier
136912b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief If true, treat this inline assembly as having side effects.
137012b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// This assembly statement should not be optimized, deleted or moved.
1371728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsVolatile;
1372728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1373066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumOutputs;
1374066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumInputs;
1375066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumClobbers;
1376066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
137719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  Stmt **Exprs;
1378066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1379066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1380066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier          unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1381066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1382066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1383728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1384aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  friend class ASTStmtReader;
1385aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1386728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierpublic:
1387728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  /// \brief Build an empty inline-assembly statement.
1388728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
1389aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    Stmt(SC, Empty), Exprs(0) { }
139029760b452876548f59804e8c02c3276bc7281d5dMatt Beaumont-Gay
1391066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation getAsmLoc() const { return AsmLoc; }
1392066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1393728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1394728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isSimple() const { return IsSimple; }
1395728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setSimple(bool V) { IsSimple = V; }
1396728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1397728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isVolatile() const { return IsVolatile; }
1398728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setVolatile(bool V) { IsVolatile = V; }
1399728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
140065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
140165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1402728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1403da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  //===--- Asm String Analysis ---===//
1404da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1405da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1406aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1407da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1408066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Output operands ---===//
1409066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1410066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumOutputs() const { return NumOutputs; }
1411066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1412c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getOutputConstraint - Return the constraint string for the specified
1413c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// output operand.  All output constraints are known to be non-empty (either
1414c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// '=' or '+').
1415aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getOutputConstraint(unsigned i) const;
1416c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1417c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// isOutputPlusConstraint - Return true if the specified output constraint
1418c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is a "+" constraint (which is both an input and an output) or false if it
1419c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is an "=" constraint (just an output).
1420c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  bool isOutputPlusConstraint(unsigned i) const {
1421c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier    return getOutputConstraint(i)[0] == '+';
1422c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  }
1423c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1424aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getOutputExpr(unsigned i) const;
1425c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1426c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getNumPlusOperands - Return the number of output operands that have a "+"
1427c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraint.
1428c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  unsigned getNumPlusOperands() const;
1429c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1430066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Input operands ---===//
1431066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1432066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumInputs() const { return NumInputs; }
1433066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1434c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getInputConstraint - Return the specified input constraint.  Unlike output
1435c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraints, these can be empty.
1436aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getInputConstraint(unsigned i) const;
1437aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier
1438aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getInputExpr(unsigned i) const;
1439c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1440066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Other ---===//
1441066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
14422fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier  unsigned getNumClobbers() const { return NumClobbers; }
1443aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getClobber(unsigned i) const;
14442fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier
1445728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  static bool classof(const Stmt *T) {
1446728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass ||
1447728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier      T->getStmtClass() == MSAsmStmtClass;
1448728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  }
144919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
145019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Input expr iterators.
145119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
145219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator inputs_iterator;
145319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_inputs_iterator;
145419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
145519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator begin_inputs() {
145619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
145719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
145819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
145919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator end_inputs() {
146019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
146119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
146219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
146319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator begin_inputs() const {
146419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
146519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
146619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
146719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator end_inputs() const {
146819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
146919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
147019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Output expr iterators.
147219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator outputs_iterator;
147419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_outputs_iterator;
147519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator begin_outputs() {
147719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
147819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
147919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator end_outputs() {
148019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
148119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator begin_outputs() const {
148419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
148519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator end_outputs() const {
148719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
148819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  child_range children() {
149119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
149219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
1493728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier};
1494728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
14957d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a GCC inline-assembly statement extension.
1496fe795956194141c91ae555985c9b930595bff43fChris Lattner///
1497728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass GCCAsmStmt : public AsmStmt {
1498066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation RParenLoc;
14996a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  StringLiteral *AsmStr;
1500b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1501966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  // FIXME: If we wanted to, we could allocate all of these in one big array.
1502966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Constraints;
1503966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Clobbers;
1504aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  IdentifierInfo **Names;
1505aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1506aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  friend class ASTStmtReader;
1507ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1508fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic:
1509df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
1510df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             bool isvolatile, unsigned numoutputs, unsigned numinputs,
1511df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1512df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral *asmstr, unsigned numclobbers,
1513df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral **clobbers, SourceLocation rparenloc);
1514b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1515cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  /// \brief Build an empty inline-assembly statement.
1516728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
1517aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    Constraints(0), Clobbers(0), Names(0) { }
1518cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1519cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1520cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1521cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1522458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  //===--- Asm String Analysis ---===//
1523458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1524458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  const StringLiteral *getAsmString() const { return AsmStr; }
1525458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  StringLiteral *getAsmString() { return AsmStr; }
1526cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmString(StringLiteral *E) { AsmStr = E; }
1527cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1528458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AsmStringPiece - this is part of a decomposed asm string specification
1529458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// (for use with the AnalyzeAsmString function below).  An asm string is
1530458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// considered to be a concatenation of these parts.
1531458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  class AsmStringPiece {
1532458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1533458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    enum Kind {
1534458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1535458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Operand  // Operand reference, with optional modifier %c4.
1536458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    };
1537458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  private:
1538458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    Kind MyKind;
1539458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    std::string Str;
1540458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned OperandNo;
1541458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1542458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1543458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(unsigned OpNo, char Modifier)
1544458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      : MyKind(Operand), Str(), OperandNo(OpNo) {
1545458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Str += Modifier;
1546458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1548458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isString() const { return MyKind == String; }
1549458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isOperand() const { return MyKind == Operand; }
15501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1551458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    const std::string &getString() const {
1552458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isString());
1553458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str;
1554458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1555458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1556458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned getOperandNo() const {
1557458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1558458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return OperandNo;
1559458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1561458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// getModifier - Get the modifier for this operand, if present.  This
1562458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// returns '\0' if there was no modifier.
1563458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    char getModifier() const {
1564458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1565458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str[0];
1566458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1567458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  };
15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1569458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1570458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// it into pieces.  If the asm string is erroneous, emit errors and return
1571458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// true, otherwise return false.  This handles canonicalization and
1572458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
15731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1574686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1575fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner                            ASTContext &C, unsigned &DiagOffs) const;
15761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1577da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1578da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1580b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Output operands ---===//
1581b327793860737d1c103a73aeda8057dd628a101dChris Lattner
1582aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1583aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return Names[i];
1584aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1585aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1586aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getOutputName(unsigned i) const {
1587aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    if (IdentifierInfo *II = getOutputIdentifier(i))
1588aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall      return II->getName();
1589aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1590aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return StringRef();
1591aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1592aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1593686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputConstraint(unsigned i) const;
15941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1595b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1596ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i];
1597ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1598b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1599b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return Constraints[i];
1600b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1602ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getOutputExpr(unsigned i);
16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1604b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getOutputExpr(unsigned i) const {
1605df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1606b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1608b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Input operands ---===//
16091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1610aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  IdentifierInfo *getInputIdentifier(unsigned i) const {
1611aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return Names[i + NumOutputs];
1612aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1613aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1614aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getInputName(unsigned i) const {
1615aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    if (IdentifierInfo *II = getInputIdentifier(i))
1616aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall      return II->getName();
1617aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1618aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return StringRef();
1619aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1620aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1621686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputConstraint(unsigned i) const;
16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1623b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1624ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1625ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1626b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getInputConstraintLiteral(unsigned i) {
1627ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1628ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
16291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1630ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getInputExpr(unsigned i);
1631935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner  void setInputExpr(unsigned i, Expr *E);
1632ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1633b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getInputExpr(unsigned i) const {
1634df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1635b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
1636cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1637aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate:
1638acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson  void setOutputsAndInputsAndClobbers(ASTContext &C,
1639ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                      IdentifierInfo **Names,
1640fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Constraints,
1641fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      Stmt **Exprs,
1642fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumOutputs,
1643ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      unsigned NumInputs,
1644fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Clobbers,
1645fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumClobbers);
1646aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic:
1647cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
164810ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  //===--- Other ---===//
16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
165010ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// getNamedOperand - Given a symbolic operand reference like %[foo],
165110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// translate this into a numeric value needed to reference the same operand.
165210ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// This returns -1 if the operand name is invalid.
1653686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  int getNamedOperand(StringRef SymbolicName) const;
165410ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner
165533f0558f75f70061707d1388e305b8f92f4e55deChad Rosier  StringRef getClobber(unsigned i) const;
16565c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
16575c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  const StringLiteral *getClobberStringLiteral(unsigned i) const {
16585c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier    return Clobbers[i];
16595c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  }
1660cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
166165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
166265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
16631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1664df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  static bool classof(const Stmt *T) {
1665df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass;
1666df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  }
1667fe795956194141c91ae555985c9b930595bff43fChris Lattner};
166878492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek
16697d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a Microsoft inline-assembly statement extension.
16708cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier///
1671728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass MSAsmStmt : public AsmStmt {
1672c4cca7b2408bdfd99ea0f63fec1421c1327593b2Enea Zaffanella  SourceLocation LBraceLoc, EndLoc;
1673aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef AsmStr;
16748cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
167579efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned NumAsmToks;
167679efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier
167779efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *AsmToks;
167889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef *Constraints;
167933c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier  StringRef *Clobbers;
16808cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1681aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  friend class ASTStmtReader;
1682aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
16838cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic:
16847bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc,
16857bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier            bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
1686e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            unsigned numoutputs, unsigned numinputs,
1687aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall            ArrayRef<StringRef> constraints,
1688e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            ArrayRef<Expr*> exprs, StringRef asmstr,
168989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier            ArrayRef<StringRef> clobbers, SourceLocation endloc);
16908cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1691cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier  /// \brief Build an empty MS-style inline-assembly statement.
1692728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
169389fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { }
1694cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier
16957bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  SourceLocation getLBraceLoc() const { return LBraceLoc; }
16967bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
16978cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceLocation getEndLoc() const { return EndLoc; }
16988cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setEndLoc(SourceLocation L) { EndLoc = L; }
16998cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17007bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  bool hasBraces() const { return LBraceLoc.isValid(); }
17017bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier
170279efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned getNumAsmToks() { return NumAsmToks; }
170379efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *getAsmToks() { return AsmToks; }
17048f726de55412870ef70e788b852c6cc50873e15bChad Rosier
17058cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Asm String Analysis ---===//
1706aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getAsmString() const { return AsmStr; }
17078cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1708da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1709da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1710da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
17112603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Output operands ---===//
17122603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
171389fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getOutputConstraint(unsigned i) const {
1714aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    assert(i < NumOutputs);
171589fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i];
171689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1717c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1718633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getOutputExpr(unsigned i);
1719633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17202603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getOutputExpr(unsigned i) const {
17212603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
17222603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17232603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17242603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Input operands ---===//
17252603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
172689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getInputConstraint(unsigned i) const {
1727aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    assert(i < NumInputs);
172889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i + NumOutputs];
172989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1730c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1731633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getInputExpr(unsigned i);
1732633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  void setInputExpr(unsigned i, Expr *E);
1733633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17342603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getInputExpr(unsigned i) const {
17352603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
17362603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17372603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17388cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Other ---===//
17398cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1740aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  ArrayRef<StringRef> getAllConstraints() const {
1741aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return ArrayRef<StringRef>(Constraints, NumInputs + NumOutputs);
1742aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1743aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  ArrayRef<StringRef> getClobbers() const {
1744aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return ArrayRef<StringRef>(Clobbers, NumClobbers);
1745aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1746aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  ArrayRef<Expr*> getAllExprs() const {
1747aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return ArrayRef<Expr*>(reinterpret_cast<Expr**>(Exprs),
1748aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                           NumInputs + NumOutputs);
1749aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1750aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1751aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
1752aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1753aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate:
1754aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  void initialize(ASTContext &C,
1755aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  StringRef AsmString,
1756aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  ArrayRef<Token> AsmToks,
1757aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  ArrayRef<StringRef> Constraints,
1758aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  ArrayRef<Expr*> Exprs,
1759aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  ArrayRef<StringRef> Clobbers);
1760aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic:
17614399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier
176265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
176365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
176465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
17658cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  static bool classof(const Stmt *T) {
17668cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return T->getStmtClass() == MSAsmStmtClass;
17678cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17688cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17698cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  child_range children() {
17708cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return child_range(&Exprs[0], &Exprs[0]);
17718cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17728cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier};
17738cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
177428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt {
177528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
177628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
177728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
177828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { FILTER_EXPR, BLOCK };
177928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
178028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt(SourceLocation Loc,
178128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Expr *FilterExpr,
178228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Stmt *Block);
178328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
17847110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
17857110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
17867110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
17877110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
178828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
178928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHExceptStmt* Create(ASTContext &C,
179028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation ExceptLoc,
179128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Expr *FilterExpr,
179228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Block);
179365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
179465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
179565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
179628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getExceptLoc() const { return Loc; }
179828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
179928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1800ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getFilterExpr() const {
1801ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1802ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1803ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1804ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt *getBlock() const {
1805cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(Children[BLOCK]);
1806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
180728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
180928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
181028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
181128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
181228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
181328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHExceptStmtClass;
181428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
181528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
181628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
181728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
181828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt {
181928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
182028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Block;
182128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt(SourceLocation Loc,
182328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                 Stmt *Block);
182428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18257110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18267110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18277110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
18287110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
182928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
183028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHFinallyStmt* Create(ASTContext &C,
183128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                SourceLocation FinallyLoc,
183228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                Stmt *Block);
183328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
183565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
183628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getFinallyLoc() const { return Loc; }
183828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
183928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1840cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
184128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
184228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
184328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(&Block,&Block+1);
184428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
184528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
184628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
184728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHFinallyStmtClass;
184828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
184928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
185128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt {
185328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool            IsCXXTry;
185428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  TryLoc;
185528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
185628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { TRY = 0, HANDLER = 1 };
185828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
186028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             SourceLocation TryLoc,
186128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *TryBlock,
186228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *Handler);
186328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18647110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18657110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18667110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
18677110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
186828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
186928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHTryStmt* Create(ASTContext &C,
187028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            bool isCXXTry,
187128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            SourceLocation TryLoc,
187228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *TryBlock,
187328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *Handler);
187428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
187565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
187665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
187728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
187828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getTryLoc() const { return TryLoc; }
187928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
188028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
188128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool getIsCXXTry() const { return IsCXXTry; }
1882ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1883ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt* getTryBlock() const {
1884cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(Children[TRY]);
1885ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1886ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
188728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt *getHandler() const { return Children[HANDLER]; }
188828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
188928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Returns 0 if not defined
189028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt  *getExceptHandler() const;
189128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt *getFinallyHandler() const;
189228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
189328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
189428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
189528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
189628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
189728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
189828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHTryStmtClass;
189928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
190028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
1901ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1902051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// \brief This captures a statement into a function. For example, the following
1903051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// pragma annotated compound statement can be represented as a CapturedStmt,
1904051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// and this compound statement is the body of an anonymous outlined function.
1905051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @code
1906051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// #pragma omp parallel
1907051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// {
1908051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj///   compute();
1909051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// }
1910051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @endcode
1911051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajclass CapturedStmt : public Stmt {
1912051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic:
1913051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The different capture forms: by 'this' or by reference, etc.
1914051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  enum VariableCaptureKind {
1915051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    VCK_This,
1916051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    VCK_ByRef
1917051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  };
1918051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1919051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Describes the capture of either a variable or 'this'.
1920051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  class Capture {
19213a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    llvm::PointerIntPair<VarDecl *, 1, VariableCaptureKind> VarAndKind;
1922051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    SourceLocation Loc;
1923051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1924051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  public:
1925051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Create a new capture.
1926051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1927051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \param Loc The source location associated with this capture.
1928051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1929051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \param Kind The kind of capture (this, ByRef, ...).
1930051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1931051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \param Var The variable being captured, or null if capturing this.
1932051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1933051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var = 0)
19343a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir      : VarAndKind(Var, Kind), Loc(Loc) {
1935051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      switch (Kind) {
1936051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      case VCK_This:
1937051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        assert(Var == 0 && "'this' capture cannot have a variable!");
1938051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        break;
1939051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      case VCK_ByRef:
1940051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        assert(Var && "capturing by reference must have a variable!");
1941051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        break;
1942051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      }
1943051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    }
1944051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1945051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Determine the kind of capture.
19463a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    VariableCaptureKind getCaptureKind() const { return VarAndKind.getInt(); }
1947051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1948051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Retrieve the source location at which the variable or 'this' was
1949051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// first used.
1950051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    SourceLocation getLocation() const { return Loc; }
1951051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1952051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Determine whether this capture handles the C++ 'this' pointer.
19533a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    bool capturesThis() const { return getCaptureKind() == VCK_This; }
1954051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1955051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Determine whether this capture handles a variable.
19563a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    bool capturesVariable() const { return getCaptureKind() != VCK_This; }
1957051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1958051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Retrieve the declaration of the variable being captured.
1959051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1960051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// This operation is only valid if this capture does not capture 'this'.
1961051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    VarDecl *getCapturedVar() const {
1962051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      assert(!capturesThis() && "No variable available for 'this' capture");
19633a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir      return VarAndKind.getPointer();
1964051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    }
1965dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir    friend class ASTStmtReader;
1966051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  };
1967051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1968051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajprivate:
1969051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The number of variable captured, including 'this'.
1970051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  unsigned NumCaptures;
1971051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
19729fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief The pointer part is the implicit the outlined function and the
19739fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// int part is the captured region kind, 'CR_Default' etc.
19749fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind;
1975051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1976051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl.
1977051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  RecordDecl *TheRecordDecl;
1978051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1979051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Construct a captured statement.
19809fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
19819fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan               ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
1982051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1983051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Construct an empty captured statement.
1984051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
1985051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1986051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  Stmt **getStoredStmts() const {
1987051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1);
1988051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
1989051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1990051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  Capture *getStoredCaptures() const;
1991051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1992dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
1993dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir
1994051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic:
1995051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  static CapturedStmt *Create(ASTContext &Context, Stmt *S,
19969fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan                              CapturedRegionKind Kind,
1997051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj                              ArrayRef<Capture> Captures,
1998051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj                              ArrayRef<Expr *> CaptureInits,
19996afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj                              CapturedDecl *CD, RecordDecl *RD);
2000051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2001051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  static CapturedStmt *CreateDeserialized(ASTContext &Context,
2002051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj                                          unsigned NumCaptures);
2003051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2004051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the statement being captured.
2005051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
2006051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  const Stmt *getCapturedStmt() const {
2007051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return const_cast<CapturedStmt *>(this)->getCapturedStmt();
2008051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2009051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2010051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the outlined function declaration.
20119fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  CapturedDecl *getCapturedDecl() { return CapDeclAndKind.getPointer(); }
20129fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  const CapturedDecl *getCapturedDecl() const {
20139fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    return const_cast<CapturedStmt *>(this)->getCapturedDecl();
20149fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
20159fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan
20169fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief Set the outlined function declaration.
20179fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  void setCapturedDecl(CapturedDecl *D) {
20189fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    assert(D && "null CapturedDecl");
20199fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    CapDeclAndKind.setPointer(D);
20209fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
20219fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan
20229fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief Retrieve the captured region kind.
20239fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  CapturedRegionKind getCapturedRegionKind() const {
20249fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    return CapDeclAndKind.getInt();
20259fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
20269fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan
20279fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief Set the captured region kind.
20289fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  void setCapturedRegionKind(CapturedRegionKind Kind) {
20299fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    CapDeclAndKind.setInt(Kind);
20309fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
2031051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2032051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the record declaration for captured variables.
2033051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
2034051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
20359fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief Set the record declaration for captured variables.
20369fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  void setCapturedRecordDecl(RecordDecl *D) {
20379fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    assert(D && "null RecordDecl");
20389fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    TheRecordDecl = D;
20399fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
20409fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan
2041051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief True if this variable has been captured.
2042051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  bool capturesVariable(const VarDecl *Var) const;
2043051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2044051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief An iterator that walks over the captures.
2045dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  typedef Capture *capture_iterator;
2046dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  typedef const Capture *const_capture_iterator;
2047051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2048051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve an iterator pointing to the first capture.
2049dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  capture_iterator capture_begin() { return getStoredCaptures(); }
2050dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  const_capture_iterator capture_begin() const { return getStoredCaptures(); }
2051051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2052051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve an iterator pointing past the end of the sequence of
2053051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// captures.
2054051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_iterator capture_end() const {
2055051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getStoredCaptures() + NumCaptures;
2056051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2057051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2058051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the number of captures, including 'this'.
2059051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  unsigned capture_size() const { return NumCaptures; }
2060051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2061051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Iterator that walks over the capture initialization arguments.
2062051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  typedef Expr **capture_init_iterator;
2063051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2064051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the first initialization argument.
2065051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_init_iterator capture_init_begin() const {
2066051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return reinterpret_cast<Expr **>(getStoredStmts());
2067051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2068051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2069051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the iterator pointing one past the last initialization
2070051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// argument.
2071051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_init_iterator capture_init_end() const {
2072051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return capture_init_begin() + NumCaptures;
2073051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2074051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2075051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  SourceLocation getLocStart() const LLVM_READONLY {
2076051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getCapturedStmt()->getLocStart();
2077051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2078051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  SourceLocation getLocEnd() const LLVM_READONLY {
2079051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getCapturedStmt()->getLocEnd();
2080051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2081051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  SourceRange getSourceRange() const LLVM_READONLY {
2082051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getCapturedStmt()->getSourceRange();
2083051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2084051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2085051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  static bool classof(const Stmt *T) {
2086051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return T->getStmtClass() == CapturedStmtClass;
2087051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2088051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2089051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  child_range children();
2090dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir
2091dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  friend class ASTStmtReader;
2092051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj};
2093051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
20945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
20955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2097