Stmt.h revision 9ec55f24b8f848bb37a9971100cf2fca379d5572
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Stmt interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_STMT_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_STMT_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
172fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/DeclGroup.h"
189caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h"
192fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/IdentifierTable.h"
202fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/LLVM.h"
212fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/SourceLocation.h"
222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "llvm/ADT/ArrayRef.h"
23aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
24a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer#include "llvm/Support/ErrorHandling.h"
256e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string>
267573098b83e780d1c5bea13b384b610d8f155676Steve Naroff
2741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm {
2841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  class FoldingSetNodeID;
2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor}
3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
32e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  class ASTContext;
332fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Attr;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
352fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Expr;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class IdentifierInfo;
37478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class LabelDecl;
382fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class ParmVarDecl;
39a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class PrinterHelper;
40a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  struct PrintingPolicy;
412fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class QualType;
420c727a35718556866a978f64ac549d9798735f08Chris Lattner  class SourceManager;
436a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  class StringLiteral;
446c36be5b383875b490684bcf439d6d427298c1afChris Lattner  class SwitchStmt;
45a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class Token;
46478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class VarDecl;
471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
49ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  // ExprIterator - Iterators for iterating over Stmt* arrays that contain
50ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
51ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  references to children (to be compatible with StmtIterator).
52ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Stmt;
55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Expr;
561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ExprIterator {
58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Stmt** I;
59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator(Stmt** i) : I(i) {}
611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExprIterator() : I(0) {}
62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator& operator++() { ++I; return *this; }
63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator-(size_t i) { return I-i; }
64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator+(size_t i) { return I+i; }
65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator[](size_t idx);
66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    // FIXME: Verify that this will correctly return a signed distance.
67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ExprIterator& R) const { return I - R.I; }
68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator*() const;
69ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator->() const;
70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ExprIterator& R) const { return I == R.I; }
71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ExprIterator& R) const { return I != R.I; }
72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ExprIterator& R) const { return I > R.I; }
73ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ExprIterator& R) const { return I >= R.I; }
74ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  };
751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ConstExprIterator {
771705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    const Stmt * const *I;
78ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
791705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator(const Stmt * const *i) : I(i) {}
801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ConstExprIterator() : I(0) {}
81ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ConstExprIterator& operator++() { ++I; return *this; }
821705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator+(size_t i) const { return I+i; }
831705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator-(size_t i) const { return I-i; }
84ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator[](size_t idx) const;
85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ConstExprIterator& R) const { return I - R.I; }
86ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator*() const;
87ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator->() const;
88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ConstExprIterator& R) const { return I == R.I; }
89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ConstExprIterator& R) const { return I != R.I; }
90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ConstExprIterator& R) const { return I > R.I; }
91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  };
931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
94ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
95ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements.
96ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement.
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt {
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum StmtClass {
103f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor    NoStmtClass = 0,
104f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class,
1057381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \
1069a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
1077381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
1089a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
1097381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT)
1104bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
1118e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Make vanilla 'new' and 'delete' illegal for Stmts.
1148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected:
1158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes) throw() {
116b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
1178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void operator delete(void* data) throw() {
119b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
1208189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class StmtBitfields {
1238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Stmt;
1248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    /// \brief The statement class.
1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned sClass : 8;
1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  enum { NumStmtBits = 8 };
1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CompoundStmtBitfields {
1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CompoundStmt;
1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned NumStmts : 32 - NumStmtBits;
1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class ExprBitfields {
1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Expr;
1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DeclRefExpr; // computeDependence
1408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class InitListExpr; // ctor
1418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DesignatedInitExpr; // ctor
142d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor    friend class BlockDeclRefExpr; // ctor
143bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ASTStmtReader; // deserialization
144bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXNewExpr; // ctor
145bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class DependentScopeDeclRefExpr; // ctor
146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXConstructExpr; // ctor
147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CallExpr; // ctor
148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OffsetOfExpr; // ctor
149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ObjCMessageExpr; // ctor
150ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCArrayLiteral; // ctor
151ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCDictionaryLiteral; // ctor
152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ShuffleVectorExpr; // ctor
153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ParenListExpr; // ctor
154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXUnresolvedConstructExpr; // ctor
155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXDependentScopeMemberExpr; // ctor
156bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OverloadExpr; // ctor
1574b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr; // ctor
158dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    friend class AtomicExpr; // ctor
1598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueKind : 2;
162f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    unsigned ObjectKind : 2;
1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned TypeDependent : 1;
1648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueDependent : 1;
165561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
166d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  enum { NumExprBits = 16 };
1698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
170bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class CharacterLiteralBitfields {
171bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class CharacterLiteral;
172bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
173bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
1779ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover  enum APFloatSemantics {
1789ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEhalf,
1799ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEsingle,
1809ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEdouble,
1819ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    x87DoubleExtended,
1829ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    IEEEquad,
1839ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    PPCDoubleDouble
1849ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover  };
1859ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover
186bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class FloatingLiteralBitfields {
187bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class FloatingLiteral;
188bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
189bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
1909ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover    unsigned Semantics : 3; // Provides semantics for APFloat construction
191bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsExact : 1;
192bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
193bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
194bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class UnaryExprOrTypeTraitExprBitfields {
195bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class UnaryExprOrTypeTraitExpr;
196bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
197bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
198bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
199bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsType : 1; // true if operand is a type, false if an expression.
200bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
201bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
202cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  class DeclRefExprBitfields {
203cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class DeclRefExpr;
204cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class ASTStmtReader; // deserialization
205cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned : NumExprBits;
206cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
207cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasQualifier : 1;
208e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    unsigned HasTemplateKWAndArgsInfo : 1;
2093aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    unsigned HasFoundDecl : 1;
2107cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    unsigned HadMultipleCandidates : 1;
211f4b88a45902af1802a1cb42ba48b1c474474f228John McCall    unsigned RefersToEnclosingLocal : 1;
212cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  };
213cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
2148e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CastExprBitfields {
2158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CastExpr;
2168e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumExprBits;
2178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2182bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned Kind : 6;
2192bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned BasePathSize : 32 - 6 - NumExprBits;
2208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
222cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  class CallExprBitfields {
223cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    friend class CallExpr;
224cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned : NumExprBits;
225cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
226cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned NumPreArgs : 1;
227cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  };
228cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
22980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  class ExprWithCleanupsBitfields {
23080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ExprWithCleanups;
23180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ASTStmtReader; // deserialization
23280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
23380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned : NumExprBits;
23480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
23580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned NumObjects : 32 - NumExprBits;
23680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  };
23780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
2384b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class PseudoObjectExprBitfields {
2394b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr;
2404b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class ASTStmtReader; // deserialization
2414b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2424b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned : NumExprBits;
2434b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2444b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // These don't need to be particularly wide, because they're
2454b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // strictly limited by the forms of expressions we permit.
2464b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned NumSubExprs : 8;
2474b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned ResultIndex : 32 - 8 - NumExprBits;
2484b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
2494b9c2d235fb9449e249d74f48ecfec601650de93John McCall
250f85e193739c953358c865005855253af4f68a497John McCall  class ObjCIndirectCopyRestoreExprBitfields {
251f85e193739c953358c865005855253af4f68a497John McCall    friend class ObjCIndirectCopyRestoreExpr;
252f85e193739c953358c865005855253af4f68a497John McCall    unsigned : NumExprBits;
253f85e193739c953358c865005855253af4f68a497John McCall
254f85e193739c953358c865005855253af4f68a497John McCall    unsigned ShouldCopy : 1;
255f85e193739c953358c865005855253af4f68a497John McCall  };
256f85e193739c953358c865005855253af4f68a497John McCall
25732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  class InitListExprBitfields {
25832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    friend class InitListExpr;
25932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned : NumExprBits;
26132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list originally had a GNU array-range
26332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// designator in it. This is a temporary marker used by CodeGen.
26432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned HadArrayRangeDesignator : 1;
26532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
26632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list initializes a std::initializer_list
26732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// object.
26832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned InitializesStdInitializerList : 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  };
2884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
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.
3158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext& C,
3162fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer                     unsigned alignment = 8) throw();
3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext* C,
3192fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer                     unsigned alignment = 8) throw();
3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3218189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, void* mem) throw() {
3228189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return mem;
3238189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
324e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
325fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext&, unsigned) throw() { }
326fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext*, unsigned) throw() { }
327e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor  void operator delete(void*, std::size_t) throw() { }
328fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, void*) throw() { }
329e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
330025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic:
331025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief A placeholder type used to construct an empty shell of a
332025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// type, that will be filled in later (e.g., by some
333025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// de-serialization).
334025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  struct EmptyShell { };
335025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
33602892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate:
33702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  /// \brief Whether statistic collection is enabled.
33802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static bool StatisticsEnabled;
33902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar
3409c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected:
341025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Construct an empty statement.
3428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  explicit Stmt(StmtClass SC, EmptyShell) {
3438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
34402892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
345025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  }
346025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3488e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt(StmtClass SC) {
3498e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
35002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
353ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  StmtClass getStmtClass() const {
3548e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    return static_cast<StmtClass>(StmtBits.sClass);
355b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor  }
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStmtClassName() const;
3571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
358b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// SourceLocation tokens are not useful in isolation - they are low level
359b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// value objects created/interpreted by SourceManager. We assume AST
360b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// clients will have a pointer to the respective SourceManager.
361aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
362aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
363aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // global temp stats (until we have a per-module visitor)
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void addStmtClass(const StmtClass s);
36702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static void EnableStatistics();
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void PrintStats();
3696000dace22f110d8768476989313e9d981d690d0Chris Lattner
37095f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \brief Dumps the specified AST fragment and all subtrees to
37195f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \c llvm::errs().
372f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump() const;
373f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
3748cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS, SourceManager &SM) const;
3756000dace22f110d8768476989313e9d981d690d0Chris Lattner
3766000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
3776000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// back to its original source language syntax.
378d1420c6fa788669e49f21e184927c7833881e399Richard Smith  void dumpPretty(ASTContext &Context) const;
3798cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
380e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
381d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                   unsigned Indentation = 0) const;
3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
383d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
384d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
385d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  void viewAST() const;
3861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3877e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// Skip past any implicit AST nodes which might surround this
3887e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
3897e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  Stmt *IgnoreImplicit();
3907e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
391a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  const Stmt *stripLabelLikeStatements() const;
392a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  Stmt *stripLabelLikeStatements() {
393a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth    return const_cast<Stmt*>(
394a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
395a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  }
396a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth
397d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
398d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  contain implicit control-flow in the order their subexpressions
399d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  are evaluated.  This predicate returns true if this statement has
400d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  such implicit control-flow.  Such statements are also specially handled
401d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  within CFGs.
402d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  bool hasImplicitControlFlow() const;
403d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek
40463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// Child Iterators: All subclasses must implement 'children'
40563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// to permit easy iteration over the substatements/subexpessions of an
40663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// AST node.  This permits easy iteration over all nodes in the AST.
4079caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef StmtIterator       child_iterator;
4089caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef ConstStmtIterator  const_child_iterator;
4091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef StmtRange          child_range;
41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef ConstStmtRange     const_child_range;
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
41463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_range children() const {
41563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return const_cast<Stmt*>(this)->children();
41677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
4171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_begin() { return children().first; }
41963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_end() { return children().second; }
42063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
42163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_begin() const { return children().first; }
42263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_end() const { return children().second; }
42341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
42441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Produce a unique representation of the given statement.
42541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42670517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param ID once the profiling operation is complete, will contain
42741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// the unique representation of the given statement.
42841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42970517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Context the AST context in which the statement resides
43041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43170517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Canonical whether the profile should be based on the canonical
43241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// representation of this statement (e.g., where non-type template
4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// parameters are identified by index/level rather than their
43441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// declaration pointers) or the exact representation of the statement as
43541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// written in the source.
4364ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
437b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth               bool Canonical) const;
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions
4421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration.
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt {
4469653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor  DeclGroupRef DG;
44781c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation StartLoc, EndLoc;
4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
4518ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
4528ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek                                    StartLoc(startLoc), EndLoc(endLoc) {}
4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  /// \brief Build an empty declaration statement.
45584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
45684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4577e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  /// isSingleDecl - This method returns true if this DeclStmt refers
458fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner  /// to a single Decl.
4597e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  bool isSingleDecl() const {
460fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner    return DG.isSingleDecl();
4618ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  }
4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4637e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Decl *getSingleDecl() { return DG.getSingleDecl(); }
4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
466e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  const DeclGroupRef getDeclGroup() const { return DG; }
467e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  DeclGroupRef getDeclGroup() { return DG; }
46884f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
469b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
47081c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
47184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setStartLoc(SourceLocation L) { StartLoc = L; }
47281c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
47384f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setEndLoc(SourceLocation L) { EndLoc = L; }
47484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
47565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
47665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
4771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DeclStmtClass;
4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48214f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek  // Iterators over subexpressions.
48363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
48463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(child_iterator(DG.begin(), DG.end()),
48563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       child_iterator(DG.end(), DG.end()));
48663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4880632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::iterator decl_iterator;
4890632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::const_iterator const_decl_iterator;
4901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4918ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_begin() { return DG.begin(); }
4928ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_end() { return DG.end(); }
4938ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_begin() const { return DG.begin(); }
4948ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_end() const { return DG.end(); }
495fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose
496fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
497fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rbegin() {
498fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_end());
499fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
500fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rend() {
501fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_begin());
502fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3.
5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt {
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation SemiLoc;
50944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
510e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  /// \brief True if the null statement was preceded by an empty macro, e.g:
51144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @code
51244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   #define CALL(x)
51344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   CALL(0);
51444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @endcode
515e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool HasLeadingEmptyMacro;
5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
517e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
518e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis    : Stmt(NullStmtClass), SemiLoc(L),
519e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
521025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty null statement.
522e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
523e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(false) { }
524025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getSemiLoc() const { return SemiLoc; }
526025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
527b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
528e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
52944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
53065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
53165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == NullStmtClass;
5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
53844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
53944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtReader;
54044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtWriter;
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }.
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt {
5468189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  Stmt** Body;
547b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation LBracLoc, RBracLoc;
5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
549d36aa359e2f45cd22c7366a015ad94de08044dbbNico Weber  CompoundStmt(ASTContext &C, ArrayRef<Stmt*> Stmts,
5503a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer               SourceLocation LB, SourceLocation RB);
5513a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer
5523a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  // \brief Build an empty compound statment with a location.
5533a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  explicit CompoundStmt(SourceLocation Loc)
5543a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) {
5553a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    CompoundStmtBits.NumStmts = 0;
5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
557025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
558025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  // \brief Build an empty compound statement.
559025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CompoundStmt(EmptyShell Empty)
5608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    : Stmt(CompoundStmtClass, Empty), Body(0) {
5618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = 0;
5628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
563025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
564025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
5651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
5678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned size() const { return CompoundStmtBits.NumStmts; }
568025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5698189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt** body_iterator;
5708189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  body_iterator body_begin() { return Body; }
5718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  body_iterator body_end() { return Body + size(); }
5728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
573ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5748e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setLastStmt(Stmt *S) {
5758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    assert(!body_empty() && "setLastStmt");
5768e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Body[size()-1] = S;
5778e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5798189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt* const * const_body_iterator;
5808189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_body_iterator body_begin() const { return Body; }
5818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const_body_iterator body_end() const { return Body + size(); }
5828e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
5838189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek
5848189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
5858189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rbegin() {
5868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_end());
5878189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5888189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rend() {
5898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_begin());
5908189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5914ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<const_body_iterator>
5938189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek          const_reverse_body_iterator;
5944ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rbegin() const {
5968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_end());
5978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rend() const {
6008189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_begin());
6018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
60465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
6051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
606cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getLBracLoc() const { return LBracLoc; }
607025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
608cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getRBracLoc() const { return RBracLoc; }
609025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundStmtClass;
6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6158297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
61663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
61763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
61863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6208ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  const_child_range children() const {
6218ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
6228ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  }
6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
625c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt,
626c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt {
627103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected:
628c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // A pointer to the following CaseStmt or DefaultStmt class,
629c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // used by SwitchStmt.
630c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *NextSwitchCase;
63181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation KeywordLoc;
63281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation ColonLoc;
63381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis
63481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
63581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {}
636103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek
63781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SwitchCase(StmtClass SC, EmptyShell)
63881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : Stmt(SC), NextSwitchCase(0) {}
6391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
640c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic:
641c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
642c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
643c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
644c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
645c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
646d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek
64781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getKeywordLoc() const { return KeywordLoc; }
64881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
64981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getColonLoc() const { return ColonLoc; }
65081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setColonLoc(SourceLocation L) { ColonLoc = L; }
65181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis
65263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  Stmt *getSubStmt();
653702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  const Stmt *getSubStmt() const {
654702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner    return const_cast<SwitchCase*>(this)->getSubStmt();
655702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  }
656b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
65781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
65881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocEnd() const LLVM_READONLY;
6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass ||
66263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall           T->getStmtClass() == DefaultStmtClass;
663c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
664c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson};
665c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
666c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase {
6670a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor  enum { LHS, RHS, SUBSTMT, END_EXPR };
6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
669d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek                             // GNU "case 1 ... 4" extension
670dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation EllipsisLoc;
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
672dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
6731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation ellipsisLoc, SourceLocation colonLoc)
67481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
67524e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner    SubExprs[SUBSTMT] = 0;
676d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
677d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
678dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    EllipsisLoc = ellipsisLoc;
679d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  }
680025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
681025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty switch case statement.
68281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
683025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
68481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getCaseLoc() const { return KeywordLoc; }
68581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
686dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
687dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
688dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
689dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
690025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
691d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
692d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
693d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
694025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getLHS() const {
6961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
69751b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
6981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const {
6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
70051b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
70151b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
70320dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
70420dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
70520dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
70781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
70865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
7093fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    // Handle deeply nested case statements with iteration instead of recursion.
7103fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    const CaseStmt *CS = this;
71191ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
7123fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner      CS = CS2;
7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return CS->getSubStmt()->getLocEnd();
715b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
71665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
7171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass;
7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
721d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
72263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
72363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
72463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
727c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase {
728d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt* SubStmt;
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
73181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
732025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
733025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty default statement.
73481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  explicit DefaultStmt(EmptyShell Empty)
73581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    : SwitchCase(DefaultStmtClass, Empty) { }
736025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
737d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubStmt; }
73851b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubStmt; }
739025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSubStmt(Stmt *S) { SubStmt = S; }
740025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
74181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getDefaultLoc() const { return KeywordLoc; }
74281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
743dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
744dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
74681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
74765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
74865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DefaultStmtClass;
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
753d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
75463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
75781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidisinline SourceLocation SwitchCase::getLocEnd() const {
75881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
75981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis    return CS->getLocEnd();
76081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis  return cast<DefaultStmt>(this)->getLocEnd();
76181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis}
762ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
763ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement.  For example:
764ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///    foo: return;
765ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt {
767ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *TheDecl;
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *SubStmt;
769b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IdentLoc;
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
771ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
772ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
7738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
7741de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
7751de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  // \brief Build an empty label statement.
7761de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
7771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getIdentLoc() const { return IdentLoc; }
779ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getDecl() const { return TheDecl; }
780ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setDecl(LabelDecl *D) { TheDecl = D; }
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *getSubStmt() { return SubStmt; }
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Stmt *getSubStmt() const { return SubStmt; }
7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setSubStmt(Stmt *SS) { SubStmt = SS; }
786b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
78765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
78865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
78965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
79063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
79163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == LabelStmtClass;
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
798534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement.
799534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
800534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example:
801534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///   [[omp::for(...)]] for (...) { ... }
802534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
803534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt {
804534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *SubStmt;
805534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation AttrLoc;
8064990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  unsigned NumAttrs;
8074990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  const Attr *Attrs[1];
808534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
809534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  friend class ASTStmtReader;
810534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8114990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
8124990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
8134990890fc9428f98bef90ba349203a648c592778Alexander Kornienko      NumAttrs(Attrs.size()) {
8144990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*));
815534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
816534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8174990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
8184990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
8194990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memset(Attrs, 0, NumAttrs * sizeof(Attr*));
820534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
821534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8224990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic:
8234990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *Create(ASTContext &C, SourceLocation Loc,
8244990890fc9428f98bef90ba349203a648c592778Alexander Kornienko                                ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
8254990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  // \brief Build an empty attributed statement.
8264990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs);
8274990890fc9428f98bef90ba349203a648c592778Alexander Kornienko
828534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation getAttrLoc() const { return AttrLoc; }
8294990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  ArrayRef<const Attr*> getAttrs() const {
8304990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    return ArrayRef<const Attr*>(Attrs, NumAttrs);
8314990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  }
832534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *getSubStmt() { return SubStmt; }
833534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  const Stmt *getSubStmt() const { return SubStmt; }
834534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
83565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
83665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
83765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
838534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
839534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
840534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  static bool classof(const Stmt *T) {
841534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return T->getStmtClass() == AttributedStmtClass;
842534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
843534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith};
844534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
845534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else.
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt {
84943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, THEN, ELSE, END_EXPR };
8508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
8518cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor
852b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IfLoc;
853d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation ElseLoc;
854ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
856ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
85744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
858ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
859025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty if/then/else statement
860025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
861025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
8628cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \brief Retrieve the variable declared in this "if" statement, if any.
8638cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///
8648cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// In the following example, "x" is the condition variable.
8658cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \code
8668cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// if (int x = foo()) {
8678cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///   printf("x is %d", x);
8688cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// }
8698cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \endcode
87043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
87143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
872ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
873d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this IfStmt has a condition variable, return the faux DeclStmt
874d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
875d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
876d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
877d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
878ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8798297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
880025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
8818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getThen() const { return SubExprs[THEN]; }
8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setThen(Stmt *S) { SubExprs[THEN] = S; }
8838297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getElse() const { return SubExprs[ELSE]; }
884025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8868297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
8878297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getThen() { return SubExprs[THEN]; }
8888297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getElse() { return SubExprs[ELSE]; }
889b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
890025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getIfLoc() const { return IfLoc; }
891025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setIfLoc(SourceLocation L) { IfLoc = L; }
892d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation getElseLoc() const { return ElseLoc; }
893d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  void setElseLoc(SourceLocation L) { ElseLoc = L; }
894025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
89565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
89665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
897b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    if (SubExprs[ELSE])
89865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return SubExprs[ELSE]->getLocEnd();
899b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    else
90065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return SubExprs[THEN]->getLocEnd();
901b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
9021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
90363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators over subexpressions.  The iterators will include iterating
90463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // over the initialization expression referenced by the condition variable.
90563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
90663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
90763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
90863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IfStmtClass;
9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt.
9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt {
91743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
9181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
919c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // This points to a linked list of case and default statements.
920c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *FirstCase;
9219dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  SourceLocation SwitchLoc;
9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
923559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// If the SwitchStmt is a switch on an enum value, this records whether
924559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// all the enum values were covered by CaseStmts.  This value is meant to
925559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// be a hint for possible clients.
926559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  unsigned AllEnumCasesCovered : 1;
927559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
92943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
931025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build a empty switch statement.
932025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
933025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
934d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \brief Retrieve the variable declared in this "switch" statement, if any.
935d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///
936d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// In the following example, "x" is the condition variable.
937d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \code
938d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// switch (int x = foo()) {
939d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   case 0: break;
940d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   // ...
941d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// }
942d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \endcode
94343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
94443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
945ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
946d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
947d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
948d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
949d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
950d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
951d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor
9528297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
9538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
954c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
955c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
957025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
9588297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
959025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
960c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getSwitchCaseList() { return FirstCase; }
9611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Set the case list for this switch statement.
96343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
96443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// The caller is responsible for incrementing the retain counts on
96543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// all of the SwitchCase statements in this list.
966025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
967025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
968025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getSwitchLoc() const { return SwitchLoc; }
969025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
970c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setBody(Stmt *S, SourceLocation SL) {
9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[BODY] = S;
9739dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    SwitchLoc = SL;
9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
975c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void addSwitchCase(SwitchCase *SC) {
976ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!SC->getNextSwitchCase()
977ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           && "case/default already added to a switch");
978c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    SC->setNextSwitchCase(FirstCase);
979c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson    FirstCase = SC;
980c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
981559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
982559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
983559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// switch over an enum value then all cases have been explicitly covered.
984559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  void setAllEnumCasesCovered() {
985559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    AllEnumCasesCovered = 1;
986559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
987559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
988559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
989559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// have been explicitly covered.
990559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  bool isAllEnumCasesCovered() const {
991559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    return (bool) AllEnumCasesCovered;
992559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
993559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
99465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
99565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
99665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
9979dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  }
99865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
99963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators
100063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
100163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
100263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
100363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SwitchStmtClass;
10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt.
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt {
101343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
10148297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1015b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation WhileLoc;
10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1017ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
101843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor            SourceLocation WL);
10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1020d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty while statement.
1021d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1022d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
10235656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \brief Retrieve the variable declared in this "while" statement, if any.
10245656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///
10255656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// In the following example, "x" is the condition variable.
10265656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \code
10275656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// while (int x = random()) {
10285656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///   // ...
10295656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// }
10305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \endcode
103143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
103243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
10335656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
1034d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1035d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1036d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1037d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1038d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1039d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
10408297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10418297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1042d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10438297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10448297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1045d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1046d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1047d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
1048d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1049b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
105065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
105165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
105265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
1053b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
105465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
10551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == WhileStmtClass;
10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
106063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
106163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
106263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt.
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt {
1068c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor  enum { BODY, COND, END_EXPR };
10698297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1070b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation DoLoc;
10719f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation WhileLoc;
1072989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
10739f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor
10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1075989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1076989135901c750af61ef012b6b0a0368be415bc46Chris Lattner         SourceLocation RP)
1077989135901c750af61ef012b6b0a0368be415bc46Chris Lattner    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
10788297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
10798297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[BODY] = body;
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
108167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
108267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty do-while statement.
108367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10868297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
108767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10888297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Stmt *getBody() const { return SubExprs[BODY]; }
109067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
109167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
109267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getDoLoc() const { return DoLoc; }
109367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setDoLoc(SourceLocation L) { DoLoc = L; }
10949f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
10959f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1096b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1097989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
1098989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1099989135901c750af61ef012b6b0a0368be415bc46Chris Lattner
110065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
110165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
110265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DoStmtClass;
11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11068297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11078297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
110863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
110963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
111063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not
11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source.
11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt {
111943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
11208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1121b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation ForLoc;
11225831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation LParenLoc, RParenLoc;
11235831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor
11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1125ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
112643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
11271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
112867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty for statement.
112967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
113067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
11318297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getInit() { return SubExprs[INIT]; }
1132ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
113399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \brief Retrieve the variable declared in this "for" statement, if any.
113499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///
113599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// In the following example, "y" is the condition variable.
113699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \code
113799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// for (int x = random(); int y = mangle(x); ++x) {
113899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///   // ...
113999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// }
114099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \endcode
114143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
114243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
1143ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1144d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this ForStmt has a condition variable, return the faux DeclStmt
1145d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1146d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1147d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1148d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1149d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
11508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
11518297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11528297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
11538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getInit() const { return SubExprs[INIT]; }
11558297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
11568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1158b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
115967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInit(Stmt *S) { SubExprs[INIT] = S; }
116067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
116167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
116267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
116367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
116467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getForLoc() const { return ForLoc; }
116567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setForLoc(SourceLocation L) { ForLoc = L; }
11665831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
11675831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
11685831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11695831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
117067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
117165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
117265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
117365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
1174b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
117565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
11761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ForStmtClass;
11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11808297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
118163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
118263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
118363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto.
11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt {
1189ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
1190507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation GotoLoc;
119161f62165220e75694fe333179c78815e2e48d71fTed Kremenek  SourceLocation LabelLoc;
11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1193ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
119461f62165220e75694fe333179c78815e2e48d71fTed Kremenek    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11961de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Build an empty goto statement.
11971de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
11981de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1199ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
1200ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *D) { Label = D; }
12011de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
12021de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getGotoLoc() const { return GotoLoc; }
12031de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
12041de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
12051de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1206b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
120765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
120865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
120965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GotoStmtClass;
12125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12148297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
121563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto.
12195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt {
1221ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation GotoLoc;
12225f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation StarLoc;
12231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Target;
12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
12265f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor                   Expr *target)
12275f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
12285f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor      Target((Stmt*)target) {}
12297d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
12307d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty indirect goto statement.
12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IndirectGotoStmt(EmptyShell Empty)
12327d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Stmt(IndirectGotoStmtClass, Empty) { }
12331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1234ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1235ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation getGotoLoc() const { return GotoLoc; }
12365f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  void setStarLoc(SourceLocation L) { StarLoc = L; }
12375f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation getStarLoc() const { return StarLoc; }
12381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
123995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
124095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
12417d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1242b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
124395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// getConstantTarget - Returns the fixed target of this indirect
124495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// goto, if one exists.
1245ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getConstantTarget();
1246ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  const LabelDecl *getConstantTarget() const {
124795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
124895c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  }
124995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall
125065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
125165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IndirectGotoStmtClass;
12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
125863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Target, &Target+1); }
12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue.
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt {
1265507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation ContinueLoc;
12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1267507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1269d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty continue statement.
1270d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1271d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1272d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getContinueLoc() const { return ContinueLoc; }
1273d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1274d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
127565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
127665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1277861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor
12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ContinueStmtClass;
12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12828297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
128363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break.
12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt {
1289507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation BreakLoc;
12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1291507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1293025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty break statement.
1294025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1295025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1296025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getBreakLoc() const { return BreakLoc; }
1297025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1298025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
129965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
130065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1301b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BreakStmtClass;
13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13068297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
130763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1311c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression:
1312c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return;
1313c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return 4;
1314c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///
1315c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to
1316c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to
1317c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void.  We explicitly model this in the AST, which means you can't
1318c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument.
13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt {
13211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *RetExpr;
1322507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation RetLoc;
13235077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *NRVOCandidate;
1324ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13265077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL)
132725a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
13285077c3876beeaed32280af88244e8050078619a8Douglas Gregor
13295077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
13305077c3876beeaed32280af88244e8050078619a8Douglas Gregor    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
13315077c3876beeaed32280af88244e8050078619a8Douglas Gregor      NRVOCandidate(NRVOCandidate) {}
13320de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13330de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  /// \brief Build an empty return expression.
13340de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
13350de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getRetValue() const;
13371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getRetValue();
13380de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
13390de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13400de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  SourceLocation getReturnLoc() const { return RetLoc; }
13410de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1342b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13435077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// \brief Retrieve the variable that might be used for the named return
13445077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// value optimization.
13455077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ///
13465077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// The optimization itself can only be performed if the variable is
13475077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// also marked as an NRVO object.
13485077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
13495077c3876beeaed32280af88244e8050078619a8Douglas Gregor  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1350ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
135165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
135265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
135365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return RetExpr ? RetExpr->getLocEnd() : RetLoc;
135465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ReturnStmtClass;
13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
136163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
136263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
136363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range();
136463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
13655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1367728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1368728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier///
1369728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass AsmStmt : public Stmt {
1370728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierprotected:
1371066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation AsmLoc;
137212b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief True if the assembly statement does not have any input or output
137312b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// operands.
1374728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsSimple;
137512b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier
137612b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief If true, treat this inline assembly as having side effects.
137712b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// This assembly statement should not be optimized, deleted or moved.
1378728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsVolatile;
1379728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1380066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumOutputs;
1381066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumInputs;
1382066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumClobbers;
1383066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1384066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  IdentifierInfo **Names;
138519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  Stmt **Exprs;
1386066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1387066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1388066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier          unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1389066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1390066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1391728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1392728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierpublic:
1393728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  /// \brief Build an empty inline-assembly statement.
1394728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
139519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    Stmt(SC, Empty), Names(0), Exprs(0) { }
139629760b452876548f59804e8c02c3276bc7281d5dMatt Beaumont-Gay
1397066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation getAsmLoc() const { return AsmLoc; }
1398066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1399728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1400728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isSimple() const { return IsSimple; }
1401728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setSimple(bool V) { IsSimple = V; }
1402728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1403728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isVolatile() const { return IsVolatile; }
1404728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setVolatile(bool V) { IsVolatile = V; }
1405728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
140665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
140765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1408728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1409da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  //===--- Asm String Analysis ---===//
1410da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1411da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1412aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1413da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1414066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Output operands ---===//
1415066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1416066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumOutputs() const { return NumOutputs; }
1417066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1418066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1419066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return Names[i];
1420066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1421066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1422066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  StringRef getOutputName(unsigned i) const {
1423066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    if (IdentifierInfo *II = getOutputIdentifier(i))
1424066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier      return II->getName();
1425066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1426066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return StringRef();
1427066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1428066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1429c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getOutputConstraint - Return the constraint string for the specified
1430c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// output operand.  All output constraints are known to be non-empty (either
1431c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// '=' or '+').
1432aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getOutputConstraint(unsigned i) const;
1433c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1434c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// isOutputPlusConstraint - Return true if the specified output constraint
1435c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is a "+" constraint (which is both an input and an output) or false if it
1436c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is an "=" constraint (just an output).
1437c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  bool isOutputPlusConstraint(unsigned i) const {
1438c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier    return getOutputConstraint(i)[0] == '+';
1439c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  }
1440c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1441aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getOutputExpr(unsigned i) const;
1442c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1443c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getNumPlusOperands - Return the number of output operands that have a "+"
1444c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraint.
1445c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  unsigned getNumPlusOperands() const;
1446c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1447066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Input operands ---===//
1448066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1449066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumInputs() const { return NumInputs; }
1450066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1451066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  IdentifierInfo *getInputIdentifier(unsigned i) const {
1452066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return Names[i + NumOutputs];
1453066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1454066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1455066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  StringRef getInputName(unsigned i) const {
1456066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    if (IdentifierInfo *II = getInputIdentifier(i))
1457066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier      return II->getName();
1458066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1459066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return StringRef();
1460066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1461066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1462c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getInputConstraint - Return the specified input constraint.  Unlike output
1463c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraints, these can be empty.
1464aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getInputConstraint(unsigned i) const;
1465aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier
1466aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getInputExpr(unsigned i) const;
1467c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1468066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Other ---===//
1469066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
14702fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier  unsigned getNumClobbers() const { return NumClobbers; }
1471aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getClobber(unsigned i) const;
14722fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier
1473728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  static bool classof(const Stmt *T) {
1474728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass ||
1475728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier      T->getStmtClass() == MSAsmStmtClass;
1476728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  }
147719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Input expr iterators.
147919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator inputs_iterator;
148119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_inputs_iterator;
148219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator begin_inputs() {
148419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
148519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator end_inputs() {
148819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
148919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator begin_inputs() const {
149219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
149319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator end_inputs() const {
149619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
149719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Output expr iterators.
150019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
150119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator outputs_iterator;
150219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_outputs_iterator;
150319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
150419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator begin_outputs() {
150519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
150619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
150719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator end_outputs() {
150819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
150919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
151019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
151119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator begin_outputs() const {
151219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
151319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
151419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator end_outputs() const {
151519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
151619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
151719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
151819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  child_range children() {
151919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
152019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
1521728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier};
1522728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
15237d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a GCC inline-assembly statement extension.
1524fe795956194141c91ae555985c9b930595bff43fChris Lattner///
1525728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass GCCAsmStmt : public AsmStmt {
1526066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation RParenLoc;
15276a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  StringLiteral *AsmStr;
1528b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1529966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  // FIXME: If we wanted to, we could allocate all of these in one big array.
1530966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Constraints;
1531966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Clobbers;
1532ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1533fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic:
1534df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
1535df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             bool isvolatile, unsigned numoutputs, unsigned numinputs,
1536df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1537df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral *asmstr, unsigned numclobbers,
1538df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral **clobbers, SourceLocation rparenloc);
1539b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1540cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  /// \brief Build an empty inline-assembly statement.
1541728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
154219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    Constraints(0), Clobbers(0) { }
1543cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1544cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1545cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1546cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1547458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  //===--- Asm String Analysis ---===//
1548458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1549458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  const StringLiteral *getAsmString() const { return AsmStr; }
1550458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  StringLiteral *getAsmString() { return AsmStr; }
1551cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmString(StringLiteral *E) { AsmStr = E; }
1552cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1553458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AsmStringPiece - this is part of a decomposed asm string specification
1554458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// (for use with the AnalyzeAsmString function below).  An asm string is
1555458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// considered to be a concatenation of these parts.
1556458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  class AsmStringPiece {
1557458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1558458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    enum Kind {
1559458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1560458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Operand  // Operand reference, with optional modifier %c4.
1561458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    };
1562458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  private:
1563458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    Kind MyKind;
1564458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    std::string Str;
1565458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned OperandNo;
1566458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1567458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1568458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(unsigned OpNo, char Modifier)
1569458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      : MyKind(Operand), Str(), OperandNo(OpNo) {
1570458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Str += Modifier;
1571458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1573458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isString() const { return MyKind == String; }
1574458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isOperand() const { return MyKind == Operand; }
15751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1576458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    const std::string &getString() const {
1577458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isString());
1578458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str;
1579458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1580458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1581458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned getOperandNo() const {
1582458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1583458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return OperandNo;
1584458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1586458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// getModifier - Get the modifier for this operand, if present.  This
1587458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// returns '\0' if there was no modifier.
1588458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    char getModifier() const {
1589458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1590458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str[0];
1591458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1592458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  };
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1594458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1595458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// it into pieces.  If the asm string is erroneous, emit errors and return
1596458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// true, otherwise return false.  This handles canonicalization and
1597458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
15981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1599686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1600fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner                            ASTContext &C, unsigned &DiagOffs) const;
16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1602da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1603da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1605b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Output operands ---===//
1606b327793860737d1c103a73aeda8057dd628a101dChris Lattner
1607686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputConstraint(unsigned i) const;
16081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1609b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1610ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i];
1611ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1612b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1613b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return Constraints[i];
1614b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1616ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getOutputExpr(unsigned i);
16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1618b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getOutputExpr(unsigned i) const {
1619df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1620b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1622b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Input operands ---===//
16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1624686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputConstraint(unsigned i) const;
16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1626b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1627ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1628ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1629b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getInputConstraintLiteral(unsigned i) {
1630ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1631ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1633ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getInputExpr(unsigned i);
1634935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner  void setInputExpr(unsigned i, Expr *E);
1635ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1636b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getInputExpr(unsigned i) const {
1637df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1638b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
1639cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1640acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson  void setOutputsAndInputsAndClobbers(ASTContext &C,
1641ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                      IdentifierInfo **Names,
1642fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Constraints,
1643fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      Stmt **Exprs,
1644fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumOutputs,
1645ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      unsigned NumInputs,
1646fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Clobbers,
1647fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumClobbers);
1648cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
164910ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  //===--- Other ---===//
16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
165110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// getNamedOperand - Given a symbolic operand reference like %[foo],
165210ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// translate this into a numeric value needed to reference the same operand.
165310ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// This returns -1 if the operand name is invalid.
1654686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  int getNamedOperand(StringRef SymbolicName) const;
165510ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner
165633f0558f75f70061707d1388e305b8f92f4e55deChad Rosier  StringRef getClobber(unsigned i) const;
16575c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
16585c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  const StringLiteral *getClobberStringLiteral(unsigned i) const {
16595c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier    return Clobbers[i];
16605c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  }
1661cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
166265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
166365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
16641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1665df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  static bool classof(const Stmt *T) {
1666df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass;
1667df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  }
1668fe795956194141c91ae555985c9b930595bff43fChris Lattner};
166978492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek
16707d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a Microsoft inline-assembly statement extension.
16718cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier///
1672728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass MSAsmStmt : public AsmStmt {
16737bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  SourceLocation AsmLoc, LBraceLoc, EndLoc;
16748cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  std::string AsmStr;
16758cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
167679efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned NumAsmToks;
167779efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier
167879efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *AsmToks;
167989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef *Constraints;
168033c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier  StringRef *Clobbers;
16818cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16828cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic:
16837bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc,
16847bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier            bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
1685e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            unsigned numoutputs, unsigned numinputs,
1686e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            ArrayRef<IdentifierInfo*> names, ArrayRef<StringRef> constraints,
1687e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            ArrayRef<Expr*> exprs, StringRef asmstr,
168889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier            ArrayRef<StringRef> clobbers, SourceLocation endloc);
16898cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1690cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier  /// \brief Build an empty MS-style inline-assembly statement.
1691728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
169289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { }
1693cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier
16947bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  SourceLocation getLBraceLoc() const { return LBraceLoc; }
16957bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
16968cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceLocation getEndLoc() const { return EndLoc; }
16978cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setEndLoc(SourceLocation L) { EndLoc = L; }
16988cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16997bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  bool hasBraces() const { return LBraceLoc.isValid(); }
17007bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier
170179efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned getNumAsmToks() { return NumAsmToks; }
170279efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *getAsmToks() { return AsmToks; }
17038f726de55412870ef70e788b852c6cc50873e15bChad Rosier
17048cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Asm String Analysis ---===//
17058cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17068cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  const std::string *getAsmString() const { return &AsmStr; }
17078cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  std::string *getAsmString() { return &AsmStr; }
17088cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setAsmString(StringRef &E) { AsmStr = E.str(); }
17098cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1710da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1711da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1712da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
17132603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Output operands ---===//
17142603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
171589fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getOutputConstraint(unsigned i) const {
171689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i];
171789fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1718c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1719633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getOutputExpr(unsigned i);
1720633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17212603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getOutputExpr(unsigned i) const {
17222603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
17232603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17242603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17252603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Input operands ---===//
17262603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
172789fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getInputConstraint(unsigned i) const {
172889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i + NumOutputs];
172989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1730c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1731633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getInputExpr(unsigned i);
1732633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  void setInputExpr(unsigned i, Expr *E);
1733633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17342603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getInputExpr(unsigned i) const {
17352603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
17362603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17372603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17388cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Other ---===//
17398cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17401e059da457ba65062448f24975db386efa0d51f8Chad Rosier  StringRef getClobber(unsigned i) const { return Clobbers[i]; }
17414399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier
174265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
174365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
174465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
17458cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  static bool classof(const Stmt *T) {
17468cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return T->getStmtClass() == MSAsmStmtClass;
17478cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17488cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17498cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  child_range children() {
17508cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return child_range(&Exprs[0], &Exprs[0]);
17518cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17528cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier};
17538cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
175428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt {
175528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
175628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
175728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
175828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { FILTER_EXPR, BLOCK };
175928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
176028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt(SourceLocation Loc,
176128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Expr *FilterExpr,
176228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Stmt *Block);
176328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
17647110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
17657110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
17667110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
17677110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
176828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
176928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHExceptStmt* Create(ASTContext &C,
177028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation ExceptLoc,
177128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Expr *FilterExpr,
177228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Block);
177365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
177465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
177565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
177628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
177728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getExceptLoc() const { return Loc; }
177828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
177928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1780ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getFilterExpr() const {
1781ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1782ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1784ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt *getBlock() const {
1785cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(Children[BLOCK]);
1786ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
178728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
178828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
178928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
179028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
179128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
179328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHExceptStmtClass;
179428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
179528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
179728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt {
179928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
180028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Block;
180128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt(SourceLocation Loc,
180328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                 Stmt *Block);
180428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18057110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18067110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18077110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
18087110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
180928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
181028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHFinallyStmt* Create(ASTContext &C,
181128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                SourceLocation FinallyLoc,
181228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                Stmt *Block);
181328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
181465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
181565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
181628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
181728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getFinallyLoc() const { return Loc; }
181828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
181928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1820cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
182128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
182328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(&Block,&Block+1);
182428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
182528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
182728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHFinallyStmtClass;
182828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
182928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
183128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt {
183328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool            IsCXXTry;
183428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  TryLoc;
183528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
183628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { TRY = 0, HANDLER = 1 };
183828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
184028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             SourceLocation TryLoc,
184128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *TryBlock,
184228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *Handler);
184328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18447110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18457110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18467110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
18477110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
184828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
184928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHTryStmt* Create(ASTContext &C,
185028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            bool isCXXTry,
185128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            SourceLocation TryLoc,
185228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *TryBlock,
185328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *Handler);
185428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
185665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
185728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getTryLoc() const { return TryLoc; }
185928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
186028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
186128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool getIsCXXTry() const { return IsCXXTry; }
1862ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1863ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt* getTryBlock() const {
1864cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(Children[TRY]);
1865ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1866ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
186728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt *getHandler() const { return Children[HANDLER]; }
186828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
186928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Returns 0 if not defined
187028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt  *getExceptHandler() const;
187128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt *getFinallyHandler() const;
187228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
187328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
187428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
187528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
187628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
187728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
187828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHTryStmtClass;
187928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
188028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
1881ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
18835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1885