Stmt.h revision 6bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Stmt interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_STMT_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_STMT_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
172fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/DeclGroup.h"
189caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h"
199fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan#include "clang/Basic/CapturedStmt.h"
202fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/IdentifierTable.h"
212fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/LLVM.h"
222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/SourceLocation.h"
232fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "llvm/ADT/ArrayRef.h"
243a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir#include "llvm/ADT/PointerIntPair.h"
25aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
26a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer#include "llvm/Support/ErrorHandling.h"
276e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string>
287573098b83e780d1c5bea13b384b610d8f155676Steve Naroff
2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm {
3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  class FoldingSetNodeID;
3141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor}
3241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
34e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  class ASTContext;
352fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Attr;
366afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  class CapturedDecl;
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
382fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Expr;
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class IdentifierInfo;
40478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class LabelDecl;
412fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class ParmVarDecl;
42a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class PrinterHelper;
43a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  struct PrintingPolicy;
442fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class QualType;
45051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  class RecordDecl;
460c727a35718556866a978f64ac549d9798735f08Chris Lattner  class SourceManager;
476a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  class StringLiteral;
486c36be5b383875b490684bcf439d6d427298c1afChris Lattner  class SwitchStmt;
49a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class Token;
50478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class VarDecl;
511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  // ExprIterator - Iterators for iterating over Stmt* arrays that contain
54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  references to children (to be compatible with StmtIterator).
56ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Stmt;
59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Expr;
601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ExprIterator {
62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Stmt** I;
63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator(Stmt** i) : I(i) {}
656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    ExprIterator() : I(nullptr) {}
66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator& operator++() { ++I; return *this; }
67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator-(size_t i) { return I-i; }
68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator+(size_t i) { return I+i; }
69ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator[](size_t idx);
70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    // FIXME: Verify that this will correctly return a signed distance.
71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ExprIterator& R) const { return I - R.I; }
72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator*() const;
73ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator->() const;
74ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ExprIterator& R) const { return I == R.I; }
75ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ExprIterator& R) const { return I != R.I; }
76ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ExprIterator& R) const { return I > R.I; }
77ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ExprIterator& R) const { return I >= R.I; }
78ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  };
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ConstExprIterator {
811705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    const Stmt * const *I;
82ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
831705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator(const Stmt * const *i) : I(i) {}
846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    ConstExprIterator() : I(nullptr) {}
85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ConstExprIterator& operator++() { ++I; return *this; }
861705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator+(size_t i) const { return I+i; }
871705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator-(size_t i) const { return I-i; }
88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator[](size_t idx) const;
89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ConstExprIterator& R) const { return I - R.I; }
90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator*() const;
91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator->() const;
92ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ConstExprIterator& R) const { return I == R.I; }
93ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ConstExprIterator& R) const { return I != R.I; }
94ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ConstExprIterator& R) const { return I > R.I; }
95ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  };
971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
99ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements.
100ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement.
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt {
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum StmtClass {
107f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor    NoStmtClass = 0,
108f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class,
1097381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \
1109a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
1117381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
1129a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
1137381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT)
1144bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
1158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Make vanilla 'new' and 'delete' illegal for Stmts.
1188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected:
1198189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes) throw() {
120b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
1218189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1228189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void operator delete(void* data) throw() {
123b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
1248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class StmtBitfields {
1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Stmt;
1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    /// \brief The statement class.
1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned sClass : 8;
1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  enum { NumStmtBits = 8 };
1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CompoundStmtBitfields {
1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CompoundStmt;
1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned NumStmts : 32 - NumStmtBits;
1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class ExprBitfields {
1428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Expr;
1438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DeclRefExpr; // computeDependence
1448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class InitListExpr; // ctor
1458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DesignatedInitExpr; // ctor
146d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor    friend class BlockDeclRefExpr; // ctor
147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ASTStmtReader; // deserialization
148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXNewExpr; // ctor
149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class DependentScopeDeclRefExpr; // ctor
150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXConstructExpr; // ctor
151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CallExpr; // ctor
152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OffsetOfExpr; // ctor
153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ObjCMessageExpr; // ctor
154ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCArrayLiteral; // ctor
155ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCDictionaryLiteral; // ctor
156bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ShuffleVectorExpr; // ctor
157bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ParenListExpr; // ctor
158bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXUnresolvedConstructExpr; // ctor
159bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXDependentScopeMemberExpr; // ctor
160bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OverloadExpr; // ctor
1614b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr; // ctor
162dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    friend class AtomicExpr; // ctor
1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueKind : 2;
166f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    unsigned ObjectKind : 2;
1678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned TypeDependent : 1;
1688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueDependent : 1;
169561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
170d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
172561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  enum { NumExprBits = 16 };
1738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class CharacterLiteralBitfields {
175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class CharacterLiteral;
176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
179bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
180bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
1819ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover  enum APFloatSemantics {
1829ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEhalf,
1839ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEsingle,
1849ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEdouble,
1859ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    x87DoubleExtended,
1869ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEquad,
1879ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    PPCDoubleDouble
1889ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover  };
1899ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover
190bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class FloatingLiteralBitfields {
191bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class FloatingLiteral;
192bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
193bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
1949ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    unsigned Semantics : 3; // Provides semantics for APFloat construction
195bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsExact : 1;
196bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
197bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
198bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class UnaryExprOrTypeTraitExprBitfields {
199bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class UnaryExprOrTypeTraitExpr;
200bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
201bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
202bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
203bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsType : 1; // true if operand is a type, false if an expression.
204bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
205bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
206cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  class DeclRefExprBitfields {
207cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class DeclRefExpr;
208cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class ASTStmtReader; // deserialization
209cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned : NumExprBits;
210cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
211cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasQualifier : 1;
212e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    unsigned HasTemplateKWAndArgsInfo : 1;
2133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    unsigned HasFoundDecl : 1;
2147cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    unsigned HadMultipleCandidates : 1;
215f4b88a45902af1802a1cb42ba48b1c474474f228John McCall    unsigned RefersToEnclosingLocal : 1;
216cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  };
217cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
2188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CastExprBitfields {
2198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CastExpr;
2208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumExprBits;
2218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2222bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned Kind : 6;
2232bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned BasePathSize : 32 - 6 - NumExprBits;
2248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
226cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  class CallExprBitfields {
227cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    friend class CallExpr;
228cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned : NumExprBits;
229cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
230cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned NumPreArgs : 1;
231cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  };
232cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
23380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  class ExprWithCleanupsBitfields {
23480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ExprWithCleanups;
23580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ASTStmtReader; // deserialization
23680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
23780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned : NumExprBits;
23880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
23980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned NumObjects : 32 - NumExprBits;
24080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  };
24180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
2424b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class PseudoObjectExprBitfields {
2434b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr;
2444b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class ASTStmtReader; // deserialization
2454b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2464b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned : NumExprBits;
2474b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2484b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // These don't need to be particularly wide, because they're
2494b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // strictly limited by the forms of expressions we permit.
2504b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned NumSubExprs : 8;
2514b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned ResultIndex : 32 - 8 - NumExprBits;
2524b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
2534b9c2d235fb9449e249d74f48ecfec601650de93John McCall
254f85e193739c953358c865005855253af4f68a497John McCall  class ObjCIndirectCopyRestoreExprBitfields {
255f85e193739c953358c865005855253af4f68a497John McCall    friend class ObjCIndirectCopyRestoreExpr;
256f85e193739c953358c865005855253af4f68a497John McCall    unsigned : NumExprBits;
257f85e193739c953358c865005855253af4f68a497John McCall
258f85e193739c953358c865005855253af4f68a497John McCall    unsigned ShouldCopy : 1;
259f85e193739c953358c865005855253af4f68a497John McCall  };
260f85e193739c953358c865005855253af4f68a497John McCall
26132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  class InitListExprBitfields {
26232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    friend class InitListExpr;
26332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned : NumExprBits;
26532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list originally had a GNU array-range
26732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// designator in it. This is a temporary marker used by CodeGen.
26832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned HadArrayRangeDesignator : 1;
26932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  };
27032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
2714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  class TypeTraitExprBitfields {
2724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class TypeTraitExpr;
2734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtReader;
2744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtWriter;
2754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned : NumExprBits;
2774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
2794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Kind : 8;
2804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief If this expression is not value-dependent, this indicates whether
2824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// the trait evaluated true or false.
2834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Value : 1;
2844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The number of arguments to this type trait.
2864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
2874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  };
288211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith
2898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  union {
29063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    // FIXME: this is wasteful on 64-bit platforms.
29163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    void *Aligner;
29263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
2938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBitfields StmtBits;
2948e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBitfields CompoundStmtBits;
2958e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBitfields ExprBits;
296bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    CharacterLiteralBitfields CharacterLiteralBits;
297bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    FloatingLiteralBitfields FloatingLiteralBits;
298bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
299cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    DeclRefExprBitfields DeclRefExprBits;
3008e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBitfields CastExprBits;
301cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    CallExprBitfields CallExprBits;
30280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    ExprWithCleanupsBitfields ExprWithCleanupsBits;
3034b9c2d235fb9449e249d74f48ecfec601650de93John McCall    PseudoObjectExprBitfields PseudoObjectExprBits;
304f85e193739c953358c865005855253af4f68a497John McCall    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
30532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    InitListExprBitfields InitListExprBits;
3064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeTraitExprBitfields TypeTraitExprBits;
3078e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
3088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
309d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  friend class ASTStmtReader;
3104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
311d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
3128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic:
3138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Only allow allocation of Stmts using the allocator in ASTContext
3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // or by doing a placement new.
31505ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper  void* operator new(size_t bytes, const ASTContext& C,
3165b3ebb4356ac62abd8767c4c3388b773d9d61802Craig Topper                     unsigned alignment = 8);
3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
318bdf253de659442bc3fd4fc28d6145ad46113a0a7Craig Topper  void* operator new(size_t bytes, const ASTContext* C,
319536bcedb8e6fea6458789f99f0ef554ce65514ccCraig Topper                     unsigned alignment = 8) {
320536bcedb8e6fea6458789f99f0ef554ce65514ccCraig Topper    return operator new(bytes, *C, alignment);
321536bcedb8e6fea6458789f99f0ef554ce65514ccCraig Topper  }
322bdf253de659442bc3fd4fc28d6145ad46113a0a7Craig Topper
3238189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, void* mem) throw() {
3248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return mem;
3258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
326e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
32705ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper  void operator delete(void*, const ASTContext&, unsigned) throw() { }
32805ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper  void operator delete(void*, const ASTContext*, unsigned) throw() { }
32905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper  void operator delete(void*, size_t) throw() { }
330fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, void*) throw() { }
331e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
332025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic:
333025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief A placeholder type used to construct an empty shell of a
334025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// type, that will be filled in later (e.g., by some
335025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// de-serialization).
336025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  struct EmptyShell { };
337025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
33802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate:
33902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  /// \brief Whether statistic collection is enabled.
34002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static bool StatisticsEnabled;
34102892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar
3429c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected:
343025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Construct an empty statement.
3448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  explicit Stmt(StmtClass SC, EmptyShell) {
3458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
34602892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
347025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  }
348025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3508e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt(StmtClass SC) {
3518e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
35202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
355ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  StmtClass getStmtClass() const {
3568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    return static_cast<StmtClass>(StmtBits.sClass);
357b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor  }
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStmtClassName() const;
3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
360b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// SourceLocation tokens are not useful in isolation - they are low level
361b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// value objects created/interpreted by SourceManager. We assume AST
362b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// clients will have a pointer to the respective SourceManager.
363aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
364aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
365aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // global temp stats (until we have a per-module visitor)
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void addStmtClass(const StmtClass s);
36902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static void EnableStatistics();
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void PrintStats();
3716000dace22f110d8768476989313e9d981d690d0Chris Lattner
37295f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \brief Dumps the specified AST fragment and all subtrees to
37395f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \c llvm::errs().
374651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void dump() const;
375651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void dump(SourceManager &SM) const;
3768cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS, SourceManager &SM) const;
3776000dace22f110d8768476989313e9d981d690d0Chris Lattner
3787ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu  /// dumpColor - same as dump(), but forces color highlighting.
379651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void dumpColor() const;
3807ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu
3816000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
3826000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// back to its original source language syntax.
3838b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper  void dumpPretty(const ASTContext &Context) const;
3848cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
385e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
386d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                   unsigned Indentation = 0) const;
3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
388d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
389d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
390d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  void viewAST() const;
3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3927e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// Skip past any implicit AST nodes which might surround this
3937e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
3947e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  Stmt *IgnoreImplicit();
3957e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
396a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  const Stmt *stripLabelLikeStatements() const;
397a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  Stmt *stripLabelLikeStatements() {
398a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth    return const_cast<Stmt*>(
399a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
400a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  }
401a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth
40263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// Child Iterators: All subclasses must implement 'children'
40363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// to permit easy iteration over the substatements/subexpessions of an
40463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// AST node.  This permits easy iteration over all nodes in the AST.
4059caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef StmtIterator       child_iterator;
4069caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef ConstStmtIterator  const_child_iterator;
4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef StmtRange          child_range;
40963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef ConstStmtRange     const_child_range;
4101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
41263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_range children() const {
41363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return const_cast<Stmt*>(this)->children();
41477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_begin() { return children().first; }
41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_end() { return children().second; }
41863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
41963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_begin() const { return children().first; }
42063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_end() const { return children().second; }
42141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
42241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Produce a unique representation of the given statement.
42341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42470517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param ID once the profiling operation is complete, will contain
42541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// the unique representation of the given statement.
42641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42770517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Context the AST context in which the statement resides
42841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42970517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Canonical whether the profile should be based on the canonical
43041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// representation of this statement (e.g., where non-type template
4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// parameters are identified by index/level rather than their
43241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// declaration pointers) or the exact representation of the statement as
43341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// written in the source.
4344ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
435b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth               bool Canonical) const;
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions
4401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration.
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt {
4449653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor  DeclGroupRef DG;
44581c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation StartLoc, EndLoc;
4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
4498ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
4508ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek                                    StartLoc(startLoc), EndLoc(endLoc) {}
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  /// \brief Build an empty declaration statement.
45384f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
45484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4557e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  /// isSingleDecl - This method returns true if this DeclStmt refers
456fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner  /// to a single Decl.
4577e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  bool isSingleDecl() const {
458fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner    return DG.isSingleDecl();
4598ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  }
4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4617e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Decl *getSingleDecl() { return DG.getSingleDecl(); }
4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
464e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  const DeclGroupRef getDeclGroup() const { return DG; }
465e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  DeclGroupRef getDeclGroup() { return DG; }
46684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
467b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
46881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
46984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setStartLoc(SourceLocation L) { StartLoc = L; }
47081c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
47184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setEndLoc(SourceLocation L) { EndLoc = L; }
47284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
47365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
47465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
4751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DeclStmtClass;
4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48014f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek  // Iterators over subexpressions.
48163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
48263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(child_iterator(DG.begin(), DG.end()),
48363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       child_iterator(DG.end(), DG.end()));
48463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4860632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::iterator decl_iterator;
4870632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::const_iterator const_decl_iterator;
488651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  typedef llvm::iterator_range<decl_iterator> decl_range;
489651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  typedef llvm::iterator_range<const_decl_iterator> decl_const_range;
4901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
491651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  decl_range decls() { return decl_range(decl_begin(), decl_end()); }
492651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  decl_const_range decls() const {
493651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return decl_const_range(decl_begin(), decl_end());
494651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  }
4958ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_begin() { return DG.begin(); }
4968ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_end() { return DG.end(); }
4978ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_begin() const { return DG.begin(); }
4988ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_end() const { return DG.end(); }
499fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose
500fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
501fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rbegin() {
502fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_end());
503fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
504fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rend() {
505fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_begin());
506fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3.
5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt {
5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation SemiLoc;
51344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
514e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  /// \brief True if the null statement was preceded by an empty macro, e.g:
51544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @code
51644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   #define CALL(x)
51744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   CALL(0);
51844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @endcode
519e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool HasLeadingEmptyMacro;
5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
521e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
522e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis    : Stmt(NullStmtClass), SemiLoc(L),
523e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
525025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty null statement.
526e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
527e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(false) { }
528025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getSemiLoc() const { return SemiLoc; }
530025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
531b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
532e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
53344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
53465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
53565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == NullStmtClass;
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
54244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
54344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtReader;
54444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtWriter;
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }.
5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt {
5508189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  Stmt** Body;
551b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation LBracLoc, RBracLoc;
5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5530b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
5543a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer               SourceLocation LB, SourceLocation RB);
5553a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer
556063820655db8121f0022a7c51458463c7250324cBenjamin Kramer  // \brief Build an empty compound statement with a location.
5573a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  explicit CompoundStmt(SourceLocation Loc)
5586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    : Stmt(CompoundStmtClass), Body(nullptr), LBracLoc(Loc), RBracLoc(Loc) {
5593a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    CompoundStmtBits.NumStmts = 0;
5601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
561025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
562025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  // \brief Build an empty compound statement.
563025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CompoundStmt(EmptyShell Empty)
5646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    : Stmt(CompoundStmtClass, Empty), Body(nullptr) {
5658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = 0;
5668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
567025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5688b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper  void setStmts(const ASTContext &C, Stmt **Stmts, unsigned NumStmts);
5691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
5718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned size() const { return CompoundStmtBits.NumStmts; }
572025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5738189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt** body_iterator;
574651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  typedef llvm::iterator_range<body_iterator> body_range;
575651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
576651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  body_range body() { return body_range(body_begin(), body_end()); }
5778189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  body_iterator body_begin() { return Body; }
5788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  body_iterator body_end() { return Body + size(); }
5796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  Stmt *body_back() { return !body_empty() ? Body[size()-1] : nullptr; }
580ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setLastStmt(Stmt *S) {
5828e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    assert(!body_empty() && "setLastStmt");
5838e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Body[size()-1] = S;
5848e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt* const * const_body_iterator;
587651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  typedef llvm::iterator_range<const_body_iterator> body_const_range;
588651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
589651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  body_const_range body() const {
590651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return body_const_range(body_begin(), body_end());
591651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  }
5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_body_iterator body_begin() const { return Body; }
5938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const_body_iterator body_end() const { return Body + size(); }
5946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  const Stmt *body_back() const {
5956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return !body_empty() ? Body[size() - 1] : nullptr;
5966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  }
5978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek
5988189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
5998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rbegin() {
6008189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_end());
6018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rend() {
6038189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_begin());
6048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6054ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
6068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<const_body_iterator>
6078189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek          const_reverse_body_iterator;
6084ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
6098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rbegin() const {
6108189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_end());
6118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rend() const {
6148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_begin());
6158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
61865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
620cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getLBracLoc() const { return LBracLoc; }
621025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
622cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getRBracLoc() const { return RBracLoc; }
623025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
6241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundStmtClass;
6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6298297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
63063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
631651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return child_range(Body, Body + CompoundStmtBits.NumStmts);
63263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
633ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6348ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  const_child_range children() const {
635651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return child_range(Body, Body + CompoundStmtBits.NumStmts);
6368ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  }
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
639c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt,
640c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt {
641103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected:
642c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // A pointer to the following CaseStmt or DefaultStmt class,
643c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // used by SwitchStmt.
644c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *NextSwitchCase;
64581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation KeywordLoc;
64681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation ColonLoc;
64781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis
64881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
6496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    : Stmt(SC), NextSwitchCase(nullptr), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {
6506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  }
651103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek
65281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SwitchCase(StmtClass SC, EmptyShell)
6536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    : Stmt(SC), NextSwitchCase(nullptr) {}
6541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
655c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic:
656c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
657c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
658c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
659c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
660c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
661d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek
66281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getKeywordLoc() const { return KeywordLoc; }
66381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
66481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getColonLoc() const { return ColonLoc; }
66581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setColonLoc(SourceLocation L) { ColonLoc = L; }
66681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis
66763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  Stmt *getSubStmt();
668702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  const Stmt *getSubStmt() const {
669702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner    return const_cast<SwitchCase*>(this)->getSubStmt();
670702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  }
671b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
67281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
67381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocEnd() const LLVM_READONLY;
6741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass ||
67763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall           T->getStmtClass() == DefaultStmtClass;
678c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
679c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson};
680c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
681c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase {
6820a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor  enum { LHS, RHS, SUBSTMT, END_EXPR };
6831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
684d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek                             // GNU "case 1 ... 4" extension
685dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation EllipsisLoc;
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
687dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
6881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation ellipsisLoc, SourceLocation colonLoc)
68981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
6906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    SubExprs[SUBSTMT] = nullptr;
691d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
692d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
693dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    EllipsisLoc = ellipsisLoc;
694d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  }
695025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
696025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty switch case statement.
69781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
698025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
69981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getCaseLoc() const { return KeywordLoc; }
70081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
701dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
702dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
703dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
704dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
705025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
706d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
707d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
708d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
709025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getLHS() const {
7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
71251b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const {
7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
71551b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
71651b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
71820dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
71920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
72020dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
7211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
72365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
7243fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    // Handle deeply nested case statements with iteration instead of recursion.
7253fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    const CaseStmt *CS = this;
72691ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
7273fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner      CS = CS2;
7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return CS->getSubStmt()->getLocEnd();
730b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
73165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass;
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
736d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
73763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
73863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
73963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
742c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase {
743d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt* SubStmt;
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
74681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
747025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
748025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty default statement.
74981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  explicit DefaultStmt(EmptyShell Empty)
75081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : SwitchCase(DefaultStmtClass, Empty) { }
751025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
752d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubStmt; }
75351b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubStmt; }
754025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSubStmt(Stmt *S) { SubStmt = S; }
755025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
75681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getDefaultLoc() const { return KeywordLoc; }
75781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
758dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
759dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
76181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
76265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
76365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DefaultStmtClass;
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
768d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
76963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
77281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidisinline SourceLocation SwitchCase::getLocEnd() const {
77381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
77481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    return CS->getLocEnd();
77581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  return cast<DefaultStmt>(this)->getLocEnd();
77681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis}
777ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
778ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement.  For example:
779ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///    foo: return;
780ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt {
782ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *TheDecl;
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *SubStmt;
784b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IdentLoc;
7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
786ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
787ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
7888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
7891de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
7901de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  // \brief Build an empty label statement.
7911de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getIdentLoc() const { return IdentLoc; }
794ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getDecl() const { return TheDecl; }
795ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setDecl(LabelDecl *D) { TheDecl = D; }
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *getSubStmt() { return SubStmt; }
7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Stmt *getSubStmt() const { return SubStmt; }
7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setSubStmt(Stmt *SS) { SubStmt = SS; }
801b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
80265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
80365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
80465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
80563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
80663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
8071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == LabelStmtClass;
8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
813534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement.
814534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
815534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example:
816534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///   [[omp::for(...)]] for (...) { ... }
817534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
818534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt {
819534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *SubStmt;
820534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation AttrLoc;
8214990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  unsigned NumAttrs;
822534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
823534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  friend class ASTStmtReader;
824534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8254990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
8264990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
8274990890fc9428f98bef90ba349203a648c592778Alexander Kornienko      NumAttrs(Attrs.size()) {
8286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    memcpy(getAttrArrayPtr(), Attrs.data(), Attrs.size() * sizeof(Attr *));
829534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
830534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8314990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
8324990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
8336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    memset(getAttrArrayPtr(), 0, NumAttrs * sizeof(Attr *));
8346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  }
8356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
8366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  Attr *const *getAttrArrayPtr() const {
8376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return reinterpret_cast<Attr *const *>(this + 1);
838534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
8396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  Attr **getAttrArrayPtr() { return reinterpret_cast<Attr **>(this + 1); }
840534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8414990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic:
8420b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
8434990890fc9428f98bef90ba349203a648c592778Alexander Kornienko                                ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
8444990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  // \brief Build an empty attributed statement.
8450b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
8464990890fc9428f98bef90ba349203a648c592778Alexander Kornienko
847534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation getAttrLoc() const { return AttrLoc; }
8484990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  ArrayRef<const Attr*> getAttrs() const {
8496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return ArrayRef<const Attr*>(getAttrArrayPtr(), NumAttrs);
8504990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  }
851534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *getSubStmt() { return SubStmt; }
852534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  const Stmt *getSubStmt() const { return SubStmt; }
853534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
85465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
85565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
85665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
857534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
858534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
859534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  static bool classof(const Stmt *T) {
860534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return T->getStmtClass() == AttributedStmtClass;
861534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
862534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith};
863534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
864534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else.
8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt {
86843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, THEN, ELSE, END_EXPR };
8698297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
8708cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor
871b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IfLoc;
872d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation ElseLoc;
873ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8750b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
8766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines         Stmt *then, SourceLocation EL = SourceLocation(),
8776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines         Stmt *elsev = nullptr);
878ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
879025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty if/then/else statement
880025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
881025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
8828cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \brief Retrieve the variable declared in this "if" statement, if any.
8838cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///
8848cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// In the following example, "x" is the condition variable.
8858cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \code
8868cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// if (int x = foo()) {
8878cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///   printf("x is %d", x);
8888cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// }
8898cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \endcode
89043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
8910b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  void setConditionVariable(const ASTContext &C, VarDecl *V);
892ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
893d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this IfStmt has a condition variable, return the faux DeclStmt
894d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
895d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
896d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
897d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
898ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8998297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
900025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
9018297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getThen() const { return SubExprs[THEN]; }
9021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setThen(Stmt *S) { SubExprs[THEN] = S; }
9038297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getElse() const { return SubExprs[ELSE]; }
904025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9068297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
9078297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getThen() { return SubExprs[THEN]; }
9088297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getElse() { return SubExprs[ELSE]; }
909b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
910025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getIfLoc() const { return IfLoc; }
911025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setIfLoc(SourceLocation L) { IfLoc = L; }
912d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation getElseLoc() const { return ElseLoc; }
913d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  void setElseLoc(SourceLocation L) { ElseLoc = L; }
914025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
91565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
91665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
917b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    if (SubExprs[ELSE])
91865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return SubExprs[ELSE]->getLocEnd();
919b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    else
92065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return SubExprs[THEN]->getLocEnd();
921b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators over subexpressions.  The iterators will include iterating
92463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // over the initialization expression referenced by the condition variable.
92563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
92663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
92763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
92863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
9291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IfStmtClass;
9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt.
9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt {
93743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
9381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
939c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // This points to a linked list of case and default statements.
940c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *FirstCase;
9419dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  SourceLocation SwitchLoc;
9421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
943559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// If the SwitchStmt is a switch on an enum value, this records whether
944559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// all the enum values were covered by CaseStmts.  This value is meant to
945559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// be a hint for possible clients.
946559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  unsigned AllEnumCasesCovered : 1;
947559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
9490b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond);
9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
951025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build a empty switch statement.
952025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
953025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
954d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \brief Retrieve the variable declared in this "switch" statement, if any.
955d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///
956d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// In the following example, "x" is the condition variable.
957d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \code
958d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// switch (int x = foo()) {
959d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   case 0: break;
960d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   // ...
961d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// }
962d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \endcode
96343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
9640b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  void setConditionVariable(const ASTContext &C, VarDecl *V);
965ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
966d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
967d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
968d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
969d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
970d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
971d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor
9728297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
9738297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
974c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
975c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9768297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
977025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
9788297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
979025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
980c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getSwitchCaseList() { return FirstCase; }
9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Set the case list for this switch statement.
983025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
984025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
985025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getSwitchLoc() const { return SwitchLoc; }
986025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
987c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setBody(Stmt *S, SourceLocation SL) {
9891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[BODY] = S;
9909dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    SwitchLoc = SL;
9911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
992c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void addSwitchCase(SwitchCase *SC) {
993ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!SC->getNextSwitchCase()
994ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           && "case/default already added to a switch");
995c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    SC->setNextSwitchCase(FirstCase);
996c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson    FirstCase = SC;
997c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
998559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
999559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
1000559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// switch over an enum value then all cases have been explicitly covered.
1001559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  void setAllEnumCasesCovered() {
1002559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    AllEnumCasesCovered = 1;
1003559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
1004559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
1005559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
1006559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// have been explicitly covered.
1007559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  bool isAllEnumCasesCovered() const {
1008559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    return (bool) AllEnumCasesCovered;
1009559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
1010559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
101165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
101265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
101365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
10149dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  }
101565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
101663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators
101763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
101863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
101963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
102063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
10211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SwitchStmtClass;
10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt.
10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt {
103043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
10318297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1032b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation WhileLoc;
10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10340b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
103543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor            SourceLocation WL);
10361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1037d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty while statement.
1038d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1039d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
10405656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \brief Retrieve the variable declared in this "while" statement, if any.
10415656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///
10425656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// In the following example, "x" is the condition variable.
10435656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \code
10445656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// while (int x = random()) {
10455656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///   // ...
10465656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// }
10475656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \endcode
104843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
10490b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  void setConditionVariable(const ASTContext &C, VarDecl *V);
10505656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
1051d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1052d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1053d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1054d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1055d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1056d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
10578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10588297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1059d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1062d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1063d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1064d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
1065d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1066b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
106765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
106865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
106965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
1070b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
107165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
10721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == WhileStmtClass;
10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10768297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
107763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
107863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
107963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt.
10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt {
1085c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor  enum { BODY, COND, END_EXPR };
10868297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1087b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation DoLoc;
10889f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation WhileLoc;
1089989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
10909f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor
10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1092989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1093989135901c750af61ef012b6b0a0368be415bc46Chris Lattner         SourceLocation RP)
1094989135901c750af61ef012b6b0a0368be415bc46Chris Lattner    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
10958297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
10968297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[BODY] = body;
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
109867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
109967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty do-while statement.
110067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
11011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11028297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
11038297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
110467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
11058297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Stmt *getBody() const { return SubExprs[BODY]; }
110767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
110867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
110967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getDoLoc() const { return DoLoc; }
111067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setDoLoc(SourceLocation L) { DoLoc = L; }
11119f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
11129f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1113b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1114989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
1115989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1116989135901c750af61ef012b6b0a0368be415bc46Chris Lattner
111765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
111865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
111965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DoStmtClass;
11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11238297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11248297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
112563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
112663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
112763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not
11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source.
11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt {
113643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
11378297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1138b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation ForLoc;
11395831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation LParenLoc, RParenLoc;
11405831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor
11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11420b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
11430b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper          Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
11440b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper          SourceLocation RP);
11451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
114667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty for statement.
114767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
114867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
11498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getInit() { return SubExprs[INIT]; }
1150ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
115199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \brief Retrieve the variable declared in this "for" statement, if any.
115299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///
115399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// In the following example, "y" is the condition variable.
115499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \code
115599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// for (int x = random(); int y = mangle(x); ++x) {
115699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///   // ...
115799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// }
115899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \endcode
115943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
11600b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  void setConditionVariable(const ASTContext &C, VarDecl *V);
1161ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1162d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this ForStmt has a condition variable, return the faux DeclStmt
1163d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1164d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1165d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1166d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1167d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
11688297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
11698297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11708297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
11718297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11728297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getInit() const { return SubExprs[INIT]; }
11738297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
11748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1176b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
117767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInit(Stmt *S) { SubExprs[INIT] = S; }
117867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
117967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
118067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
118167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
118267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getForLoc() const { return ForLoc; }
118367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setForLoc(SourceLocation L) { ForLoc = L; }
11845831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
11855831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
11865831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11875831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
118867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
118965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
119065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
119165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
1192b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
119365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
11941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ForStmtClass;
11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11988297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
119963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
120063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
120163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto.
12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt {
1207ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
1208507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation GotoLoc;
120961f62165220e75694fe333179c78815e2e48d71fTed Kremenek  SourceLocation LabelLoc;
12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1211ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
121261f62165220e75694fe333179c78815e2e48d71fTed Kremenek    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12141de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Build an empty goto statement.
12151de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
12161de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1217ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
1218ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *D) { Label = D; }
12191de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
12201de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getGotoLoc() const { return GotoLoc; }
12211de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
12221de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
12231de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1224b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
122565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
122665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
122765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GotoStmtClass;
12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12328297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
123363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto.
12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt {
1239ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation GotoLoc;
12405f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation StarLoc;
12411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Target;
12425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
12445f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor                   Expr *target)
12455f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
12465f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor      Target((Stmt*)target) {}
12477d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
12487d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty indirect goto statement.
12491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IndirectGotoStmt(EmptyShell Empty)
12507d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Stmt(IndirectGotoStmtClass, Empty) { }
12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1252ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1253ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation getGotoLoc() const { return GotoLoc; }
12545f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  void setStarLoc(SourceLocation L) { StarLoc = L; }
12555f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation getStarLoc() const { return StarLoc; }
12561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
125795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
125895c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
12597d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1260b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
126195c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// getConstantTarget - Returns the fixed target of this indirect
126295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// goto, if one exists.
1263ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getConstantTarget();
1264ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  const LabelDecl *getConstantTarget() const {
126595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
126695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  }
126795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall
126865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
126965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
12701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IndirectGotoStmtClass;
12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
127663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Target, &Target+1); }
12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue.
12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt {
1283507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation ContinueLoc;
12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1285507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1287d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty continue statement.
1288d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1289d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1290d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getContinueLoc() const { return ContinueLoc; }
1291d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1292d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
129365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
129465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1295861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor
12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ContinueStmtClass;
12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13008297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
130163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break.
13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt {
1307507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation BreakLoc;
13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1309507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1311025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty break statement.
1312025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1313025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1314025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getBreakLoc() const { return BreakLoc; }
1315025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1316025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
131765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
131865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1319b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BreakStmtClass;
13225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13248297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
132563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1329c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression:
1330c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return;
1331c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return 4;
1332c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///
1333c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to
1334c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to
1335c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void.  We explicitly model this in the AST, which means you can't
1336c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument.
13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt {
13391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *RetExpr;
1340507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation RetLoc;
13415077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *NRVOCandidate;
1342ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13445077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL)
13456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    : Stmt(ReturnStmtClass), RetExpr(nullptr), RetLoc(RL),
13466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines      NRVOCandidate(nullptr) {}
13475077c3876beeaed32280af88244e8050078619a8Douglas Gregor
13485077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
13495077c3876beeaed32280af88244e8050078619a8Douglas Gregor    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
13505077c3876beeaed32280af88244e8050078619a8Douglas Gregor      NRVOCandidate(NRVOCandidate) {}
13510de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13520de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  /// \brief Build an empty return expression.
13530de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
13540de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getRetValue() const;
13561060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getRetValue();
13570de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
13580de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13590de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  SourceLocation getReturnLoc() const { return RetLoc; }
13600de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1361b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13625077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// \brief Retrieve the variable that might be used for the named return
13635077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// value optimization.
13645077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ///
13655077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// The optimization itself can only be performed if the variable is
13665077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// also marked as an NRVO object.
13675077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
13685077c3876beeaed32280af88244e8050078619a8Douglas Gregor  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1369ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
137065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
137165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
137265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return RetExpr ? RetExpr->getLocEnd() : RetLoc;
137365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ReturnStmtClass;
13775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13798297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
138063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
138163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
138263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range();
138363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
13845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1386728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1387728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier///
1388728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass AsmStmt : public Stmt {
1389728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierprotected:
1390066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation AsmLoc;
139112b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief True if the assembly statement does not have any input or output
139212b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// operands.
1393728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsSimple;
139412b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier
139512b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief If true, treat this inline assembly as having side effects.
139612b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// This assembly statement should not be optimized, deleted or moved.
1397728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsVolatile;
1398728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1399066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumOutputs;
1400066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumInputs;
1401066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumClobbers;
1402066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
140319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  Stmt **Exprs;
1404066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1405066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1406066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier          unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1407066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1408066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1409728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1410aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  friend class ASTStmtReader;
1411aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1412728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierpublic:
1413728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  /// \brief Build an empty inline-assembly statement.
1414728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
14156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Stmt(SC, Empty), Exprs(nullptr) { }
141629760b452876548f59804e8c02c3276bc7281d5dMatt Beaumont-Gay
1417066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation getAsmLoc() const { return AsmLoc; }
1418066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1419728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1420728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isSimple() const { return IsSimple; }
1421728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setSimple(bool V) { IsSimple = V; }
1422728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1423728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isVolatile() const { return IsVolatile; }
1424728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setVolatile(bool V) { IsVolatile = V; }
1425728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
142665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
142765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1428728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1429da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  //===--- Asm String Analysis ---===//
1430da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1431da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
14328b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper  std::string generateAsmString(const ASTContext &C) const;
1433da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1434066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Output operands ---===//
1435066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1436066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumOutputs() const { return NumOutputs; }
1437066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1438c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getOutputConstraint - Return the constraint string for the specified
1439c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// output operand.  All output constraints are known to be non-empty (either
1440c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// '=' or '+').
1441aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getOutputConstraint(unsigned i) const;
1442c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1443c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// isOutputPlusConstraint - Return true if the specified output constraint
1444c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is a "+" constraint (which is both an input and an output) or false if it
1445c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is an "=" constraint (just an output).
1446c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  bool isOutputPlusConstraint(unsigned i) const {
1447c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier    return getOutputConstraint(i)[0] == '+';
1448c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  }
1449c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1450aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getOutputExpr(unsigned i) const;
1451c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1452c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getNumPlusOperands - Return the number of output operands that have a "+"
1453c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraint.
1454c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  unsigned getNumPlusOperands() const;
1455c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1456066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Input operands ---===//
1457066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1458066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumInputs() const { return NumInputs; }
1459066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1460c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getInputConstraint - Return the specified input constraint.  Unlike output
1461c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraints, these can be empty.
1462aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getInputConstraint(unsigned i) const;
1463aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier
1464aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getInputExpr(unsigned i) const;
1465c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1466066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Other ---===//
1467066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
14682fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier  unsigned getNumClobbers() const { return NumClobbers; }
1469aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getClobber(unsigned i) const;
14702fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier
1471728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  static bool classof(const Stmt *T) {
1472728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass ||
1473728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier      T->getStmtClass() == MSAsmStmtClass;
1474728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  }
147519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Input expr iterators.
147719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator inputs_iterator;
147919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_inputs_iterator;
148019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator begin_inputs() {
148219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
148319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator end_inputs() {
148619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
148719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator begin_inputs() const {
149019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
149119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator end_inputs() const {
149419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
149519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Output expr iterators.
149819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator outputs_iterator;
150019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_outputs_iterator;
150119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
150219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator begin_outputs() {
150319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
150419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
150519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator end_outputs() {
150619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
150719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
150819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
150919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator begin_outputs() const {
151019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
151119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
151219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator end_outputs() const {
151319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
151419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
151519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
151619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  child_range children() {
151719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
151819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
1519728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier};
1520728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
15217d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a GCC inline-assembly statement extension.
1522fe795956194141c91ae555985c9b930595bff43fChris Lattner///
1523728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass GCCAsmStmt : public AsmStmt {
1524066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation RParenLoc;
15256a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  StringLiteral *AsmStr;
1526b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1527966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  // FIXME: If we wanted to, we could allocate all of these in one big array.
1528966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Constraints;
1529966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Clobbers;
1530aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  IdentifierInfo **Names;
1531aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1532aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  friend class ASTStmtReader;
1533ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1534fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic:
15350b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
1536df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             bool isvolatile, unsigned numoutputs, unsigned numinputs,
1537df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1538df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral *asmstr, unsigned numclobbers,
1539df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral **clobbers, SourceLocation rparenloc);
1540b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1541cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  /// \brief Build an empty inline-assembly statement.
1542728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
15436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Constraints(nullptr), Clobbers(nullptr), Names(nullptr) { }
1544cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1545cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1546cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1547cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1548458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  //===--- Asm String Analysis ---===//
1549458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1550458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  const StringLiteral *getAsmString() const { return AsmStr; }
1551458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  StringLiteral *getAsmString() { return AsmStr; }
1552cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmString(StringLiteral *E) { AsmStr = E; }
1553cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1554458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AsmStringPiece - this is part of a decomposed asm string specification
1555458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// (for use with the AnalyzeAsmString function below).  An asm string is
1556458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// considered to be a concatenation of these parts.
1557458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  class AsmStringPiece {
1558458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1559458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    enum Kind {
1560458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1561458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Operand  // Operand reference, with optional modifier %c4.
1562458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    };
1563458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  private:
1564458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    Kind MyKind;
1565458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    std::string Str;
1566458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned OperandNo;
1567458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1568458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1569458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(unsigned OpNo, char Modifier)
1570458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      : MyKind(Operand), Str(), OperandNo(OpNo) {
1571458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Str += Modifier;
1572458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1574458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isString() const { return MyKind == String; }
1575458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isOperand() const { return MyKind == Operand; }
15761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1577458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    const std::string &getString() const {
1578458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isString());
1579458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str;
1580458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1581458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1582458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned getOperandNo() const {
1583458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1584458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return OperandNo;
1585458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1587458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// getModifier - Get the modifier for this operand, if present.  This
1588458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// returns '\0' if there was no modifier.
1589458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    char getModifier() const {
1590458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1591458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str[0];
1592458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1593458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  };
15941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1595458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1596458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// it into pieces.  If the asm string is erroneous, emit errors and return
1597458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// true, otherwise return false.  This handles canonicalization and
1598458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1600686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
16018b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper                            const ASTContext &C, unsigned &DiagOffs) const;
16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1603da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
16048b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper  std::string generateAsmString(const ASTContext &C) const;
16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1606b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Output operands ---===//
1607b327793860737d1c103a73aeda8057dd628a101dChris Lattner
1608aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1609aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return Names[i];
1610aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1611aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1612aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getOutputName(unsigned i) const {
1613aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    if (IdentifierInfo *II = getOutputIdentifier(i))
1614aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall      return II->getName();
1615aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1616aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return StringRef();
1617aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1618aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1619686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputConstraint(unsigned i) const;
16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1621b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1622ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i];
1623ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1624b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1625b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return Constraints[i];
1626b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1628ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getOutputExpr(unsigned i);
16291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1630b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getOutputExpr(unsigned i) const {
1631df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1632b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1634b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Input operands ---===//
16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1636aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  IdentifierInfo *getInputIdentifier(unsigned i) const {
1637aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return Names[i + NumOutputs];
1638aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1639aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1640aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getInputName(unsigned i) const {
1641aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    if (IdentifierInfo *II = getInputIdentifier(i))
1642aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall      return II->getName();
1643aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1644aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return StringRef();
1645aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1646aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1647686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputConstraint(unsigned i) const;
16481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1649b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1650ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1651ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1652b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getInputConstraintLiteral(unsigned i) {
1653ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1654ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
16551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1656ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getInputExpr(unsigned i);
1657935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner  void setInputExpr(unsigned i, Expr *E);
1658ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1659b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getInputExpr(unsigned i) const {
1660df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1661b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
1662cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1663aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate:
16648b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper  void setOutputsAndInputsAndClobbers(const ASTContext &C,
1665ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                      IdentifierInfo **Names,
1666fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Constraints,
1667fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      Stmt **Exprs,
1668fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumOutputs,
1669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      unsigned NumInputs,
1670fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Clobbers,
1671fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumClobbers);
1672aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic:
1673cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
167410ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  //===--- Other ---===//
16751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
167610ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// getNamedOperand - Given a symbolic operand reference like %[foo],
167710ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// translate this into a numeric value needed to reference the same operand.
167810ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// This returns -1 if the operand name is invalid.
1679686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  int getNamedOperand(StringRef SymbolicName) const;
168010ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner
168133f0558f75f70061707d1388e305b8f92f4e55deChad Rosier  StringRef getClobber(unsigned i) const;
16825c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
16835c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  const StringLiteral *getClobberStringLiteral(unsigned i) const {
16845c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier    return Clobbers[i];
16855c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  }
1686cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
168765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
168865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
16891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1690df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  static bool classof(const Stmt *T) {
1691df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass;
1692df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  }
1693fe795956194141c91ae555985c9b930595bff43fChris Lattner};
169478492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek
16957d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a Microsoft inline-assembly statement extension.
16968cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier///
1697728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass MSAsmStmt : public AsmStmt {
1698c4cca7b2408bdfd99ea0f63fec1421c1327593b2Enea Zaffanella  SourceLocation LBraceLoc, EndLoc;
1699aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef AsmStr;
17008cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
170179efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned NumAsmToks;
170279efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier
170379efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *AsmToks;
170489fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef *Constraints;
170533c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier  StringRef *Clobbers;
17068cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1707aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  friend class ASTStmtReader;
1708aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
17098cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic:
17100b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
17110b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper            SourceLocation lbraceloc, bool issimple, bool isvolatile,
17120b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper            ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
1713aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall            ArrayRef<StringRef> constraints,
1714e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            ArrayRef<Expr*> exprs, StringRef asmstr,
171589fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier            ArrayRef<StringRef> clobbers, SourceLocation endloc);
17168cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1717cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier  /// \brief Build an empty MS-style inline-assembly statement.
1718728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
17196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    NumAsmToks(0), AsmToks(nullptr), Constraints(nullptr), Clobbers(nullptr) { }
1720cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier
17217bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  SourceLocation getLBraceLoc() const { return LBraceLoc; }
17227bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
17238cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceLocation getEndLoc() const { return EndLoc; }
17248cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setEndLoc(SourceLocation L) { EndLoc = L; }
17258cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17267bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  bool hasBraces() const { return LBraceLoc.isValid(); }
17277bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier
172879efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned getNumAsmToks() { return NumAsmToks; }
172979efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *getAsmToks() { return AsmToks; }
17308f726de55412870ef70e788b852c6cc50873e15bChad Rosier
17318cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Asm String Analysis ---===//
1732aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getAsmString() const { return AsmStr; }
17338cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1734da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
17358b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper  std::string generateAsmString(const ASTContext &C) const;
1736da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
17372603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Output operands ---===//
17382603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
173989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getOutputConstraint(unsigned i) const {
1740aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    assert(i < NumOutputs);
174189fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i];
174289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1743c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1744633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getOutputExpr(unsigned i);
1745633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17462603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getOutputExpr(unsigned i) const {
17472603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
17482603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17492603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17502603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Input operands ---===//
17512603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
175289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getInputConstraint(unsigned i) const {
1753aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    assert(i < NumInputs);
175489fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i + NumOutputs];
175589fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1756c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1757633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getInputExpr(unsigned i);
1758633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  void setInputExpr(unsigned i, Expr *E);
1759633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17602603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getInputExpr(unsigned i) const {
17612603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
17622603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17632603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17648cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Other ---===//
17658cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1766aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  ArrayRef<StringRef> getAllConstraints() const {
1767aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return ArrayRef<StringRef>(Constraints, NumInputs + NumOutputs);
1768aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1769aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  ArrayRef<StringRef> getClobbers() const {
1770aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return ArrayRef<StringRef>(Clobbers, NumClobbers);
1771aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1772aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  ArrayRef<Expr*> getAllExprs() const {
1773aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall    return ArrayRef<Expr*>(reinterpret_cast<Expr**>(Exprs),
1774aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall                           NumInputs + NumOutputs);
1775aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  }
1776aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1777aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall  StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
1778aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall
1779aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate:
17800b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  void initialize(const ASTContext &C, StringRef AsmString,
17810b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper                  ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
17820b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper                  ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers);
1783aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic:
17844399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier
178565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
178665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
178765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
17888cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  static bool classof(const Stmt *T) {
17898cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return T->getStmtClass() == MSAsmStmtClass;
17908cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17918cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17928cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  child_range children() {
1793651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
17948cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17958cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier};
17968cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
179728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt {
179828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
179928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
180028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { FILTER_EXPR, BLOCK };
180228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt(SourceLocation Loc,
180428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Expr *FilterExpr,
180528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Stmt *Block);
180628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18077110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18087110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18097110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
18107110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
181128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
18120b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  static SEHExceptStmt* Create(const ASTContext &C,
181328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation ExceptLoc,
181428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Expr *FilterExpr,
181528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Block);
181665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
181765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
181865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
181928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getExceptLoc() const { return Loc; }
182128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
182228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1823ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getFilterExpr() const {
1824ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1825ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1826ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1827ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt *getBlock() const {
1828cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(Children[BLOCK]);
1829ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
183028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
183228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
183328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
183428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
183628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHExceptStmtClass;
183728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
183828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
184028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
184128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt {
184228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
184328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Block;
184428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
184528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt(SourceLocation Loc,
184628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                 Stmt *Block);
184728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18487110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18497110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18507110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
18517110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
185228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
18530b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  static SEHFinallyStmt* Create(const ASTContext &C,
185428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                SourceLocation FinallyLoc,
185528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                Stmt *Block);
185628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
185865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
185928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
186028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getFinallyLoc() const { return Loc; }
186128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
186228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1863cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
186428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
186528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
186628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(&Block,&Block+1);
186728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
186828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
186928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
187028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHFinallyStmtClass;
187128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
187228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
187328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
187428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
187528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt {
187628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool            IsCXXTry;
187728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  TryLoc;
187828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
187928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
188028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { TRY = 0, HANDLER = 1 };
188128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
188228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
188328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             SourceLocation TryLoc,
188428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *TryBlock,
188528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *Handler);
188628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18877110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18887110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18897110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
18907110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
189128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
18920b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
18930b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper                            SourceLocation TryLoc, Stmt *TryBlock,
189428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *Handler);
189528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
189665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
189765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
189828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
189928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getTryLoc() const { return TryLoc; }
190028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
190128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
190228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool getIsCXXTry() const { return IsCXXTry; }
1903ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1904ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt* getTryBlock() const {
1905cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(Children[TRY]);
1906ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1907ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
190828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt *getHandler() const { return Children[HANDLER]; }
190928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
191028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Returns 0 if not defined
191128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt  *getExceptHandler() const;
191228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt *getFinallyHandler() const;
191328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
191428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
191528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
191628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
191728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
191828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
191928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHTryStmtClass;
192028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
192128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
1922ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1923051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// \brief This captures a statement into a function. For example, the following
1924051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// pragma annotated compound statement can be represented as a CapturedStmt,
1925051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// and this compound statement is the body of an anonymous outlined function.
1926051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @code
1927051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// #pragma omp parallel
1928051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// {
1929051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj///   compute();
1930051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// }
1931051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @endcode
1932051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajclass CapturedStmt : public Stmt {
1933051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic:
1934051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The different capture forms: by 'this' or by reference, etc.
1935051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  enum VariableCaptureKind {
1936051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    VCK_This,
1937051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    VCK_ByRef
1938051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  };
1939051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1940051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Describes the capture of either a variable or 'this'.
1941051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  class Capture {
19423a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    llvm::PointerIntPair<VarDecl *, 1, VariableCaptureKind> VarAndKind;
1943051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    SourceLocation Loc;
1944051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1945051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  public:
1946051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Create a new capture.
1947051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1948051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \param Loc The source location associated with this capture.
1949051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1950051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \param Kind The kind of capture (this, ByRef, ...).
1951051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1952051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \param Var The variable being captured, or null if capturing this.
1953051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
19546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Capture(SourceLocation Loc, VariableCaptureKind Kind,
19556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines            VarDecl *Var = nullptr)
19563a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir      : VarAndKind(Var, Kind), Loc(Loc) {
1957051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      switch (Kind) {
1958051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      case VCK_This:
19596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        assert(!Var && "'this' capture cannot have a variable!");
1960051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        break;
1961051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      case VCK_ByRef:
1962051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        assert(Var && "capturing by reference must have a variable!");
1963051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj        break;
1964051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      }
1965051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    }
1966051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1967051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Determine the kind of capture.
19683a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    VariableCaptureKind getCaptureKind() const { return VarAndKind.getInt(); }
1969051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1970051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Retrieve the source location at which the variable or 'this' was
1971051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// first used.
1972051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    SourceLocation getLocation() const { return Loc; }
1973051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1974051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Determine whether this capture handles the C++ 'this' pointer.
19753a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    bool capturesThis() const { return getCaptureKind() == VCK_This; }
1976051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1977051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Determine whether this capture handles a variable.
19783a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir    bool capturesVariable() const { return getCaptureKind() != VCK_This; }
1979051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1980051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// \brief Retrieve the declaration of the variable being captured.
1981051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    ///
1982051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    /// This operation is only valid if this capture does not capture 'this'.
1983051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    VarDecl *getCapturedVar() const {
1984051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj      assert(!capturesThis() && "No variable available for 'this' capture");
19853a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir      return VarAndKind.getPointer();
1986051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    }
1987dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir    friend class ASTStmtReader;
1988051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  };
1989051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1990051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajprivate:
1991051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The number of variable captured, including 'this'.
1992051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  unsigned NumCaptures;
1993051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
19949fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief The pointer part is the implicit the outlined function and the
19959fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// int part is the captured region kind, 'CR_Default' etc.
19969fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind;
1997051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
1998051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl.
1999051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  RecordDecl *TheRecordDecl;
2000051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2001051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Construct a captured statement.
20029fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
20039fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan               ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
2004051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2005051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Construct an empty captured statement.
2006051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
2007051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2008051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  Stmt **getStoredStmts() const {
2009051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1);
2010051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2011051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2012051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  Capture *getStoredCaptures() const;
2013051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2014dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
2015dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir
2016051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic:
20170b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
20189fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan                              CapturedRegionKind Kind,
2019051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj                              ArrayRef<Capture> Captures,
2020051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj                              ArrayRef<Expr *> CaptureInits,
20216afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj                              CapturedDecl *CD, RecordDecl *RD);
2022051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
20230b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  static CapturedStmt *CreateDeserialized(const ASTContext &Context,
2024051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj                                          unsigned NumCaptures);
2025051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2026051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the statement being captured.
2027051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
2028051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  const Stmt *getCapturedStmt() const {
2029051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return const_cast<CapturedStmt *>(this)->getCapturedStmt();
2030051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2031051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2032051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the outlined function declaration.
20339fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  CapturedDecl *getCapturedDecl() { return CapDeclAndKind.getPointer(); }
20349fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  const CapturedDecl *getCapturedDecl() const {
20359fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    return const_cast<CapturedStmt *>(this)->getCapturedDecl();
20369fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
20379fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan
20389fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief Set the outlined function declaration.
20399fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  void setCapturedDecl(CapturedDecl *D) {
20409fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    assert(D && "null CapturedDecl");
20419fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    CapDeclAndKind.setPointer(D);
20429fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
20439fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan
20449fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief Retrieve the captured region kind.
20459fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  CapturedRegionKind getCapturedRegionKind() const {
20469fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    return CapDeclAndKind.getInt();
20479fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
20489fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan
20499fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief Set the captured region kind.
20509fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  void setCapturedRegionKind(CapturedRegionKind Kind) {
20519fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    CapDeclAndKind.setInt(Kind);
20529fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
2053051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2054051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the record declaration for captured variables.
2055051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
2056051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
20579fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  /// \brief Set the record declaration for captured variables.
20589fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  void setCapturedRecordDecl(RecordDecl *D) {
20599fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    assert(D && "null RecordDecl");
20609fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan    TheRecordDecl = D;
20619fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan  }
20629fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan
2063051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief True if this variable has been captured.
2064051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  bool capturesVariable(const VarDecl *Var) const;
2065051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2066051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief An iterator that walks over the captures.
2067dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  typedef Capture *capture_iterator;
2068dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  typedef const Capture *const_capture_iterator;
2069651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  typedef llvm::iterator_range<capture_iterator> capture_range;
2070651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  typedef llvm::iterator_range<const_capture_iterator> capture_const_range;
2071651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
2072651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  capture_range captures() {
2073651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return capture_range(capture_begin(), capture_end());
2074651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  }
2075651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  capture_const_range captures() const {
2076651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return capture_const_range(capture_begin(), capture_end());
2077651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  }
2078051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2079051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve an iterator pointing to the first capture.
2080dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  capture_iterator capture_begin() { return getStoredCaptures(); }
2081dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  const_capture_iterator capture_begin() const { return getStoredCaptures(); }
2082051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2083051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve an iterator pointing past the end of the sequence of
2084051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// captures.
2085051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_iterator capture_end() const {
2086051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getStoredCaptures() + NumCaptures;
2087051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2088051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2089051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the number of captures, including 'this'.
2090051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  unsigned capture_size() const { return NumCaptures; }
2091051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2092051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Iterator that walks over the capture initialization arguments.
2093051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  typedef Expr **capture_init_iterator;
2094651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  typedef llvm::iterator_range<capture_init_iterator> capture_init_range;
2095651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
2096651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  capture_init_range capture_inits() const {
2097651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return capture_init_range(capture_init_begin(), capture_init_end());
2098651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  }
2099051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2100051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the first initialization argument.
2101051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_init_iterator capture_init_begin() const {
2102051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return reinterpret_cast<Expr **>(getStoredStmts());
2103051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2104051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2105051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// \brief Retrieve the iterator pointing one past the last initialization
2106051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  /// argument.
2107051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  capture_init_iterator capture_init_end() const {
2108051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return capture_init_begin() + NumCaptures;
2109051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2110051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2111051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  SourceLocation getLocStart() const LLVM_READONLY {
2112051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getCapturedStmt()->getLocStart();
2113051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2114051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  SourceLocation getLocEnd() const LLVM_READONLY {
2115051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getCapturedStmt()->getLocEnd();
2116051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2117051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  SourceRange getSourceRange() const LLVM_READONLY {
2118051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return getCapturedStmt()->getSourceRange();
2119051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2120051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2121051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  static bool classof(const Stmt *T) {
2122051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    return T->getStmtClass() == CapturedStmtClass;
2123051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  }
2124051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
2125051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  child_range children();
2126dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir
2127dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir  friend class ASTStmtReader;
2128051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj};
2129051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
21305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
21315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2133