Stmt.h revision 478851c3ed6bd784e7377dffd8e57b200c1b9ba9
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Stmt interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_STMT_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_STMT_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
179594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "clang/Basic/LLVM.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/SourceLocation.h"
19d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h"
209caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h"
218ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek#include "clang/AST/DeclGroup.h"
22534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith#include "clang/AST/Attr.h"
239594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "llvm/ADT/SmallVector.h"
24aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
25aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/raw_ostream.h"
266e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string>
277573098b83e780d1c5bea13b384b610d8f155676Steve Naroff
2841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm {
2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  class FoldingSetNodeID;
3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor}
3141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
33e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  class ASTContext;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
367ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff  class ParmVarDecl;
374b07b2968f87f3cd5a3d8c76145f1cbfd718d42dSebastian Redl  class QualType;
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class IdentifierInfo;
39478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class LabelDecl;
400c727a35718556866a978f64ac549d9798735f08Chris Lattner  class SourceManager;
416a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  class StringLiteral;
426c36be5b383875b490684bcf439d6d427298c1afChris Lattner  class SwitchStmt;
43478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class VarDecl;
441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
46ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  // ExprIterator - Iterators for iterating over Stmt* arrays that contain
47ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
48ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  references to children (to be compatible with StmtIterator).
49ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Stmt;
52ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Expr;
531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ExprIterator {
55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Stmt** I;
56ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
57ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator(Stmt** i) : I(i) {}
581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExprIterator() : I(0) {}
59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator& operator++() { ++I; return *this; }
60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator-(size_t i) { return I-i; }
61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator+(size_t i) { return I+i; }
62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator[](size_t idx);
63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    // FIXME: Verify that this will correctly return a signed distance.
64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ExprIterator& R) const { return I - R.I; }
65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator*() const;
66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator->() const;
67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ExprIterator& R) const { return I == R.I; }
68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ExprIterator& R) const { return I != R.I; }
69ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ExprIterator& R) const { return I > R.I; }
70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ExprIterator& R) const { return I >= R.I; }
71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  };
721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ConstExprIterator {
741705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    const Stmt * const *I;
75ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
761705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator(const Stmt * const *i) : I(i) {}
771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ConstExprIterator() : I(0) {}
78ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ConstExprIterator& operator++() { ++I; return *this; }
791705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator+(size_t i) const { return I+i; }
801705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator-(size_t i) const { return I-i; }
81ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator[](size_t idx) const;
82ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ConstExprIterator& R) const { return I - R.I; }
83ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator*() const;
84ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator->() const;
85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ConstExprIterator& R) const { return I == R.I; }
86ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ConstExprIterator& R) const { return I != R.I; }
87ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ConstExprIterator& R) const { return I > R.I; }
88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  };
901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
92ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements.
93ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement.
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt {
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum StmtClass {
100f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor    NoStmtClass = 0,
101f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class,
1027381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \
1039a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
1047381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
1059a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
1067381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT)
1074bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
1088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1108189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Make vanilla 'new' and 'delete' illegal for Stmts.
1118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected:
1128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes) throw() {
113b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
1148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void operator delete(void* data) throw() {
116b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
1178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class StmtBitfields {
1208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Stmt;
1218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    /// \brief The statement class.
1238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned sClass : 8;
1248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  enum { NumStmtBits = 8 };
1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CompoundStmtBitfields {
1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CompoundStmt;
1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned NumStmts : 32 - NumStmtBits;
1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class ExprBitfields {
1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Expr;
1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DeclRefExpr; // computeDependence
1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class InitListExpr; // ctor
1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DesignatedInitExpr; // ctor
139d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor    friend class BlockDeclRefExpr; // ctor
140bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ASTStmtReader; // deserialization
141bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXNewExpr; // ctor
142bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class DependentScopeDeclRefExpr; // ctor
143bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXConstructExpr; // ctor
144bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CallExpr; // ctor
145bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OffsetOfExpr; // ctor
146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ObjCMessageExpr; // ctor
147ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCArrayLiteral; // ctor
148ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCDictionaryLiteral; // ctor
149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ShuffleVectorExpr; // ctor
150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ParenListExpr; // ctor
151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXUnresolvedConstructExpr; // ctor
152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXDependentScopeMemberExpr; // ctor
153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OverloadExpr; // ctor
1544b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr; // ctor
155dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    friend class AtomicExpr; // ctor
1568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueKind : 2;
159f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    unsigned ObjectKind : 2;
1608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned TypeDependent : 1;
1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueDependent : 1;
162561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
163d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
165561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  enum { NumExprBits = 16 };
1668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
167bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class CharacterLiteralBitfields {
168bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class CharacterLiteral;
169bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
170bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
171bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
172bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
173bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class FloatingLiteralBitfields {
175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class FloatingLiteral;
176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsIEEE : 1; // Distinguishes between PPC128 and IEEE128.
179bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsExact : 1;
180bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
181bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
182bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class UnaryExprOrTypeTraitExprBitfields {
183bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class UnaryExprOrTypeTraitExpr;
184bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
185bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
186bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
187bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsType : 1; // true if operand is a type, false if an expression.
188bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
189bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
190cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  class DeclRefExprBitfields {
191cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class DeclRefExpr;
192cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class ASTStmtReader; // deserialization
193cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned : NumExprBits;
194cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
195cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasQualifier : 1;
196e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    unsigned HasTemplateKWAndArgsInfo : 1;
1973aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    unsigned HasFoundDecl : 1;
1987cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    unsigned HadMultipleCandidates : 1;
199f4b88a45902af1802a1cb42ba48b1c474474f228John McCall    unsigned RefersToEnclosingLocal : 1;
200cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  };
201cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
2028e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CastExprBitfields {
2038e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CastExpr;
2048e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumExprBits;
2058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2062bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned Kind : 6;
2072bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned BasePathSize : 32 - 6 - NumExprBits;
2088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
210cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  class CallExprBitfields {
211cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    friend class CallExpr;
212cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned : NumExprBits;
213cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
214cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned NumPreArgs : 1;
215cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  };
216cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
21780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  class ExprWithCleanupsBitfields {
21880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ExprWithCleanups;
21980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ASTStmtReader; // deserialization
22080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
22180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned : NumExprBits;
22280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
22380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned NumObjects : 32 - NumExprBits;
22480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  };
22580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
2264b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class PseudoObjectExprBitfields {
2274b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr;
2284b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class ASTStmtReader; // deserialization
2294b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2304b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned : NumExprBits;
2314b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2324b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // These don't need to be particularly wide, because they're
2334b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // strictly limited by the forms of expressions we permit.
2344b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned NumSubExprs : 8;
2354b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned ResultIndex : 32 - 8 - NumExprBits;
2364b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
2374b9c2d235fb9449e249d74f48ecfec601650de93John McCall
238f85e193739c953358c865005855253af4f68a497John McCall  class ObjCIndirectCopyRestoreExprBitfields {
239f85e193739c953358c865005855253af4f68a497John McCall    friend class ObjCIndirectCopyRestoreExpr;
240f85e193739c953358c865005855253af4f68a497John McCall    unsigned : NumExprBits;
241f85e193739c953358c865005855253af4f68a497John McCall
242f85e193739c953358c865005855253af4f68a497John McCall    unsigned ShouldCopy : 1;
243f85e193739c953358c865005855253af4f68a497John McCall  };
244f85e193739c953358c865005855253af4f68a497John McCall
24532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  class InitListExprBitfields {
24632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    friend class InitListExpr;
24732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
24832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned : NumExprBits;
24932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
25032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list originally had a GNU array-range
25132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// designator in it. This is a temporary marker used by CodeGen.
25232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned HadArrayRangeDesignator : 1;
25332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
25432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list initializes a std::initializer_list
25532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// object.
25632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned InitializesStdInitializerList : 1;
25732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  };
25832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
2594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  class TypeTraitExprBitfields {
2604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class TypeTraitExpr;
2614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtReader;
2624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtWriter;
2634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned : NumExprBits;
2654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
2674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Kind : 8;
2684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief If this expression is not value-dependent, this indicates whether
2704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// the trait evaluated true or false.
2714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Value : 1;
2724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The number of arguments to this type trait.
2744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
2754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  };
2764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2778e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  union {
27863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    // FIXME: this is wasteful on 64-bit platforms.
27963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    void *Aligner;
28063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
2818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBitfields StmtBits;
2828e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBitfields CompoundStmtBits;
2838e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBitfields ExprBits;
284bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    CharacterLiteralBitfields CharacterLiteralBits;
285bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    FloatingLiteralBitfields FloatingLiteralBits;
286bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
287cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    DeclRefExprBitfields DeclRefExprBits;
2888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBitfields CastExprBits;
289cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    CallExprBitfields CallExprBits;
29080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    ExprWithCleanupsBitfields ExprWithCleanupsBits;
2914b9c2d235fb9449e249d74f48ecfec601650de93John McCall    PseudoObjectExprBitfields PseudoObjectExprBits;
292f85e193739c953358c865005855253af4f68a497John McCall    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
29332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    InitListExprBitfields InitListExprBits;
2944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeTraitExprBitfields TypeTraitExprBits;
2958e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
297d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  friend class ASTStmtReader;
2984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
299d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
3008189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic:
3018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Only allow allocation of Stmts using the allocator in ASTContext
3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // or by doing a placement new.
3038189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext& C,
304f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor                     unsigned alignment = 8) throw() {
3058189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return ::operator new(bytes, C, alignment);
3068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
3071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3088189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext* C,
309f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor                     unsigned alignment = 8) throw() {
3108189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return ::operator new(bytes, *C, alignment);
3118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
3121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, void* mem) throw() {
3148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return mem;
3158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
316e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
317fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext&, unsigned) throw() { }
318fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext*, unsigned) throw() { }
319e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor  void operator delete(void*, std::size_t) throw() { }
320fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, void*) throw() { }
321e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
322025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic:
323025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief A placeholder type used to construct an empty shell of a
324025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// type, that will be filled in later (e.g., by some
325025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// de-serialization).
326025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  struct EmptyShell { };
327025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
32802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate:
32902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  /// \brief Whether statistic collection is enabled.
33002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static bool StatisticsEnabled;
33102892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar
3329c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected:
333025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Construct an empty statement.
3348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  explicit Stmt(StmtClass SC, EmptyShell) {
3358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
33602892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
337025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  }
338025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt(StmtClass SC) {
3418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
34202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
345ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  StmtClass getStmtClass() const {
3468e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    return static_cast<StmtClass>(StmtBits.sClass);
347b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor  }
3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStmtClassName() const;
3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
350b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// SourceLocation tokens are not useful in isolation - they are low level
351b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// value objects created/interpreted by SourceManager. We assume AST
352b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// clients will have a pointer to the respective SourceManager.
353aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
354aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
355aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // global temp stats (until we have a per-module visitor)
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void addStmtClass(const StmtClass s);
35902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static void EnableStatistics();
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void PrintStats();
3616000dace22f110d8768476989313e9d981d690d0Chris Lattner
3626000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dump - This does a local dump of the specified AST fragment.  It dumps the
3636000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// specified node and a few nodes underneath it, but not the whole subtree.
3646000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// This is useful in a debugger.
365f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump() const;
366f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
3678cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS, SourceManager &SM) const;
3686000dace22f110d8768476989313e9d981d690d0Chris Lattner
3696000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpAll - This does a dump of the specified AST fragment and all subtrees.
3706000dace22f110d8768476989313e9d981d690d0Chris Lattner  void dumpAll() const;
371e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  void dumpAll(SourceManager &SM) const;
3726000dace22f110d8768476989313e9d981d690d0Chris Lattner
3736000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
3746000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// back to its original source language syntax.
37548d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman  void dumpPretty(ASTContext& Context) const;
3768cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
377e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
37848d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman                   unsigned Indentation = 0) const {
37948d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman    printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation);
38048d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman  }
3818cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, ASTContext &Context,
3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                   PrinterHelper *Helper,
383e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
384d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                   unsigned Indentation = 0) const;
3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
386d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
387d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
388d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  void viewAST() const;
3891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3907e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// Skip past any implicit AST nodes which might surround this
3917e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
3927e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  Stmt *IgnoreImplicit();
3937e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
394a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  const Stmt *stripLabelLikeStatements() const;
395a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  Stmt *stripLabelLikeStatements() {
396a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth    return const_cast<Stmt*>(
397a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
398a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  }
399a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Implement isa<T> support.
4011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *) { return true; }
4021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
403d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
404d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  contain implicit control-flow in the order their subexpressions
405d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  are evaluated.  This predicate returns true if this statement has
406d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  such implicit control-flow.  Such statements are also specially handled
407d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  within CFGs.
408d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  bool hasImplicitControlFlow() const;
409d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek
41063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// Child Iterators: All subclasses must implement 'children'
41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// to permit easy iteration over the substatements/subexpessions of an
41263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// AST node.  This permits easy iteration over all nodes in the AST.
4139caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef StmtIterator       child_iterator;
4149caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef ConstStmtIterator  const_child_iterator;
4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef StmtRange          child_range;
41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef ConstStmtRange     const_child_range;
4181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
42063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_range children() const {
42163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return const_cast<Stmt*>(this)->children();
42277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_begin() { return children().first; }
42563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_end() { return children().second; }
42663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
42763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_begin() const { return children().first; }
42863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_end() const { return children().second; }
42941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
43041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Produce a unique representation of the given statement.
43141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief ID once the profiling operation is complete, will contain
43341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// the unique representation of the given statement.
43441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Context the AST context in which the statement resides
43641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Canonical whether the profile should be based on the canonical
43841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// representation of this statement (e.g., where non-type template
4391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// parameters are identified by index/level rather than their
44041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// declaration pointers) or the exact representation of the statement as
44141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// written in the source.
4424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
443b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth               bool Canonical) const;
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions
4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where
4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration.
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt {
4529653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor  DeclGroupRef DG;
45381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation StartLoc, EndLoc;
4541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
4578ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
4588ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek                                    StartLoc(startLoc), EndLoc(endLoc) {}
4591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  /// \brief Build an empty declaration statement.
46184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
46284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4637e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  /// isSingleDecl - This method returns true if this DeclStmt refers
464fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner  /// to a single Decl.
4657e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  bool isSingleDecl() const {
466fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner    return DG.isSingleDecl();
4678ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  }
4681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4697e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Decl *getSingleDecl() { return DG.getSingleDecl(); }
4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
472e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  const DeclGroupRef getDeclGroup() const { return DG; }
473e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  DeclGroupRef getDeclGroup() { return DG; }
47484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
475b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
47681c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
47784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setStartLoc(SourceLocation L) { StartLoc = L; }
47881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
47984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setEndLoc(SourceLocation L) { EndLoc = L; }
48084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
481aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
48281c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner    return SourceRange(StartLoc, EndLoc);
48381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  }
4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DeclStmtClass;
4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclStmt *) { return true; }
4891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49014f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek  // Iterators over subexpressions.
49163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
49263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(child_iterator(DG.begin(), DG.end()),
49363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       child_iterator(DG.end(), DG.end()));
49463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4960632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::iterator decl_iterator;
4970632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::const_iterator const_decl_iterator;
4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4998ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_begin() { return DG.begin(); }
5008ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_end() { return DG.end(); }
5018ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_begin() const { return DG.begin(); }
5028ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_end() const { return DG.end(); }
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
530aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(SemiLoc); }
5311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == NullStmtClass;
5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const NullStmt *) { return true; }
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:
5493a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts,
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
603aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
6041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(LBracLoc, RBracLoc);
605b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
607cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getLBracLoc() const { return LBracLoc; }
608025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
609cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getRBracLoc() const { return RBracLoc; }
610025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundStmtClass;
6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundStmt *) { return true; }
6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
61863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
61963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
62063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
621ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6228ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  const_child_range children() const {
6238ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
6248ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  }
6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
627c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt,
628c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt {
629103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected:
630c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // A pointer to the following CaseStmt or DefaultStmt class,
631c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // used by SwitchStmt.
632c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *NextSwitchCase;
633103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek
634d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
636c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic:
637c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
638c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
639c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
640c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
641c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
642d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek
64363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  Stmt *getSubStmt();
644702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  const Stmt *getSubStmt() const {
645702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner    return const_cast<SwitchCase*>(this)->getSubStmt();
646702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  }
647b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
648aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); }
6491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass ||
65263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall           T->getStmtClass() == DefaultStmtClass;
653c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
654c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  static bool classof(const SwitchCase *) { return true; }
655c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson};
656c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
657c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase {
6580a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor  enum { LHS, RHS, SUBSTMT, END_EXPR };
6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
660d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek                             // GNU "case 1 ... 4" extension
661b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation CaseLoc;
662dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation EllipsisLoc;
663dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
665dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation ellipsisLoc, SourceLocation colonLoc)
667d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    : SwitchCase(CaseStmtClass) {
66824e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner    SubExprs[SUBSTMT] = 0;
669d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
670d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
671b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    CaseLoc = caseLoc;
672dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    EllipsisLoc = ellipsisLoc;
673dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc = colonLoc;
674d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  }
675025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
676025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty switch case statement.
677025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { }
678025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
679764a7ce5217f9569e100a3445f47496ee82daf86Chris Lattner  SourceLocation getCaseLoc() const { return CaseLoc; }
680025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCaseLoc(SourceLocation L) { CaseLoc = L; }
681dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
682dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
683dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
684dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
685025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
686d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
687d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
688d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
689025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getLHS() const {
6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
69251b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
6931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const {
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
69551b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
69651b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
69820dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
69920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
70020dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
703aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7043fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    // Handle deeply nested case statements with iteration instead of recursion.
7053fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    const CaseStmt *CS = this;
70691ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
7073fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner      CS = CS2;
7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
710b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass;
7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CaseStmt *) { return true; }
7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
716d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
71763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
71863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
71963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
722c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase {
723d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt* SubStmt;
7246c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation DefaultLoc;
725dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
728dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL),
729dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc(CL) {}
730025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
731025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty default statement.
732025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { }
733025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
734d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubStmt; }
73551b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubStmt; }
736025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSubStmt(Stmt *S) { SubStmt = S; }
737025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
7386c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation getDefaultLoc() const { return DefaultLoc; }
739025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setDefaultLoc(SourceLocation L) { DefaultLoc = L; }
740dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
741dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
743aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DefaultLoc, SubStmt->getLocEnd());
745b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
7461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DefaultStmtClass;
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DefaultStmt *) { return true; }
7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
751d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
75263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
755ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
756ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement.  For example:
757ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///    foo: return;
758ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///
7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt {
760ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *TheDecl;
7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *SubStmt;
762b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IdentLoc;
7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
764ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
765ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
7668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
7671de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
7681de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  // \brief Build an empty label statement.
7691de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
7701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getIdentLoc() const { return IdentLoc; }
772ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getDecl() const { return TheDecl; }
773ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setDecl(LabelDecl *D) { TheDecl = D; }
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *getSubStmt() { return SubStmt; }
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Stmt *getSubStmt() const { return SubStmt; }
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setSubStmt(Stmt *SS) { SubStmt = SS; }
779b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
780aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(IdentLoc, SubStmt->getLocEnd());
7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
78363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
78463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
7851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == LabelStmtClass;
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const LabelStmt *) { return true; }
7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
792534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement.
793534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
794534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example:
795534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///   [[omp::for(...)]] for (...) { ... }
796534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
797534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt {
798534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *SubStmt;
799534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation AttrLoc;
800534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  AttrVec Attrs;
801534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  // TODO: It can be done as Attr *Attrs[1]; and variable size array as in
802534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  // StringLiteral
803534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
804534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  friend class ASTStmtReader;
805534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
806534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithpublic:
807534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  AttributedStmt(SourceLocation loc, const AttrVec &attrs, Stmt *substmt)
808534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    : Stmt(AttributedStmtClass), SubStmt(substmt), AttrLoc(loc), Attrs(attrs) {
809534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
810534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
811534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  // \brief Build an empty attributed statement.
812534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  explicit AttributedStmt(EmptyShell Empty)
813534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    : Stmt(AttributedStmtClass, Empty) {
814534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
815534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
816534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation getAttrLoc() const { return AttrLoc; }
817534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  const AttrVec &getAttrs() const { return Attrs; }
818534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *getSubStmt() { return SubStmt; }
819534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  const Stmt *getSubStmt() const { return SubStmt; }
820534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
821534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceRange getSourceRange() const LLVM_READONLY {
822534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return SourceRange(AttrLoc, SubStmt->getLocEnd());
823534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
824534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
825534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
826534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  static bool classof(const Stmt *T) {
827534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return T->getStmtClass() == AttributedStmtClass;
828534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
829534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  static bool classof(const AttributedStmt *) { return true; }
830534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith};
831534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
832534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else.
8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt {
83643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, THEN, ELSE, END_EXPR };
8378297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
8388cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor
839b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IfLoc;
840d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation ElseLoc;
841ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
843ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
84444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
845ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
846025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty if/then/else statement
847025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
848025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
8498cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \brief Retrieve the variable declared in this "if" statement, if any.
8508cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///
8518cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// In the following example, "x" is the condition variable.
8528cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \code
8538cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// if (int x = foo()) {
8548cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///   printf("x is %d", x);
8558cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// }
8568cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \endcode
85743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
85843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
859ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
860d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this IfStmt has a condition variable, return the faux DeclStmt
861d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
862d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
863d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
864d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
865ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8668297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
867025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
8688297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getThen() const { return SubExprs[THEN]; }
8691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setThen(Stmt *S) { SubExprs[THEN] = S; }
8708297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getElse() const { return SubExprs[ELSE]; }
871025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8738297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
8748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getThen() { return SubExprs[THEN]; }
8758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getElse() { return SubExprs[ELSE]; }
876b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
877025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getIfLoc() const { return IfLoc; }
878025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setIfLoc(SourceLocation L) { IfLoc = L; }
879d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation getElseLoc() const { return ElseLoc; }
880d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  void setElseLoc(SourceLocation L) { ElseLoc = L; }
881025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
882aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
883b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    if (SubExprs[ELSE])
884b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
885b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    else
886b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
887b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
88963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators over subexpressions.  The iterators will include iterating
89063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // over the initialization expression referenced by the condition variable.
89163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
89263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
89363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
89463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IfStmtClass;
8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IfStmt *) { return true; }
8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt.
9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt {
90443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
9051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
906c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // This points to a linked list of case and default statements.
907c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *FirstCase;
9089dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  SourceLocation SwitchLoc;
9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
910559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// If the SwitchStmt is a switch on an enum value, this records whether
911559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// all the enum values were covered by CaseStmts.  This value is meant to
912559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// be a hint for possible clients.
913559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  unsigned AllEnumCasesCovered : 1;
914559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
91643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
9171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
918025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build a empty switch statement.
919025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
920025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
921d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \brief Retrieve the variable declared in this "switch" statement, if any.
922d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///
923d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// In the following example, "x" is the condition variable.
924d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \code
925d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// switch (int x = foo()) {
926d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   case 0: break;
927d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   // ...
928d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// }
929d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \endcode
93043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
93143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
932ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
933d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
934d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
935d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
936d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
937d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
938d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor
9398297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
9408297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
941c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
942c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9438297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
944025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
9458297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
946025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
947c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getSwitchCaseList() { return FirstCase; }
9481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
94943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Set the case list for this switch statement.
95043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
95143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// The caller is responsible for incrementing the retain counts on
95243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// all of the SwitchCase statements in this list.
953025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
954025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
955025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getSwitchLoc() const { return SwitchLoc; }
956025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
957c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setBody(Stmt *S, SourceLocation SL) {
9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[BODY] = S;
9609dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    SwitchLoc = SL;
9611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
962c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void addSwitchCase(SwitchCase *SC) {
963ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!SC->getNextSwitchCase()
964ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           && "case/default already added to a switch");
965c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    SC->setNextSwitchCase(FirstCase);
966c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson    FirstCase = SC;
967c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
968559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
969559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
970559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// switch over an enum value then all cases have been explicitly covered.
971559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  void setAllEnumCasesCovered() {
972559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    AllEnumCasesCovered = 1;
973559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
974559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
975559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
976559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// have been explicitly covered.
977559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  bool isAllEnumCasesCovered() const {
978559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    return (bool) AllEnumCasesCovered;
979559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
980559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
981aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
9839dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  }
98463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators
98563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
98663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
98763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
98863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
9891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SwitchStmtClass;
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const SwitchStmt *) { return true; }
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt.
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt {
99943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
10008297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1001b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation WhileLoc;
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1003ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
100443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor            SourceLocation WL);
10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1006d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty while statement.
1007d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1008d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
10095656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \brief Retrieve the variable declared in this "while" statement, if any.
10105656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///
10115656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// In the following example, "x" is the condition variable.
10125656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \code
10135656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// while (int x = random()) {
10145656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///   // ...
10155656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// }
10165656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \endcode
101743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
101843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
10195656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
1020d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1021d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1022d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1023d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1024d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1025d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
10268297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10278297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1028d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10298297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10308297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1031d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1032d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1033d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
1034d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1035b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1036aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
10371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
1038b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
10391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == WhileStmtClass;
10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const WhileStmt *) { return true; }
10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10448297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
104563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
104663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
104763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt.
10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt {
1053c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor  enum { BODY, COND, END_EXPR };
10548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1055b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation DoLoc;
10569f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation WhileLoc;
1057989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
10589f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor
10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1060989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1061989135901c750af61ef012b6b0a0368be415bc46Chris Lattner         SourceLocation RP)
1062989135901c750af61ef012b6b0a0368be415bc46Chris Lattner    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
10638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
10648297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[BODY] = body;
10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
106667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
106767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty do-while statement.
106867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10708297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10718297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
107267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10738297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Stmt *getBody() const { return SubExprs[BODY]; }
107567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
107667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
107767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getDoLoc() const { return DoLoc; }
107867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setDoLoc(SourceLocation L) { DoLoc = L; }
10799f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
10809f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1081b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1082989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
1083989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1084989135901c750af61ef012b6b0a0368be415bc46Chris Lattner
1085aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DoLoc, RParenLoc);
1087b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DoStmtClass;
10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DoStmt *) { return true; }
10928297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
10938297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
109463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
109563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
109663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source.
11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt {
110543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
11068297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1107b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation ForLoc;
11085831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation LParenLoc, RParenLoc;
11095831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor
11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1111ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
111243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
111467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty for statement.
111567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
111667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
11178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getInit() { return SubExprs[INIT]; }
1118ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
111999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \brief Retrieve the variable declared in this "for" statement, if any.
112099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///
112199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// In the following example, "y" is the condition variable.
112299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \code
112399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// for (int x = random(); int y = mangle(x); ++x) {
112499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///   // ...
112599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// }
112699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \endcode
112743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
112843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
1129ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1130d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this ForStmt has a condition variable, return the faux DeclStmt
1131d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1132d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1133d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1134d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1135d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
11368297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
11378297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11388297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
11398297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11408297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getInit() const { return SubExprs[INIT]; }
11418297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
11428297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11438297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1144b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
114567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInit(Stmt *S) { SubExprs[INIT] = S; }
114667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
114767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
114867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
114967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
115067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getForLoc() const { return ForLoc; }
115167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setForLoc(SourceLocation L) { ForLoc = L; }
11525831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
11535831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
11545831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11555831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
115667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
1157aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
1159b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ForStmtClass;
11625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ForStmt *) { return true; }
11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11658297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
116663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
116763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
116863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto.
11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt {
1174ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
1175507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation GotoLoc;
117661f62165220e75694fe333179c78815e2e48d71fTed Kremenek  SourceLocation LabelLoc;
11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1178ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
117961f62165220e75694fe333179c78815e2e48d71fTed Kremenek    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
11801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11811de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Build an empty goto statement.
11821de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
11831de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1184ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
1185ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *D) { Label = D; }
11861de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
11871de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getGotoLoc() const { return GotoLoc; }
11881de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
11891de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
11901de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1191b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1192aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(GotoLoc, LabelLoc);
1194507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GotoStmtClass;
11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const GotoStmt *) { return true; }
11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12008297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
120163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto.
12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt {
1207ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation GotoLoc;
12085f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation StarLoc;
12091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Target;
12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
12125f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor                   Expr *target)
12135f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
12145f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor      Target((Stmt*)target) {}
12157d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
12167d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty indirect goto statement.
12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IndirectGotoStmt(EmptyShell Empty)
12187d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Stmt(IndirectGotoStmtClass, Empty) { }
12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1220ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1221ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation getGotoLoc() const { return GotoLoc; }
12225f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  void setStarLoc(SourceLocation L) { StarLoc = L; }
12235f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation getStarLoc() const { return StarLoc; }
12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
122595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
122695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
12277d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1228b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
122995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// getConstantTarget - Returns the fixed target of this indirect
123095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// goto, if one exists.
1231ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getConstantTarget();
1232ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  const LabelDecl *getConstantTarget() const {
123395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
123495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  }
123595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall
1236aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1237ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner    return SourceRange(GotoLoc, Target->getLocEnd());
1238ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  }
12391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IndirectGotoStmtClass;
12425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IndirectGotoStmt *) { return true; }
12441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12458297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
124663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Target, &Target+1); }
12475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue.
12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt {
1253507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation ContinueLoc;
12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1255507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
12561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1257d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty continue statement.
1258d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1259d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1260d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getContinueLoc() const { return ContinueLoc; }
1261d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1262d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1263aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
12641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ContinueLoc);
1265507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
1266861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor
12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ContinueStmtClass;
12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ContinueStmt *) { return true; }
12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12728297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
127363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break.
12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt {
1279507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation BreakLoc;
12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1281507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1283025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty break statement.
1284025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1285025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1286025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getBreakLoc() const { return BreakLoc; }
1287025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1288025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1289aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(BreakLoc); }
1290b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
12911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BreakStmtClass;
12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BreakStmt *) { return true; }
12951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12968297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
129763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1301c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression:
1302c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return;
1303c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return 4;
1304c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///
1305c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to
1306c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to
1307c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void.  We explicitly model this in the AST, which means you can't
1308c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument.
13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt {
13111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *RetExpr;
1312507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation RetLoc;
13135077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *NRVOCandidate;
1314ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13165077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL)
131725a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
13185077c3876beeaed32280af88244e8050078619a8Douglas Gregor
13195077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
13205077c3876beeaed32280af88244e8050078619a8Douglas Gregor    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
13215077c3876beeaed32280af88244e8050078619a8Douglas Gregor      NRVOCandidate(NRVOCandidate) {}
13220de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13230de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  /// \brief Build an empty return expression.
13240de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
13250de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getRetValue() const;
13271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getRetValue();
13280de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
13290de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13300de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  SourceLocation getReturnLoc() const { return RetLoc; }
13310de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1332b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13335077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// \brief Retrieve the variable that might be used for the named return
13345077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// value optimization.
13355077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ///
13365077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// The optimization itself can only be performed if the variable is
13375077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// also marked as an NRVO object.
13385077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
13395077c3876beeaed32280af88244e8050078619a8Douglas Gregor  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1340ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1341aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ReturnStmtClass;
13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReturnStmt *) { return true; }
13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
134963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
135063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
135163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range();
135263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
13535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1355fe795956194141c91ae555985c9b930595bff43fChris Lattner/// AsmStmt - This represents a GNU inline-assembly statement extension.
1356fe795956194141c91ae555985c9b930595bff43fChris Lattner///
1357fe795956194141c91ae555985c9b930595bff43fChris Lattnerclass AsmStmt : public Stmt {
1358fe795956194141c91ae555985c9b930595bff43fChris Lattner  SourceLocation AsmLoc, RParenLoc;
13596a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  StringLiteral *AsmStr;
1360b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1361dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson  bool IsSimple;
136239c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson  bool IsVolatile;
13633b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump  bool MSAsm;
13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1365b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  unsigned NumOutputs;
1366b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  unsigned NumInputs;
1367966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  unsigned NumClobbers;
13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1369966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  // FIXME: If we wanted to, we could allocate all of these in one big array.
1370966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  IdentifierInfo **Names;
1371966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Constraints;
1372966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  Stmt **Exprs;
1373966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Clobbers;
1374ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1375fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic:
1376ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile,
1377966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson          bool msasm, unsigned numoutputs, unsigned numinputs,
1378ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson          IdentifierInfo **names, StringLiteral **constraints,
1379db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner          Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
1380db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner          StringLiteral **clobbers, SourceLocation rparenloc);
1381b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1382cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  /// \brief Build an empty inline-assembly statement.
1383ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty),
1384966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    Names(0), Constraints(0), Exprs(0), Clobbers(0) { }
1385cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1386cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getAsmLoc() const { return AsmLoc; }
1387cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1388cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1389cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1390cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
139139c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson  bool isVolatile() const { return IsVolatile; }
1392cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setVolatile(bool V) { IsVolatile = V; }
1393dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson  bool isSimple() const { return IsSimple; }
13946ffe643322949dd776285a6df60d3578f3918be4Chris Lattner  void setSimple(bool V) { IsSimple = V; }
13953b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump  bool isMSAsm() const { return MSAsm; }
13963b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump  void setMSAsm(bool V) { MSAsm = V; }
1397dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson
1398458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  //===--- Asm String Analysis ---===//
1399458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1400458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  const StringLiteral *getAsmString() const { return AsmStr; }
1401458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  StringLiteral *getAsmString() { return AsmStr; }
1402cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmString(StringLiteral *E) { AsmStr = E; }
1403cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1404458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AsmStringPiece - this is part of a decomposed asm string specification
1405458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// (for use with the AnalyzeAsmString function below).  An asm string is
1406458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// considered to be a concatenation of these parts.
1407458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  class AsmStringPiece {
1408458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1409458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    enum Kind {
1410458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1411458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Operand  // Operand reference, with optional modifier %c4.
1412458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    };
1413458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  private:
1414458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    Kind MyKind;
1415458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    std::string Str;
1416458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned OperandNo;
1417458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1418458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1419458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(unsigned OpNo, char Modifier)
1420458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      : MyKind(Operand), Str(), OperandNo(OpNo) {
1421458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Str += Modifier;
1422458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
14231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1424458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isString() const { return MyKind == String; }
1425458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isOperand() const { return MyKind == Operand; }
14261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1427458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    const std::string &getString() const {
1428458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isString());
1429458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str;
1430458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1431458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1432458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned getOperandNo() const {
1433458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1434458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return OperandNo;
1435458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
14361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1437458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// getModifier - Get the modifier for this operand, if present.  This
1438458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// returns '\0' if there was no modifier.
1439458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    char getModifier() const {
1440458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1441458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str[0];
1442458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1443458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  };
14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1445458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1446458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// it into pieces.  If the asm string is erroneous, emit errors and return
1447458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// true, otherwise return false.  This handles canonicalization and
1448458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1450686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1451fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner                            ASTContext &C, unsigned &DiagOffs) const;
14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1454b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Output operands ---===//
1455b327793860737d1c103a73aeda8057dd628a101dChris Lattner
1456b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  unsigned getNumOutputs() const { return NumOutputs; }
1457ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
1458ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1459ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Names[i];
1460ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1461ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
1462686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputName(unsigned i) const {
1463ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    if (IdentifierInfo *II = getOutputIdentifier(i))
1464ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson      return II->getName();
1465ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1466686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    return StringRef();
1467ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  }
1468ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson
1469b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// getOutputConstraint - Return the constraint string for the specified
1470b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// output operand.  All output constraints are known to be non-empty (either
1471b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// '=' or '+').
1472686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputConstraint(unsigned i) const;
14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1474b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1475ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i];
1476ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1477b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1478b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return Constraints[i];
1479b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
14801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1481ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getOutputExpr(unsigned i);
14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1483b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getOutputExpr(unsigned i) const {
1484b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return const_cast<AsmStmt*>(this)->getOutputExpr(i);
1485b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
14861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1487b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// isOutputPlusConstraint - Return true if the specified output constraint
1488b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// is a "+" constraint (which is both an input and an output) or false if it
1489b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// is an "=" constraint (just an output).
1490b327793860737d1c103a73aeda8057dd628a101dChris Lattner  bool isOutputPlusConstraint(unsigned i) const {
1491b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return getOutputConstraint(i)[0] == '+';
1492b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
14931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
149485759278332404e96d4bb89d0e976e46158cd026Chris Lattner  /// getNumPlusOperands - Return the number of output operands that have a "+"
149585759278332404e96d4bb89d0e976e46158cd026Chris Lattner  /// constraint.
149685759278332404e96d4bb89d0e976e46158cd026Chris Lattner  unsigned getNumPlusOperands() const;
14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1498b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Input operands ---===//
14991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumInputs() const { return NumInputs; }
15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1502ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  IdentifierInfo *getInputIdentifier(unsigned i) const {
1503ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Names[i + NumOutputs];
1504ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
15051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1506686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputName(unsigned i) const {
1507ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    if (IdentifierInfo *II = getInputIdentifier(i))
1508ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson      return II->getName();
1509ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson
1510686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    return StringRef();
1511ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  }
1512ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson
1513b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// getInputConstraint - Return the specified input constraint.  Unlike output
1514b327793860737d1c103a73aeda8057dd628a101dChris Lattner  /// constraints, these can be empty.
1515686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputConstraint(unsigned i) const;
15161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1517b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1518ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1519ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1520b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getInputConstraintLiteral(unsigned i) {
1521ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1522ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
15231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1524ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getInputExpr(unsigned i);
1525935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner  void setInputExpr(unsigned i, Expr *E);
1526ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1527b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getInputExpr(unsigned i) const {
1528b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return const_cast<AsmStmt*>(this)->getInputExpr(i);
1529b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
1530cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1531acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson  void setOutputsAndInputsAndClobbers(ASTContext &C,
1532ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                      IdentifierInfo **Names,
1533fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Constraints,
1534fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      Stmt **Exprs,
1535fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumOutputs,
1536ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      unsigned NumInputs,
1537fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Clobbers,
1538fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumClobbers);
1539cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
154010ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  //===--- Other ---===//
15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
154210ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// getNamedOperand - Given a symbolic operand reference like %[foo],
154310ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// translate this into a numeric value needed to reference the same operand.
154410ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// This returns -1 if the operand name is invalid.
1545686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  int getNamedOperand(StringRef SymbolicName) const;
154610ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner
1547966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  unsigned getNumClobbers() const { return NumClobbers; }
1548b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson  StringLiteral *getClobber(unsigned i) { return Clobbers[i]; }
1549d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson  const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; }
1550cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1551aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1552fe795956194141c91ae555985c9b930595bff43fChris Lattner    return SourceRange(AsmLoc, RParenLoc);
1553fe795956194141c91ae555985c9b930595bff43fChris Lattner  }
15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1555fe795956194141c91ae555985c9b930595bff43fChris Lattner  static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;}
1556fe795956194141c91ae555985c9b930595bff43fChris Lattner  static bool classof(const AsmStmt *) { return true; }
15571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1558ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek  // Input expr iterators.
15591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1560ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ExprIterator inputs_iterator;
1561ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ConstExprIterator const_inputs_iterator;
15621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1563ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  inputs_iterator begin_inputs() {
1564966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1565ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1567ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  inputs_iterator end_inputs() {
1568966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs + NumInputs;
1569ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1571ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  const_inputs_iterator begin_inputs() const {
1572966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1573ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1575ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  const_inputs_iterator end_inputs() const {
1576966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs + NumInputs;
1577d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
15781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1579ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek  // Output expr iterators.
15801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1581ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ExprIterator outputs_iterator;
1582ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  typedef ConstExprIterator const_outputs_iterator;
15831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1584d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  outputs_iterator begin_outputs() {
1585966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0];
1586d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
1587d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  outputs_iterator end_outputs() {
1588966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1589d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
15901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1591d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  const_outputs_iterator begin_outputs() const {
1592966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0];
1593d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
1594d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  const_outputs_iterator end_outputs() const {
1595966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson    return &Exprs[0] + NumOutputs;
1596d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek  }
15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
159863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
159963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
160063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
1601fe795956194141c91ae555985c9b930595bff43fChris Lattner};
160278492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek
16038cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier/// MSAsmStmt - This represents a MS inline-assembly statement extension.
16048cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier///
16058cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierclass MSAsmStmt : public Stmt {
16068cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceLocation AsmLoc, EndLoc;
16078cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  std::string AsmStr;
16088cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16098cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  bool IsSimple;
16108cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  bool IsVolatile;
16118cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16128cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  Stmt **Exprs;
16138cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16148cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic:
16158cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  MSAsmStmt(ASTContext &C, SourceLocation asmloc, std::string &asmstr,
16168cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier            SourceLocation endloc);
16178cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16188cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceLocation getAsmLoc() const { return AsmLoc; }
16198cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
16208cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceLocation getEndLoc() const { return EndLoc; }
16218cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setEndLoc(SourceLocation L) { EndLoc = L; }
16228cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16238cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  bool isVolatile() const { return IsVolatile; }
16248cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setVolatile(bool V) { IsVolatile = V; }
16258cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  bool isSimple() const { return IsSimple; }
16268cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setSimple(bool V) { IsSimple = V; }
16278cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16288cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Asm String Analysis ---===//
16298cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16308cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  const std::string *getAsmString() const { return &AsmStr; }
16318cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  std::string *getAsmString() { return &AsmStr; }
16328cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setAsmString(StringRef &E) { AsmStr = E.str(); }
16338cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16348cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Other ---===//
16358cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16368cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceRange getSourceRange() const LLVM_READONLY {
16378cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return SourceRange(AsmLoc, EndLoc);
16388cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
16398cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  static bool classof(const Stmt *T) {
16408cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return T->getStmtClass() == MSAsmStmtClass;
16418cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
16428cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  static bool classof(const MSAsmStmt *) { return true; }
16438cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16448cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  child_range children() {
16458cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return child_range(&Exprs[0], &Exprs[0]);
16468cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
16478cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier};
16488cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
164928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt {
165028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
165128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
165228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
165328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { FILTER_EXPR, BLOCK };
165428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
165528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt(SourceLocation Loc,
165628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Expr *FilterExpr,
165728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Stmt *Block);
165828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
16597110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
16607110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
16617110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
16627110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
166328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
166428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHExceptStmt* Create(ASTContext &C,
166528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation ExceptLoc,
166628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Expr *FilterExpr,
166728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Block);
1668aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
166928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getExceptLoc(), getEndLoc());
167028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
167128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
167228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getExceptLoc() const { return Loc; }
167328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
167428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1675ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getFilterExpr() const {
1676ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1677ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1678ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1679ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt *getBlock() const {
1680ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return llvm::cast<CompoundStmt>(Children[BLOCK]);
1681ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
168228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
168328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
168428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
168528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
168628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
168728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
168828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHExceptStmtClass;
168928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
169028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
169128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHExceptStmt *) { return true; }
169228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
169328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
169428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
169528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt {
169628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
169728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Block;
169828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
169928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt(SourceLocation Loc,
170028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                 Stmt *Block);
170128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
17027110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
17037110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
17047110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
17057110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
170628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
170728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHFinallyStmt* Create(ASTContext &C,
170828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                SourceLocation FinallyLoc,
170928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                Stmt *Block);
171028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1711aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
171228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getFinallyLoc(), getEndLoc());
171328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
171428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
171528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getFinallyLoc() const { return Loc; }
171628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
171728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
171828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); }
171928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
172028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
172128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(&Block,&Block+1);
172228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
172328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
172428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
172528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHFinallyStmtClass;
172628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
172728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
172828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHFinallyStmt *) { return true; }
172928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
173028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
173128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
173228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt {
173328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool            IsCXXTry;
173428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  TryLoc;
173528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
173628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
173728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { TRY = 0, HANDLER = 1 };
173828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
173928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
174028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             SourceLocation TryLoc,
174128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *TryBlock,
174228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *Handler);
174328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
17447110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
17457110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
17467110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
17477110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
174828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
174928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHTryStmt* Create(ASTContext &C,
175028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            bool isCXXTry,
175128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            SourceLocation TryLoc,
175228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *TryBlock,
175328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *Handler);
175428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1755aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
175628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getTryLoc(), getEndLoc());
175728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
175828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
175928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getTryLoc() const { return TryLoc; }
176028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
176128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
176228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool getIsCXXTry() const { return IsCXXTry; }
1763ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1764ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt* getTryBlock() const {
1765ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return llvm::cast<CompoundStmt>(Children[TRY]);
1766ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1767ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
176828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt *getHandler() const { return Children[HANDLER]; }
176928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
177028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Returns 0 if not defined
177128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt  *getExceptHandler() const;
177228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt *getFinallyHandler() const;
177328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
177428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
177528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
177628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
177728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
177828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
177928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHTryStmtClass;
178028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
178128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
178228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHTryStmt *) { return true; }
178328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
1784ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1788