Stmt.h revision a93d0f280693b8418bc88cf7a8c93325f7fcf4c6
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Stmt interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_STMT_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_STMT_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
172fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/DeclGroup.h"
189caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h"
192fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/IdentifierTable.h"
202fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/LLVM.h"
212fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/SourceLocation.h"
222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "llvm/ADT/ArrayRef.h"
23aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
24a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer#include "llvm/Support/ErrorHandling.h"
256e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string>
267573098b83e780d1c5bea13b384b610d8f155676Steve Naroff
2741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm {
2841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  class FoldingSetNodeID;
2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor}
3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
32e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  class ASTContext;
332fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Attr;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
352fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class Expr;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class IdentifierInfo;
37478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class LabelDecl;
382fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class ParmVarDecl;
39a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class PrinterHelper;
40a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  struct PrintingPolicy;
412fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  class QualType;
420c727a35718556866a978f64ac549d9798735f08Chris Lattner  class SourceManager;
436a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  class StringLiteral;
446c36be5b383875b490684bcf439d6d427298c1afChris Lattner  class SwitchStmt;
45a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer  class Token;
46478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  class VarDecl;
471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
49ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  // ExprIterator - Iterators for iterating over Stmt* arrays that contain
50ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
51ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  //  references to children (to be compatible with StmtIterator).
52ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //===--------------------------------------------------------------------===//
531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Stmt;
55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class Expr;
561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ExprIterator {
58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Stmt** I;
59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator(Stmt** i) : I(i) {}
611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExprIterator() : I(0) {}
62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator& operator++() { ++I; return *this; }
63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator-(size_t i) { return I-i; }
64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ExprIterator operator+(size_t i) { return I+i; }
65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator[](size_t idx);
66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    // FIXME: Verify that this will correctly return a signed distance.
67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ExprIterator& R) const { return I - R.I; }
68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator*() const;
69ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    Expr* operator->() const;
70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ExprIterator& R) const { return I == R.I; }
71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ExprIterator& R) const { return I != R.I; }
72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ExprIterator& R) const { return I > R.I; }
73ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ExprIterator& R) const { return I >= R.I; }
74ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  };
751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  class ConstExprIterator {
771705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    const Stmt * const *I;
78ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  public:
791705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator(const Stmt * const *i) : I(i) {}
801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ConstExprIterator() : I(0) {}
81ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    ConstExprIterator& operator++() { ++I; return *this; }
821705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator+(size_t i) const { return I+i; }
831705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer    ConstExprIterator operator-(size_t i) const { return I-i; }
84ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator[](size_t idx) const;
85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    signed operator-(const ConstExprIterator& R) const { return I - R.I; }
86ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator*() const;
87ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    const Expr * operator->() const;
88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator==(const ConstExprIterator& R) const { return I == R.I; }
89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator!=(const ConstExprIterator& R) const { return I != R.I; }
90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>(const ConstExprIterator& R) const { return I > R.I; }
91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  };
931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
94ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
95ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements.
96ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement.
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt {
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum StmtClass {
103f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor    NoStmtClass = 0,
104f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class,
1057381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \
1069a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
1077381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
1089a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
1097381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT)
1104bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
1118e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Make vanilla 'new' and 'delete' illegal for Stmts.
1148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected:
1158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes) throw() {
116b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
1178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void operator delete(void* data) throw() {
119b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
1208189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class StmtBitfields {
1238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Stmt;
1248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    /// \brief The statement class.
1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned sClass : 8;
1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  enum { NumStmtBits = 8 };
1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CompoundStmtBitfields {
1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CompoundStmt;
1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned NumStmts : 32 - NumStmtBits;
1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class ExprBitfields {
1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class Expr;
1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DeclRefExpr; // computeDependence
1408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class InitListExpr; // ctor
1418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class DesignatedInitExpr; // ctor
142d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor    friend class BlockDeclRefExpr; // ctor
143bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ASTStmtReader; // deserialization
144bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXNewExpr; // ctor
145bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class DependentScopeDeclRefExpr; // ctor
146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXConstructExpr; // ctor
147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CallExpr; // ctor
148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OffsetOfExpr; // ctor
149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ObjCMessageExpr; // ctor
150ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCArrayLiteral; // ctor
151ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    friend class ObjCDictionaryLiteral; // ctor
152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ShuffleVectorExpr; // ctor
153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class ParenListExpr; // ctor
154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXUnresolvedConstructExpr; // ctor
155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class CXXDependentScopeMemberExpr; // ctor
156bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    friend class OverloadExpr; // ctor
1574b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr; // ctor
158dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    friend class AtomicExpr; // ctor
1598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumStmtBits;
1608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueKind : 2;
162f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    unsigned ObjectKind : 2;
1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned TypeDependent : 1;
1648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned ValueDependent : 1;
165561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
166d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  enum { NumExprBits = 16 };
1698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
170bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class CharacterLiteralBitfields {
171bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class CharacterLiteral;
172bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
173bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class FloatingLiteralBitfields {
178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class FloatingLiteral;
179bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
180bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
181bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsIEEE : 1; // Distinguishes between PPC128 and IEEE128.
182bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsExact : 1;
183bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
184bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
185bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  class UnaryExprOrTypeTraitExprBitfields {
186bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    friend class UnaryExprOrTypeTraitExpr;
187bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned : NumExprBits;
188bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
189bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned Kind : 2;
190bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    unsigned IsType : 1; // true if operand is a type, false if an expression.
191bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  };
192bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer
193cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  class DeclRefExprBitfields {
194cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class DeclRefExpr;
195cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    friend class ASTStmtReader; // deserialization
196cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned : NumExprBits;
197cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
198cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    unsigned HasQualifier : 1;
199e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    unsigned HasTemplateKWAndArgsInfo : 1;
2003aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    unsigned HasFoundDecl : 1;
2017cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    unsigned HadMultipleCandidates : 1;
202f4b88a45902af1802a1cb42ba48b1c474474f228John McCall    unsigned RefersToEnclosingLocal : 1;
203cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  };
204cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
2058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  class CastExprBitfields {
2068e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    friend class CastExpr;
2078e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    unsigned : NumExprBits;
2088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2092bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned Kind : 6;
2102bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    unsigned BasePathSize : 32 - 6 - NumExprBits;
2118e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2128e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
213cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  class CallExprBitfields {
214cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    friend class CallExpr;
215cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned : NumExprBits;
216cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
217cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    unsigned NumPreArgs : 1;
218cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  };
219cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
22080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  class ExprWithCleanupsBitfields {
22180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ExprWithCleanups;
22280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    friend class ASTStmtReader; // deserialization
22380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
22480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned : NumExprBits;
22580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
22680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    unsigned NumObjects : 32 - NumExprBits;
22780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  };
22880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
2294b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class PseudoObjectExprBitfields {
2304b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class PseudoObjectExpr;
2314b9c2d235fb9449e249d74f48ecfec601650de93John McCall    friend class ASTStmtReader; // deserialization
2324b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2334b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned : NumExprBits;
2344b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2354b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // These don't need to be particularly wide, because they're
2364b9c2d235fb9449e249d74f48ecfec601650de93John McCall    // strictly limited by the forms of expressions we permit.
2374b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned NumSubExprs : 8;
2384b9c2d235fb9449e249d74f48ecfec601650de93John McCall    unsigned ResultIndex : 32 - 8 - NumExprBits;
2394b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
2404b9c2d235fb9449e249d74f48ecfec601650de93John McCall
241f85e193739c953358c865005855253af4f68a497John McCall  class ObjCIndirectCopyRestoreExprBitfields {
242f85e193739c953358c865005855253af4f68a497John McCall    friend class ObjCIndirectCopyRestoreExpr;
243f85e193739c953358c865005855253af4f68a497John McCall    unsigned : NumExprBits;
244f85e193739c953358c865005855253af4f68a497John McCall
245f85e193739c953358c865005855253af4f68a497John McCall    unsigned ShouldCopy : 1;
246f85e193739c953358c865005855253af4f68a497John McCall  };
247f85e193739c953358c865005855253af4f68a497John McCall
24832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  class InitListExprBitfields {
24932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    friend class InitListExpr;
25032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
25132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned : NumExprBits;
25232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
25332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list originally had a GNU array-range
25432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// designator in it. This is a temporary marker used by CodeGen.
25532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned HadArrayRangeDesignator : 1;
25632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
25732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// Whether this initializer list initializes a std::initializer_list
25832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    /// object.
25932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    unsigned InitializesStdInitializerList : 1;
26032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  };
26132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
2624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  class TypeTraitExprBitfields {
2634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class TypeTraitExpr;
2644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtReader;
2654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    friend class ASTStmtWriter;
2664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned : NumExprBits;
2684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
2704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Kind : 8;
2714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief If this expression is not value-dependent, this indicates whether
2734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// the trait evaluated true or false.
2744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned Value : 1;
2754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    /// \brief The number of arguments to this type trait.
2774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
2784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  };
2794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2808e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  union {
28163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    // FIXME: this is wasteful on 64-bit platforms.
28263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    void *Aligner;
28363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
2848e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBitfields StmtBits;
2858e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBitfields CompoundStmtBits;
2868e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBitfields ExprBits;
287bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    CharacterLiteralBitfields CharacterLiteralBits;
288bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    FloatingLiteralBitfields FloatingLiteralBits;
289bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
290cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    DeclRefExprBitfields DeclRefExprBits;
2918e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBitfields CastExprBits;
292cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    CallExprBitfields CallExprBits;
29380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    ExprWithCleanupsBitfields ExprWithCleanupsBits;
2944b9c2d235fb9449e249d74f48ecfec601650de93John McCall    PseudoObjectExprBitfields PseudoObjectExprBits;
295f85e193739c953358c865005855253af4f68a497John McCall    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
29632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    InitListExprBitfields InitListExprBits;
2974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeTraitExprBitfields TypeTraitExprBits;
2988e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  };
2998e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
300d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  friend class ASTStmtReader;
3014ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
302d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
3038189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic:
3048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  // Only allow allocation of Stmts using the allocator in ASTContext
3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // or by doing a placement new.
3068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext& C,
3072fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer                     unsigned alignment = 8) throw();
3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, ASTContext* C,
3102fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer                     unsigned alignment = 8) throw();
3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void* operator new(size_t bytes, void* mem) throw() {
3138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return mem;
3148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
315e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
316fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext&, unsigned) throw() { }
317fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, ASTContext*, unsigned) throw() { }
318e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor  void operator delete(void*, std::size_t) throw() { }
319fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner  void operator delete(void*, void*) throw() { }
320e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor
321025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic:
322025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief A placeholder type used to construct an empty shell of a
323025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// type, that will be filled in later (e.g., by some
324025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// de-serialization).
325025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  struct EmptyShell { };
326025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
32702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate:
32802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  /// \brief Whether statistic collection is enabled.
32902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static bool StatisticsEnabled;
33002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar
3319c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected:
332025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Construct an empty statement.
3338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  explicit Stmt(StmtClass SC, EmptyShell) {
3348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
33502892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
336025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  }
337025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt(StmtClass SC) {
3408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    StmtBits.sClass = SC;
34102892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar    if (StatisticsEnabled) Stmt::addStmtClass(SC);
3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
344ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  StmtClass getStmtClass() const {
3458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    return static_cast<StmtClass>(StmtBits.sClass);
346b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor  }
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStmtClassName() const;
3481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
349b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// SourceLocation tokens are not useful in isolation - they are low level
350b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// value objects created/interpreted by SourceManager. We assume AST
351b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  /// clients will have a pointer to the respective SourceManager.
352aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
353aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
354aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // global temp stats (until we have a per-module visitor)
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void addStmtClass(const StmtClass s);
35802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar  static void EnableStatistics();
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void PrintStats();
3606000dace22f110d8768476989313e9d981d690d0Chris Lattner
36195f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \brief Dumps the specified AST fragment and all subtrees to
36295f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko  /// \c llvm::errs().
363f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump() const;
364f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
3658cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS, SourceManager &SM) const;
3666000dace22f110d8768476989313e9d981d690d0Chris Lattner
3676000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
3686000dace22f110d8768476989313e9d981d690d0Chris Lattner  /// back to its original source language syntax.
369d1420c6fa788669e49f21e184927c7833881e399Richard Smith  void dumpPretty(ASTContext &Context) const;
3708cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
371e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                   const PrintingPolicy &Policy,
372d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                   unsigned Indentation = 0) const;
3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
374d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
375d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
376d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek  void viewAST() const;
3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3787e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// Skip past any implicit AST nodes which might surround this
3797e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
3807e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  Stmt *IgnoreImplicit();
3817e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
382a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  const Stmt *stripLabelLikeStatements() const;
383a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  Stmt *stripLabelLikeStatements() {
384a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth    return const_cast<Stmt*>(
385a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
386a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth  }
387a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth
388d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
389d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  contain implicit control-flow in the order their subexpressions
390d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  are evaluated.  This predicate returns true if this statement has
391d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  such implicit control-flow.  Such statements are also specially handled
392d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  ///  within CFGs.
393d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek  bool hasImplicitControlFlow() const;
394d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek
39563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// Child Iterators: All subclasses must implement 'children'
39663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// to permit easy iteration over the substatements/subexpessions of an
39763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  /// AST node.  This permits easy iteration over all nodes in the AST.
3989caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef StmtIterator       child_iterator;
3999caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek  typedef ConstStmtIterator  const_child_iterator;
4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef StmtRange          child_range;
40263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  typedef ConstStmtRange     const_child_range;
4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
40563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_range children() const {
40663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return const_cast<Stmt*>(this)->children();
40777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_begin() { return children().first; }
41063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_iterator child_end() { return children().second; }
41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
41263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_begin() const { return children().first; }
41363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  const_child_iterator child_end() const { return children().second; }
41441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor
41541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// \brief Produce a unique representation of the given statement.
41641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
41770517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param ID once the profiling operation is complete, will contain
41841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// the unique representation of the given statement.
41941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42070517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Context the AST context in which the statement resides
42141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  ///
42270517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param Canonical whether the profile should be based on the canonical
42341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// representation of this statement (e.g., where non-type template
4241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// parameters are identified by index/level rather than their
42541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// declaration pointers) or the exact representation of the statement as
42641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  /// written in the source.
4274ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
428b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth               bool Canonical) const;
4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions
4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration.
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt {
4379653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor  DeclGroupRef DG;
43881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation StartLoc, EndLoc;
4391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
4428ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
4438ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek                                    StartLoc(startLoc), EndLoc(endLoc) {}
4441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  /// \brief Build an empty declaration statement.
44684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
44784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
4487e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  /// isSingleDecl - This method returns true if this DeclStmt refers
449fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner  /// to a single Decl.
4507e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  bool isSingleDecl() const {
451fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner    return DG.isSingleDecl();
4528ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  }
4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4547e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Decl *getSingleDecl() { return DG.getSingleDecl(); }
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
457e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  const DeclGroupRef getDeclGroup() const { return DG; }
458e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner  DeclGroupRef getDeclGroup() { return DG; }
45984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
460b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
46181c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
46284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setStartLoc(SourceLocation L) { StartLoc = L; }
46381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
46484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor  void setEndLoc(SourceLocation L) { EndLoc = L; }
46584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor
466aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
46781c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner    return SourceRange(StartLoc, EndLoc);
46881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  }
4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DeclStmtClass;
4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47414f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek  // Iterators over subexpressions.
47563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
47663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(child_iterator(DG.begin(), DG.end()),
47763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       child_iterator(DG.end(), DG.end()));
47863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4800632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::iterator decl_iterator;
4810632dd6fe068011af5710c0d6a745724021ff620Chris Lattner  typedef DeclGroupRef::const_iterator const_decl_iterator;
4821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4838ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_begin() { return DG.begin(); }
4848ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  decl_iterator decl_end() { return DG.end(); }
4858ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_begin() const { return DG.begin(); }
4868ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek  const_decl_iterator decl_end() const { return DG.end(); }
487fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose
488fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
489fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rbegin() {
490fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_end());
491fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
492fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  reverse_decl_iterator decl_rend() {
493fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose    return reverse_decl_iterator(decl_begin());
494fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose  }
4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3.
4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt {
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation SemiLoc;
50144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
502e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  /// \brief True if the null statement was preceded by an empty macro, e.g:
50344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @code
50444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   #define CALL(x)
50544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  ///   CALL(0);
50644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  /// @endcode
507e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool HasLeadingEmptyMacro;
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
509e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
510e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis    : Stmt(NullStmtClass), SemiLoc(L),
511e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
513025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty null statement.
514e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
515e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis      HasLeadingEmptyMacro(false) { }
516025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getSemiLoc() const { return SemiLoc; }
518025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
519b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
520e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
52144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
522aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(SemiLoc); }
5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == NullStmtClass;
5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
52944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis
53044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtReader;
53144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis  friend class ASTStmtWriter;
5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }.
5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt {
5378189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  Stmt** Body;
538b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation LBracLoc, RBracLoc;
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5403a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts,
5413a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer               SourceLocation LB, SourceLocation RB);
5423a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer
5433a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  // \brief Build an empty compound statment with a location.
5443a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer  explicit CompoundStmt(SourceLocation Loc)
5453a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) {
5463a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer    CompoundStmtBits.NumStmts = 0;
5471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
548025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
549025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  // \brief Build an empty compound statement.
550025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CompoundStmt(EmptyShell Empty)
5518e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    : Stmt(CompoundStmtClass, Empty), Body(0) {
5528e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CompoundStmtBits.NumStmts = 0;
5538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
554025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
555025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
5588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned size() const { return CompoundStmtBits.NumStmts; }
559025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
5608189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt** body_iterator;
5618189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  body_iterator body_begin() { return Body; }
5628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  body_iterator body_end() { return Body + size(); }
5638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
564ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setLastStmt(Stmt *S) {
5668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    assert(!body_empty() && "setLastStmt");
5678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Body[size()-1] = S;
5688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5708189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef Stmt* const * const_body_iterator;
5718189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_body_iterator body_begin() const { return Body; }
5728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const_body_iterator body_end() const { return Body + size(); }
5738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
5748189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek
5758189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
5768189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rbegin() {
5778189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_end());
5788189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5798189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  reverse_body_iterator body_rend() {
5808189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return reverse_body_iterator(body_begin());
5818189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5824ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5838189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  typedef std::reverse_iterator<const_body_iterator>
5848189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek          const_reverse_body_iterator;
5854ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek
5868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rbegin() const {
5878189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_end());
5888189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5908189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  const_reverse_body_iterator body_rend() const {
5918189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    return const_reverse_body_iterator(body_begin());
5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
594aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
5951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(LBracLoc, RBracLoc);
596b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
5971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
598cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getLBracLoc() const { return LBracLoc; }
599025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
600cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek  SourceLocation getRBracLoc() const { return RBracLoc; }
601025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
6021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundStmtClass;
6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6078297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
60863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
60963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
61063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
611ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6128ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  const_child_range children() const {
6138ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
6148ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek  }
6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
617c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt,
618c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt {
619103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected:
620c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // A pointer to the following CaseStmt or DefaultStmt class,
621c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // used by SwitchStmt.
622c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *NextSwitchCase;
623103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek
624d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
626c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic:
627c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
628c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
629c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
630c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
631c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
632d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek
63363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  Stmt *getSubStmt();
634702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  const Stmt *getSubStmt() const {
635702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner    return const_cast<SwitchCase*>(this)->getSubStmt();
636702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner  }
637b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
638aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); }
6391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass ||
64263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall           T->getStmtClass() == DefaultStmtClass;
643c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
644c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson};
645c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
646c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase {
6470a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor  enum { LHS, RHS, SUBSTMT, END_EXPR };
6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
649d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek                             // GNU "case 1 ... 4" extension
650b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation CaseLoc;
651dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation EllipsisLoc;
652dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
654dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation ellipsisLoc, SourceLocation colonLoc)
656d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    : SwitchCase(CaseStmtClass) {
65724e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner    SubExprs[SUBSTMT] = 0;
658d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
659d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
660b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    CaseLoc = caseLoc;
661dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    EllipsisLoc = ellipsisLoc;
662dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc = colonLoc;
663d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  }
664025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
665025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty switch case statement.
666025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { }
667025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
668764a7ce5217f9569e100a3445f47496ee82daf86Chris Lattner  SourceLocation getCaseLoc() const { return CaseLoc; }
669025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCaseLoc(SourceLocation L) { CaseLoc = L; }
670dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
671dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
672dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
673dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
674025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
675d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
676d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
677d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
678025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
6791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getLHS() const {
6801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
68151b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
6821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const {
6831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
68451b09f2c528c8460b5465c676173324e44176d62Devang Patel  }
68551b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
68720dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
68820dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
68920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
692aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
6933fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    // Handle deeply nested case statements with iteration instead of recursion.
6943fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner    const CaseStmt *CS = this;
69591ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
6963fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner      CS = CS2;
6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
699b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CaseStmtClass;
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
704d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
70563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
70663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
70763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
710c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase {
711d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt* SubStmt;
7126c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation DefaultLoc;
713dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation ColonLoc;
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
716dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL),
717dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor    ColonLoc(CL) {}
718025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
719025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty default statement.
720025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { }
721025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
722d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  Stmt *getSubStmt() { return SubStmt; }
72351b09f2c528c8460b5465c676173324e44176d62Devang Patel  const Stmt *getSubStmt() const { return SubStmt; }
724025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSubStmt(Stmt *S) { SubStmt = S; }
725025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
7266c36be5b383875b490684bcf439d6d427298c1afChris Lattner  SourceLocation getDefaultLoc() const { return DefaultLoc; }
727025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setDefaultLoc(SourceLocation L) { DefaultLoc = L; }
728dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
729dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
731aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DefaultLoc, SubStmt->getLocEnd());
733b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DefaultStmtClass;
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
738d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek  // Iterators
73963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
742ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
743ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement.  For example:
744ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///    foo: return;
745ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner///
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt {
747ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *TheDecl;
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *SubStmt;
749b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IdentLoc;
7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
751ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
752ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
7538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
7541de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
7551de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  // \brief Build an empty label statement.
7561de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getIdentLoc() const { return IdentLoc; }
759ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getDecl() const { return TheDecl; }
760ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setDecl(LabelDecl *D) { TheDecl = D; }
7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *getSubStmt() { return SubStmt; }
7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Stmt *getSubStmt() const { return SubStmt; }
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setSubStmt(Stmt *SS) { SubStmt = SS; }
766b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
767aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(IdentLoc, SubStmt->getLocEnd());
7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
77063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
77163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == LabelStmtClass;
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
778534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement.
779534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
780534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example:
781534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///   [[omp::for(...)]] for (...) { ... }
782534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith///
783534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt {
784534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *SubStmt;
785534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation AttrLoc;
7864990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  unsigned NumAttrs;
7874990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  const Attr *Attrs[1];
788534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
789534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  friend class ASTStmtReader;
790534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
7914990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
7924990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
7934990890fc9428f98bef90ba349203a648c592778Alexander Kornienko      NumAttrs(Attrs.size()) {
7944990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*));
795534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
796534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
7974990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
7984990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
7994990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    memset(Attrs, 0, NumAttrs * sizeof(Attr*));
800534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
801534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8024990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic:
8034990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *Create(ASTContext &C, SourceLocation Loc,
8044990890fc9428f98bef90ba349203a648c592778Alexander Kornienko                                ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
8054990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  // \brief Build an empty attributed statement.
8064990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs);
8074990890fc9428f98bef90ba349203a648c592778Alexander Kornienko
808534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceLocation getAttrLoc() const { return AttrLoc; }
8094990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  ArrayRef<const Attr*> getAttrs() const {
8104990890fc9428f98bef90ba349203a648c592778Alexander Kornienko    return ArrayRef<const Attr*>(Attrs, NumAttrs);
8114990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  }
812534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  Stmt *getSubStmt() { return SubStmt; }
813534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  const Stmt *getSubStmt() const { return SubStmt; }
814534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
815534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  SourceRange getSourceRange() const LLVM_READONLY {
816534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return SourceRange(AttrLoc, SubStmt->getLocEnd());
817534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
818534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
819534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
820534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  static bool classof(const Stmt *T) {
821534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return T->getStmtClass() == AttributedStmtClass;
822534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
823534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith};
824534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
825534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else.
8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt {
82943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, THEN, ELSE, END_EXPR };
8308297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
8318cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor
832b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation IfLoc;
833d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation ElseLoc;
834ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
836ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
83744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
838ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
839025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty if/then/else statement
840025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
841025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
8428cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \brief Retrieve the variable declared in this "if" statement, if any.
8438cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///
8448cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// In the following example, "x" is the condition variable.
8458cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \code
8468cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// if (int x = foo()) {
8478cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  ///   printf("x is %d", x);
8488cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// }
8498cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  /// \endcode
85043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
85143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
852ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
853d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this IfStmt has a condition variable, return the faux DeclStmt
854d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
855d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
856d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
857d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
858ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
860025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
8618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getThen() const { return SubExprs[THEN]; }
8621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setThen(Stmt *S) { SubExprs[THEN] = S; }
8638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getElse() const { return SubExprs[ELSE]; }
864025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8668297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
8678297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getThen() { return SubExprs[THEN]; }
8688297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getElse() { return SubExprs[ELSE]; }
869b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
870025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getIfLoc() const { return IfLoc; }
871025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setIfLoc(SourceLocation L) { IfLoc = L; }
872d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  SourceLocation getElseLoc() const { return ElseLoc; }
873d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor  void setElseLoc(SourceLocation L) { ElseLoc = L; }
874025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
875aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
876b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    if (SubExprs[ELSE])
877b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
878b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff    else
879b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff      return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
880b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
88263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators over subexpressions.  The iterators will include iterating
88363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // over the initialization expression referenced by the condition variable.
88463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
88563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
88663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
88763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IfStmtClass;
8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt.
8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt {
89643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
8971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
898c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  // This points to a linked list of case and default statements.
899c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *FirstCase;
9009dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  SourceLocation SwitchLoc;
9011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
902559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// If the SwitchStmt is a switch on an enum value, this records whether
903559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// all the enum values were covered by CaseStmts.  This value is meant to
904559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// be a hint for possible clients.
905559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  unsigned AllEnumCasesCovered : 1;
906559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
90843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
910025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build a empty switch statement.
911025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
912025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
913d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \brief Retrieve the variable declared in this "switch" statement, if any.
914d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///
915d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// In the following example, "x" is the condition variable.
916d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \code
917d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// switch (int x = foo()) {
918d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   case 0: break;
919d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  ///   // ...
920d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// }
921d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  /// \endcode
92243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
92343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
924ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
925d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
926d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
927d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
928d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
929d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
930d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor
9318297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
9328297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
933c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
934c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9358297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
936025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
9378297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
938025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
939c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  SwitchCase *getSwitchCaseList() { return FirstCase; }
9401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
94143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Set the case list for this switch statement.
94243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
94343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// The caller is responsible for incrementing the retain counts on
94443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// all of the SwitchCase statements in this list.
945025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
946025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
947025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getSwitchLoc() const { return SwitchLoc; }
948025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
949c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson
9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setBody(Stmt *S, SourceLocation SL) {
9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[BODY] = S;
9529dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff    SwitchLoc = SL;
9531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
954c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  void addSwitchCase(SwitchCase *SC) {
955ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!SC->getNextSwitchCase()
956ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           && "case/default already added to a switch");
957c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor    SC->setNextSwitchCase(FirstCase);
958c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson    FirstCase = SC;
959c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson  }
960559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
961559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
962559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// switch over an enum value then all cases have been explicitly covered.
963559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  void setAllEnumCasesCovered() {
964559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    AllEnumCasesCovered = 1;
965559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
966559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
967559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
968559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  /// have been explicitly covered.
969559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  bool isAllEnumCasesCovered() const {
970559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek    return (bool) AllEnumCasesCovered;
971559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek  }
972559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek
973aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
9759dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff  }
97663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  // Iterators
97763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
97863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
97963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
98063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SwitchStmtClass;
9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt.
9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt {
99043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { VAR, COND, BODY, END_EXPR };
9918297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
992b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation WhileLoc;
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
994ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
99543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor            SourceLocation WL);
9961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
997d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty while statement.
998d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
999d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
10005656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \brief Retrieve the variable declared in this "while" statement, if any.
10015656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///
10025656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// In the following example, "x" is the condition variable.
10035656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \code
10045656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// while (int x = random()) {
10055656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  ///   // ...
10065656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// }
10075656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  /// \endcode
100843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
100943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
10105656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
1011d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1012d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1013d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1014d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1015d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1016d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
10178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10188297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1019d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10218297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1022d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1023d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1024d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
1025d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1026b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1027aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
1029b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == WhileStmtClass;
10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10348297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
103563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
103663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
103763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt.
10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt {
1043c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor  enum { BODY, COND, END_EXPR };
10448297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR];
1045b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation DoLoc;
10469f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation WhileLoc;
1047989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
10489f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor
10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1050989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1051989135901c750af61ef012b6b0a0368be415bc46Chris Lattner         SourceLocation RP)
1052989135901c750af61ef012b6b0a0368be415bc46Chris Lattner    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
10538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
10548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek    SubExprs[BODY] = body;
10551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
105667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
105767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty do-while statement.
105867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
10591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
10618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
106267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
10638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Stmt *getBody() const { return SubExprs[BODY]; }
106567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
106667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
106767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getDoLoc() const { return DoLoc; }
106867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setDoLoc(SourceLocation L) { DoLoc = L; }
10699f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  SourceLocation getWhileLoc() const { return WhileLoc; }
10709f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1071b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1072989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
1073989135901c750af61ef012b6b0a0368be415bc46Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1074989135901c750af61ef012b6b0a0368be415bc46Chris Lattner
1075aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(DoLoc, RParenLoc);
1077b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DoStmtClass;
10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
10828297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
108363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
108463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
108563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not
10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source.
10925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt {
109443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
10958297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1096b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  SourceLocation ForLoc;
10975831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation LParenLoc, RParenLoc;
10985831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor
10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1100ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
110143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
110367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  /// \brief Build an empty for statement.
110467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
110567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
11068297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getInit() { return SubExprs[INIT]; }
1107ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
110899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \brief Retrieve the variable declared in this "for" statement, if any.
110999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///
111099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// In the following example, "y" is the condition variable.
111199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \code
111299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// for (int x = random(); int y = mangle(x); ++x) {
111399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  ///   // ...
111499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// }
111599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  /// \endcode
111643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  VarDecl *getConditionVariable() const;
111743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor  void setConditionVariable(ASTContext &C, VarDecl *V);
1118ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1119d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// If this ForStmt has a condition variable, return the faux DeclStmt
1120d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  /// associated with the creation of that condition variable.
1121d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  const DeclStmt *getConditionVariableDeclStmt() const {
1122d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1123d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek  }
1124d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek
11258297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
11268297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11278297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  Stmt *getBody() { return SubExprs[BODY]; }
11288297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek
11298297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getInit() const { return SubExprs[INIT]; }
11308297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
11318297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
11328297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  const Stmt *getBody() const { return SubExprs[BODY]; }
1133b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
113467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInit(Stmt *S) { SubExprs[INIT] = S; }
113567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
113667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
113767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setBody(Stmt *S) { SubExprs[BODY] = S; }
113867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
113967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  SourceLocation getForLoc() const { return ForLoc; }
114067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor  void setForLoc(SourceLocation L) { ForLoc = L; }
11415831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
11425831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
11435831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11445831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
114567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor
1146aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
11471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
1148b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff  }
11491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ForStmtClass;
11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
115463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
115563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
115663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto.
11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt {
1162ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
1163507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation GotoLoc;
116461f62165220e75694fe333179c78815e2e48d71fTed Kremenek  SourceLocation LabelLoc;
11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1166ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
116761f62165220e75694fe333179c78815e2e48d71fTed Kremenek    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11691de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Build an empty goto statement.
11701de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
11711de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1172ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
1173ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *D) { Label = D; }
11741de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
11751de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getGotoLoc() const { return GotoLoc; }
11761de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
11771de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
11781de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1179b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
1180aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(GotoLoc, LabelLoc);
1182507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
11831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GotoStmtClass;
11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11878297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
118863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
11895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto.
11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt {
1194ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation GotoLoc;
11955f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation StarLoc;
11961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Target;
11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
11995f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor                   Expr *target)
12005f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
12015f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor      Target((Stmt*)target) {}
12027d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
12037d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty indirect goto statement.
12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IndirectGotoStmt(EmptyShell Empty)
12057d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Stmt(IndirectGotoStmtClass, Empty) { }
12061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1207ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1208ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  SourceLocation getGotoLoc() const { return GotoLoc; }
12095f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  void setStarLoc(SourceLocation L) { StarLoc = L; }
12105f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor  SourceLocation getStarLoc() const { return StarLoc; }
12111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
121295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
121395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
12147d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1215b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
121695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// getConstantTarget - Returns the fixed target of this indirect
121795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  /// goto, if one exists.
1218ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getConstantTarget();
1219ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  const LabelDecl *getConstantTarget() const {
122095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
122195c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall  }
122295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall
1223aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1224ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner    return SourceRange(GotoLoc, Target->getLocEnd());
1225ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner  }
12261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IndirectGotoStmtClass;
12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12318297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
123263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Target, &Target+1); }
12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue.
12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt {
1239507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation ContinueLoc;
12405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1241507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1243d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  /// \brief Build an empty continue statement.
1244d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1245d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1246d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  SourceLocation getContinueLoc() const { return ContinueLoc; }
1247d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1248d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor
1249aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(ContinueLoc);
1251507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  }
1252861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor
12531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ContinueStmtClass;
12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
125863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break.
12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt {
1264507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation BreakLoc;
12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1266507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1268025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Build an empty break statement.
1269025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1270025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1271025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SourceLocation getBreakLoc() const { return BreakLoc; }
1272025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1273025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1274aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(BreakLoc); }
1275b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
12761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BreakStmtClass;
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12808297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
128163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1285c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression:
1286c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return;
1287c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///   return 4;
1288c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner///
1289c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to
1290c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to
1291c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void.  We explicitly model this in the AST, which means you can't
1292c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument.
12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt {
12951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *RetExpr;
1296507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff  SourceLocation RetLoc;
12975077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *NRVOCandidate;
1298ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13005077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL)
130125a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
13025077c3876beeaed32280af88244e8050078619a8Douglas Gregor
13035077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
13045077c3876beeaed32280af88244e8050078619a8Douglas Gregor    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
13055077c3876beeaed32280af88244e8050078619a8Douglas Gregor      NRVOCandidate(NRVOCandidate) {}
13060de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13070de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  /// \brief Build an empty return expression.
13080de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
13090de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getRetValue() const;
13111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getRetValue();
13120de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
13130de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor
13140de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  SourceLocation getReturnLoc() const { return RetLoc; }
13150de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1316b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff
13175077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// \brief Retrieve the variable that might be used for the named return
13185077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// value optimization.
13195077c3876beeaed32280af88244e8050078619a8Douglas Gregor  ///
13205077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// The optimization itself can only be performed if the variable is
13215077c3876beeaed32280af88244e8050078619a8Douglas Gregor  /// also marked as an NRVO object.
13225077c3876beeaed32280af88244e8050078619a8Douglas Gregor  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
13235077c3876beeaed32280af88244e8050078619a8Douglas Gregor  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1324ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1325aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
13261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ReturnStmtClass;
13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13318297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek  // Iterators
133263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
133363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
133463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range();
133563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
13365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1338728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1339728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier///
1340728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass AsmStmt : public Stmt {
1341728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierprotected:
1342066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation AsmLoc;
134312b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief True if the assembly statement does not have any input or output
134412b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// operands.
1345728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsSimple;
134612b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier
134712b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// \brief If true, treat this inline assembly as having side effects.
134812b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier  /// This assembly statement should not be optimized, deleted or moved.
1349728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool IsVolatile;
1350728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1351066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumOutputs;
1352066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumInputs;
1353066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned NumClobbers;
1354066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1355066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  IdentifierInfo **Names;
135619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  Stmt **Exprs;
1357066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1358066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1359066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier          unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1360066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1361066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1362728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1363728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierpublic:
1364728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  /// \brief Build an empty inline-assembly statement.
1365728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
136619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    Stmt(SC, Empty), Names(0), Exprs(0) { }
136729760b452876548f59804e8c02c3276bc7281d5dMatt Beaumont-Gay
1368066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation getAsmLoc() const { return AsmLoc; }
1369066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1370728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1371728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isSimple() const { return IsSimple; }
1372728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setSimple(bool V) { IsSimple = V; }
1373728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1374728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  bool isVolatile() const { return IsVolatile; }
1375728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  void setVolatile(bool V) { IsVolatile = V; }
1376728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1377728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); }
1378728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
1379da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  //===--- Asm String Analysis ---===//
1380da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1381da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1382aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1383da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
1384066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Output operands ---===//
1385066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1386066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumOutputs() const { return NumOutputs; }
1387066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1388066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1389066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return Names[i];
1390066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1391066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1392066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  StringRef getOutputName(unsigned i) const {
1393066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    if (IdentifierInfo *II = getOutputIdentifier(i))
1394066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier      return II->getName();
1395066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1396066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return StringRef();
1397066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1398066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1399c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getOutputConstraint - Return the constraint string for the specified
1400c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// output operand.  All output constraints are known to be non-empty (either
1401c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// '=' or '+').
1402aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getOutputConstraint(unsigned i) const;
1403c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1404c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// isOutputPlusConstraint - Return true if the specified output constraint
1405c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is a "+" constraint (which is both an input and an output) or false if it
1406c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// is an "=" constraint (just an output).
1407c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  bool isOutputPlusConstraint(unsigned i) const {
1408c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier    return getOutputConstraint(i)[0] == '+';
1409c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  }
1410c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1411aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getOutputExpr(unsigned i) const;
1412c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1413c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getNumPlusOperands - Return the number of output operands that have a "+"
1414c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraint.
1415c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  unsigned getNumPlusOperands() const;
1416c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1417066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Input operands ---===//
1418066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1419066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  unsigned getNumInputs() const { return NumInputs; }
1420066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1421066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  IdentifierInfo *getInputIdentifier(unsigned i) const {
1422066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return Names[i + NumOutputs];
1423066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1424066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1425066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  StringRef getInputName(unsigned i) const {
1426066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    if (IdentifierInfo *II = getInputIdentifier(i))
1427066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier      return II->getName();
1428066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1429066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier    return StringRef();
1430066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  }
1431066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
1432c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// getInputConstraint - Return the specified input constraint.  Unlike output
1433c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier  /// constraints, these can be empty.
1434aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getInputConstraint(unsigned i) const;
1435aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier
1436aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  const Expr *getInputExpr(unsigned i) const;
1437c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1438066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  //===--- Other ---===//
1439066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier
14402fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier  unsigned getNumClobbers() const { return NumClobbers; }
1441aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier  StringRef getClobber(unsigned i) const;
14422fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier
1443728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  static bool classof(const Stmt *T) {
1444728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass ||
1445728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier      T->getStmtClass() == MSAsmStmtClass;
1446728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  }
144719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
144819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Input expr iterators.
144919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
145019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator inputs_iterator;
145119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_inputs_iterator;
145219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
145319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator begin_inputs() {
145419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
145519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
145619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
145719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  inputs_iterator end_inputs() {
145819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
145919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
146019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
146119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator begin_inputs() const {
146219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
146319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
146419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
146519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_inputs_iterator end_inputs() const {
146619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs + NumInputs;
146719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
146819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
146919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  // Output expr iterators.
147019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ExprIterator outputs_iterator;
147219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  typedef ConstExprIterator const_outputs_iterator;
147319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
147419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator begin_outputs() {
147519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
147619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
147719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  outputs_iterator end_outputs() {
147819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
147919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator begin_outputs() const {
148219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0];
148319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  const_outputs_iterator end_outputs() const {
148519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return &Exprs[0] + NumOutputs;
148619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
148719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier
148819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  child_range children() {
148919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
149019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier  }
1491728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier};
1492728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier
14937d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a GCC inline-assembly statement extension.
1494fe795956194141c91ae555985c9b930595bff43fChris Lattner///
1495728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass GCCAsmStmt : public AsmStmt {
1496066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier  SourceLocation RParenLoc;
14976a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson  StringLiteral *AsmStr;
1498b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1499966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  // FIXME: If we wanted to, we could allocate all of these in one big array.
1500966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Constraints;
1501966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson  StringLiteral **Clobbers;
1502ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1503fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic:
1504df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
1505df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             bool isvolatile, unsigned numoutputs, unsigned numinputs,
1506df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1507df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral *asmstr, unsigned numclobbers,
1508df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier             StringLiteral **clobbers, SourceLocation rparenloc);
1509b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
1510cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  /// \brief Build an empty inline-assembly statement.
1511728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
151219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier    Constraints(0), Clobbers(0) { }
1513cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1514cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1515cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1516cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1517458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  //===--- Asm String Analysis ---===//
1518458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1519458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  const StringLiteral *getAsmString() const { return AsmStr; }
1520458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  StringLiteral *getAsmString() { return AsmStr; }
1521cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor  void setAsmString(StringLiteral *E) { AsmStr = E; }
1522cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1523458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AsmStringPiece - this is part of a decomposed asm string specification
1524458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// (for use with the AnalyzeAsmString function below).  An asm string is
1525458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// considered to be a concatenation of these parts.
1526458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  class AsmStringPiece {
1527458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1528458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    enum Kind {
1529458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1530458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Operand  // Operand reference, with optional modifier %c4.
1531458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    };
1532458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  private:
1533458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    Kind MyKind;
1534458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    std::string Str;
1535458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned OperandNo;
1536458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  public:
1537458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1538458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    AsmStringPiece(unsigned OpNo, char Modifier)
1539458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      : MyKind(Operand), Str(), OperandNo(OpNo) {
1540458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      Str += Modifier;
1541458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1543458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isString() const { return MyKind == String; }
1544458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    bool isOperand() const { return MyKind == Operand; }
15451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1546458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    const std::string &getString() const {
1547458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isString());
1548458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str;
1549458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1550458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner
1551458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    unsigned getOperandNo() const {
1552458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1553458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return OperandNo;
1554458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
15551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1556458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// getModifier - Get the modifier for this operand, if present.  This
1557458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    /// returns '\0' if there was no modifier.
1558458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    char getModifier() const {
1559458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      assert(isOperand());
1560458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner      return Str[0];
1561458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner    }
1562458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  };
15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1564458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1565458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// it into pieces.  If the asm string is erroneous, emit errors and return
1566458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// true, otherwise return false.  This handles canonicalization and
1567458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1569686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1570fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner                            ASTContext &C, unsigned &DiagOffs) const;
15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1572da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1573da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1575b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Output operands ---===//
1576b327793860737d1c103a73aeda8057dd628a101dChris Lattner
1577686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getOutputConstraint(unsigned i) const;
15781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1579b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1580ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i];
1581ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1582b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1583b327793860737d1c103a73aeda8057dd628a101dChris Lattner    return Constraints[i];
1584b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1586ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getOutputExpr(unsigned i);
15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1588b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getOutputExpr(unsigned i) const {
1589df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1590b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
15911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1592b327793860737d1c103a73aeda8057dd628a101dChris Lattner  //===--- Input operands ---===//
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1594686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getInputConstraint(unsigned i) const;
15951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1596b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1597ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1598ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
1599b327793860737d1c103a73aeda8057dd628a101dChris Lattner  StringLiteral *getInputConstraintLiteral(unsigned i) {
1600ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek    return Constraints[i + NumOutputs];
1601ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  }
16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1603ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  Expr *getInputExpr(unsigned i);
1604935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner  void setInputExpr(unsigned i, Expr *E);
1605ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1606b327793860737d1c103a73aeda8057dd628a101dChris Lattner  const Expr *getInputExpr(unsigned i) const {
1607df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1608b327793860737d1c103a73aeda8057dd628a101dChris Lattner  }
1609cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1610acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson  void setOutputsAndInputsAndClobbers(ASTContext &C,
1611ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                      IdentifierInfo **Names,
1612fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Constraints,
1613fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      Stmt **Exprs,
1614fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumOutputs,
1615ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      unsigned NumInputs,
1616fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      StringLiteral **Clobbers,
1617fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson                                      unsigned NumClobbers);
1618cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
161910ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  //===--- Other ---===//
16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
162110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// getNamedOperand - Given a symbolic operand reference like %[foo],
162210ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// translate this into a numeric value needed to reference the same operand.
162310ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner  /// This returns -1 if the operand name is invalid.
1624686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  int getNamedOperand(StringRef SymbolicName) const;
162510ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner
162633f0558f75f70061707d1388e305b8f92f4e55deChad Rosier  StringRef getClobber(unsigned i) const;
16275c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
16285c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  const StringLiteral *getClobberStringLiteral(unsigned i) const {
16295c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier    return Clobbers[i];
16305c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier  }
1631cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor
1632aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1633fe795956194141c91ae555985c9b930595bff43fChris Lattner    return SourceRange(AsmLoc, RParenLoc);
1634fe795956194141c91ae555985c9b930595bff43fChris Lattner  }
16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1636df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  static bool classof(const Stmt *T) {
1637df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return T->getStmtClass() == GCCAsmStmtClass;
1638df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  }
1639fe795956194141c91ae555985c9b930595bff43fChris Lattner};
164078492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek
16417d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a Microsoft inline-assembly statement extension.
16428cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier///
1643728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass MSAsmStmt : public AsmStmt {
16447bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  SourceLocation AsmLoc, LBraceLoc, EndLoc;
16458cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  std::string AsmStr;
16468cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
164779efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned NumAsmToks;
164879efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier
164979efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *AsmToks;
165089fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef *Constraints;
165133c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier  StringRef *Clobbers;
16528cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16538cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic:
16547bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc,
16557bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier            bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
1656e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            unsigned numoutputs, unsigned numinputs,
1657e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            ArrayRef<IdentifierInfo*> names, ArrayRef<StringRef> constraints,
1658e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier            ArrayRef<Expr*> exprs, StringRef asmstr,
165989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier            ArrayRef<StringRef> clobbers, SourceLocation endloc);
16608cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1661cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier  /// \brief Build an empty MS-style inline-assembly statement.
1662728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
166389fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { }
1664cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier
16657bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  SourceLocation getLBraceLoc() const { return LBraceLoc; }
16667bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
16678cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceLocation getEndLoc() const { return EndLoc; }
16688cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setEndLoc(SourceLocation L) { EndLoc = L; }
16698cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16707bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  bool hasBraces() const { return LBraceLoc.isValid(); }
16717bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier
167279efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  unsigned getNumAsmToks() { return NumAsmToks; }
167379efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  Token *getAsmToks() { return AsmToks; }
16748f726de55412870ef70e788b852c6cc50873e15bChad Rosier
16758cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Asm String Analysis ---===//
16768cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
16778cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  const std::string *getAsmString() const { return &AsmStr; }
16788cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  std::string *getAsmString() { return &AsmStr; }
16798cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  void setAsmString(StringRef &E) { AsmStr = E.str(); }
16808cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1681da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  /// Assemble final IR asm string.
1682da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier  std::string generateAsmString(ASTContext &C) const;
1683da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier
16842603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Output operands ---===//
16852603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
168689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getOutputConstraint(unsigned i) const {
168789fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i];
168889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1689c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1690633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getOutputExpr(unsigned i);
1691633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
16922603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getOutputExpr(unsigned i) const {
16932603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
16942603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
16952603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
16962603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  //===--- Input operands ---===//
16972603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
169889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  StringRef getInputConstraint(unsigned i) const {
169989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier    return Constraints[i + NumOutputs];
170089fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier  }
1701c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier
1702633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  Expr *getInputExpr(unsigned i);
1703633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier  void setInputExpr(unsigned i, Expr *E);
1704633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier
17052603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  const Expr *getInputExpr(unsigned i) const {
17062603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
17072603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier  }
17082603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier
17098cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  //===--- Other ---===//
17108cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17111e059da457ba65062448f24975db386efa0d51f8Chad Rosier  StringRef getClobber(unsigned i) const { return Clobbers[i]; }
17124399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier
17138cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  SourceRange getSourceRange() const LLVM_READONLY {
17148cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return SourceRange(AsmLoc, EndLoc);
17158cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17168cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  static bool classof(const Stmt *T) {
17178cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return T->getStmtClass() == MSAsmStmtClass;
17188cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17198cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
17208cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  child_range children() {
17218cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    return child_range(&Exprs[0], &Exprs[0]);
17228cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
17238cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier};
17248cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
172528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt {
172628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
172728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
172828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
172928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { FILTER_EXPR, BLOCK };
173028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
173128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt(SourceLocation Loc,
173228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Expr *FilterExpr,
173328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                Stmt *Block);
173428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
17357110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
17367110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
17377110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
17387110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
173928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
174028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHExceptStmt* Create(ASTContext &C,
174128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation ExceptLoc,
174228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Expr *FilterExpr,
174328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Block);
1744aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
174528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getExceptLoc(), getEndLoc());
174628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
174728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
174828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getExceptLoc() const { return Loc; }
174928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
175028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1751ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getFilterExpr() const {
1752ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1753ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1754ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1755ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt *getBlock() const {
1756ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return llvm::cast<CompoundStmt>(Children[BLOCK]);
1757ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
175828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
175928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
176028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
176128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
176228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
176328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
176428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHExceptStmtClass;
176528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
176628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
176728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
176828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
176928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt {
177028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  Loc;
177128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Block;
177228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
177328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt(SourceLocation Loc,
177428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                 Stmt *Block);
177528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
17767110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
17777110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
17787110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
17797110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
178028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
178128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHFinallyStmt* Create(ASTContext &C,
178228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                SourceLocation FinallyLoc,
178328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                Stmt *Block);
178428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1785aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
178628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getFinallyLoc(), getEndLoc());
178728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
178828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
178928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getFinallyLoc() const { return Loc; }
179028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
179128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); }
179328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
179528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(&Block,&Block+1);
179628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
179728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
179828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
179928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHFinallyStmtClass;
180028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
180128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
180328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt {
180528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool            IsCXXTry;
180628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation  TryLoc;
180728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt           *Children[2];
180828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
180928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  enum { TRY = 0, HANDLER = 1 };
181028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
181128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
181228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             SourceLocation TryLoc,
181328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *TryBlock,
181428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley             Stmt *Handler);
181528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
18167110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
18177110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
18187110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
18197110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
182028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
182128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static SEHTryStmt* Create(ASTContext &C,
182228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            bool isCXXTry,
182328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            SourceLocation TryLoc,
182428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *TryBlock,
182528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                            Stmt *Handler);
182628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1827aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
182828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SourceRange(getTryLoc(), getEndLoc());
182928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
183028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getTryLoc() const { return TryLoc; }
183228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
183328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
183428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  bool getIsCXXTry() const { return IsCXXTry; }
1835ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1836ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt* getTryBlock() const {
1837ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return llvm::cast<CompoundStmt>(Children[TRY]);
1838ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
1839ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
184028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Stmt *getHandler() const { return Children[HANDLER]; }
184128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
184228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Returns 0 if not defined
184328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHExceptStmt  *getExceptHandler() const;
184428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  SEHFinallyStmt *getFinallyHandler() const;
184528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
184628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  child_range children() {
184728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return child_range(Children,Children+2);
184828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
184928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
185028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  static bool classof(const Stmt *T) {
185128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return T->getStmtClass() == SEHTryStmtClass;
185228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
185328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
1854ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
18565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1858