Stmt.h revision aeeacf725c9e0ddd64ea9764bd008e5b6873ce51
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"
192fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/IdentifierTable.h"
202fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/LLVM.h"
212fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/SourceLocation.h"
222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "llvm/ADT/ArrayRef.h"
233a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir#include "llvm/ADT/PointerIntPair.h"
24aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
25a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer#include "llvm/Support/ErrorHandling.h"
266e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string>
277573098b83e780d1c5bea13b384b610d8f155676Steve Naroff
2841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm {
2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  class FoldingSetNodeID;
3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor}
3141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
33e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  class ASTContext;
342fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Attr;
356afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  class CapturedDecl;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
372fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Expr;
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class IdentifierInfo;
39478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class LabelDecl;
402fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class ParmVarDecl;
41a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class PrinterHelper;
42a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  struct PrintingPolicy;
432fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class QualType;
44051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  class RecordDecl;
450c727a35718556866a978f64ac549d9798735f08Chris Lattner  class SourceManager;
466a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  class StringLiteral;
476c36be5b383875b490684bcf439d6d427298c1afChris Lattner  class SwitchStmt;
48a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class Token;
49478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class VarDecl;
501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
52ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  // ExprIterator - Iterators for iterating over Stmt* arrays that contain
53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  references to children (to be compatible with StmtIterator).
55ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Stmt;
58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Expr;
591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ExprIterator {
61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Stmt** I;
62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator(Stmt** i) : I(i) {}
641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExprIterator() : I(0) {}
65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator& operator++() { ++I; return *this; }
66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator-(size_t i) { return I-i; }
67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator+(size_t i) { return I+i; }
68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator[](size_t idx);
69ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    // FIXME: Verify that this will correctly return a signed distance.
70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ExprIterator& R) const { return I - R.I; }
71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator*() const;
72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator->() const;
73ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ExprIterator& R) const { return I == R.I; }
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  };
781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ConstExprIterator {
801705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    const Stmt * const *I;
81ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
821705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator(const Stmt * const *i) : I(i) {}
831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ConstExprIterator() : I(0) {}
84ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ConstExprIterator& operator++() { ++I; return *this; }
851705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator+(size_t i) const { return I+i; }
861705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator-(size_t i) const { return I-i; }
87ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator[](size_t idx) const;
88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ConstExprIterator& R) const { return I - R.I; }
89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator*() const;
90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator->() const;
91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ConstExprIterator& R) const { return I == R.I; }
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; }
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  };
961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
98ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements.
99ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement.
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt {
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum StmtClass {
106f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor    NoStmtClass = 0,
107f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class,
1087381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \
1099a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
1107381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
1119a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
1127381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT)
1134bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
1148e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Make vanilla 'new' and 'delete' illegal for Stmts.
1178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected:
1188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes) throw() {
119b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
1208189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1218189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void operator delete(void* data) throw() {
122b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
1238189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class StmtBitfields {
1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Stmt;
1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    /// \brief The statement class.
1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned sClass : 8;
1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  enum { NumStmtBits = 8 };
1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CompoundStmtBitfields {
1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CompoundStmt;
1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned NumStmts : 32 - NumStmtBits;
1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class ExprBitfields {
1418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Expr;
1428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DeclRefExpr; // computeDependence
1438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class InitListExpr; // ctor
1448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DesignatedInitExpr; // ctor
145d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor    friend class BlockDeclRefExpr; // ctor
146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ASTStmtReader; // deserialization
147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXNewExpr; // ctor
148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class DependentScopeDeclRefExpr; // ctor
149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXConstructExpr; // ctor
150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CallExpr; // ctor
151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OffsetOfExpr; // ctor
152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ObjCMessageExpr; // ctor
153ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCArrayLiteral; // ctor
154ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCDictionaryLiteral; // ctor
155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ShuffleVectorExpr; // ctor
156bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ParenListExpr; // ctor
157bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXUnresolvedConstructExpr; // ctor
158bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXDependentScopeMemberExpr; // ctor
159bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OverloadExpr; // ctor
1604b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr; // ctor
161dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    friend class AtomicExpr; // ctor
1628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueKind : 2;
165f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    unsigned ObjectKind : 2;
1668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned TypeDependent : 1;
1678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueDependent : 1;
168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
169d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
171561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  enum { NumExprBits = 16 };
1728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
173bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class CharacterLiteralBitfields {
174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class CharacterLiteral;
175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
179bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
1809ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover  enum APFloatSemantics {
1819ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEhalf,
1829ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEsingle,
1839ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEdouble,
1849ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    x87DoubleExtended,
1859ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEquad,
1869ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    PPCDoubleDouble
1879ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover  };
1889ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover
189bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class FloatingLiteralBitfields {
190bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class FloatingLiteral;
191bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
192bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
1939ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    unsigned Semantics : 3; // Provides semantics for APFloat construction
194bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsExact : 1;
195bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
196bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
197bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class UnaryExprOrTypeTraitExprBitfields {
198bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class UnaryExprOrTypeTraitExpr;
199bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
200bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
201bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
202bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsType : 1; // true if operand is a type, false if an expression.
203bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
204bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
205cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  class DeclRefExprBitfields {
206cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class DeclRefExpr;
207cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class ASTStmtReader; // deserialization
208cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned : NumExprBits;
209cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
210cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasQualifier : 1;
211e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    unsigned HasTemplateKWAndArgsInfo : 1;
2123aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    unsigned HasFoundDecl : 1;
2137cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    unsigned HadMultipleCandidates : 1;
214f4b88a45902af1802a1cb42ba48b1c474474f228John McCall    unsigned RefersToEnclosingLocal : 1;
215cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  };
216cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
2178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CastExprBitfields {
2188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CastExpr;
2198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumExprBits;
2208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2212bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned Kind : 6;
2222bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned BasePathSize : 32 - 6 - NumExprBits;
2238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
225cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  class CallExprBitfields {
226cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    friend class CallExpr;
227cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned : NumExprBits;
228cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
229cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned NumPreArgs : 1;
230cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  };
231cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
23280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  class ExprWithCleanupsBitfields {
23380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ExprWithCleanups;
23480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ASTStmtReader; // deserialization
23580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
23680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned : NumExprBits;
23780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
23880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned NumObjects : 32 - NumExprBits;
23980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  };
24080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
2414b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class PseudoObjectExprBitfields {
2424b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr;
2434b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class ASTStmtReader; // deserialization
2444b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2454b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned : NumExprBits;
2464b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2474b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // These don't need to be particularly wide, because they're
2484b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // strictly limited by the forms of expressions we permit.
2494b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned NumSubExprs : 8;
2504b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned ResultIndex : 32 - 8 - NumExprBits;
2514b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
2524b9c2d235fb9449e249d74f48ecfec601650de93John McCall
253f85e193739c953358c865005855253af4f68a497John McCall  class ObjCIndirectCopyRestoreExprBitfields {
254f85e193739c953358c865005855253af4f68a497John McCall    friend class ObjCIndirectCopyRestoreExpr;
255f85e193739c953358c865005855253af4f68a497John McCall    unsigned : NumExprBits;
256f85e193739c953358c865005855253af4f68a497John McCall
257f85e193739c953358c865005855253af4f68a497John McCall    unsigned ShouldCopy : 1;
258f85e193739c953358c865005855253af4f68a497John McCall  };
259f85e193739c953358c865005855253af4f68a497John McCall
26032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  class InitListExprBitfields {
26132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    friend class InitListExpr;
26232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned : NumExprBits;
26432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list originally had a GNU array-range
26632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// designator in it. This is a temporary marker used by CodeGen.
26732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned HadArrayRangeDesignator : 1;
26832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list initializes a std::initializer_list
27032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// object.
27132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned InitializesStdInitializerList : 1;
27232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  };
27332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
2744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  class TypeTraitExprBitfields {
2754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class TypeTraitExpr;
2764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtReader;
2774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtWriter;
2784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned : NumExprBits;
2804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
2824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Kind : 8;
2834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief If this expression is not value-dependent, this indicates whether
2854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// the trait evaluated true or false.
2864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Value : 1;
2874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The number of arguments to this type trait.
2894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
2904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  };
2914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2928e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  union {
29363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    // FIXME: this is wasteful on 64-bit platforms.
29463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    void *Aligner;
29563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
2968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBitfields StmtBits;
2978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBitfields CompoundStmtBits;
2988e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBitfields ExprBits;
299bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    CharacterLiteralBitfields CharacterLiteralBits;
300bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    FloatingLiteralBitfields FloatingLiteralBits;
301bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
302cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    DeclRefExprBitfields DeclRefExprBits;
3038e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBitfields CastExprBits;
304cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    CallExprBitfields CallExprBits;
30580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    ExprWithCleanupsBitfields ExprWithCleanupsBits;
3064b9c2d235fb9449e249d74f48ecfec601650de93John McCall    PseudoObjectExprBitfields PseudoObjectExprBits;
307f85e193739c953358c865005855253af4f68a497John McCall    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
30832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    InitListExprBitfields InitListExprBits;
3094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeTraitExprBitfields TypeTraitExprBits;
3108e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
3118e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
312d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  friend class ASTStmtReader;
3134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
314d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
3158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic:
3168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Only allow allocation of Stmts using the allocator in ASTContext
3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // or by doing a placement new.
3188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext& C,
3192fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer                     unsigned alignment = 8) throw();
3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3218189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext* C,
3222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer                     unsigned alignment = 8) throw();
3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, void* mem) throw() {
3258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return mem;
3268189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
327e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
328fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext&, unsigned) throw() { }
329fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext*, unsigned) throw() { }
330e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor  void operator delete(void*, std::size_t) throw() { }
331fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, void*) throw() { }
332e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
333025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic:
334025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief A placeholder type used to construct an empty shell of a
335025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// type, that will be filled in later (e.g., by some
336025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// de-serialization).
337025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  struct EmptyShell { };
338025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
33902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate:
34002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  /// \brief Whether statistic collection is enabled.
34102892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static bool StatisticsEnabled;
34202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar
3439c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected:
344025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Construct an empty statement.
3458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  explicit Stmt(StmtClass SC, EmptyShell) {
3468e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
34702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
348025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  }
349025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3518e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt(StmtClass SC) {
3528e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
35302892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
356ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  StmtClass getStmtClass() const {
3578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    return static_cast<StmtClass>(StmtBits.sClass);
358b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor  }
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStmtClassName() const;
3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
361b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// SourceLocation tokens are not useful in isolation - they are low level
362b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// value objects created/interpreted by SourceManager. We assume AST
363b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// clients will have a pointer to the respective SourceManager.
364aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
365aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
366aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // global temp stats (until we have a per-module visitor)
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void addStmtClass(const StmtClass s);
37002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static void EnableStatistics();
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void PrintStats();
3726000dace22f110d8768476989313e9d981d690d0Chris Lattner
37395f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \brief Dumps the specified AST fragment and all subtrees to
37495f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \c llvm::errs().
375f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump() const;
376f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
3778cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS, SourceManager &SM) const;
3786000dace22f110d8768476989313e9d981d690d0Chris Lattner
3797ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu  /// dumpColor - same as dump(), but forces color highlighting.
3807ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu  LLVM_ATTRIBUTE_USED void dumpColor() const;
3817ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu
3826000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
3836000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// back to its original source language syntax.
384d1420c6fa788669e49f21e184927c7833881e399Richard Smith  void dumpPretty(ASTContext &Context) const;
3858cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
386e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
387d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                   unsigned Indentation = 0) const;
3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
389d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
390d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
391d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  void viewAST() const;
3921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3937e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// Skip past any implicit AST nodes which might surround this
3947e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
3957e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  Stmt *IgnoreImplicit();
3967e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
397a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  const Stmt *stripLabelLikeStatements() const;
398a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  Stmt *stripLabelLikeStatements() {
399a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth    return const_cast<Stmt*>(
400a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
401a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  }
402a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth
403d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
404d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  contain implicit control-flow in the order their subexpressions
405d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  are evaluated.  This predicate returns true if this statement has
406d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  such implicit control-flow.  Such statements are also specially handled
407d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  within CFGs.
408d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  bool hasImplicitControlFlow() const;
409d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek
41063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// Child Iterators: All subclasses must implement 'children'
41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// to permit easy iteration over the substatements/subexpessions of an
41263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// AST node.  This permits easy iteration over all nodes in the AST.
4139caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef StmtIterator       child_iterator;
4149caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef ConstStmtIterator  const_child_iterator;
4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef StmtRange          child_range;
41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef ConstStmtRange     const_child_range;
4181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
42063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_range children() const {
42163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return const_cast<Stmt*>(this)->children();
42277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_begin() { return children().first; }
42563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_end() { return children().second; }
42663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
42763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_begin() const { return children().first; }
42863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_end() const { return children().second; }
42941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
43041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Produce a unique representation of the given statement.
43141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43270517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param ID once the profiling operation is complete, will contain
43341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// the unique representation of the given statement.
43441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43570517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Context the AST context in which the statement resides
43641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43770517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Canonical whether the profile should be based on the canonical
43841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// representation of this statement (e.g., where non-type template
4391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// parameters are identified by index/level rather than their
44041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// declaration pointers) or the exact representation of the statement as
44141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// written in the source.
4424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
443b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth               bool Canonical) const;
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions
4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where
4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration.
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt {
4529653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor  DeclGroupRef DG;
45381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation StartLoc, EndLoc;
4541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
4578ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
4588ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek                                    StartLoc(startLoc), EndLoc(endLoc) {}
4591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  /// \brief Build an empty declaration statement.
46184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
46284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4637e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  /// isSingleDecl - This method returns true if this DeclStmt refers
464fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner  /// to a single Decl.
4657e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  bool isSingleDecl() const {
466fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner    return DG.isSingleDecl();
4678ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  }
4681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4697e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Decl *getSingleDecl() { return DG.getSingleDecl(); }
4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
472e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  const DeclGroupRef getDeclGroup() const { return DG; }
473e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  DeclGroupRef getDeclGroup() { return DG; }
47484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
475b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
47681c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
47784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setStartLoc(SourceLocation L) { StartLoc = L; }
47881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
47984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setEndLoc(SourceLocation L) { EndLoc = L; }
48084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
48165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
48265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DeclStmtClass;
4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48814f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek  // Iterators over subexpressions.
48963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
49063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(child_iterator(DG.begin(), DG.end()),
49163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       child_iterator(DG.end(), DG.end()));
49263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
4931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4940632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::iterator decl_iterator;
4950632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::const_iterator const_decl_iterator;
4961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4978ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_begin() { return DG.begin(); }
4988ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_end() { return DG.end(); }
4998ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_begin() const { return DG.begin(); }
5008ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_end() const { return DG.end(); }
501fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose
502fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
503fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rbegin() {
504fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_end());
505fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
506fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rend() {
507fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_begin());
508fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3.
5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt {
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation SemiLoc;
51544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
516e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  /// \brief True if the null statement was preceded by an empty macro, e.g:
51744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @code
51844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   #define CALL(x)
51944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   CALL(0);
52044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @endcode
521e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool HasLeadingEmptyMacro;
5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
523e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
524e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis    : Stmt(NullStmtClass), SemiLoc(L),
525e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
527025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty null statement.
528e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
529e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(false) { }
530025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getSemiLoc() const { return SemiLoc; }
532025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
533b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
534e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
53544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
53665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
53765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == NullStmtClass;
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
54444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
54544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtReader;
54644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtWriter;
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }.
5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt {
5528189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  Stmt** Body;
553b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation LBracLoc, RBracLoc;
5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
555d36aa359e2f45cd22c7366a015ad94de08044dbbNico Weber  CompoundStmt(ASTContext &C, ArrayRef<Stmt*> Stmts,
5563a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer               SourceLocation LB, SourceLocation RB);
5573a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer
5583a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  // \brief Build an empty compound statment with a location.
5593a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  explicit CompoundStmt(SourceLocation Loc)
5603a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) {
5613a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    CompoundStmtBits.NumStmts = 0;
5621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
563025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
564025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  // \brief Build an empty compound statement.
565025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CompoundStmt(EmptyShell Empty)
5668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    : Stmt(CompoundStmtClass, Empty), Body(0) {
5678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = 0;
5688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
569025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
570025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
5738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned size() const { return CompoundStmtBits.NumStmts; }
574025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5758189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt** body_iterator;
5768189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  body_iterator body_begin() { return Body; }
5778e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  body_iterator body_end() { return Body + size(); }
5788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
579ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5808e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setLastStmt(Stmt *S) {
5818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    assert(!body_empty() && "setLastStmt");
5828e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Body[size()-1] = S;
5838e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5858189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt* const * const_body_iterator;
5868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_body_iterator body_begin() const { return Body; }
5878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const_body_iterator body_end() const { return Body + size(); }
5888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
5898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek
5908189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
5918189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rbegin() {
5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_end());
5938189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5948189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rend() {
5958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_begin());
5968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5974ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5988189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<const_body_iterator>
5998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek          const_reverse_body_iterator;
6004ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
6018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rbegin() const {
6028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_end());
6038189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6058189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rend() const {
6068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_begin());
6078189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
61065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
612cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getLBracLoc() const { return LBracLoc; }
613025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
614cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getRBracLoc() const { return RBracLoc; }
615025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundStmtClass;
6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6218297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
62263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
62363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
62463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
625ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6268ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  const_child_range children() const {
6278ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
6288ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  }
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
631c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt,
632c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt {
633103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected:
634c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // A pointer to the following CaseStmt or DefaultStmt class,
635c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // used by SwitchStmt.
636c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *NextSwitchCase;
63781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation KeywordLoc;
63881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation ColonLoc;
63981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis
64081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
64181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {}
642103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek
64381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SwitchCase(StmtClass SC, EmptyShell)
64481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : Stmt(SC), NextSwitchCase(0) {}
6451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
646c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic:
647c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
648c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
649c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
650c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
651c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
652d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek
65381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getKeywordLoc() const { return KeywordLoc; }
65481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
65581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getColonLoc() const { return ColonLoc; }
65681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setColonLoc(SourceLocation L) { ColonLoc = L; }
65781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis
65863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  Stmt *getSubStmt();
659702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  const Stmt *getSubStmt() const {
660702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner    return const_cast<SwitchCase*>(this)->getSubStmt();
661702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  }
662b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
66381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
66481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocEnd() const LLVM_READONLY;
6651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass ||
66863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall           T->getStmtClass() == DefaultStmtClass;
669c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
670c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson};
671c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
672c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase {
6730a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor  enum { LHS, RHS, SUBSTMT, END_EXPR };
6741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
675d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek                             // GNU "case 1 ... 4" extension
676dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation EllipsisLoc;
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
678dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
6791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation ellipsisLoc, SourceLocation colonLoc)
68081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
68124e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner    SubExprs[SUBSTMT] = 0;
682d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
683d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
684dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    EllipsisLoc = ellipsisLoc;
685d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  }
686025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
687025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty switch case statement.
68881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
689025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
69081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getCaseLoc() const { return KeywordLoc; }
69181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
692dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
693dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
694dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
695dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
696025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
697d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
698d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
699d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
700025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getLHS() const {
7021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
70351b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const {
7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
70651b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
70751b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
70920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
71020dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
71120dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
71465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
7153fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    // Handle deeply nested case statements with iteration instead of recursion.
7163fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    const CaseStmt *CS = this;
71791ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
7183fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner      CS = CS2;
7191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return CS->getSubStmt()->getLocEnd();
721b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
72265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
7231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass;
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
727d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
72863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
72963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
73063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
733c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase {
734d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt* SubStmt;
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
73781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
738025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
739025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty default statement.
74081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  explicit DefaultStmt(EmptyShell Empty)
74181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : SwitchCase(DefaultStmtClass, Empty) { }
742025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
743d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubStmt; }
74451b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubStmt; }
745025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSubStmt(Stmt *S) { SubStmt = S; }
746025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
74781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getDefaultLoc() const { return KeywordLoc; }
74881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
749dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
750dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
75281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
75365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
75465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
7551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DefaultStmtClass;
7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
759d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
76063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
76381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidisinline SourceLocation SwitchCase::getLocEnd() const {
76481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
76581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    return CS->getLocEnd();
76681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  return cast<DefaultStmt>(this)->getLocEnd();
76781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis}
768ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
769ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement.  For example:
770ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///    foo: return;
771ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///
7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt {
773ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *TheDecl;
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *SubStmt;
775b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IdentLoc;
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
777ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
778ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
7798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
7801de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
7811de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  // \brief Build an empty label statement.
7821de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
7831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getIdentLoc() const { return IdentLoc; }
785ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getDecl() const { return TheDecl; }
786ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setDecl(LabelDecl *D) { TheDecl = D; }
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *getSubStmt() { return SubStmt; }
7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Stmt *getSubStmt() const { return SubStmt; }
7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setSubStmt(Stmt *SS) { SubStmt = SS; }
792b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
79365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
79465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
79565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
79663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
79763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == LabelStmtClass;
8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
804534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement.
805534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
806534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example:
807534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///   [[omp::for(...)]] for (...) { ... }
808534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
809534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt {
810534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *SubStmt;
811534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation AttrLoc;
8124990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  unsigned NumAttrs;
8134990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  const Attr *Attrs[1];
814534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
815534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  friend class ASTStmtReader;
816534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8174990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
8184990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
8194990890fc9428f98bef90ba349203a648c592778Alexander Kornienko      NumAttrs(Attrs.size()) {
8204990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*));
821534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
822534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8234990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
8244990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
8254990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memset(Attrs, 0, NumAttrs * sizeof(Attr*));
826534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
827534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8284990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic:
8294990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *Create(ASTContext &C, SourceLocation Loc,
8304990890fc9428f98bef90ba349203a648c592778Alexander Kornienko                                ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
8314990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  // \brief Build an empty attributed statement.
8324990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs);
8334990890fc9428f98bef90ba349203a648c592778Alexander Kornienko
834534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation getAttrLoc() const { return AttrLoc; }
8354990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  ArrayRef<const Attr*> getAttrs() const {
8364990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    return ArrayRef<const Attr*>(Attrs, NumAttrs);
8374990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  }
838534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *getSubStmt() { return SubStmt; }
839534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  const Stmt *getSubStmt() const { return SubStmt; }
840534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
84165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
84265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
84365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
844534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
845534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
846534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  static bool classof(const Stmt *T) {
847534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return T->getStmtClass() == AttributedStmtClass;
848534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
849534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith};
850534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
851534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else.
8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt {
85543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, THEN, ELSE, END_EXPR };
8568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
8578cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor
858b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IfLoc;
859d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation ElseLoc;
860ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
862ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
86344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
864ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
865025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty if/then/else statement
866025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
867025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
8688cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \brief Retrieve the variable declared in this "if" statement, if any.
8698cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///
8708cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// In the following example, "x" is the condition variable.
8718cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \code
8728cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// if (int x = foo()) {
8738cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///   printf("x is %d", x);
8748cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// }
8758cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \endcode
87643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
87743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
878ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
879d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this IfStmt has a condition variable, return the faux DeclStmt
880d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
881d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
882d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
883d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
884ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
886025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
8878297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getThen() const { return SubExprs[THEN]; }
8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setThen(Stmt *S) { SubExprs[THEN] = S; }
8898297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getElse() const { return SubExprs[ELSE]; }
890025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8928297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
8938297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getThen() { return SubExprs[THEN]; }
8948297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getElse() { return SubExprs[ELSE]; }
895b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
896025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getIfLoc() const { return IfLoc; }
897025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setIfLoc(SourceLocation L) { IfLoc = L; }
898d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation getElseLoc() const { return ElseLoc; }
899d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  void setElseLoc(SourceLocation L) { ElseLoc = L; }
900025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
90165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
90265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
903b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    if (SubExprs[ELSE])
90465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return SubExprs[ELSE]->getLocEnd();
905b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    else
90665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return SubExprs[THEN]->getLocEnd();
907b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
90963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators over subexpressions.  The iterators will include iterating
91063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // over the initialization expression referenced by the condition variable.
91163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
91263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
91363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
91463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
9151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IfStmtClass;
9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt.
9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt {
92343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
925c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // This points to a linked list of case and default statements.
926c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *FirstCase;
9279dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  SourceLocation SwitchLoc;
9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
929559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// If the SwitchStmt is a switch on an enum value, this records whether
930559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// all the enum values were covered by CaseStmts.  This value is meant to
931559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// be a hint for possible clients.
932559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  unsigned AllEnumCasesCovered : 1;
933559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
93543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
937025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build a empty switch statement.
938025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
939025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
940d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \brief Retrieve the variable declared in this "switch" statement, if any.
941d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///
942d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// In the following example, "x" is the condition variable.
943d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \code
944d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// switch (int x = foo()) {
945d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   case 0: break;
946d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   // ...
947d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// }
948d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \endcode
94943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
95043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
951ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
952d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
953d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
954d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
955d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
956d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
957d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor
9588297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
9598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
960c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
961c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
963025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
9648297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
965025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
966c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getSwitchCaseList() { return FirstCase; }
9671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Set the case list for this switch statement.
96943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
97043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// The caller is responsible for incrementing the retain counts on
97143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// all of the SwitchCase statements in this list.
972025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
973025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
974025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getSwitchLoc() const { return SwitchLoc; }
975025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
976c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setBody(Stmt *S, SourceLocation SL) {
9781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[BODY] = S;
9799dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    SwitchLoc = SL;
9801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
981c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void addSwitchCase(SwitchCase *SC) {
982ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!SC->getNextSwitchCase()
983ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           && "case/default already added to a switch");
984c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    SC->setNextSwitchCase(FirstCase);
985c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson    FirstCase = SC;
986c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
987559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
988559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
989559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// switch over an enum value then all cases have been explicitly covered.
990559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  void setAllEnumCasesCovered() {
991559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    AllEnumCasesCovered = 1;
992559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
993559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
994559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
995559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// have been explicitly covered.
996559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  bool isAllEnumCasesCovered() const {
997559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    return (bool) AllEnumCasesCovered;
998559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
999559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
100065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
100165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
100265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
10039dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  }
100465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
100563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators
100663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
100763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
100863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
100963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SwitchStmtClass;
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt.
10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt {
101943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
10208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1021b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation WhileLoc;
10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1023ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
102443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor            SourceLocation WL);
10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1026d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty while statement.
1027d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1028d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
10295656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \brief Retrieve the variable declared in this "while" statement, if any.
10305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///
10315656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// In the following example, "x" is the condition variable.
10325656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \code
10335656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// while (int x = random()) {
10345656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///   // ...
10355656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// }
10365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \endcode
103743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
103843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
10395656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
1040d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1041d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1042d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1043d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1044d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1045d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
10468297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10478297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1048d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1051d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1052d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1053d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
1054d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1055b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
105665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
105765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
105865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
1059b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
106065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
10611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == WhileStmtClass;
10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10658297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
106663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
106763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
106863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt.
10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt {
1074c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor  enum { BODY, COND, END_EXPR };
10758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1076b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation DoLoc;
10779f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation WhileLoc;
1078989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
10799f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor
10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1081989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1082989135901c750af61ef012b6b0a0368be415bc46Chris Lattner         SourceLocation RP)
1083989135901c750af61ef012b6b0a0368be415bc46Chris Lattner    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
10848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
10858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[BODY] = body;
10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
108767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
108867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty do-while statement.
108967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
10901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10918297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10928297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
109367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10948297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Stmt *getBody() const { return SubExprs[BODY]; }
109667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
109767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
109867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getDoLoc() const { return DoLoc; }
109967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setDoLoc(SourceLocation L) { DoLoc = L; }
11009f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
11019f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1102b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1103989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
1104989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1105989135901c750af61ef012b6b0a0368be415bc46Chris Lattner
110665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
110765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
110865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DoStmtClass;
11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11128297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11138297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
111463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
111563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
111663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not
11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source.
11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt {
112543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
11268297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1127b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation ForLoc;
11285831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation LParenLoc, RParenLoc;
11295831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor
11305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1131ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
113243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
11331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
113467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty for statement.
113567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
113667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
11378297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getInit() { return SubExprs[INIT]; }
1138ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
113999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \brief Retrieve the variable declared in this "for" statement, if any.
114099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///
114199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// In the following example, "y" is the condition variable.
114299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \code
114399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// for (int x = random(); int y = mangle(x); ++x) {
114499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///   // ...
114599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// }
114699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \endcode
114743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
114843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
1149ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1150d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this ForStmt has a condition variable, return the faux DeclStmt
1151d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1152d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1153d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1154d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1155d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
11568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
11578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11588297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
11598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getInit() const { return SubExprs[INIT]; }
11618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
11628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1164b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
116567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInit(Stmt *S) { SubExprs[INIT] = S; }
116667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
116767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
116867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
116967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
117067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getForLoc() const { return ForLoc; }
117167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setForLoc(SourceLocation L) { ForLoc = L; }
11725831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
11735831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
11745831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11755831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
117667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
117765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
117865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
117965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
1180b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
118165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
11821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ForStmtClass;
11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11868297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
118763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
118863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
118963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto.
11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt {
1195ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
1196507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation GotoLoc;
119761f62165220e75694fe333179c78815e2e48d71fTed Kremenek  SourceLocation LabelLoc;
11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1199ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
120061f62165220e75694fe333179c78815e2e48d71fTed Kremenek    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
12011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12021de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Build an empty goto statement.
12031de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
12041de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1205ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
1206ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *D) { Label = D; }
12071de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
12081de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getGotoLoc() const { return GotoLoc; }
12091de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
12101de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
12111de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1212b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
121365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
121465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
121565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
12161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GotoStmtClass;
12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
122163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto.
12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt {
1227ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation GotoLoc;
12285f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation StarLoc;
12291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Target;
12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
12325f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor                   Expr *target)
12335f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
12345f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor      Target((Stmt*)target) {}
12357d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
12367d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty indirect goto statement.
12371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IndirectGotoStmt(EmptyShell Empty)
12387d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Stmt(IndirectGotoStmtClass, Empty) { }
12391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1240ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1241ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation getGotoLoc() const { return GotoLoc; }
12425f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  void setStarLoc(SourceLocation L) { StarLoc = L; }
12435f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation getStarLoc() const { return StarLoc; }
12441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
124595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
124695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
12477d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1248b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
124995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// getConstantTarget - Returns the fixed target of this indirect
125095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// goto, if one exists.
1251ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getConstantTarget();
1252ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  const LabelDecl *getConstantTarget() const {
125395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
125495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  }
125595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall
125665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
125765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IndirectGotoStmtClass;
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
126463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Target, &Target+1); }
12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue.
12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt {
1271507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation ContinueLoc;
12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1273507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1275d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty continue statement.
1276d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1277d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1278d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getContinueLoc() const { return ContinueLoc; }
1279d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1280d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
128165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
128265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1283861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor
12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ContinueStmtClass;
12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12888297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
128963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break.
12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt {
1295507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation BreakLoc;
12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1297507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
12981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1299025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty break statement.
1300025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1301025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1302025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getBreakLoc() const { return BreakLoc; }
1303025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1304025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
130565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
130665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1307b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BreakStmtClass;
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13128297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
131363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1317c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression:
1318c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return;
1319c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return 4;
1320c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///
1321c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to
1322c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to
1323c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void.  We explicitly model this in the AST, which means you can't
1324c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument.
13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt {
13271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *RetExpr;
1328507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation RetLoc;
13295077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *NRVOCandidate;
1330ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13325077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL)
133325a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
13345077c3876beeaed32280af88244e8050078619a8Douglas Gregor
13355077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
13365077c3876beeaed32280af88244e8050078619a8Douglas Gregor    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
13375077c3876beeaed32280af88244e8050078619a8Douglas Gregor      NRVOCandidate(NRVOCandidate) {}
13380de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13390de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  /// \brief Build an empty return expression.
13400de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
13410de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getRetValue() const;
13431060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getRetValue();
13440de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
13450de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13460de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  SourceLocation getReturnLoc() const { return RetLoc; }
13470de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1348b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13495077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// \brief Retrieve the variable that might be used for the named return
13505077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// value optimization.
13515077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ///
13525077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// The optimization itself can only be performed if the variable is
13535077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// also marked as an NRVO object.
13545077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
13555077c3876beeaed32280af88244e8050078619a8Douglas Gregor  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1356ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
135765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
135865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
135965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return RetExpr ? RetExpr->getLocEnd() : RetLoc;
136065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ReturnStmtClass;
13645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13668297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
136763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
136863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
136963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range();
137063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1373728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1374728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier///
1375728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass AsmStmt : public Stmt {
1376728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierprotected:
1377066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation AsmLoc;
137812b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief True if the assembly statement does not have any input or output
137912b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// operands.
1380728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsSimple;
138112b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier
138212b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief If true, treat this inline assembly as having side effects.
138312b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// This assembly statement should not be optimized, deleted or moved.
1384728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsVolatile;
1385728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1386066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumOutputs;
1387066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumInputs;
1388066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumClobbers;
1389066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
139019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  Stmt **Exprs;
1391066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1392066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1393066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier          unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1394066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1395066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1396728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1397aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  friend class ASTStmtReader;
1398aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1399728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierpublic:
1400728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  /// \brief Build an empty inline-assembly statement.
1401728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
1402aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    Stmt(SC, Empty), Exprs(0) { }
140329760b452876548f59804e8c02c3276bc7281d5dMatt Beaumont-Gay
1404066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation getAsmLoc() const { return AsmLoc; }
1405066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1406728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1407728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isSimple() const { return IsSimple; }
1408728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setSimple(bool V) { IsSimple = V; }
1409728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1410728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isVolatile() const { return IsVolatile; }
1411728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setVolatile(bool V) { IsVolatile = V; }
1412728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
141365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
141465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1415728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1416da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  //===--- Asm String Analysis ---===//
1417da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1418da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1419aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1420da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1421066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Output operands ---===//
1422066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1423066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumOutputs() const { return NumOutputs; }
1424066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1425c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getOutputConstraint - Return the constraint string for the specified
1426c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// output operand.  All output constraints are known to be non-empty (either
1427c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// '=' or '+').
1428aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getOutputConstraint(unsigned i) const;
1429c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1430c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// isOutputPlusConstraint - Return true if the specified output constraint
1431c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is a "+" constraint (which is both an input and an output) or false if it
1432c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is an "=" constraint (just an output).
1433c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  bool isOutputPlusConstraint(unsigned i) const {
1434c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier    return getOutputConstraint(i)[0] == '+';
1435c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  }
1436c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1437aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getOutputExpr(unsigned i) const;
1438c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1439c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getNumPlusOperands - Return the number of output operands that have a "+"
1440c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraint.
1441c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  unsigned getNumPlusOperands() const;
1442c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1443066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Input operands ---===//
1444066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1445066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumInputs() const { return NumInputs; }
1446066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1447c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getInputConstraint - Return the specified input constraint.  Unlike output
1448c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraints, these can be empty.
1449aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getInputConstraint(unsigned i) const;
1450aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier
1451aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getInputExpr(unsigned i) const;
1452c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1453066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Other ---===//
1454066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
14552fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier  unsigned getNumClobbers() const { return NumClobbers; }
1456aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getClobber(unsigned i) const;
14572fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier
1458728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  static bool classof(const Stmt *T) {
1459728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass ||
1460728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier      T->getStmtClass() == MSAsmStmtClass;
1461728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  }
146219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
146319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Input expr iterators.
146419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
146519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator inputs_iterator;
146619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_inputs_iterator;
146719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
146819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator begin_inputs() {
146919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
147019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
147119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator end_inputs() {
147319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
147419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
147519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator begin_inputs() const {
147719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
147819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
147919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator end_inputs() const {
148119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
148219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Output expr iterators.
148519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator outputs_iterator;
148719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_outputs_iterator;
148819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator begin_outputs() {
149019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
149119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator end_outputs() {
149319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
149419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator begin_outputs() const {
149719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
149819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator end_outputs() const {
150019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
150119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
150219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
150319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  child_range children() {
150419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
150519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
1506728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier};
1507728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
15087d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a GCC inline-assembly statement extension.
1509fe795956194141c91ae555985c9b930595bff43fChris Lattner///
1510728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass GCCAsmStmt : public AsmStmt {
1511066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation RParenLoc;
15126a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  StringLiteral *AsmStr;
1513b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1514966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  // FIXME: If we wanted to, we could allocate all of these in one big array.
1515966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Constraints;
1516966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Clobbers;
1517aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  IdentifierInfo **Names;
1518aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1519aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  friend class ASTStmtReader;
1520ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1521fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic:
1522df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
1523df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             bool isvolatile, unsigned numoutputs, unsigned numinputs,
1524df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1525df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral *asmstr, unsigned numclobbers,
1526df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral **clobbers, SourceLocation rparenloc);
1527b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1528cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  /// \brief Build an empty inline-assembly statement.
1529728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
1530aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    Constraints(0), Clobbers(0), Names(0) { }
1531cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1532cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1533cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1534cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1535458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  //===--- Asm String Analysis ---===//
1536458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1537458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  const StringLiteral *getAsmString() const { return AsmStr; }
1538458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  StringLiteral *getAsmString() { return AsmStr; }
1539cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmString(StringLiteral *E) { AsmStr = E; }
1540cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1541458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AsmStringPiece - this is part of a decomposed asm string specification
1542458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// (for use with the AnalyzeAsmString function below).  An asm string is
1543458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// considered to be a concatenation of these parts.
1544458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  class AsmStringPiece {
1545458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1546458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    enum Kind {
1547458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1548458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Operand  // Operand reference, with optional modifier %c4.
1549458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    };
1550458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  private:
1551458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    Kind MyKind;
1552458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    std::string Str;
1553458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned OperandNo;
1554458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1555458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1556458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(unsigned OpNo, char Modifier)
1557458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      : MyKind(Operand), Str(), OperandNo(OpNo) {
1558458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Str += Modifier;
1559458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1561458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isString() const { return MyKind == String; }
1562458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isOperand() const { return MyKind == Operand; }
15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1564458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    const std::string &getString() const {
1565458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isString());
1566458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str;
1567458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1568458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1569458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned getOperandNo() const {
1570458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1571458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return OperandNo;
1572458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1574458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// getModifier - Get the modifier for this operand, if present.  This
1575458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// returns '\0' if there was no modifier.
1576458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    char getModifier() const {
1577458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1578458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str[0];
1579458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1580458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  };
15811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1582458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1583458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// it into pieces.  If the asm string is erroneous, emit errors and return
1584458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// true, otherwise return false.  This handles canonicalization and
1585458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
15861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1587686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1588fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner                            ASTContext &C, unsigned &DiagOffs) const;
15891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1590da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1591da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1593b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Output operands ---===//
1594b327793860737d1c103a73aeda8057dd628a101dChris Lattner
1595aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1596aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return Names[i];
1597aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1598aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1599aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getOutputName(unsigned i) const {
1600aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    if (IdentifierInfo *II = getOutputIdentifier(i))
1601aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall      return II->getName();
1602aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1603aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return StringRef();
1604aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1605aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1606686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputConstraint(unsigned i) const;
16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1608b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1609ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i];
1610ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1611b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1612b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return Constraints[i];
1613b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1615ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getOutputExpr(unsigned i);
16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1617b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getOutputExpr(unsigned i) const {
1618df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1619b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1621b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Input operands ---===//
16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1623aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  IdentifierInfo *getInputIdentifier(unsigned i) const {
1624aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return Names[i + NumOutputs];
1625aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1626aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1627aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getInputName(unsigned i) const {
1628aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    if (IdentifierInfo *II = getInputIdentifier(i))
1629aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall      return II->getName();
1630aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1631aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return StringRef();
1632aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1633aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1634686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputConstraint(unsigned i) const;
16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1636b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1637ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1638ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1639b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getInputConstraintLiteral(unsigned i) {
1640ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1641ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
16421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1643ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getInputExpr(unsigned i);
1644935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner  void setInputExpr(unsigned i, Expr *E);
1645ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1646b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getInputExpr(unsigned i) const {
1647df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1648b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
1649cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1650aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate:
1651acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson  void setOutputsAndInputsAndClobbers(ASTContext &C,
1652ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                      IdentifierInfo **Names,
1653fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Constraints,
1654fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      Stmt **Exprs,
1655fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumOutputs,
1656ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      unsigned NumInputs,
1657fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Clobbers,
1658fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumClobbers);
1659aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic:
1660cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
166110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  //===--- Other ---===//
16621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
166310ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// getNamedOperand - Given a symbolic operand reference like %[foo],
166410ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// translate this into a numeric value needed to reference the same operand.
166510ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// This returns -1 if the operand name is invalid.
1666686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  int getNamedOperand(StringRef SymbolicName) const;
166710ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner
166833f0558f75f70061707d1388e305b8f92f4e55deChad Rosier  StringRef getClobber(unsigned i) const;
16695c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
16705c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  const StringLiteral *getClobberStringLiteral(unsigned i) const {
16715c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier    return Clobbers[i];
16725c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  }
1673cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
167465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
167565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1677df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  static bool classof(const Stmt *T) {
1678df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass;
1679df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  }
1680fe795956194141c91ae555985c9b930595bff43fChris Lattner};
168178492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek
16827d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a Microsoft inline-assembly statement extension.
16838cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier///
1684728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass MSAsmStmt : public AsmStmt {
1685c4cca7b2408bdfd99ea0f63fec1421c1327593b2Enea Zaffanella  SourceLocation LBraceLoc, EndLoc;
1686aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef AsmStr;
16878cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
168879efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned NumAsmToks;
168979efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier
169079efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *AsmToks;
169189fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef *Constraints;
169233c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier  StringRef *Clobbers;
16938cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1694aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  friend class ASTStmtReader;
1695aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
16968cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic:
16977bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc,
16987bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier            bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
1699e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            unsigned numoutputs, unsigned numinputs,
1700aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall            ArrayRef<StringRef> constraints,
1701e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            ArrayRef<Expr*> exprs, StringRef asmstr,
170289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier            ArrayRef<StringRef> clobbers, SourceLocation endloc);
17038cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1704cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier  /// \brief Build an empty MS-style inline-assembly statement.
1705728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
170689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { }
1707cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier
17087bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  SourceLocation getLBraceLoc() const { return LBraceLoc; }
17097bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
17108cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceLocation getEndLoc() const { return EndLoc; }
17118cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setEndLoc(SourceLocation L) { EndLoc = L; }
17128cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17137bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  bool hasBraces() const { return LBraceLoc.isValid(); }
17147bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier
171579efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned getNumAsmToks() { return NumAsmToks; }
171679efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *getAsmToks() { return AsmToks; }
17178f726de55412870ef70e788b852c6cc50873e15bChad Rosier
17188cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Asm String Analysis ---===//
1719aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getAsmString() const { return AsmStr; }
17208cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1721da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1722da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1723da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
17242603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Output operands ---===//
17252603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
172689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getOutputConstraint(unsigned i) const {
1727aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    assert(i < NumOutputs);
172889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i];
172989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1730c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1731633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getOutputExpr(unsigned i);
1732633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17332603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getOutputExpr(unsigned i) const {
17342603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
17352603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17362603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17372603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Input operands ---===//
17382603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
173989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getInputConstraint(unsigned i) const {
1740aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    assert(i < NumInputs);
174189fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i + NumOutputs];
174289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1743c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1744633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getInputExpr(unsigned i);
1745633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  void setInputExpr(unsigned i, Expr *E);
1746633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17472603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getInputExpr(unsigned i) const {
17482603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
17492603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17502603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17518cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Other ---===//
17528cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1753aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  ArrayRef<StringRef> getAllConstraints() const {
1754aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return ArrayRef<StringRef>(Constraints, NumInputs + NumOutputs);
1755aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1756aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  ArrayRef<StringRef> getClobbers() const {
1757aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return ArrayRef<StringRef>(Clobbers, NumClobbers);
1758aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1759aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  ArrayRef<Expr*> getAllExprs() const {
1760aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return ArrayRef<Expr*>(reinterpret_cast<Expr**>(Exprs),
1761aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                           NumInputs + NumOutputs);
1762aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1763aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1764aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
1765aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1766aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate:
1767aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  void initialize(ASTContext &C,
1768aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  StringRef AsmString,
1769aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  ArrayRef<Token> AsmToks,
1770aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  ArrayRef<StringRef> Constraints,
1771aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  ArrayRef<Expr*> Exprs,
1772aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                  ArrayRef<StringRef> Clobbers);
1773aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic:
17744399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier
177565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
177665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
177765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
17788cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  static bool classof(const Stmt *T) {
17798cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return T->getStmtClass() == MSAsmStmtClass;
17808cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17818cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17828cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  child_range children() {
17838cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return child_range(&Exprs[0], &Exprs[0]);
17848cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17858cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier};
17868cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
178728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt {
178828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
178928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
179028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { FILTER_EXPR, BLOCK };
179228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt(SourceLocation Loc,
179428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Expr *FilterExpr,
179528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Stmt *Block);
179628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
17977110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
17987110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
17997110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
18007110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
180128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
180228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHExceptStmt* Create(ASTContext &C,
180328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation ExceptLoc,
180428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Expr *FilterExpr,
180528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Block);
180665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
180765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
180865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
180928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
181028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getExceptLoc() const { return Loc; }
181128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
181228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1813ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getFilterExpr() const {
1814ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1815ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1816ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1817ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt *getBlock() const {
1818cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(Children[BLOCK]);
1819ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
182028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
182228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
182328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
182428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
182628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHExceptStmtClass;
182728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
182828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
183028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt {
183228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
183328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Block;
183428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt(SourceLocation Loc,
183628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                 Stmt *Block);
183728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18387110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18397110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18407110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
18417110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
184228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
184328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHFinallyStmt* Create(ASTContext &C,
184428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                SourceLocation FinallyLoc,
184528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                Stmt *Block);
184628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
184765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
184865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
184928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getFinallyLoc() const { return Loc; }
185128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
185228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1853cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
185428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
185628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(&Block,&Block+1);
185728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
185828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
186028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHFinallyStmtClass;
186128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
186228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
186328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
186428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
186528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt {
186628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool            IsCXXTry;
186728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  TryLoc;
186828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
186928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
187028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { TRY = 0, HANDLER = 1 };
187128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
187228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
187328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             SourceLocation TryLoc,
187428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *TryBlock,
187528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *Handler);
187628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18777110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18787110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18797110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
18807110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
188128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
188228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHTryStmt* Create(ASTContext &C,
188328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            bool isCXXTry,
188428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            SourceLocation TryLoc,
188528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *TryBlock,
188628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *Handler);
188728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
188865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
188965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
189028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
189128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getTryLoc() const { return TryLoc; }
189228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
189328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
189428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool getIsCXXTry() const { return IsCXXTry; }
1895ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1896ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt* getTryBlock() const {
1897cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(Children[TRY]);
1898ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1899ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
190028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt *getHandler() const { return Children[HANDLER]; }
190128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
190228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Returns 0 if not defined
190328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt  *getExceptHandler() const;
190428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt *getFinallyHandler() const;
190528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
190628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
190728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
190828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
190928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
191028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
191128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHTryStmtClass;
191228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
191328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
1914ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1915051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// \brief This captures a statement into a function. For example, the following
1916051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// pragma annotated compound statement can be represented as a CapturedStmt,
1917051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// and this compound statement is the body of an anonymous outlined function.
1918051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @code
1919051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// #pragma omp parallel
1920051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// {
1921051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj///   compute();
1922051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// }
1923051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @endcode
1924051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajclass CapturedStmt : public Stmt {
1925051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic:
1926051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The different capture forms: by 'this' or by reference, etc.
1927051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  enum VariableCaptureKind {
1928051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    VCK_This,
1929051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    VCK_ByRef
1930051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  };
1931051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1932051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Describes the capture of either a variable or 'this'.
1933051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  class Capture {
19343a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    llvm::PointerIntPair<VarDecl *, 1, VariableCaptureKind> VarAndKind;
1935051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    SourceLocation Loc;
1936051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1937051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  public:
1938051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Create a new capture.
1939051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1940051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \param Loc The source location associated with this capture.
1941051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1942051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \param Kind The kind of capture (this, ByRef, ...).
1943051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1944051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \param Var The variable being captured, or null if capturing this.
1945051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1946051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var = 0)
19473a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir      : VarAndKind(Var, Kind), Loc(Loc) {
1948051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      switch (Kind) {
1949051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      case VCK_This:
1950051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        assert(Var == 0 && "'this' capture cannot have a variable!");
1951051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        break;
1952051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      case VCK_ByRef:
1953051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        assert(Var && "capturing by reference must have a variable!");
1954051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        break;
1955051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      }
1956051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    }
1957051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1958051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Determine the kind of capture.
19593a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    VariableCaptureKind getCaptureKind() const { return VarAndKind.getInt(); }
1960051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1961051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Retrieve the source location at which the variable or 'this' was
1962051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// first used.
1963051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    SourceLocation getLocation() const { return Loc; }
1964051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1965051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Determine whether this capture handles the C++ 'this' pointer.
19663a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    bool capturesThis() const { return getCaptureKind() == VCK_This; }
1967051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1968051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Determine whether this capture handles a variable.
19693a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    bool capturesVariable() const { return getCaptureKind() != VCK_This; }
1970051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1971051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Retrieve the declaration of the variable being captured.
1972051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1973051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// This operation is only valid if this capture does not capture 'this'.
1974051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    VarDecl *getCapturedVar() const {
1975051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      assert(!capturesThis() && "No variable available for 'this' capture");
19763a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir      return VarAndKind.getPointer();
1977051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    }
1978051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  };
1979051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1980051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajprivate:
1981051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The number of variable captured, including 'this'.
1982051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  unsigned NumCaptures;
1983051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1984051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The implicit outlined function.
19856afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  CapturedDecl *TheCapturedDecl;
1986051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1987051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl.
1988051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  RecordDecl *TheRecordDecl;
1989051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1990051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Construct a captured statement.
1991051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  CapturedStmt(Stmt *S, ArrayRef<Capture> Captures,
1992051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj               ArrayRef<Expr *> CaptureInits,
19936afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj               CapturedDecl *CD, RecordDecl *RD);
1994051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1995051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Construct an empty captured statement.
1996051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
1997051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1998051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  Stmt **getStoredStmts() const {
1999051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1);
2000051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2001051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2002051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  Capture *getStoredCaptures() const;
2003051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2004051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic:
2005051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  static CapturedStmt *Create(ASTContext &Context, Stmt *S,
2006051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj                              ArrayRef<Capture> Captures,
2007051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj                              ArrayRef<Expr *> CaptureInits,
20086afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj                              CapturedDecl *CD, RecordDecl *RD);
2009051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2010051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  static CapturedStmt *CreateDeserialized(ASTContext &Context,
2011051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj                                          unsigned NumCaptures);
2012051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2013051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the statement being captured.
2014051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
2015051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  const Stmt *getCapturedStmt() const {
2016051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return const_cast<CapturedStmt *>(this)->getCapturedStmt();
2017051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2018051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2019051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the outlined function declaration.
20206afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  CapturedDecl *getCapturedDecl() const { return TheCapturedDecl; }
2021051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2022051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the record declaration for captured variables.
2023051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
2024051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2025051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief True if this variable has been captured.
2026051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  bool capturesVariable(const VarDecl *Var) const;
2027051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2028051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief An iterator that walks over the captures.
2029051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  typedef const Capture *capture_iterator;
2030051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2031051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve an iterator pointing to the first capture.
2032051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_iterator capture_begin() const { return getStoredCaptures(); }
2033051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2034051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve an iterator pointing past the end of the sequence of
2035051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// captures.
2036051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_iterator capture_end() const {
2037051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getStoredCaptures() + NumCaptures;
2038051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2039051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2040051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the number of captures, including 'this'.
2041051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  unsigned capture_size() const { return NumCaptures; }
2042051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2043051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Iterator that walks over the capture initialization arguments.
2044051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  typedef Expr **capture_init_iterator;
2045051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2046051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the first initialization argument.
2047051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_init_iterator capture_init_begin() const {
2048051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return reinterpret_cast<Expr **>(getStoredStmts());
2049051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2050051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2051051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the iterator pointing one past the last initialization
2052051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// argument.
2053051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_init_iterator capture_init_end() const {
2054051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return capture_init_begin() + NumCaptures;
2055051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2056051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2057051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  SourceLocation getLocStart() const LLVM_READONLY {
2058051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getCapturedStmt()->getLocStart();
2059051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2060051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  SourceLocation getLocEnd() const LLVM_READONLY {
2061051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getCapturedStmt()->getLocEnd();
2062051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2063051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  SourceRange getSourceRange() const LLVM_READONLY {
2064051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getCapturedStmt()->getSourceRange();
2065051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2066051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2067051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  static bool classof(const Stmt *T) {
2068051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return T->getStmtClass() == CapturedStmtClass;
2069051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2070051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2071051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  child_range children();
2072051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj};
2073051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
20745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
20755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2077