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"
238f726de55412870ef70e788b852c6cc50873e15bChad Rosier#include "clang/Lex/Token.h"
249594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "llvm/ADT/SmallVector.h"
25aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
26aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/raw_ostream.h"
276e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string>
287573098b83e780d1c5bea13b384b610d8f155676Steve Naroff
2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm {
3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  class FoldingSetNodeID;
3141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor}
3241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
34e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  class ASTContext;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
377ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff  class ParmVarDecl;
384b07b2968f87f3cd5a3d8c76145f1cbfd718d42dSebastian Redl  class QualType;
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class IdentifierInfo;
40478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class LabelDecl;
410c727a35718556866a978f64ac549d9798735f08Chris Lattner  class SourceManager;
426a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  class StringLiteral;
436c36be5b383875b490684bcf439d6d427298c1afChris Lattner  class SwitchStmt;
44478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class VarDecl;
451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
47ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  // ExprIterator - Iterators for iterating over Stmt* arrays that contain
48ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
49ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  references to children (to be compatible with StmtIterator).
50ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Stmt;
53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Expr;
541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ExprIterator {
56ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Stmt** I;
57ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator(Stmt** i) : I(i) {}
591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExprIterator() : I(0) {}
60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator& operator++() { ++I; return *this; }
61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator-(size_t i) { return I-i; }
62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator+(size_t i) { return I+i; }
63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator[](size_t idx);
64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    // FIXME: Verify that this will correctly return a signed distance.
65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ExprIterator& R) const { return I - R.I; }
66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator*() const;
67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator->() const;
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    bool operator>=(const ExprIterator& R) const { return I >= R.I; }
72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  };
731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ConstExprIterator {
751705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    const Stmt * const *I;
76ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
771705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator(const Stmt * const *i) : I(i) {}
781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ConstExprIterator() : I(0) {}
79ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ConstExprIterator& operator++() { ++I; return *this; }
801705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator+(size_t i) const { return I+i; }
811705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator-(size_t i) const { return I-i; }
82ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator[](size_t idx) const;
83ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ConstExprIterator& R) const { return I - R.I; }
84ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator*() const;
85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator->() const;
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; }
89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  };
911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
93ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements.
94ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement.
975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt {
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum StmtClass {
101f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor    NoStmtClass = 0,
102f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class,
1037381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \
1049a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
1057381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
1069a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
1077381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT)
1084bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
1098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Make vanilla 'new' and 'delete' illegal for Stmts.
1128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected:
1138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes) throw() {
114b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
1158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void operator delete(void* data) throw() {
117b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
1188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class StmtBitfields {
1218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Stmt;
1228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    /// \brief The statement class.
1248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned sClass : 8;
1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  enum { NumStmtBits = 8 };
1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CompoundStmtBitfields {
1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CompoundStmt;
1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned NumStmts : 32 - NumStmtBits;
1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class ExprBitfields {
1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Expr;
1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DeclRefExpr; // computeDependence
1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class InitListExpr; // ctor
1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DesignatedInitExpr; // ctor
140d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor    friend class BlockDeclRefExpr; // ctor
141bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ASTStmtReader; // deserialization
142bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXNewExpr; // ctor
143bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class DependentScopeDeclRefExpr; // ctor
144bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXConstructExpr; // ctor
145bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CallExpr; // ctor
146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OffsetOfExpr; // ctor
147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ObjCMessageExpr; // ctor
148ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCArrayLiteral; // ctor
149ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCDictionaryLiteral; // ctor
150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ShuffleVectorExpr; // ctor
151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ParenListExpr; // ctor
152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXUnresolvedConstructExpr; // ctor
153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXDependentScopeMemberExpr; // ctor
154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OverloadExpr; // ctor
1554b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr; // ctor
156dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    friend class AtomicExpr; // ctor
1578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueKind : 2;
160f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    unsigned ObjectKind : 2;
1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned TypeDependent : 1;
1628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueDependent : 1;
163561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
166561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  enum { NumExprBits = 16 };
1678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
168bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class CharacterLiteralBitfields {
169bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class CharacterLiteral;
170bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
171bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
172bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
173bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class FloatingLiteralBitfields {
176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class FloatingLiteral;
177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
179bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsIEEE : 1; // Distinguishes between PPC128 and IEEE128.
180bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsExact : 1;
181bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
182bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
183bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class UnaryExprOrTypeTraitExprBitfields {
184bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class UnaryExprOrTypeTraitExpr;
185bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
186bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
187bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
188bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsType : 1; // true if operand is a type, false if an expression.
189bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
190bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
191cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  class DeclRefExprBitfields {
192cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class DeclRefExpr;
193cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class ASTStmtReader; // deserialization
194cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned : NumExprBits;
195cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
196cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasQualifier : 1;
197e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    unsigned HasTemplateKWAndArgsInfo : 1;
1983aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    unsigned HasFoundDecl : 1;
1997cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    unsigned HadMultipleCandidates : 1;
200f4b88a45902af1802a1cb42ba48b1c474474f228John McCall    unsigned RefersToEnclosingLocal : 1;
201cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  };
202cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
2038e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CastExprBitfields {
2048e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CastExpr;
2058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumExprBits;
2068e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2072bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned Kind : 6;
2082bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned BasePathSize : 32 - 6 - NumExprBits;
2098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2108e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
211cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  class CallExprBitfields {
212cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    friend class CallExpr;
213cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned : NumExprBits;
214cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
215cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned NumPreArgs : 1;
216cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  };
217cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
21880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  class ExprWithCleanupsBitfields {
21980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ExprWithCleanups;
22080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ASTStmtReader; // deserialization
22180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
22280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned : NumExprBits;
22380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
22480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned NumObjects : 32 - NumExprBits;
22580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  };
22680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
2274b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class PseudoObjectExprBitfields {
2284b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr;
2294b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class ASTStmtReader; // deserialization
2304b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2314b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned : NumExprBits;
2324b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2334b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // These don't need to be particularly wide, because they're
2344b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // strictly limited by the forms of expressions we permit.
2354b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned NumSubExprs : 8;
2364b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned ResultIndex : 32 - 8 - NumExprBits;
2374b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
2384b9c2d235fb9449e249d74f48ecfec601650de93John McCall
239f85e193739c953358c865005855253af4f68a497John McCall  class ObjCIndirectCopyRestoreExprBitfields {
240f85e193739c953358c865005855253af4f68a497John McCall    friend class ObjCIndirectCopyRestoreExpr;
241f85e193739c953358c865005855253af4f68a497John McCall    unsigned : NumExprBits;
242f85e193739c953358c865005855253af4f68a497John McCall
243f85e193739c953358c865005855253af4f68a497John McCall    unsigned ShouldCopy : 1;
244f85e193739c953358c865005855253af4f68a497John McCall  };
245f85e193739c953358c865005855253af4f68a497John McCall
24632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  class InitListExprBitfields {
24732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    friend class InitListExpr;
24832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
24932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned : NumExprBits;
25032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
25132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list originally had a GNU array-range
25232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// designator in it. This is a temporary marker used by CodeGen.
25332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned HadArrayRangeDesignator : 1;
25432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
25532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list initializes a std::initializer_list
25632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// object.
25732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned InitializesStdInitializerList : 1;
25832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  };
25932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
2604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  class TypeTraitExprBitfields {
2614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class TypeTraitExpr;
2624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtReader;
2634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtWriter;
2644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned : NumExprBits;
2664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
2684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Kind : 8;
2694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief If this expression is not value-dependent, this indicates whether
2714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// the trait evaluated true or false.
2724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Value : 1;
2734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The number of arguments to this type trait.
2754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
2764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  };
2774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  union {
27963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    // FIXME: this is wasteful on 64-bit platforms.
28063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    void *Aligner;
28163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
2828e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBitfields StmtBits;
2838e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBitfields CompoundStmtBits;
2848e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBitfields ExprBits;
285bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    CharacterLiteralBitfields CharacterLiteralBits;
286bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    FloatingLiteralBitfields FloatingLiteralBits;
287bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
288cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    DeclRefExprBitfields DeclRefExprBits;
2898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBitfields CastExprBits;
290cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    CallExprBitfields CallExprBits;
29180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    ExprWithCleanupsBitfields ExprWithCleanupsBits;
2924b9c2d235fb9449e249d74f48ecfec601650de93John McCall    PseudoObjectExprBitfields PseudoObjectExprBits;
293f85e193739c953358c865005855253af4f68a497John McCall    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
29432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    InitListExprBitfields InitListExprBits;
2954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeTraitExprBitfields TypeTraitExprBits;
2968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
298d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  friend class ASTStmtReader;
2994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
300d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
3018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic:
3028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Only allow allocation of Stmts using the allocator in ASTContext
3031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // or by doing a placement new.
3048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext& C,
305f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor                     unsigned alignment = 8) throw() {
3068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return ::operator new(bytes, C, alignment);
3078189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext* C,
310f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor                     unsigned alignment = 8) throw() {
3118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return ::operator new(bytes, *C, alignment);
3128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, void* mem) throw() {
3158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return mem;
3168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
317e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
318fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext&, unsigned) throw() { }
319fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext*, unsigned) throw() { }
320e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor  void operator delete(void*, std::size_t) throw() { }
321fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, void*) throw() { }
322e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
323025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic:
324025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief A placeholder type used to construct an empty shell of a
325025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// type, that will be filled in later (e.g., by some
326025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// de-serialization).
327025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  struct EmptyShell { };
328025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
32902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate:
33002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  /// \brief Whether statistic collection is enabled.
33102892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static bool StatisticsEnabled;
33202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar
3339c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected:
334025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Construct an empty statement.
3358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  explicit Stmt(StmtClass SC, EmptyShell) {
3368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
33702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
338025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  }
339025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt(StmtClass SC) {
3428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
34302892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
346ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  StmtClass getStmtClass() const {
3478e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    return static_cast<StmtClass>(StmtBits.sClass);
348b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor  }
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStmtClassName() const;
3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
351b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// SourceLocation tokens are not useful in isolation - they are low level
352b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// value objects created/interpreted by SourceManager. We assume AST
353b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// clients will have a pointer to the respective SourceManager.
354aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
355aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
356aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // global temp stats (until we have a per-module visitor)
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void addStmtClass(const StmtClass s);
36002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static void EnableStatistics();
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void PrintStats();
3626000dace22f110d8768476989313e9d981d690d0Chris Lattner
3636000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dump - This does a local dump of the specified AST fragment.  It dumps the
3646000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// specified node and a few nodes underneath it, but not the whole subtree.
3656000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// This is useful in a debugger.
366f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump() const;
367f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
3688cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS, SourceManager &SM) const;
3696000dace22f110d8768476989313e9d981d690d0Chris Lattner
3706000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpAll - This does a dump of the specified AST fragment and all subtrees.
3716000dace22f110d8768476989313e9d981d690d0Chris Lattner  void dumpAll() const;
372e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner  void dumpAll(SourceManager &SM) const;
3736000dace22f110d8768476989313e9d981d690d0Chris Lattner
3746000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
3756000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// back to its original source language syntax.
376d1420c6fa788669e49f21e184927c7833881e399Richard Smith  void dumpPretty(ASTContext &Context) const;
3778cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
378e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
379d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                   unsigned Indentation = 0) const;
3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
381d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
382d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
383d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  void viewAST() const;
3841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3857e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// Skip past any implicit AST nodes which might surround this
3867e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
3877e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  Stmt *IgnoreImplicit();
3887e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
389a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  const Stmt *stripLabelLikeStatements() const;
390a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  Stmt *stripLabelLikeStatements() {
391a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth    return const_cast<Stmt*>(
392a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
393a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  }
394a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Implement isa<T> support.
3961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *) { return true; }
3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
398d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
399d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  contain implicit control-flow in the order their subexpressions
400d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  are evaluated.  This predicate returns true if this statement has
401d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  such implicit control-flow.  Such statements are also specially handled
402d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  within CFGs.
403d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  bool hasImplicitControlFlow() const;
404d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek
40563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// Child Iterators: All subclasses must implement 'children'
40663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// to permit easy iteration over the substatements/subexpessions of an
40763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// AST node.  This permits easy iteration over all nodes in the AST.
4089caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef StmtIterator       child_iterator;
4099caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef ConstStmtIterator  const_child_iterator;
4101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef StmtRange          child_range;
41263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef ConstStmtRange     const_child_range;
4131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
41563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_range children() const {
41663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return const_cast<Stmt*>(this)->children();
41777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
4181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_begin() { return children().first; }
42063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_end() { return children().second; }
42163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
42263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_begin() const { return children().first; }
42363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_end() const { return children().second; }
42441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
42541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Produce a unique representation of the given statement.
42641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42770517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param ID once the profiling operation is complete, will contain
42841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// the unique representation of the given statement.
42941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43070517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Context the AST context in which the statement resides
43141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
43270517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Canonical whether the profile should be based on the canonical
43341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// representation of this statement (e.g., where non-type template
4341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// parameters are identified by index/level rather than their
43541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// declaration pointers) or the exact representation of the statement as
43641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// written in the source.
4374ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
438b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth               bool Canonical) const;
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions
4431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration.
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt {
4479653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor  DeclGroupRef DG;
44881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation StartLoc, EndLoc;
4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
4528ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
4538ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek                                    StartLoc(startLoc), EndLoc(endLoc) {}
4541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  /// \brief Build an empty declaration statement.
45684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
45784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4587e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  /// isSingleDecl - This method returns true if this DeclStmt refers
459fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner  /// to a single Decl.
4607e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  bool isSingleDecl() const {
461fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner    return DG.isSingleDecl();
4628ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  }
4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4647e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Decl *getSingleDecl() { return DG.getSingleDecl(); }
4661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
467e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  const DeclGroupRef getDeclGroup() const { return DG; }
468e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  DeclGroupRef getDeclGroup() { return DG; }
46984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
470b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
47181c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
47284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setStartLoc(SourceLocation L) { StartLoc = L; }
47381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
47484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setEndLoc(SourceLocation L) { EndLoc = L; }
47584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
476aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
47781c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner    return SourceRange(StartLoc, EndLoc);
47881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  }
4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DeclStmtClass;
4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclStmt *) { return true; }
4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48514f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek  // Iterators over subexpressions.
48663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
48763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(child_iterator(DG.begin(), DG.end()),
48863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       child_iterator(DG.end(), DG.end()));
48963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
4901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4910632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::iterator decl_iterator;
4920632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::const_iterator const_decl_iterator;
4931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4948ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_begin() { return DG.begin(); }
4958ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_end() { return DG.end(); }
4968ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_begin() const { return DG.begin(); }
4978ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_end() const { return DG.end(); }
498fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose
499fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
500fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rbegin() {
501fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_end());
502fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
503fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rend() {
504fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_begin());
505fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3.
5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt {
5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation SemiLoc;
51244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
513e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  /// \brief True if the null statement was preceded by an empty macro, e.g:
51444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @code
51544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   #define CALL(x)
51644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   CALL(0);
51744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @endcode
518e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool HasLeadingEmptyMacro;
5195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
520e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
521e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis    : Stmt(NullStmtClass), SemiLoc(L),
522e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
524025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty null statement.
525e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
526e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(false) { }
527025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getSemiLoc() const { return SemiLoc; }
529025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
530b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
531e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
53244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
533aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(SemiLoc); }
5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == NullStmtClass;
5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const NullStmt *) { return true; }
5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
54144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
54244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtReader;
54344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtWriter;
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }.
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt {
5498189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  Stmt** Body;
550b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation LBracLoc, RBracLoc;
5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5523a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts,
5533a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer               SourceLocation LB, SourceLocation RB);
5543a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer
5553a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  // \brief Build an empty compound statment with a location.
5563a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  explicit CompoundStmt(SourceLocation Loc)
5573a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) {
5583a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    CompoundStmtBits.NumStmts = 0;
5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
560025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
561025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  // \brief Build an empty compound statement.
562025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CompoundStmt(EmptyShell Empty)
5638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    : Stmt(CompoundStmtClass, Empty), Body(0) {
5648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = 0;
5658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
566025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
567025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
5681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
5708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned size() const { return CompoundStmtBits.NumStmts; }
571025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5728189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt** body_iterator;
5738189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  body_iterator body_begin() { return Body; }
5748e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  body_iterator body_end() { return Body + size(); }
5758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
576ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5778e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setLastStmt(Stmt *S) {
5788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    assert(!body_empty() && "setLastStmt");
5798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Body[size()-1] = S;
5808e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5828189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt* const * const_body_iterator;
5838189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_body_iterator body_begin() const { return Body; }
5848e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const_body_iterator body_end() const { return Body + size(); }
5858e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
5868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek
5878189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
5888189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rbegin() {
5898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_end());
5908189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5918189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rend() {
5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_begin());
5938189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5944ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<const_body_iterator>
5968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek          const_reverse_body_iterator;
5974ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5988189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rbegin() const {
5998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_end());
6008189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rend() const {
6038189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_begin());
6048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
6051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
606aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
6071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(LBracLoc, RBracLoc);
608b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
610cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getLBracLoc() const { return LBracLoc; }
611025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
612cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getRBracLoc() const { return RBracLoc; }
613025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundStmtClass;
6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundStmt *) { return true; }
6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
62163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
62263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
62363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6258ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  const_child_range children() const {
6268ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
6278ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  }
6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
630c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt,
631c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt {
632103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected:
633c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // A pointer to the following CaseStmt or DefaultStmt class,
634c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // used by SwitchStmt.
635c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *NextSwitchCase;
636103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek
637d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
6381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
639c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic:
640c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
641c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
642c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
643c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
644c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
645d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek
64663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  Stmt *getSubStmt();
647702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  const Stmt *getSubStmt() const {
648702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner    return const_cast<SwitchCase*>(this)->getSubStmt();
649702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  }
650b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
651aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); }
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass ||
65563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall           T->getStmtClass() == DefaultStmtClass;
656c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
657c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  static bool classof(const SwitchCase *) { return true; }
658c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson};
659c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
660c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase {
6610a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor  enum { LHS, RHS, SUBSTMT, END_EXPR };
6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
663d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek                             // GNU "case 1 ... 4" extension
664b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation CaseLoc;
665dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation EllipsisLoc;
666dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
668dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation ellipsisLoc, SourceLocation colonLoc)
670d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    : SwitchCase(CaseStmtClass) {
67124e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner    SubExprs[SUBSTMT] = 0;
672d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
673d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
674b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    CaseLoc = caseLoc;
675dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    EllipsisLoc = ellipsisLoc;
676dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc = colonLoc;
677d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  }
678025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
679025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty switch case statement.
680025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { }
681025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
682764a7ce5217f9569e100a3445f47496ee82daf86Chris Lattner  SourceLocation getCaseLoc() const { return CaseLoc; }
683025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCaseLoc(SourceLocation L) { CaseLoc = L; }
684dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
685dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
686dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
687dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
688025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
689d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
690d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
691d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
692025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
6931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getLHS() const {
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
69551b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
6961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const {
6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
69851b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
69951b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
70120dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
70220dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
70320dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
706aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7073fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    // Handle deeply nested case statements with iteration instead of recursion.
7083fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    const CaseStmt *CS = this;
70991ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
7103fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner      CS = CS2;
7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
713b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass;
7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CaseStmt *) { return true; }
7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
719d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
72063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
72163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
72263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
725c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase {
726d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt* SubStmt;
7276c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation DefaultLoc;
728dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
731dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL),
732dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc(CL) {}
733025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
734025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty default statement.
735025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { }
736025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
737d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubStmt; }
73851b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubStmt; }
739025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSubStmt(Stmt *S) { SubStmt = S; }
740025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
7416c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation getDefaultLoc() const { return DefaultLoc; }
742025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setDefaultLoc(SourceLocation L) { DefaultLoc = L; }
743dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
744dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
746aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DefaultLoc, SubStmt->getLocEnd());
748b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DefaultStmtClass;
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DefaultStmt *) { return true; }
7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
754d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
75563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
758ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
759ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement.  For example:
760ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///    foo: return;
761ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt {
763ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *TheDecl;
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *SubStmt;
765b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IdentLoc;
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
767ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
768ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
7698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
7701de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
7711de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  // \brief Build an empty label statement.
7721de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getIdentLoc() const { return IdentLoc; }
775ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getDecl() const { return TheDecl; }
776ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setDecl(LabelDecl *D) { TheDecl = D; }
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *getSubStmt() { return SubStmt; }
7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Stmt *getSubStmt() const { return SubStmt; }
7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setSubStmt(Stmt *SS) { SubStmt = SS; }
782b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
783aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(IdentLoc, SubStmt->getLocEnd());
7851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
78663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
78763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
7881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == LabelStmtClass;
7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const LabelStmt *) { return true; }
7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
795534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement.
796534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
797534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example:
798534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///   [[omp::for(...)]] for (...) { ... }
799534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
800534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt {
801534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *SubStmt;
802534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation AttrLoc;
8034990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  unsigned NumAttrs;
8044990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  const Attr *Attrs[1];
805534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
806534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  friend class ASTStmtReader;
807534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8084990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
8094990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
8104990890fc9428f98bef90ba349203a648c592778Alexander Kornienko      NumAttrs(Attrs.size()) {
8114990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*));
812534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
813534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8144990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
8154990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
8164990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memset(Attrs, 0, NumAttrs * sizeof(Attr*));
817534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
818534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8194990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic:
8204990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *Create(ASTContext &C, SourceLocation Loc,
8214990890fc9428f98bef90ba349203a648c592778Alexander Kornienko                                ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
8224990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  // \brief Build an empty attributed statement.
8234990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs);
8244990890fc9428f98bef90ba349203a648c592778Alexander Kornienko
825534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation getAttrLoc() const { return AttrLoc; }
8264990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  ArrayRef<const Attr*> getAttrs() const {
8274990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    return ArrayRef<const Attr*>(Attrs, NumAttrs);
8284990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  }
829534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *getSubStmt() { return SubStmt; }
830534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  const Stmt *getSubStmt() const { return SubStmt; }
831534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
832534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceRange getSourceRange() const LLVM_READONLY {
833534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return SourceRange(AttrLoc, SubStmt->getLocEnd());
834534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
835534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
836534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
837534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  static bool classof(const Stmt *T) {
838534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return T->getStmtClass() == AttributedStmtClass;
839534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
840534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  static bool classof(const AttributedStmt *) { return true; }
841534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith};
842534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
843534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else.
8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt {
84743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, THEN, ELSE, END_EXPR };
8488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
8498cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor
850b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IfLoc;
851d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation ElseLoc;
852ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
854ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
85544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
856ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
857025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty if/then/else statement
858025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
859025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
8608cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \brief Retrieve the variable declared in this "if" statement, if any.
8618cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///
8628cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// In the following example, "x" is the condition variable.
8638cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \code
8648cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// if (int x = foo()) {
8658cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///   printf("x is %d", x);
8668cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// }
8678cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \endcode
86843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
86943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
871d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this IfStmt has a condition variable, return the faux DeclStmt
872d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
873d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
874d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
875d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
876ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8778297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
878025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
8798297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getThen() const { return SubExprs[THEN]; }
8801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setThen(Stmt *S) { SubExprs[THEN] = S; }
8818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getElse() const { return SubExprs[ELSE]; }
882025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
8858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getThen() { return SubExprs[THEN]; }
8868297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getElse() { return SubExprs[ELSE]; }
887b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
888025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getIfLoc() const { return IfLoc; }
889025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setIfLoc(SourceLocation L) { IfLoc = L; }
890d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation getElseLoc() const { return ElseLoc; }
891d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  void setElseLoc(SourceLocation L) { ElseLoc = L; }
892025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
893aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
894b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    if (SubExprs[ELSE])
895b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
896b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    else
897b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
898b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
8991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
90063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators over subexpressions.  The iterators will include iterating
90163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // over the initialization expression referenced by the condition variable.
90263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
90363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
90463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
90563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IfStmtClass;
9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IfStmt *) { return true; }
9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt.
9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt {
91543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
917c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // This points to a linked list of case and default statements.
918c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *FirstCase;
9199dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  SourceLocation SwitchLoc;
9201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
921559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// If the SwitchStmt is a switch on an enum value, this records whether
922559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// all the enum values were covered by CaseStmts.  This value is meant to
923559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// be a hint for possible clients.
924559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  unsigned AllEnumCasesCovered : 1;
925559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
92743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
929025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build a empty switch statement.
930025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
931025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
932d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \brief Retrieve the variable declared in this "switch" statement, if any.
933d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///
934d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// In the following example, "x" is the condition variable.
935d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \code
936d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// switch (int x = foo()) {
937d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   case 0: break;
938d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   // ...
939d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// }
940d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \endcode
94143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
94243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
943ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
944d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
945d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
946d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
947d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
948d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
949d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor
9508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
9518297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
952c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
953c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
955025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
9568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
957025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
958c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getSwitchCaseList() { return FirstCase; }
9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Set the case list for this switch statement.
96143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
96243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// The caller is responsible for incrementing the retain counts on
96343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// all of the SwitchCase statements in this list.
964025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
965025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
966025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getSwitchLoc() const { return SwitchLoc; }
967025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
968c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setBody(Stmt *S, SourceLocation SL) {
9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[BODY] = S;
9719dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    SwitchLoc = SL;
9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
973c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void addSwitchCase(SwitchCase *SC) {
974ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!SC->getNextSwitchCase()
975ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           && "case/default already added to a switch");
976c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    SC->setNextSwitchCase(FirstCase);
977c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson    FirstCase = SC;
978c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
979559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
980559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
981559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// switch over an enum value then all cases have been explicitly covered.
982559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  void setAllEnumCasesCovered() {
983559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    AllEnumCasesCovered = 1;
984559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
985559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
986559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
987559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// have been explicitly covered.
988559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  bool isAllEnumCasesCovered() const {
989559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    return (bool) AllEnumCasesCovered;
990559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
991559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
992aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
9931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
9949dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  }
99563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators
99663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
99763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
99863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
99963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SwitchStmtClass;
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const SwitchStmt *) { return true; }
10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt.
10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt {
101043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
10118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1012b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation WhileLoc;
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1014ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
101543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor            SourceLocation WL);
10161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1017d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty while statement.
1018d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1019d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
10205656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \brief Retrieve the variable declared in this "while" statement, if any.
10215656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///
10225656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// In the following example, "x" is the condition variable.
10235656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \code
10245656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// while (int x = random()) {
10255656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///   // ...
10265656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// }
10275656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \endcode
102843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
102943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
10305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
1031d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1032d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1033d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1034d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1035d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1036d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
10378297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10388297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1039d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10408297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10418297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1042d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1043d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1044d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
1045d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1046b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1047aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
1049b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
10501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == WhileStmtClass;
10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const WhileStmt *) { return true; }
10541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10558297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
105663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
105763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
105863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt.
10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt {
1064c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor  enum { BODY, COND, END_EXPR };
10658297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1066b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation DoLoc;
10679f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation WhileLoc;
1068989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
10699f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor
10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1071989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1072989135901c750af61ef012b6b0a0368be415bc46Chris Lattner         SourceLocation RP)
1073989135901c750af61ef012b6b0a0368be415bc46Chris Lattner    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
10748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
10758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[BODY] = body;
10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
107767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
107867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty do-while statement.
107967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10828297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
108367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Stmt *getBody() const { return SubExprs[BODY]; }
108667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
108767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
108867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getDoLoc() const { return DoLoc; }
108967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setDoLoc(SourceLocation L) { DoLoc = L; }
10909f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
10919f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1092b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1093989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
1094989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1095989135901c750af61ef012b6b0a0368be415bc46Chris Lattner
1096aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DoLoc, RParenLoc);
1098b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DoStmtClass;
11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DoStmt *) { return true; }
11038297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11048297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
110563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
110663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
110763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not
11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source.
11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt {
111643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
11178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1118b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation ForLoc;
11195831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation LParenLoc, RParenLoc;
11205831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor
11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1122ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
112343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
112567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty for statement.
112667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
112767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
11288297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getInit() { return SubExprs[INIT]; }
1129ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
113099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \brief Retrieve the variable declared in this "for" statement, if any.
113199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///
113299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// In the following example, "y" is the condition variable.
113399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \code
113499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// for (int x = random(); int y = mangle(x); ++x) {
113599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///   // ...
113699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// }
113799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \endcode
113843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
113943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
1140ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1141d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this ForStmt has a condition variable, return the faux DeclStmt
1142d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1143d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1144d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1145d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1146d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
11478297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
11488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
11508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11518297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getInit() const { return SubExprs[INIT]; }
11528297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
11538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1155b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
115667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInit(Stmt *S) { SubExprs[INIT] = S; }
115767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
115867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
115967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
116067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
116167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getForLoc() const { return ForLoc; }
116267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setForLoc(SourceLocation L) { ForLoc = L; }
11635831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
11645831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
11655831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11665831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
116767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
1168aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
11691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
1170b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
11711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ForStmtClass;
11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ForStmt *) { return true; }
11751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11768297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
117763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
117863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
117963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto.
11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt {
1185ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
1186507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation GotoLoc;
118761f62165220e75694fe333179c78815e2e48d71fTed Kremenek  SourceLocation LabelLoc;
11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1189ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
119061f62165220e75694fe333179c78815e2e48d71fTed Kremenek    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
11911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11921de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Build an empty goto statement.
11931de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
11941de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1195ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
1196ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *D) { Label = D; }
11971de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
11981de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getGotoLoc() const { return GotoLoc; }
11991de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
12001de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
12011de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1202b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1203aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(GotoLoc, LabelLoc);
1205507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
12061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GotoStmtClass;
12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const GotoStmt *) { return true; }
12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
121263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto.
12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt {
1218ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation GotoLoc;
12195f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation StarLoc;
12201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Target;
12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
12235f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor                   Expr *target)
12245f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
12255f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor      Target((Stmt*)target) {}
12267d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
12277d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty indirect goto statement.
12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IndirectGotoStmt(EmptyShell Empty)
12297d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Stmt(IndirectGotoStmtClass, Empty) { }
12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1231ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1232ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation getGotoLoc() const { return GotoLoc; }
12335f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  void setStarLoc(SourceLocation L) { StarLoc = L; }
12345f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation getStarLoc() const { return StarLoc; }
12351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
123695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
123795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
12387d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1239b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
124095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// getConstantTarget - Returns the fixed target of this indirect
124195c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// goto, if one exists.
1242ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getConstantTarget();
1243ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  const LabelDecl *getConstantTarget() const {
124495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
124595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  }
124695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall
1247aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1248ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner    return SourceRange(GotoLoc, Target->getLocEnd());
1249ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  }
12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IndirectGotoStmtClass;
12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IndirectGotoStmt *) { return true; }
12551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
125763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Target, &Target+1); }
12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue.
12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt {
1264507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation ContinueLoc;
12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1266507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1268d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty continue statement.
1269d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1270d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1271d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getContinueLoc() const { return ContinueLoc; }
1272d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1273d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1274aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
12751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ContinueLoc);
1276507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
1277861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor
12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ContinueStmtClass;
12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ContinueStmt *) { return true; }
12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12838297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
128463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break.
12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt {
1290507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation BreakLoc;
12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1292507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
12931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1294025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty break statement.
1295025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1296025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1297025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getBreakLoc() const { return BreakLoc; }
1298025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1299025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1300aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(BreakLoc); }
1301b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BreakStmtClass;
13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BreakStmt *) { return true; }
13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13078297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
130863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1312c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression:
1313c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return;
1314c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return 4;
1315c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///
1316c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to
1317c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to
1318c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void.  We explicitly model this in the AST, which means you can't
1319c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument.
13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt {
13221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *RetExpr;
1323507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation RetLoc;
13245077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *NRVOCandidate;
1325ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13275077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL)
132825a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
13295077c3876beeaed32280af88244e8050078619a8Douglas Gregor
13305077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
13315077c3876beeaed32280af88244e8050078619a8Douglas Gregor    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
13325077c3876beeaed32280af88244e8050078619a8Douglas Gregor      NRVOCandidate(NRVOCandidate) {}
13330de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13340de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  /// \brief Build an empty return expression.
13350de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
13360de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getRetValue() const;
13381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getRetValue();
13390de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
13400de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13410de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  SourceLocation getReturnLoc() const { return RetLoc; }
13420de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1343b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13445077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// \brief Retrieve the variable that might be used for the named return
13455077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// value optimization.
13465077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ///
13475077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// The optimization itself can only be performed if the variable is
13485077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// also marked as an NRVO object.
13495077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
13505077c3876beeaed32280af88244e8050078619a8Douglas Gregor  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1351ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1352aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ReturnStmtClass;
13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReturnStmt *) { return true; }
13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
136063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
136163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
136263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range();
136363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
13645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1366728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1367728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier///
1368728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass AsmStmt : public Stmt {
1369728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierprotected:
1370066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation AsmLoc;
137112b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief True if the assembly statement does not have any input or output
137212b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// operands.
1373728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsSimple;
137412b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier
137512b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief If true, treat this inline assembly as having side effects.
137612b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// This assembly statement should not be optimized, deleted or moved.
1377728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsVolatile;
1378728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1379066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumOutputs;
1380066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumInputs;
1381066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumClobbers;
1382066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1383066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  IdentifierInfo **Names;
138419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  Stmt **Exprs;
1385066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1386066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1387066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier          unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1388066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1389066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1390728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1391728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierpublic:
1392728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  /// \brief Build an empty inline-assembly statement.
1393728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
139419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    Stmt(SC, Empty), Names(0), Exprs(0) { }
139529760b452876548f59804e8c02c3276bc7281d5dMatt Beaumont-Gay
1396066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation getAsmLoc() const { return AsmLoc; }
1397066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1398728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1399728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isSimple() const { return IsSimple; }
1400728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setSimple(bool V) { IsSimple = V; }
1401728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1402728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isVolatile() const { return IsVolatile; }
1403728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setVolatile(bool V) { IsVolatile = V; }
1404728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1405728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); }
1406728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1407da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  //===--- Asm String Analysis ---===//
1408da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1409da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1410aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1411da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1412066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Output operands ---===//
1413066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1414066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumOutputs() const { return NumOutputs; }
1415066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1416066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1417066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return Names[i];
1418066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1419066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1420066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  StringRef getOutputName(unsigned i) const {
1421066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    if (IdentifierInfo *II = getOutputIdentifier(i))
1422066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier      return II->getName();
1423066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1424066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return StringRef();
1425066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1426066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1427c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getOutputConstraint - Return the constraint string for the specified
1428c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// output operand.  All output constraints are known to be non-empty (either
1429c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// '=' or '+').
1430aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getOutputConstraint(unsigned i) const;
1431c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1432c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// isOutputPlusConstraint - Return true if the specified output constraint
1433c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is a "+" constraint (which is both an input and an output) or false if it
1434c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is an "=" constraint (just an output).
1435c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  bool isOutputPlusConstraint(unsigned i) const {
1436c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier    return getOutputConstraint(i)[0] == '+';
1437c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  }
1438c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1439aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getOutputExpr(unsigned i) const;
1440c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1441c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getNumPlusOperands - Return the number of output operands that have a "+"
1442c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraint.
1443c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  unsigned getNumPlusOperands() const;
1444c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1445066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Input operands ---===//
1446066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1447066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumInputs() const { return NumInputs; }
1448066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1449066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  IdentifierInfo *getInputIdentifier(unsigned i) const {
1450066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return Names[i + NumOutputs];
1451066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1452066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1453066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  StringRef getInputName(unsigned i) const {
1454066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    if (IdentifierInfo *II = getInputIdentifier(i))
1455066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier      return II->getName();
1456066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1457066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return StringRef();
1458066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1459066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1460c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getInputConstraint - Return the specified input constraint.  Unlike output
1461c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraints, these can be empty.
1462aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getInputConstraint(unsigned i) const;
1463aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier
1464aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getInputExpr(unsigned i) const;
1465c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1466066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Other ---===//
1467066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
14682fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier  unsigned getNumClobbers() const { return NumClobbers; }
1469aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getClobber(unsigned i) const;
14702fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier
1471728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  static bool classof(const Stmt *T) {
1472728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass ||
1473728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier      T->getStmtClass() == MSAsmStmtClass;
1474728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  }
1475728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  static bool classof(const AsmStmt *) { return true; }
147619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Input expr iterators.
147819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator inputs_iterator;
148019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_inputs_iterator;
148119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator begin_inputs() {
148319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
148419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator end_inputs() {
148719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
148819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator begin_inputs() const {
149119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
149219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator end_inputs() const {
149519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
149619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
149719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
149819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Output expr iterators.
149919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
150019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator outputs_iterator;
150119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_outputs_iterator;
150219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
150319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator begin_outputs() {
150419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
150519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
150619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator end_outputs() {
150719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
150819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
150919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
151019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator begin_outputs() const {
151119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
151219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
151319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator end_outputs() const {
151419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
151519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
151619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
151719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  child_range children() {
151819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
151919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
1520728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier};
1521728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
15227d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a GCC inline-assembly statement extension.
1523fe795956194141c91ae555985c9b930595bff43fChris Lattner///
1524728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass GCCAsmStmt : public AsmStmt {
1525066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation RParenLoc;
15266a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  StringLiteral *AsmStr;
1527b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1528966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  // FIXME: If we wanted to, we could allocate all of these in one big array.
1529966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Constraints;
1530966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Clobbers;
1531ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1532fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic:
1533df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
1534df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             bool isvolatile, unsigned numoutputs, unsigned numinputs,
1535df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1536df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral *asmstr, unsigned numclobbers,
1537df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral **clobbers, SourceLocation rparenloc);
1538b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1539cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  /// \brief Build an empty inline-assembly statement.
1540728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
154119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    Constraints(0), Clobbers(0) { }
1542cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1543cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1544cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1545cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1546458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  //===--- Asm String Analysis ---===//
1547458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1548458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  const StringLiteral *getAsmString() const { return AsmStr; }
1549458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  StringLiteral *getAsmString() { return AsmStr; }
1550cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmString(StringLiteral *E) { AsmStr = E; }
1551cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1552458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AsmStringPiece - this is part of a decomposed asm string specification
1553458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// (for use with the AnalyzeAsmString function below).  An asm string is
1554458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// considered to be a concatenation of these parts.
1555458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  class AsmStringPiece {
1556458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1557458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    enum Kind {
1558458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1559458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Operand  // Operand reference, with optional modifier %c4.
1560458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    };
1561458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  private:
1562458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    Kind MyKind;
1563458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    std::string Str;
1564458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned OperandNo;
1565458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1566458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1567458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(unsigned OpNo, char Modifier)
1568458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      : MyKind(Operand), Str(), OperandNo(OpNo) {
1569458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Str += Modifier;
1570458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1572458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isString() const { return MyKind == String; }
1573458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isOperand() const { return MyKind == Operand; }
15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1575458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    const std::string &getString() const {
1576458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isString());
1577458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str;
1578458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1579458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1580458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned getOperandNo() const {
1581458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1582458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return OperandNo;
1583458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1585458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// getModifier - Get the modifier for this operand, if present.  This
1586458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// returns '\0' if there was no modifier.
1587458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    char getModifier() const {
1588458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1589458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str[0];
1590458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1591458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  };
15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1593458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1594458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// it into pieces.  If the asm string is erroneous, emit errors and return
1595458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// true, otherwise return false.  This handles canonicalization and
1596458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1598686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1599fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner                            ASTContext &C, unsigned &DiagOffs) const;
16001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1601da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1602da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1604b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Output operands ---===//
1605b327793860737d1c103a73aeda8057dd628a101dChris Lattner
1606686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputConstraint(unsigned i) const;
16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1608b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1609ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i];
1610ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1611b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1612b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return Constraints[i];
1613b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1615ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getOutputExpr(unsigned i);
16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1617b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getOutputExpr(unsigned i) const {
1618df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1619b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1621b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Input operands ---===//
16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1623686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputConstraint(unsigned i) const;
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1625b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1626ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1627ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1628b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getInputConstraintLiteral(unsigned i) {
1629ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1630ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1632ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getInputExpr(unsigned i);
1633935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner  void setInputExpr(unsigned i, Expr *E);
1634ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1635b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getInputExpr(unsigned i) const {
1636df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1637b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
1638cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1639acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson  void setOutputsAndInputsAndClobbers(ASTContext &C,
1640ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                      IdentifierInfo **Names,
1641fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Constraints,
1642fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      Stmt **Exprs,
1643fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumOutputs,
1644ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      unsigned NumInputs,
1645fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Clobbers,
1646fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumClobbers);
1647cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
164810ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  //===--- Other ---===//
16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
165010ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// getNamedOperand - Given a symbolic operand reference like %[foo],
165110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// translate this into a numeric value needed to reference the same operand.
165210ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// This returns -1 if the operand name is invalid.
1653686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  int getNamedOperand(StringRef SymbolicName) const;
165410ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner
165533f0558f75f70061707d1388e305b8f92f4e55deChad Rosier  StringRef getClobber(unsigned i) const;
16565c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
16575c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  const StringLiteral *getClobberStringLiteral(unsigned i) const {
16585c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier    return Clobbers[i];
16595c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  }
1660cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1661aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1662fe795956194141c91ae555985c9b930595bff43fChris Lattner    return SourceRange(AsmLoc, RParenLoc);
1663fe795956194141c91ae555985c9b930595bff43fChris Lattner  }
16641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1665df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  static bool classof(const Stmt *T) {
1666df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass;
1667df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  }
1668df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  static bool classof(const GCCAsmStmt *) { return true; }
1669fe795956194141c91ae555985c9b930595bff43fChris Lattner};
167078492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek
16717d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a Microsoft inline-assembly statement extension.
16728cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier///
1673728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass MSAsmStmt : public AsmStmt {
16747bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  SourceLocation AsmLoc, LBraceLoc, EndLoc;
16758cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  std::string AsmStr;
16768cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
167779efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned NumAsmToks;
167879efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier
167979efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *AsmToks;
168089fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef *Constraints;
168133c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier  StringRef *Clobbers;
16828cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16838cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic:
16847bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc,
16857bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier            bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
1686058ab170a5b8597f32c3f343a1e9de2cd7b05848Chad Rosier            ArrayRef<IdentifierInfo*> inputs, ArrayRef<IdentifierInfo*> outputs,
1687633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier            ArrayRef<Expr*> inputexprs, ArrayRef<Expr*> outputexprs,
168889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier            StringRef asmstr, ArrayRef<StringRef> constraints,
168989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier            ArrayRef<StringRef> clobbers, SourceLocation endloc);
16908cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1691cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier  /// \brief Build an empty MS-style inline-assembly statement.
1692728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
169389fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { }
1694cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier
16957bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  SourceLocation getLBraceLoc() const { return LBraceLoc; }
16967bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
16978cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceLocation getEndLoc() const { return EndLoc; }
16988cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setEndLoc(SourceLocation L) { EndLoc = L; }
16998cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17007bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  bool hasBraces() const { return LBraceLoc.isValid(); }
17017bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier
170279efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned getNumAsmToks() { return NumAsmToks; }
170379efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *getAsmToks() { return AsmToks; }
17048f726de55412870ef70e788b852c6cc50873e15bChad Rosier
17058cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Asm String Analysis ---===//
17068cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17078cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  const std::string *getAsmString() const { return &AsmStr; }
17088cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  std::string *getAsmString() { return &AsmStr; }
17098cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setAsmString(StringRef &E) { AsmStr = E.str(); }
17108cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1711da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1712da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1713da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
17142603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Output operands ---===//
17152603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
171689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getOutputConstraint(unsigned i) const {
171789fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i];
171889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1719c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1720633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getOutputExpr(unsigned i);
1721633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17222603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getOutputExpr(unsigned i) const {
17232603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
17242603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17252603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17262603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Input operands ---===//
17272603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
172889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getInputConstraint(unsigned i) const {
172989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i + NumOutputs];
173089fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1731c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1732633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getInputExpr(unsigned i);
1733633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  void setInputExpr(unsigned i, Expr *E);
1734633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17352603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getInputExpr(unsigned i) const {
17362603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
17372603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17382603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17398cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Other ---===//
17408cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17411e059da457ba65062448f24975db386efa0d51f8Chad Rosier  StringRef getClobber(unsigned i) const { return Clobbers[i]; }
17424399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier
17438cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceRange getSourceRange() const LLVM_READONLY {
17448cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return SourceRange(AsmLoc, EndLoc);
17458cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17468cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  static bool classof(const Stmt *T) {
17478cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return T->getStmtClass() == MSAsmStmtClass;
17488cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17498cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  static bool classof(const MSAsmStmt *) { return true; }
17508cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17518cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  child_range children() {
17528cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return child_range(&Exprs[0], &Exprs[0]);
17538cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17548cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier};
17558cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
175628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt {
175728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
175828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
175928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
176028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { FILTER_EXPR, BLOCK };
176128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
176228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt(SourceLocation Loc,
176328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Expr *FilterExpr,
176428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Stmt *Block);
176528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
17667110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
17677110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
17687110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
17697110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
177028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
177128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHExceptStmt* Create(ASTContext &C,
177228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation ExceptLoc,
177328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Expr *FilterExpr,
177428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Block);
1775aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
177628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getExceptLoc(), getEndLoc());
177728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
177828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
177928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getExceptLoc() const { return Loc; }
178028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
178128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1782ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getFilterExpr() const {
1783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1784ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1786ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt *getBlock() const {
1787ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return llvm::cast<CompoundStmt>(Children[BLOCK]);
1788ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
178928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
179128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
179228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
179328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
179528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHExceptStmtClass;
179628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
179728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHExceptStmt *) { return true; }
179928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
180128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt {
180328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
180428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Block;
180528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt(SourceLocation Loc,
180728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                 Stmt *Block);
180828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18097110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18107110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18117110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
18127110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
181328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
181428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHFinallyStmt* Create(ASTContext &C,
181528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                SourceLocation FinallyLoc,
181628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                Stmt *Block);
181728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1818aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
181928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getFinallyLoc(), getEndLoc());
182028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
182128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getFinallyLoc() const { return Loc; }
182328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
182428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); }
182628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
182728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
182828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(&Block,&Block+1);
182928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
183028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
183228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHFinallyStmtClass;
183328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
183428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHFinallyStmt *) { return true; }
183628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
183828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt {
184028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool            IsCXXTry;
184128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  TryLoc;
184228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
184328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
184428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { TRY = 0, HANDLER = 1 };
184528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
184628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
184728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             SourceLocation TryLoc,
184828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *TryBlock,
184928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *Handler);
185028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18517110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18527110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18537110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
18547110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
185528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
185628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHTryStmt* Create(ASTContext &C,
185728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            bool isCXXTry,
185828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            SourceLocation TryLoc,
185928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *TryBlock,
186028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *Handler);
186128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1862aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
186328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getTryLoc(), getEndLoc());
186428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
186528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
186628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getTryLoc() const { return TryLoc; }
186728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
186828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
186928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool getIsCXXTry() const { return IsCXXTry; }
1870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1871ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt* getTryBlock() const {
1872ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return llvm::cast<CompoundStmt>(Children[TRY]);
1873ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1874ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
187528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt *getHandler() const { return Children[HANDLER]; }
187628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
187728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Returns 0 if not defined
187828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt  *getExceptHandler() const;
187928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt *getFinallyHandler() const;
188028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
188128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
188228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
188328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
188428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
188528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
188628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHTryStmtClass;
188728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
188828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
188928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(SEHTryStmt *) { return true; }
189028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
1891ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
18935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1895