Stmt.h revision 063820655db8121f0022a7c51458463c7250324c
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Stmt interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_STMT_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_STMT_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 172fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/DeclGroup.h" 189caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h" 199fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan#include "clang/Basic/CapturedStmt.h" 202fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/IdentifierTable.h" 212fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/LLVM.h" 222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/SourceLocation.h" 232fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "llvm/ADT/ArrayRef.h" 243a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir#include "llvm/ADT/PointerIntPair.h" 25aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 26a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer#include "llvm/Support/ErrorHandling.h" 276e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string> 287573098b83e780d1c5bea13b384b610d8f155676Steve Naroff 2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm { 3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor class FoldingSetNodeID; 3141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor} 3241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 34e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop class ASTContext; 352fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer class Attr; 366afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj class CapturedDecl; 375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 382fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer class Expr; 395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class IdentifierInfo; 40478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer class LabelDecl; 412fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer class ParmVarDecl; 42a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer class PrinterHelper; 43a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer struct PrintingPolicy; 442fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer class QualType; 45051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj class RecordDecl; 460c727a35718556866a978f64ac549d9798735f08Chris Lattner class SourceManager; 476a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson class StringLiteral; 486c36be5b383875b490684bcf439d6d427298c1afChris Lattner class SwitchStmt; 49a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer class Token; 50478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer class VarDecl; 511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie //===--------------------------------------------------------------------===// 53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // ExprIterator - Iterators for iterating over Stmt* arrays that contain 54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // only Expr*. This is needed because AST nodes use Stmt* arrays to store 55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // references to children (to be compatible with StmtIterator). 56ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie //===--------------------------------------------------------------------===// 571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Stmt; 59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Expr; 601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ExprIterator { 62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Stmt** I; 63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator(Stmt** i) : I(i) {} 651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExprIterator() : I(0) {} 66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator& operator++() { ++I; return *this; } 67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator-(size_t i) { return I-i; } 68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator+(size_t i) { return I+i; } 69ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator[](size_t idx); 70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // FIXME: Verify that this will correctly return a signed distance. 71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ExprIterator& R) const { return I - R.I; } 72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator*() const; 73ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator->() const; 74ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator==(const ExprIterator& R) const { return I == R.I; } 75ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator!=(const ExprIterator& R) const { return I != R.I; } 76ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>(const ExprIterator& R) const { return I > R.I; } 77ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>=(const ExprIterator& R) const { return I >= R.I; } 78ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek }; 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 80ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ConstExprIterator { 811705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer const Stmt * const *I; 82ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 831705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator(const Stmt * const *i) : I(i) {} 841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ConstExprIterator() : I(0) {} 85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ConstExprIterator& operator++() { ++I; return *this; } 861705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator+(size_t i) const { return I+i; } 871705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator-(size_t i) const { return I-i; } 88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator[](size_t idx) const; 89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ConstExprIterator& R) const { return I - R.I; } 90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator*() const; 91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator->() const; 92ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator==(const ConstExprIterator& R) const { return I == R.I; } 93ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator!=(const ConstExprIterator& R) const { return I != R.I; } 94ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>(const ConstExprIterator& R) const { return I > R.I; } 95ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>=(const ConstExprIterator& R) const { return I >= R.I; } 961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }; 971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 99ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements. 100ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement. 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt { 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum StmtClass { 107f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor NoStmtClass = 0, 108f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class, 1097381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \ 1109a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class, 1117381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \ 1129a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class 1137381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT) 1144bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 1158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Make vanilla 'new' and 'delete' illegal for Stmts. 1188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected: 1198189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes) throw() { 120b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Stmts cannot be allocated with regular 'new'."); 1218189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1228189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void operator delete(void* data) throw() { 123b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Stmts cannot be released with regular 'delete'."); 1248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class StmtBitfields { 1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Stmt; 1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall /// \brief The statement class. 1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned sClass : 8; 1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall enum { NumStmtBits = 8 }; 1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CompoundStmtBitfields { 1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CompoundStmt; 1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned NumStmts : 32 - NumStmtBits; 1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class ExprBitfields { 1428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Expr; 1438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DeclRefExpr; // computeDependence 1448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class InitListExpr; // ctor 1458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DesignatedInitExpr; // ctor 146d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor friend class BlockDeclRefExpr; // ctor 147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ASTStmtReader; // deserialization 148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXNewExpr; // ctor 149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class DependentScopeDeclRefExpr; // ctor 150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXConstructExpr; // ctor 151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CallExpr; // ctor 152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OffsetOfExpr; // ctor 153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ObjCMessageExpr; // ctor 154ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ObjCArrayLiteral; // ctor 155ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ObjCDictionaryLiteral; // ctor 156bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ShuffleVectorExpr; // ctor 157bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ParenListExpr; // ctor 158bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXUnresolvedConstructExpr; // ctor 159bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXDependentScopeMemberExpr; // ctor 160bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OverloadExpr; // ctor 1614b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class PseudoObjectExpr; // ctor 162dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman friend class AtomicExpr; // ctor 1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueKind : 2; 166f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall unsigned ObjectKind : 2; 1678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned TypeDependent : 1; 1688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueDependent : 1; 169561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor unsigned InstantiationDependent : 1; 170d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned ContainsUnexpandedParameterPack : 1; 1718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 172561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor enum { NumExprBits = 16 }; 1738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer class CharacterLiteralBitfields { 175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer friend class CharacterLiteral; 176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned : NumExprBits; 177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned Kind : 2; 179bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer }; 180bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 1819ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover enum APFloatSemantics { 1829ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover IEEEhalf, 1839ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover IEEEsingle, 1849ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover IEEEdouble, 1859ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover x87DoubleExtended, 1869ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover IEEEquad, 1879ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover PPCDoubleDouble 1889ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover }; 1899ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 190bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer class FloatingLiteralBitfields { 191bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer friend class FloatingLiteral; 192bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned : NumExprBits; 193bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 1949ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover unsigned Semantics : 3; // Provides semantics for APFloat construction 195bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned IsExact : 1; 196bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer }; 197bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 198bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer class UnaryExprOrTypeTraitExprBitfields { 199bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer friend class UnaryExprOrTypeTraitExpr; 200bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned : NumExprBits; 201bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 202bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned Kind : 2; 203bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned IsType : 1; // true if operand is a type, false if an expression. 204bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer }; 205bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 206cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth class DeclRefExprBitfields { 207cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth friend class DeclRefExpr; 208cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth friend class ASTStmtReader; // deserialization 209cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth unsigned : NumExprBits; 210cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 211cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth unsigned HasQualifier : 1; 212e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara unsigned HasTemplateKWAndArgsInfo : 1; 2133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth unsigned HasFoundDecl : 1; 2147cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara unsigned HadMultipleCandidates : 1; 215f4b88a45902af1802a1cb42ba48b1c474474f228John McCall unsigned RefersToEnclosingLocal : 1; 216cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth }; 217cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 2188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CastExprBitfields { 2198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CastExpr; 2208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumExprBits; 2218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 2222bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned Kind : 6; 2232bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned BasePathSize : 32 - 6 - NumExprBits; 2248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 2258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 226cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne class CallExprBitfields { 227cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne friend class CallExpr; 228cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned : NumExprBits; 229cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 230cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs : 1; 231cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne }; 232cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 23380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall class ExprWithCleanupsBitfields { 23480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ExprWithCleanups; 23580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ASTStmtReader; // deserialization 23680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 23780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned : NumExprBits; 23880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 23980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned NumObjects : 32 - NumExprBits; 24080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall }; 24180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 2424b9c2d235fb9449e249d74f48ecfec601650de93John McCall class PseudoObjectExprBitfields { 2434b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class PseudoObjectExpr; 2444b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class ASTStmtReader; // deserialization 2454b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2464b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned : NumExprBits; 2474b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2484b9c2d235fb9449e249d74f48ecfec601650de93John McCall // These don't need to be particularly wide, because they're 2494b9c2d235fb9449e249d74f48ecfec601650de93John McCall // strictly limited by the forms of expressions we permit. 2504b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned NumSubExprs : 8; 2514b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned ResultIndex : 32 - 8 - NumExprBits; 2524b9c2d235fb9449e249d74f48ecfec601650de93John McCall }; 2534b9c2d235fb9449e249d74f48ecfec601650de93John McCall 254f85e193739c953358c865005855253af4f68a497John McCall class ObjCIndirectCopyRestoreExprBitfields { 255f85e193739c953358c865005855253af4f68a497John McCall friend class ObjCIndirectCopyRestoreExpr; 256f85e193739c953358c865005855253af4f68a497John McCall unsigned : NumExprBits; 257f85e193739c953358c865005855253af4f68a497John McCall 258f85e193739c953358c865005855253af4f68a497John McCall unsigned ShouldCopy : 1; 259f85e193739c953358c865005855253af4f68a497John McCall }; 260f85e193739c953358c865005855253af4f68a497John McCall 26132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl class InitListExprBitfields { 26232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl friend class InitListExpr; 26332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 26432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl unsigned : NumExprBits; 26532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 26632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// Whether this initializer list originally had a GNU array-range 26732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// designator in it. This is a temporary marker used by CodeGen. 26832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl unsigned HadArrayRangeDesignator : 1; 26932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl }; 27032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 2714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor class TypeTraitExprBitfields { 2724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class TypeTraitExpr; 2734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtReader; 2744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtWriter; 2754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned : NumExprBits; 2774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The kind of type trait, which is a value of a TypeTrait enumerator. 2794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned Kind : 8; 2804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief If this expression is not value-dependent, this indicates whether 2824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// the trait evaluated true or false. 2834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned Value : 1; 2844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The number of arguments to this type trait. 2864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned NumArgs : 32 - 8 - 1 - NumExprBits; 2874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor }; 288211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith 2898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall union { 29063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // FIXME: this is wasteful on 64-bit platforms. 29163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall void *Aligner; 29263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 2938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBitfields StmtBits; 2948e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBitfields CompoundStmtBits; 2958e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBitfields ExprBits; 296bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer CharacterLiteralBitfields CharacterLiteralBits; 297bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer FloatingLiteralBitfields FloatingLiteralBits; 298bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits; 299cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBitfields DeclRefExprBits; 3008e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBitfields CastExprBits; 301cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBitfields CallExprBits; 30280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanupsBitfields ExprWithCleanupsBits; 3034b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBitfields PseudoObjectExprBits; 304f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits; 30532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl InitListExprBitfields InitListExprBits; 3064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTraitExprBitfields TypeTraitExprBits; 3078e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 3088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 309d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor friend class ASTStmtReader; 3104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtWriter; 311d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 3128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic: 3138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Only allow allocation of Stmts using the allocator in ASTContext 3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // or by doing a placement new. 31505ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void* operator new(size_t bytes, const ASTContext& C, 3165b3ebb4356ac62abd8767c4c3388b773d9d61802Craig Topper unsigned alignment = 8); 3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 318bdf253de659442bc3fd4fc28d6145ad46113a0a7Craig Topper void* operator new(size_t bytes, const ASTContext* C, 319536bcedb8e6fea6458789f99f0ef554ce65514ccCraig Topper unsigned alignment = 8) { 320536bcedb8e6fea6458789f99f0ef554ce65514ccCraig Topper return operator new(bytes, *C, alignment); 321536bcedb8e6fea6458789f99f0ef554ce65514ccCraig Topper } 322bdf253de659442bc3fd4fc28d6145ad46113a0a7Craig Topper 3238189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, void* mem) throw() { 3248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return mem; 3258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 326e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 32705ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void operator delete(void*, const ASTContext&, unsigned) throw() { } 32805ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void operator delete(void*, const ASTContext*, unsigned) throw() { } 32905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void operator delete(void*, size_t) throw() { } 330fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, void*) throw() { } 331e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 332025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic: 333025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief A placeholder type used to construct an empty shell of a 334025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// type, that will be filled in later (e.g., by some 335025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// de-serialization). 336025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor struct EmptyShell { }; 337025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 33802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate: 33902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar /// \brief Whether statistic collection is enabled. 34002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static bool StatisticsEnabled; 34102892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar 3429c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected: 343025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Construct an empty statement. 3448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall explicit Stmt(StmtClass SC, EmptyShell) { 3458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 34602892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) Stmt::addStmtClass(SC); 347025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor } 348025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3508e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt(StmtClass SC) { 3518e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 35202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) Stmt::addStmtClass(SC); 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 355ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie StmtClass getStmtClass() const { 3568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall return static_cast<StmtClass>(StmtBits.sClass); 357b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor } 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStmtClassName() const; 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 360b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// SourceLocation tokens are not useful in isolation - they are low level 361b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// value objects created/interpreted by SourceManager. We assume AST 362b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// clients will have a pointer to the respective SourceManager. 363aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 364aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY; 365aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY; 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // global temp stats (until we have a per-module visitor) 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void addStmtClass(const StmtClass s); 36902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static void EnableStatistics(); 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void PrintStats(); 3716000dace22f110d8768476989313e9d981d690d0Chris Lattner 37295f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko /// \brief Dumps the specified AST fragment and all subtrees to 37395f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko /// \c llvm::errs(). 374f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis LLVM_ATTRIBUTE_USED void dump() const; 375f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const; 3768cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void dump(raw_ostream &OS, SourceManager &SM) const; 3776000dace22f110d8768476989313e9d981d690d0Chris Lattner 3787ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu /// dumpColor - same as dump(), but forces color highlighting. 3797ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu LLVM_ATTRIBUTE_USED void dumpColor() const; 3807ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu 3816000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST 3826000dace22f110d8768476989313e9d981d690d0Chris Lattner /// back to its original source language syntax. 3838b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper void dumpPretty(const ASTContext &Context) const; 3848cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void printPretty(raw_ostream &OS, PrinterHelper *Helper, 385e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 386d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned Indentation = 0) const; 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only 389d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// works on systems with GraphViz (Mac OS X) or dot+gv installed. 390d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek void viewAST() const; 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3927e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// Skip past any implicit AST nodes which might surround this 3937e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes. 3947e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall Stmt *IgnoreImplicit(); 3957e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 396a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth const Stmt *stripLabelLikeStatements() const; 397a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth Stmt *stripLabelLikeStatements() { 398a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth return const_cast<Stmt*>( 399a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth const_cast<const Stmt*>(this)->stripLabelLikeStatements()); 400a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth } 401a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth 40263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// Child Iterators: All subclasses must implement 'children' 40363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// to permit easy iteration over the substatements/subexpessions of an 40463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// AST node. This permits easy iteration over all nodes in the AST. 4059caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef StmtIterator child_iterator; 4069caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef ConstStmtIterator const_child_iterator; 4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef StmtRange child_range; 40963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef ConstStmtRange const_child_range; 4101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 41263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_range children() const { 41363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return const_cast<Stmt*>(this)->children(); 41477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_begin() { return children().first; } 41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_end() { return children().second; } 41863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 41963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_begin() const { return children().first; } 42063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_end() const { return children().second; } 42141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 42241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Produce a unique representation of the given statement. 42341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 42470517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko /// \param ID once the profiling operation is complete, will contain 42541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// the unique representation of the given statement. 42641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 42770517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko /// \param Context the AST context in which the statement resides 42841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 42970517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko /// \param Canonical whether the profile should be based on the canonical 43041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// representation of this statement (e.g., where non-type template 4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// parameters are identified by index/level rather than their 43241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// declaration pointers) or the exact representation of the statement as 43341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// written in the source. 4344ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 435b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth bool Canonical) const; 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions 4401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration. 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt { 4449653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor DeclGroupRef DG; 44581c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation StartLoc, EndLoc; 4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 4498ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg), 4508ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek StartLoc(startLoc), EndLoc(endLoc) {} 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 45284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor /// \brief Build an empty declaration statement. 45384f2170062014d268951902164bed0d8bdea0e82Douglas Gregor explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { } 45484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 4557e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner /// isSingleDecl - This method returns true if this DeclStmt refers 456fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner /// to a single Decl. 4577e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner bool isSingleDecl() const { 458fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner return DG.isSingleDecl(); 4598ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek } 4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4617e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner const Decl *getSingleDecl() const { return DG.getSingleDecl(); } 4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl *getSingleDecl() { return DG.getSingleDecl(); } 4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 464e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner const DeclGroupRef getDeclGroup() const { return DG; } 465e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner DeclGroupRef getDeclGroup() { return DG; } 46684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setDeclGroup(DeclGroupRef DGR) { DG = DGR; } 467b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 46881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getStartLoc() const { return StartLoc; } 46984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setStartLoc(SourceLocation L) { StartLoc = L; } 47081c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getEndLoc() const { return EndLoc; } 47184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setEndLoc(SourceLocation L) { EndLoc = L; } 47284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 47365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; } 47465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; } 4751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DeclStmtClass; 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48014f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek // Iterators over subexpressions. 48163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 48263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(DG.begin(), DG.end()), 48363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator(DG.end(), DG.end())); 48463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4860632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::iterator decl_iterator; 4870632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::const_iterator const_decl_iterator; 4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4898ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_begin() { return DG.begin(); } 4908ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_end() { return DG.end(); } 4918ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_begin() const { return DG.begin(); } 4928ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_end() const { return DG.end(); } 493fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose 494fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator; 495fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose reverse_decl_iterator decl_rbegin() { 496fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose return reverse_decl_iterator(decl_end()); 497fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose } 498fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose reverse_decl_iterator decl_rend() { 499fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose return reverse_decl_iterator(decl_begin()); 500fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose } 5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3. 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt { 5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation SemiLoc; 50744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 508e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis /// \brief True if the null statement was preceded by an empty macro, e.g: 50944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @code 51044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// #define CALL(x) 51144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// CALL(0); 51244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @endcode 513e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis bool HasLeadingEmptyMacro; 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 515e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false) 516e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis : Stmt(NullStmtClass), SemiLoc(L), 517e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis HasLeadingEmptyMacro(hasLeadingEmptyMacro) {} 5185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 519025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty null statement. 520e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty), 521e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis HasLeadingEmptyMacro(false) { } 522025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getSemiLoc() const { return SemiLoc; } 524025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSemiLoc(SourceLocation L) { SemiLoc = L; } 525b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 526e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; } 52744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 52865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; } 52965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; } 5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == NullStmtClass; 5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 53644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 53744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtReader; 53844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtWriter; 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }. 5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt { 5448189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek Stmt** Body; 545b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation LBracLoc, RBracLoc; 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5470b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, 5483a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer SourceLocation LB, SourceLocation RB); 5493a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer 550063820655db8121f0022a7c51458463c7250324cBenjamin Kramer // \brief Build an empty compound statement with a location. 5513a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer explicit CompoundStmt(SourceLocation Loc) 5523a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) { 5533a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer CompoundStmtBits.NumStmts = 0; 5541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 555025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 556025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor // \brief Build an empty compound statement. 557025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CompoundStmt(EmptyShell Empty) 5588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass, Empty), Body(0) { 5598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = 0; 5608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 561025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5628b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper void setStmts(const ASTContext &C, Stmt **Stmts, unsigned NumStmts); 5631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } 5658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned size() const { return CompoundStmtBits.NumStmts; } 566025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5678189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt** body_iterator; 5688189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek body_iterator body_begin() { return Body; } 5698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall body_iterator body_end() { return Body + size(); } 5708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; } 571ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setLastStmt(Stmt *S) { 5738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall assert(!body_empty() && "setLastStmt"); 5748e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Body[size()-1] = S; 5758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5778189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt* const * const_body_iterator; 5788189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_body_iterator body_begin() const { return Body; } 5798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const_body_iterator body_end() const { return Body + size(); } 5808e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; } 5818189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek 5828189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<body_iterator> reverse_body_iterator; 5838189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rbegin() { 5848189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_end()); 5858189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 5868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rend() { 5878189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_begin()); 5888189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 5894ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 5908189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<const_body_iterator> 5918189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator; 5924ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 5938189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rbegin() const { 5948189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_end()); 5958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 5961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rend() const { 5988189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_begin()); 5998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; } 60265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; } 6031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 604cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getLBracLoc() const { return LBracLoc; } 605025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setLBracLoc(SourceLocation L) { LBracLoc = L; } 606cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getRBracLoc() const { return RBracLoc; } 607025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setRBracLoc(SourceLocation L) { RBracLoc = L; } 6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundStmtClass; 6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6138297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 61463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 61563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 61663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 617ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6188ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek const_child_range children() const { 6198ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 6208ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek } 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 623c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt, 624c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt { 625103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected: 626c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // A pointer to the following CaseStmt or DefaultStmt class, 627c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // used by SwitchStmt. 628c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *NextSwitchCase; 62981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation KeywordLoc; 63081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation ColonLoc; 63181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis 63281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc) 63381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {} 634103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek 63581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SwitchCase(StmtClass SC, EmptyShell) 63681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : Stmt(SC), NextSwitchCase(0) {} 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 638c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic: 639c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } 640c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 641c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getNextSwitchCase() { return NextSwitchCase; } 642c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 643c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } 644d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek 64581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getKeywordLoc() const { return KeywordLoc; } 64681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setKeywordLoc(SourceLocation L) { KeywordLoc = L; } 64781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getColonLoc() const { return ColonLoc; } 64881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setColonLoc(SourceLocation L) { ColonLoc = L; } 64981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis 65063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt *getSubStmt(); 651702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner const Stmt *getSubStmt() const { 652702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner return const_cast<SwitchCase*>(this)->getSubStmt(); 653702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner } 654b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 65581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } 65681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocEnd() const LLVM_READONLY; 6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass || 66063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall T->getStmtClass() == DefaultStmtClass; 661c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 662c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson}; 663c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 664c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase { 6650a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor enum { LHS, RHS, SUBSTMT, END_EXPR }; 6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 667d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // GNU "case 1 ... 4" extension 668dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation EllipsisLoc; 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 670dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, 6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation ellipsisLoc, SourceLocation colonLoc) 67281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : SwitchCase(CaseStmtClass, caseLoc, colonLoc) { 67324e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner SubExprs[SUBSTMT] = 0; 674d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 675d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 676dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor EllipsisLoc = ellipsisLoc; 677d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek } 678025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 679025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty switch case statement. 68081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { } 681025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 68281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getCaseLoc() const { return KeywordLoc; } 68381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setCaseLoc(SourceLocation L) { KeywordLoc = L; } 684dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 685dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } 686dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 687dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 688025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 689d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 690d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 691d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 692025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 6931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getLHS() const { 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[LHS]); 69551b09f2c528c8460b5465c676173324e44176d62Devang Patel } 6961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getRHS() const { 6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[RHS]); 69851b09f2c528c8460b5465c676173324e44176d62Devang Patel } 69951b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 70120dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; } 70220dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } 70320dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } 7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } 70665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 7073fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner // Handle deeply nested case statements with iteration instead of recursion. 7083fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner const CaseStmt *CS = this; 70991ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) 7103fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner CS = CS2; 7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return CS->getSubStmt()->getLocEnd(); 713b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 71465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass; 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 719d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 72063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 72163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[END_EXPR]); 72263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 725c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase { 726d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt* SubStmt; 7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : 72981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {} 730025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 731025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty default statement. 73281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis explicit DefaultStmt(EmptyShell Empty) 73381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : SwitchCase(DefaultStmtClass, Empty) { } 734025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 735d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubStmt; } 73651b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubStmt; } 737025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSubStmt(Stmt *S) { SubStmt = S; } 738025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 73981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getDefaultLoc() const { return KeywordLoc; } 74081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setDefaultLoc(SourceLocation L) { KeywordLoc = L; } 741dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 742dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 74481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } 74565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} 74665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 7471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DefaultStmtClass; 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 751d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 75263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 75581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidisinline SourceLocation SwitchCase::getLocEnd() const { 75681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis if (const CaseStmt *CS = dyn_cast<CaseStmt>(this)) 75781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis return CS->getLocEnd(); 75881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis return cast<DefaultStmt>(this)->getLocEnd(); 75981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis} 760ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 761ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement. For example: 762ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// foo: return; 763ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt { 765ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *TheDecl; 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *SubStmt; 767b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IdentLoc; 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 769ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt) 770ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) { 7718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 7721de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 7731de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor // \brief Build an empty label statement. 7741de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { } 7751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getIdentLoc() const { return IdentLoc; } 777ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getDecl() const { return TheDecl; } 778ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setDecl(LabelDecl *D) { TheDecl = D; } 7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *getSubStmt() { return SubStmt; } 7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Stmt *getSubStmt() const { return SubStmt; } 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setIdentLoc(SourceLocation L) { IdentLoc = L; } 7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setSubStmt(Stmt *SS) { SubStmt = SS; } 784b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 78565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; } 78665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} 78765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 78863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 78963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 7901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == LabelStmtClass; 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 796534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement. 797534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// 798534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example: 799534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// [[omp::for(...)]] for (...) { ... } 800534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// 801534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt { 802534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *SubStmt; 803534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation AttrLoc; 8044990890fc9428f98bef90ba349203a648c592778Alexander Kornienko unsigned NumAttrs; 8054990890fc9428f98bef90ba349203a648c592778Alexander Kornienko const Attr *Attrs[1]; 806534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 807534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith friend class ASTStmtReader; 808534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8094990890fc9428f98bef90ba349203a648c592778Alexander Kornienko AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt) 8104990890fc9428f98bef90ba349203a648c592778Alexander Kornienko : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc), 8114990890fc9428f98bef90ba349203a648c592778Alexander Kornienko NumAttrs(Attrs.size()) { 8124990890fc9428f98bef90ba349203a648c592778Alexander Kornienko memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*)); 813534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 814534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8154990890fc9428f98bef90ba349203a648c592778Alexander Kornienko explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) 8164990890fc9428f98bef90ba349203a648c592778Alexander Kornienko : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) { 8174990890fc9428f98bef90ba349203a648c592778Alexander Kornienko memset(Attrs, 0, NumAttrs * sizeof(Attr*)); 818534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 819534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8204990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic: 8210b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc, 8224990890fc9428f98bef90ba349203a648c592778Alexander Kornienko ArrayRef<const Attr*> Attrs, Stmt *SubStmt); 8234990890fc9428f98bef90ba349203a648c592778Alexander Kornienko // \brief Build an empty attributed statement. 8240b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs); 8254990890fc9428f98bef90ba349203a648c592778Alexander Kornienko 826534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation getAttrLoc() const { return AttrLoc; } 8274990890fc9428f98bef90ba349203a648c592778Alexander Kornienko ArrayRef<const Attr*> getAttrs() const { 8284990890fc9428f98bef90ba349203a648c592778Alexander Kornienko return ArrayRef<const Attr*>(Attrs, NumAttrs); 8294990890fc9428f98bef90ba349203a648c592778Alexander Kornienko } 830534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *getSubStmt() { return SubStmt; } 831534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith const Stmt *getSubStmt() const { return SubStmt; } 832534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 83365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; } 83465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} 83565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 836534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith child_range children() { return child_range(&SubStmt, &SubStmt + 1); } 837534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 838534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith static bool classof(const Stmt *T) { 839534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return T->getStmtClass() == AttributedStmtClass; 840534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 841534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith}; 842534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 843534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else. 8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt { 84743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, THEN, ELSE, END_EXPR }; 8488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 8498cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor 850b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IfLoc; 851d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation ElseLoc; 852ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8540b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, 85544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0); 856ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 857025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty if/then/else statement 858025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { } 859025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 8608cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \brief Retrieve the variable declared in this "if" statement, if any. 8618cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// 8628cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// In the following example, "x" is the condition variable. 8638cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \code 8648cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// if (int x = foo()) { 8658cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// printf("x is %d", x); 8668cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// } 8678cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \endcode 86843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 8690b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void setConditionVariable(const ASTContext &C, VarDecl *V); 870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 871d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this IfStmt has a condition variable, return the faux DeclStmt 872d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 873d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 874d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 875d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 876ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8778297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 878025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 8798297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getThen() const { return SubExprs[THEN]; } 8801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setThen(Stmt *S) { SubExprs[THEN] = S; } 8818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getElse() const { return SubExprs[ELSE]; } 882025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setElse(Stmt *S) { SubExprs[ELSE] = S; } 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 8858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getThen() { return SubExprs[THEN]; } 8868297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getElse() { return SubExprs[ELSE]; } 887b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 888025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getIfLoc() const { return IfLoc; } 889025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setIfLoc(SourceLocation L) { IfLoc = L; } 890d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation getElseLoc() const { return ElseLoc; } 891d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor void setElseLoc(SourceLocation L) { ElseLoc = L; } 892025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 89365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; } 89465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 895b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff if (SubExprs[ELSE]) 89665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[ELSE]->getLocEnd(); 897b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff else 89865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[THEN]->getLocEnd(); 899b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 9001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 90163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators over subexpressions. The iterators will include iterating 90263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // over the initialization expression referenced by the condition variable. 90363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 90463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 90563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 90663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IfStmtClass; 9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt. 9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt { 91543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 917c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // This points to a linked list of case and default statements. 918c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *FirstCase; 9199dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SourceLocation SwitchLoc; 9201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 921559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// If the SwitchStmt is a switch on an enum value, this records whether 922559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// all the enum values were covered by CaseStmts. This value is meant to 923559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// be a hint for possible clients. 924559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek unsigned AllEnumCasesCovered : 1; 925559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9270b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond); 9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 929025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build a empty switch statement. 930025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { } 931025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 932d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \brief Retrieve the variable declared in this "switch" statement, if any. 933d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// 934d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// In the following example, "x" is the condition variable. 935d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \code 936d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// switch (int x = foo()) { 937d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// case 0: break; 938d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// // ... 939d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// } 940d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \endcode 94143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 9420b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void setConditionVariable(const ASTContext &C, VarDecl *V); 943ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 944d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this SwitchStmt has a condition variable, return the faux DeclStmt 945d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 946d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 947d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 948d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 949d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor 9508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 9518297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 952c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getSwitchCaseList() const { return FirstCase; } 953c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 9548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 955025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 9568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 957025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 958c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getSwitchCaseList() { return FirstCase; } 9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Set the case list for this switch statement. 961025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } 962025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 963025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getSwitchLoc() const { return SwitchLoc; } 964025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchLoc(SourceLocation L) { SwitchLoc = L; } 965c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setBody(Stmt *S, SourceLocation SL) { 9671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SubExprs[BODY] = S; 9689dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SwitchLoc = SL; 9691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 970c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void addSwitchCase(SwitchCase *SC) { 971ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(!SC->getNextSwitchCase() 972ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie && "case/default already added to a switch"); 973c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor SC->setNextSwitchCase(FirstCase); 974c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson FirstCase = SC; 975c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 976559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 977559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a 978559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// switch over an enum value then all cases have been explicitly covered. 979559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek void setAllEnumCasesCovered() { 980559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek AllEnumCasesCovered = 1; 981559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 982559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 983559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Returns true if the SwitchStmt is a switch of an enum value and all cases 984559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// have been explicitly covered. 985559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek bool isAllEnumCasesCovered() const { 986559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek return (bool) AllEnumCasesCovered; 987559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 988559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 98965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; } 99065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 99165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BODY]->getLocEnd(); 9929dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff } 99365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 99463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators 99563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 99663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 99763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 99863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SwitchStmtClass; 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt. 10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt { 100843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 10098297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 1010b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation WhileLoc; 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10120b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 101343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SourceLocation WL); 10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1015d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty while statement. 1016d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { } 1017d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 10185656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Retrieve the variable declared in this "while" statement, if any. 10195656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// 10205656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// In the following example, "x" is the condition variable. 10215656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \code 10225656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// while (int x = random()) { 10235656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// // ... 10245656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// } 10255656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \endcode 102643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 10270b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void setConditionVariable(const ASTContext &C, VarDecl *V); 10285656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 1029d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this WhileStmt has a condition variable, return the faux DeclStmt 1030d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 1031d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 1032d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 1033d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 1034d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 10358297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 10368297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 1037d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 10388297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 10398297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 1040d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 1041d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1042d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 1043d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1044b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 104565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; } 104665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 104765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BODY]->getLocEnd(); 1048b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 104965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 10501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == WhileStmtClass; 10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 105563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 105663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 105763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt. 10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt { 1063c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor enum { BODY, COND, END_EXPR }; 10648297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 1065b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation DoLoc; 10669f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation WhileLoc; 1067989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RParenLoc; // Location of final ')' in do stmt condition. 10689f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor 10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1070989135901c750af61ef012b6b0a0368be415bc46Chris Lattner DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL, 1071989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RP) 1072989135901c750af61ef012b6b0a0368be415bc46Chris Lattner : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) { 10738297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 10748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[BODY] = body; 10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 107667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 107767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty do-while statement. 107867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { } 10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10808297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 10818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 108267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 10838297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Stmt *getBody() const { return SubExprs[BODY]; } 108567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 108667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 108767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getDoLoc() const { return DoLoc; } 108867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setDoLoc(SourceLocation L) { DoLoc = L; } 10899f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 10909f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1091b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 1092989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 1093989135901c750af61ef012b6b0a0368be415bc46Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1094989135901c750af61ef012b6b0a0368be415bc46Chris Lattner 109565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; } 109665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 109765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DoStmtClass; 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11018297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 11028297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 110363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 110463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 110563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source. 11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt { 111443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; 11158297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 1116b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation ForLoc; 11175831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation LParenLoc, RParenLoc; 11185831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor 11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11200b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, 11210b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, 11220b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper SourceLocation RP); 11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty for statement. 112567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { } 112667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 11278297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getInit() { return SubExprs[INIT]; } 1128ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 112999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \brief Retrieve the variable declared in this "for" statement, if any. 113099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// 113199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// In the following example, "y" is the condition variable. 113299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \code 113399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// for (int x = random(); int y = mangle(x); ++x) { 113499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// // ... 113599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// } 113699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \endcode 113743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 11380b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void setConditionVariable(const ASTContext &C, VarDecl *V); 1139ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1140d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this ForStmt has a condition variable, return the faux DeclStmt 1141d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 1142d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 1143d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]); 1144d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 1145d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 11468297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 11478297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 11488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 11498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 11508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getInit() const { return SubExprs[INIT]; } 11518297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 11528297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 11538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 1154b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 115567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInit(Stmt *S) { SubExprs[INIT] = S; } 115667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 115767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } 115867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 115967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 116067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getForLoc() const { return ForLoc; } 116167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setForLoc(SourceLocation L) { ForLoc = L; } 11625831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 11635831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 11645831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 11655831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 116667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 116765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; } 116865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 116965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BODY]->getLocEnd(); 1170b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 117165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 11721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ForStmtClass; 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11768297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 117763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 117863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 117963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto. 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt { 1185ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 1186507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation GotoLoc; 118761f62165220e75694fe333179c78815e2e48d71fTed Kremenek SourceLocation LabelLoc; 11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1189ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL) 119061f62165220e75694fe333179c78815e2e48d71fTed Kremenek : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 11911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11921de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor /// \brief Build an empty goto statement. 11931de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { } 11941de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 1195ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 1196ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *D) { Label = D; } 11971de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 11981de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getGotoLoc() const { return GotoLoc; } 11991de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setGotoLoc(SourceLocation L) { GotoLoc = L; } 12001de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 12011de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 1202b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 120365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; } 120465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; } 120565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 12061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GotoStmtClass; 12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12108297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 121163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto. 12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt { 1217ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation GotoLoc; 12185f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation StarLoc; 12191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Target; 12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, 12225f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Expr *target) 12235f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc), 12245f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Target((Stmt*)target) {} 12257d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 12267d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty indirect goto statement. 12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IndirectGotoStmt(EmptyShell Empty) 12287d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Stmt(IndirectGotoStmtClass, Empty) { } 12291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1230ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner void setGotoLoc(SourceLocation L) { GotoLoc = L; } 1231ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation getGotoLoc() const { return GotoLoc; } 12325f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor void setStarLoc(SourceLocation L) { StarLoc = L; } 12335f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation getStarLoc() const { return StarLoc; } 12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 123595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall Expr *getTarget() { return reinterpret_cast<Expr*>(Target); } 123695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);} 12377d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); } 1238b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 123995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// getConstantTarget - Returns the fixed target of this indirect 124095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// goto, if one exists. 1241ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getConstantTarget(); 1242ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner const LabelDecl *getConstantTarget() const { 124395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall return const_cast<IndirectGotoStmt*>(this)->getConstantTarget(); 124495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall } 124595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall 124665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; } 124765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); } 12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IndirectGotoStmtClass; 12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 125463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Target, &Target+1); } 12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue. 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt { 1261507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation ContinueLoc; 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1263507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {} 12641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1265d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty continue statement. 1266d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { } 1267d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1268d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getContinueLoc() const { return ContinueLoc; } 1269d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setContinueLoc(SourceLocation L) { ContinueLoc = L; } 1270d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 127165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; } 127265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; } 1273861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ContinueStmtClass; 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12788297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 127963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break. 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt { 1285507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation BreakLoc; 12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1287507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 12881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1289025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty break statement. 1290025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { } 1291025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1292025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getBreakLoc() const { return BreakLoc; } 1293025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBreakLoc(SourceLocation L) { BreakLoc = L; } 1294025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 129565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; } 129665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; } 1297b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 12981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BreakStmtClass; 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13028297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 130363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1307c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression: 1308c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return; 1309c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return 4; 1310c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// 1311c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to 1312c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to 1313c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void. We explicitly model this in the AST, which means you can't 1314c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument. 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt { 13171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *RetExpr; 1318507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation RetLoc; 13195077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *NRVOCandidate; 1320ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13225077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL) 132325a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { } 13245077c3876beeaed32280af88244e8050078619a8Douglas Gregor 13255077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) 13265077c3876beeaed32280af88244e8050078619a8Douglas Gregor : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL), 13275077c3876beeaed32280af88244e8050078619a8Douglas Gregor NRVOCandidate(NRVOCandidate) {} 13280de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13290de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor /// \brief Build an empty return expression. 13300de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { } 13310de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getRetValue() const; 13331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getRetValue(); 13340de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); } 13350de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13360de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor SourceLocation getReturnLoc() const { return RetLoc; } 13370de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setReturnLoc(SourceLocation L) { RetLoc = L; } 1338b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 13395077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// \brief Retrieve the variable that might be used for the named return 13405077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// value optimization. 13415077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// 13425077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// The optimization itself can only be performed if the variable is 13435077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// also marked as an NRVO object. 13445077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *getNRVOCandidate() const { return NRVOCandidate; } 13455077c3876beeaed32280af88244e8050078619a8Douglas Gregor void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; } 1346ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 134765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; } 134865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 134965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return RetExpr ? RetExpr->getLocEnd() : RetLoc; 135065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ReturnStmtClass; 13545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 135763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 135863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (RetExpr) return child_range(&RetExpr, &RetExpr+1); 135963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 136063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1363728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt. 1364728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// 1365728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass AsmStmt : public Stmt { 1366728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierprotected: 1367066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier SourceLocation AsmLoc; 136812b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// \brief True if the assembly statement does not have any input or output 136912b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// operands. 1370728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool IsSimple; 137112b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier 137212b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// \brief If true, treat this inline assembly as having side effects. 137312b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// This assembly statement should not be optimized, deleted or moved. 1374728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool IsVolatile; 1375728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1376066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned NumOutputs; 1377066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned NumInputs; 1378066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned NumClobbers; 1379066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 138019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier Stmt **Exprs; 1381066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1382066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile, 1383066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned numoutputs, unsigned numinputs, unsigned numclobbers) : 1384066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile), 1385066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { } 1386728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1387aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall friend class ASTStmtReader; 1388aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1389728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierpublic: 1390728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier /// \brief Build an empty inline-assembly statement. 1391728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier explicit AsmStmt(StmtClass SC, EmptyShell Empty) : 1392aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall Stmt(SC, Empty), Exprs(0) { } 139329760b452876548f59804e8c02c3276bc7281d5dMatt Beaumont-Gay 1394066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier SourceLocation getAsmLoc() const { return AsmLoc; } 1395066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier void setAsmLoc(SourceLocation L) { AsmLoc = L; } 1396728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1397728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool isSimple() const { return IsSimple; } 1398728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier void setSimple(bool V) { IsSimple = V; } 1399728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1400728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool isVolatile() const { return IsVolatile; } 1401728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier void setVolatile(bool V) { IsVolatile = V; } 1402728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 140365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } 140465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } 1405728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1406da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier //===--- Asm String Analysis ---===// 1407da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier 1408da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier /// Assemble final IR asm string. 14098b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper std::string generateAsmString(const ASTContext &C) const; 1410da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier 1411066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier //===--- Output operands ---===// 1412066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1413066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned getNumOutputs() const { return NumOutputs; } 1414066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1415c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// getOutputConstraint - Return the constraint string for the specified 1416c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// output operand. All output constraints are known to be non-empty (either 1417c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// '=' or '+'). 1418aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier StringRef getOutputConstraint(unsigned i) const; 1419c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1420c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// isOutputPlusConstraint - Return true if the specified output constraint 1421c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// is a "+" constraint (which is both an input and an output) or false if it 1422c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// is an "=" constraint (just an output). 1423c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier bool isOutputPlusConstraint(unsigned i) const { 1424c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier return getOutputConstraint(i)[0] == '+'; 1425c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier } 1426c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1427aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier const Expr *getOutputExpr(unsigned i) const; 1428c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1429c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// getNumPlusOperands - Return the number of output operands that have a "+" 1430c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// constraint. 1431c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier unsigned getNumPlusOperands() const; 1432c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1433066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier //===--- Input operands ---===// 1434066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1435066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned getNumInputs() const { return NumInputs; } 1436066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1437c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// getInputConstraint - Return the specified input constraint. Unlike output 1438c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// constraints, these can be empty. 1439aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier StringRef getInputConstraint(unsigned i) const; 1440aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier 1441aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier const Expr *getInputExpr(unsigned i) const; 1442c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1443066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier //===--- Other ---===// 1444066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 14452fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier unsigned getNumClobbers() const { return NumClobbers; } 1446aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier StringRef getClobber(unsigned i) const; 14472fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier 1448728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier static bool classof(const Stmt *T) { 1449728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier return T->getStmtClass() == GCCAsmStmtClass || 1450728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier T->getStmtClass() == MSAsmStmtClass; 1451728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier } 145219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 145319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier // Input expr iterators. 145419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 145519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ExprIterator inputs_iterator; 145619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ConstExprIterator const_inputs_iterator; 145719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 145819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier inputs_iterator begin_inputs() { 145919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 146019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 146119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 146219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier inputs_iterator end_inputs() { 146319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs + NumInputs; 146419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 146519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 146619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_inputs_iterator begin_inputs() const { 146719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 146819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 146919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 147019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_inputs_iterator end_inputs() const { 147119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs + NumInputs; 147219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 147319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 147419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier // Output expr iterators. 147519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 147619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ExprIterator outputs_iterator; 147719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ConstExprIterator const_outputs_iterator; 147819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 147919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier outputs_iterator begin_outputs() { 148019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0]; 148119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 148219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier outputs_iterator end_outputs() { 148319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 148419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 148519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 148619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_outputs_iterator begin_outputs() const { 148719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0]; 148819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 148919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_outputs_iterator end_outputs() const { 149019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 149119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 149219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 149319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier child_range children() { 149419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); 149519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 1496728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier}; 1497728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 14987d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a GCC inline-assembly statement extension. 1499fe795956194141c91ae555985c9b930595bff43fChris Lattner/// 1500728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass GCCAsmStmt : public AsmStmt { 1501066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier SourceLocation RParenLoc; 15026a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson StringLiteral *AsmStr; 1503b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1504966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson // FIXME: If we wanted to, we could allocate all of these in one big array. 1505966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Constraints; 1506966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Clobbers; 1507aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall IdentifierInfo **Names; 1508aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1509aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall friend class ASTStmtReader; 1510ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1511fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic: 15120b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple, 1513df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier bool isvolatile, unsigned numoutputs, unsigned numinputs, 1514df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier IdentifierInfo **names, StringLiteral **constraints, Expr **exprs, 1515df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier StringLiteral *asmstr, unsigned numclobbers, 1516df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier StringLiteral **clobbers, SourceLocation rparenloc); 1517b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1518cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor /// \brief Build an empty inline-assembly statement. 1519728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty), 1520aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall Constraints(0), Clobbers(0), Names(0) { } 1521cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1522cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 1523cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1524cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1525458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner //===--- Asm String Analysis ---===// 1526458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1527458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const StringLiteral *getAsmString() const { return AsmStr; } 1528458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner StringLiteral *getAsmString() { return AsmStr; } 1529cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmString(StringLiteral *E) { AsmStr = E; } 1530cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1531458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AsmStringPiece - this is part of a decomposed asm string specification 1532458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// (for use with the AnalyzeAsmString function below). An asm string is 1533458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// considered to be a concatenation of these parts. 1534458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner class AsmStringPiece { 1535458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1536458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner enum Kind { 1537458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". 1538458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Operand // Operand reference, with optional modifier %c4. 1539458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 1540458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner private: 1541458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Kind MyKind; 1542458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner std::string Str; 1543458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned OperandNo; 1544458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1545458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} 1546458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(unsigned OpNo, char Modifier) 1547458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner : MyKind(Operand), Str(), OperandNo(OpNo) { 1548458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Str += Modifier; 1549458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 15501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1551458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isString() const { return MyKind == String; } 1552458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isOperand() const { return MyKind == Operand; } 15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1554458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const std::string &getString() const { 1555458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isString()); 1556458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str; 1557458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1558458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1559458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned getOperandNo() const { 1560458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1561458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return OperandNo; 1562458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1564458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// getModifier - Get the modifier for this operand, if present. This 1565458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// returns '\0' if there was no modifier. 1566458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner char getModifier() const { 1567458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1568458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str[0]; 1569458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1570458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1572458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 1573458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// it into pieces. If the asm string is erroneous, emit errors and return 1574458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// true, otherwise return false. This handles canonicalization and 1575458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// translation of strings from GCC syntax to LLVM IR syntax, and handles 15761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump //// flattening of named references like %[foo] to Operand AsmStringPiece's. 1577686775deca8b8685eb90801495880e3abdd844c2Chris Lattner unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces, 15788b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper const ASTContext &C, unsigned &DiagOffs) const; 15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1580da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier /// Assemble final IR asm string. 15818b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper std::string generateAsmString(const ASTContext &C) const; 15821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1583b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Output operands ---===// 1584b327793860737d1c103a73aeda8057dd628a101dChris Lattner 1585aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall IdentifierInfo *getOutputIdentifier(unsigned i) const { 1586aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return Names[i]; 1587aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1588aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1589aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef getOutputName(unsigned i) const { 1590aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall if (IdentifierInfo *II = getOutputIdentifier(i)) 1591aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return II->getName(); 1592aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1593aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return StringRef(); 1594aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1595aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1596686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getOutputConstraint(unsigned i) const; 15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1598b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getOutputConstraintLiteral(unsigned i) const { 1599ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i]; 1600ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1601b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getOutputConstraintLiteral(unsigned i) { 1602b327793860737d1c103a73aeda8057dd628a101dChris Lattner return Constraints[i]; 1603b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1605ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getOutputExpr(unsigned i); 16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1607b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getOutputExpr(unsigned i) const { 1608df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i); 1609b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1611b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Input operands ---===// 16121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1613aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall IdentifierInfo *getInputIdentifier(unsigned i) const { 1614aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return Names[i + NumOutputs]; 1615aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1616aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1617aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef getInputName(unsigned i) const { 1618aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall if (IdentifierInfo *II = getInputIdentifier(i)) 1619aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return II->getName(); 1620aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1621aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return StringRef(); 1622aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1623aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1624686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getInputConstraint(unsigned i) const; 16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1626b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getInputConstraintLiteral(unsigned i) const { 1627ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1628ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1629b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getInputConstraintLiteral(unsigned i) { 1630ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1631ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1633ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getInputExpr(unsigned i); 1634935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner void setInputExpr(unsigned i, Expr *E); 1635ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1636b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getInputExpr(unsigned i) const { 1637df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier return const_cast<GCCAsmStmt*>(this)->getInputExpr(i); 1638b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 1639cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1640aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate: 16418b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper void setOutputsAndInputsAndClobbers(const ASTContext &C, 1642ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1643fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Constraints, 1644fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson Stmt **Exprs, 1645fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumOutputs, 1646ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie unsigned NumInputs, 1647fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Clobbers, 1648fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumClobbers); 1649aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic: 1650cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 165110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner //===--- Other ---===// 16521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 165310ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// getNamedOperand - Given a symbolic operand reference like %[foo], 165410ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// translate this into a numeric value needed to reference the same operand. 165510ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// This returns -1 if the operand name is invalid. 1656686775deca8b8685eb90801495880e3abdd844c2Chris Lattner int getNamedOperand(StringRef SymbolicName) const; 165710ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner 165833f0558f75f70061707d1388e305b8f92f4e55deChad Rosier StringRef getClobber(unsigned i) const; 16595c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; } 16605c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier const StringLiteral *getClobberStringLiteral(unsigned i) const { 16615c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier return Clobbers[i]; 16625c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier } 1663cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 166465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; } 166565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 16661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1667df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier static bool classof(const Stmt *T) { 1668df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier return T->getStmtClass() == GCCAsmStmtClass; 1669df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier } 1670fe795956194141c91ae555985c9b930595bff43fChris Lattner}; 167178492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek 16727d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a Microsoft inline-assembly statement extension. 16738cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier/// 1674728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass MSAsmStmt : public AsmStmt { 1675c4cca7b2408bdfd99ea0f63fec1421c1327593b2Enea Zaffanella SourceLocation LBraceLoc, EndLoc; 1676aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef AsmStr; 16778cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 167879efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier unsigned NumAsmToks; 167979efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier 168079efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier Token *AsmToks; 168189fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier StringRef *Constraints; 168233c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier StringRef *Clobbers; 16838cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1684aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall friend class ASTStmtReader; 1685aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 16868cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic: 16870b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper MSAsmStmt(const ASTContext &C, SourceLocation asmloc, 16880b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper SourceLocation lbraceloc, bool issimple, bool isvolatile, 16890b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs, 1690aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall ArrayRef<StringRef> constraints, 1691e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier ArrayRef<Expr*> exprs, StringRef asmstr, 169289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier ArrayRef<StringRef> clobbers, SourceLocation endloc); 16938cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1694cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier /// \brief Build an empty MS-style inline-assembly statement. 1695728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty), 169689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { } 1697cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier 16987bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier SourceLocation getLBraceLoc() const { return LBraceLoc; } 16997bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier void setLBraceLoc(SourceLocation L) { LBraceLoc = L; } 17008cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier SourceLocation getEndLoc() const { return EndLoc; } 17018cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier void setEndLoc(SourceLocation L) { EndLoc = L; } 17028cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 17037bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier bool hasBraces() const { return LBraceLoc.isValid(); } 17047bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier 170579efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier unsigned getNumAsmToks() { return NumAsmToks; } 170679efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier Token *getAsmToks() { return AsmToks; } 17078f726de55412870ef70e788b852c6cc50873e15bChad Rosier 17088cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier //===--- Asm String Analysis ---===// 1709aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef getAsmString() const { return AsmStr; } 17108cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1711da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier /// Assemble final IR asm string. 17128b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper std::string generateAsmString(const ASTContext &C) const; 1713da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier 17142603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier //===--- Output operands ---===// 17152603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 171689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier StringRef getOutputConstraint(unsigned i) const { 1717aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall assert(i < NumOutputs); 171889fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier return Constraints[i]; 171989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier } 1720c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1721633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier Expr *getOutputExpr(unsigned i); 1722633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier 17232603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier const Expr *getOutputExpr(unsigned i) const { 17242603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier return const_cast<MSAsmStmt*>(this)->getOutputExpr(i); 17252603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier } 17262603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 17272603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier //===--- Input operands ---===// 17282603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 172989fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier StringRef getInputConstraint(unsigned i) const { 1730aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall assert(i < NumInputs); 173189fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier return Constraints[i + NumOutputs]; 173289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier } 1733c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1734633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier Expr *getInputExpr(unsigned i); 1735633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier void setInputExpr(unsigned i, Expr *E); 1736633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier 17372603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier const Expr *getInputExpr(unsigned i) const { 17382603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier return const_cast<MSAsmStmt*>(this)->getInputExpr(i); 17392603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier } 17402603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 17418cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier //===--- Other ---===// 17428cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1743aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall ArrayRef<StringRef> getAllConstraints() const { 1744aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return ArrayRef<StringRef>(Constraints, NumInputs + NumOutputs); 1745aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1746aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall ArrayRef<StringRef> getClobbers() const { 1747aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return ArrayRef<StringRef>(Clobbers, NumClobbers); 1748aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1749aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall ArrayRef<Expr*> getAllExprs() const { 1750aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return ArrayRef<Expr*>(reinterpret_cast<Expr**>(Exprs), 1751aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall NumInputs + NumOutputs); 1752aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1753aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1754aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef getClobber(unsigned i) const { return getClobbers()[i]; } 1755aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1756aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate: 17570b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void initialize(const ASTContext &C, StringRef AsmString, 17580b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints, 17590b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers); 1760aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic: 17614399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier 176265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; } 176365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; } 176465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 17658cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier static bool classof(const Stmt *T) { 17668cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return T->getStmtClass() == MSAsmStmtClass; 17678cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 17688cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 17698cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier child_range children() { 17708cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return child_range(&Exprs[0], &Exprs[0]); 17718cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 17728cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier}; 17738cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 177428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt { 177528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 177628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 177728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 177828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { FILTER_EXPR, BLOCK }; 177928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 178028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt(SourceLocation Loc, 178128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 178228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 178328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 17847110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 17857110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 17867110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { } 17877110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 178828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 17890b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static SEHExceptStmt* Create(const ASTContext &C, 179028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation ExceptLoc, 179128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 179228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 179365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 179465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); } 179565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 179628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 179728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getExceptLoc() const { return Loc; } 179828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); } 179928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1800ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr *getFilterExpr() const { 1801ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); 1802ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 1803ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1804ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CompoundStmt *getBlock() const { 1805cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko return cast<CompoundStmt>(Children[BLOCK]); 1806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 180728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 180828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 180928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 181028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 181128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 181228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 181328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHExceptStmtClass; 181428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 181528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 181628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 181728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 181828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt { 181928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 182028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block; 182128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 182228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt(SourceLocation Loc, 182328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 182428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 18257110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 18267110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 18277110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { } 18287110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 182928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 18300b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static SEHFinallyStmt* Create(const ASTContext &C, 183128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation FinallyLoc, 183228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 183328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 183465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); } 183565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 183628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 183728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getFinallyLoc() const { return Loc; } 183828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Block->getLocEnd(); } 183928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1840cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); } 184128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 184228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 184328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(&Block,&Block+1); 184428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 184528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 184628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 184728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHFinallyStmtClass; 184828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 184928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 185028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 185128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 185228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt { 185328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool IsCXXTry; 185428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc; 185528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 185628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 185728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { TRY = 0, HANDLER = 1 }; 185828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 185928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try' 186028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 186128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 186228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 186328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 18647110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 18657110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 18667110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { } 18677110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 186828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 18690b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry, 18700b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper SourceLocation TryLoc, Stmt *TryBlock, 187128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 187228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 187365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); } 187465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 187528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 187628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getTryLoc() const { return TryLoc; } 187728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); } 187828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 187928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool getIsCXXTry() const { return IsCXXTry; } 1880ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1881ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CompoundStmt* getTryBlock() const { 1882cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko return cast<CompoundStmt>(Children[TRY]); 1883ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 1884ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 188528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *getHandler() const { return Children[HANDLER]; } 188628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 188728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// Returns 0 if not defined 188828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt *getExceptHandler() const; 188928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt *getFinallyHandler() const; 189028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 189128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 189228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 189328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 189428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 189528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 189628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHTryStmtClass; 189728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 189828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 1899ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1900051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// \brief This captures a statement into a function. For example, the following 1901051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// pragma annotated compound statement can be represented as a CapturedStmt, 1902051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// and this compound statement is the body of an anonymous outlined function. 1903051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @code 1904051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// #pragma omp parallel 1905051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// { 1906051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// compute(); 1907051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// } 1908051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @endcode 1909051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajclass CapturedStmt : public Stmt { 1910051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic: 1911051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The different capture forms: by 'this' or by reference, etc. 1912051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj enum VariableCaptureKind { 1913051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VCK_This, 1914051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VCK_ByRef 1915051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj }; 1916051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1917051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Describes the capture of either a variable or 'this'. 1918051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj class Capture { 19193a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir llvm::PointerIntPair<VarDecl *, 1, VariableCaptureKind> VarAndKind; 1920051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation Loc; 1921051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1922051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj public: 1923051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Create a new capture. 1924051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1925051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \param Loc The source location associated with this capture. 1926051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1927051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \param Kind The kind of capture (this, ByRef, ...). 1928051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1929051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \param Var The variable being captured, or null if capturing this. 1930051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1931051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var = 0) 19323a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir : VarAndKind(Var, Kind), Loc(Loc) { 1933051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj switch (Kind) { 1934051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj case VCK_This: 1935051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj assert(Var == 0 && "'this' capture cannot have a variable!"); 1936051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj break; 1937051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj case VCK_ByRef: 1938051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj assert(Var && "capturing by reference must have a variable!"); 1939051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj break; 1940051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1941051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1942051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1943051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Determine the kind of capture. 19443a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir VariableCaptureKind getCaptureKind() const { return VarAndKind.getInt(); } 1945051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1946051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the source location at which the variable or 'this' was 1947051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// first used. 1948051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation getLocation() const { return Loc; } 1949051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1950051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Determine whether this capture handles the C++ 'this' pointer. 19513a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir bool capturesThis() const { return getCaptureKind() == VCK_This; } 1952051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1953051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Determine whether this capture handles a variable. 19543a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir bool capturesVariable() const { return getCaptureKind() != VCK_This; } 1955051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1956051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the declaration of the variable being captured. 1957051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1958051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// This operation is only valid if this capture does not capture 'this'. 1959051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VarDecl *getCapturedVar() const { 1960051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj assert(!capturesThis() && "No variable available for 'this' capture"); 19613a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir return VarAndKind.getPointer(); 1962051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1963dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir friend class ASTStmtReader; 1964051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj }; 1965051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1966051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajprivate: 1967051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The number of variable captured, including 'this'. 1968051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj unsigned NumCaptures; 1969051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 19709fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief The pointer part is the implicit the outlined function and the 19719fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// int part is the captured region kind, 'CR_Default' etc. 19729fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind; 1973051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1974051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl. 1975051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj RecordDecl *TheRecordDecl; 1976051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1977051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Construct a captured statement. 19789fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures, 19799fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD); 1980051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1981051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Construct an empty captured statement. 1982051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj CapturedStmt(EmptyShell Empty, unsigned NumCaptures); 1983051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1984051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Stmt **getStoredStmts() const { 1985051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1); 1986051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1987051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1988051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Capture *getStoredCaptures() const; 1989051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1990dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; } 1991dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir 1992051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic: 19930b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static CapturedStmt *Create(const ASTContext &Context, Stmt *S, 19949fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapturedRegionKind Kind, 1995051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj ArrayRef<Capture> Captures, 1996051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj ArrayRef<Expr *> CaptureInits, 19976afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj CapturedDecl *CD, RecordDecl *RD); 1998051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 19990b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static CapturedStmt *CreateDeserialized(const ASTContext &Context, 2000051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj unsigned NumCaptures); 2001051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2002051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the statement being captured. 2003051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; } 2004051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj const Stmt *getCapturedStmt() const { 2005051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return const_cast<CapturedStmt *>(this)->getCapturedStmt(); 2006051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2007051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2008051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the outlined function declaration. 20099fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapturedDecl *getCapturedDecl() { return CapDeclAndKind.getPointer(); } 20109fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan const CapturedDecl *getCapturedDecl() const { 20119fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan return const_cast<CapturedStmt *>(this)->getCapturedDecl(); 20129fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 20139fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan 20149fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief Set the outlined function declaration. 20159fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan void setCapturedDecl(CapturedDecl *D) { 20169fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan assert(D && "null CapturedDecl"); 20179fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapDeclAndKind.setPointer(D); 20189fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 20199fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan 20209fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief Retrieve the captured region kind. 20219fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapturedRegionKind getCapturedRegionKind() const { 20229fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan return CapDeclAndKind.getInt(); 20239fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 20249fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan 20259fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief Set the captured region kind. 20269fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan void setCapturedRegionKind(CapturedRegionKind Kind) { 20279fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapDeclAndKind.setInt(Kind); 20289fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 2029051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2030051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the record declaration for captured variables. 2031051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; } 2032051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 20339fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief Set the record declaration for captured variables. 20349fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan void setCapturedRecordDecl(RecordDecl *D) { 20359fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan assert(D && "null RecordDecl"); 20369fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan TheRecordDecl = D; 20379fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 20389fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan 2039051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief True if this variable has been captured. 2040051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj bool capturesVariable(const VarDecl *Var) const; 2041051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2042051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief An iterator that walks over the captures. 2043dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir typedef Capture *capture_iterator; 2044dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir typedef const Capture *const_capture_iterator; 2045051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2046051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve an iterator pointing to the first capture. 2047dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir capture_iterator capture_begin() { return getStoredCaptures(); } 2048dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir const_capture_iterator capture_begin() const { return getStoredCaptures(); } 2049051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2050051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve an iterator pointing past the end of the sequence of 2051051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// captures. 2052051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_iterator capture_end() const { 2053051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getStoredCaptures() + NumCaptures; 2054051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2055051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2056051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the number of captures, including 'this'. 2057051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj unsigned capture_size() const { return NumCaptures; } 2058051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2059051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Iterator that walks over the capture initialization arguments. 2060051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj typedef Expr **capture_init_iterator; 2061051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2062051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the first initialization argument. 2063051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_init_iterator capture_init_begin() const { 2064051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return reinterpret_cast<Expr **>(getStoredStmts()); 2065051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2066051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2067051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the iterator pointing one past the last initialization 2068051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// argument. 2069051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_init_iterator capture_init_end() const { 2070051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return capture_init_begin() + NumCaptures; 2071051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2072051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2073051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation getLocStart() const LLVM_READONLY { 2074051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getCapturedStmt()->getLocStart(); 2075051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2076051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation getLocEnd() const LLVM_READONLY { 2077051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getCapturedStmt()->getLocEnd(); 2078051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2079051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceRange getSourceRange() const LLVM_READONLY { 2080051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getCapturedStmt()->getSourceRange(); 2081051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2082051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2083051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj static bool classof(const Stmt *T) { 2084051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return T->getStmtClass() == CapturedStmtClass; 2085051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2086051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2087051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj child_range children(); 2088dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir 2089dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir friend class ASTStmtReader; 2090051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj}; 2091051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 20925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 20935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2095