Stmt.h revision 651f13cea278ec967336033dd032faef0e9fc2ec
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(). 374651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void dump() const; 375651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 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. 379651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 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; 488651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<decl_iterator> decl_range; 489651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<const_decl_iterator> decl_const_range; 4901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 491651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines decl_range decls() { return decl_range(decl_begin(), decl_end()); } 492651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines decl_const_range decls() const { 493651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return decl_const_range(decl_begin(), decl_end()); 494651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 4958ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_begin() { return DG.begin(); } 4968ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_end() { return DG.end(); } 4978ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_begin() const { return DG.begin(); } 4988ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_end() const { return DG.end(); } 499fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose 500fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator; 501fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose reverse_decl_iterator decl_rbegin() { 502fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose return reverse_decl_iterator(decl_end()); 503fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose } 504fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose reverse_decl_iterator decl_rend() { 505fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose return reverse_decl_iterator(decl_begin()); 506fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose } 5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3. 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt { 5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation SemiLoc; 51344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 514e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis /// \brief True if the null statement was preceded by an empty macro, e.g: 51544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @code 51644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// #define CALL(x) 51744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// CALL(0); 51844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @endcode 519e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis bool HasLeadingEmptyMacro; 5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 521e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false) 522e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis : Stmt(NullStmtClass), SemiLoc(L), 523e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis HasLeadingEmptyMacro(hasLeadingEmptyMacro) {} 5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 525025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty null statement. 526e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty), 527e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis HasLeadingEmptyMacro(false) { } 528025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getSemiLoc() const { return SemiLoc; } 530025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSemiLoc(SourceLocation L) { SemiLoc = L; } 531b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 532e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; } 53344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 53465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; } 53565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; } 5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == NullStmtClass; 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 54244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 54344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtReader; 54444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtWriter; 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }. 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt { 5508189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek Stmt** Body; 551b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation LBracLoc, RBracLoc; 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5530b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, 5543a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer SourceLocation LB, SourceLocation RB); 5553a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer 556063820655db8121f0022a7c51458463c7250324cBenjamin Kramer // \brief Build an empty compound statement with a location. 5573a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer explicit CompoundStmt(SourceLocation Loc) 5583a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) { 5593a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer CompoundStmtBits.NumStmts = 0; 5601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 561025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 562025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor // \brief Build an empty compound statement. 563025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CompoundStmt(EmptyShell Empty) 5648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass, Empty), Body(0) { 5658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = 0; 5668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 567025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5688b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper void setStmts(const ASTContext &C, Stmt **Stmts, unsigned NumStmts); 5691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } 5718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned size() const { return CompoundStmtBits.NumStmts; } 572025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5738189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt** body_iterator; 574651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<body_iterator> body_range; 575651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 576651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines body_range body() { return body_range(body_begin(), body_end()); } 5778189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek body_iterator body_begin() { return Body; } 5788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall body_iterator body_end() { return Body + size(); } 5798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; } 580ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setLastStmt(Stmt *S) { 5828e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall assert(!body_empty() && "setLastStmt"); 5838e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Body[size()-1] = S; 5848e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt* const * const_body_iterator; 587651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<const_body_iterator> body_const_range; 588651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 589651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines body_const_range body() const { 590651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return body_const_range(body_begin(), body_end()); 591651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_body_iterator body_begin() const { return Body; } 5938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const_body_iterator body_end() const { return Body + size(); } 5948e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; } 5958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek 5968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<body_iterator> reverse_body_iterator; 5978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rbegin() { 5988189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_end()); 5998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6008189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rend() { 6018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_begin()); 6028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6034ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 6048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<const_body_iterator> 6058189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator; 6064ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 6078189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rbegin() const { 6088189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_end()); 6098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rend() const { 6128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_begin()); 6138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; } 61665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; } 6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 618cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getLBracLoc() const { return LBracLoc; } 619025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setLBracLoc(SourceLocation L) { LBracLoc = L; } 620cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getRBracLoc() const { return RBracLoc; } 621025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setRBracLoc(SourceLocation L) { RBracLoc = L; } 6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundStmtClass; 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6278297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 62863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 629651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return child_range(Body, Body + CompoundStmtBits.NumStmts); 63063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 631ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6328ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek const_child_range children() const { 633651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return child_range(Body, Body + CompoundStmtBits.NumStmts); 6348ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek } 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 637c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt, 638c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt { 639103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected: 640c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // A pointer to the following CaseStmt or DefaultStmt class, 641c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // used by SwitchStmt. 642c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *NextSwitchCase; 64381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation KeywordLoc; 64481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation ColonLoc; 64581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis 64681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc) 64781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {} 648103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek 64981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SwitchCase(StmtClass SC, EmptyShell) 65081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : Stmt(SC), NextSwitchCase(0) {} 6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 652c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic: 653c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } 654c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 655c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getNextSwitchCase() { return NextSwitchCase; } 656c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 657c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } 658d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek 65981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getKeywordLoc() const { return KeywordLoc; } 66081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setKeywordLoc(SourceLocation L) { KeywordLoc = L; } 66181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getColonLoc() const { return ColonLoc; } 66281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setColonLoc(SourceLocation L) { ColonLoc = L; } 66381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis 66463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt *getSubStmt(); 665702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner const Stmt *getSubStmt() const { 666702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner return const_cast<SwitchCase*>(this)->getSubStmt(); 667702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner } 668b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 66981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } 67081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocEnd() const LLVM_READONLY; 6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass || 67463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall T->getStmtClass() == DefaultStmtClass; 675c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 676c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson}; 677c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 678c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase { 6790a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor enum { LHS, RHS, SUBSTMT, END_EXPR }; 6801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 681d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // GNU "case 1 ... 4" extension 682dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation EllipsisLoc; 6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 684dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, 6851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation ellipsisLoc, SourceLocation colonLoc) 68681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : SwitchCase(CaseStmtClass, caseLoc, colonLoc) { 68724e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner SubExprs[SUBSTMT] = 0; 688d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 689d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 690dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor EllipsisLoc = ellipsisLoc; 691d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek } 692025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 693025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty switch case statement. 69481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { } 695025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 69681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getCaseLoc() const { return KeywordLoc; } 69781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setCaseLoc(SourceLocation L) { KeywordLoc = L; } 698dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 699dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } 700dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 701dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 702025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 703d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 704d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 705d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 706025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 7071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getLHS() const { 7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[LHS]); 70951b09f2c528c8460b5465c676173324e44176d62Devang Patel } 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getRHS() const { 7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[RHS]); 71251b09f2c528c8460b5465c676173324e44176d62Devang Patel } 71351b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 71520dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; } 71620dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } 71720dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } 7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } 72065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 7213fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner // Handle deeply nested case statements with iteration instead of recursion. 7223fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner const CaseStmt *CS = this; 72391ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) 7243fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner CS = CS2; 7251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return CS->getSubStmt()->getLocEnd(); 727b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 72865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 7291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass; 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 733d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 73463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 73563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[END_EXPR]); 73663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 739c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase { 740d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt* SubStmt; 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : 74381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {} 744025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 745025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty default statement. 74681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis explicit DefaultStmt(EmptyShell Empty) 74781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : SwitchCase(DefaultStmtClass, Empty) { } 748025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 749d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubStmt; } 75051b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubStmt; } 751025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSubStmt(Stmt *S) { SubStmt = S; } 752025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 75381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getDefaultLoc() const { return KeywordLoc; } 75481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setDefaultLoc(SourceLocation L) { KeywordLoc = L; } 755dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 756dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 75881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } 75965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} 76065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 7611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DefaultStmtClass; 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 765d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 76663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 76981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidisinline SourceLocation SwitchCase::getLocEnd() const { 77081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis if (const CaseStmt *CS = dyn_cast<CaseStmt>(this)) 77181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis return CS->getLocEnd(); 77281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis return cast<DefaultStmt>(this)->getLocEnd(); 77381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis} 774ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 775ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement. For example: 776ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// foo: return; 777ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt { 779ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *TheDecl; 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *SubStmt; 781b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IdentLoc; 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 783ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt) 784ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) { 7858e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 7861de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 7871de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor // \brief Build an empty label statement. 7881de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { } 7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getIdentLoc() const { return IdentLoc; } 791ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getDecl() const { return TheDecl; } 792ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setDecl(LabelDecl *D) { TheDecl = D; } 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *getSubStmt() { return SubStmt; } 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Stmt *getSubStmt() const { return SubStmt; } 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setIdentLoc(SourceLocation L) { IdentLoc = L; } 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setSubStmt(Stmt *SS) { SubStmt = SS; } 798b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 79965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; } 80065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} 80165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 80263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 80363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == LabelStmtClass; 8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 810534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement. 811534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// 812534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example: 813534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// [[omp::for(...)]] for (...) { ... } 814534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// 815534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt { 816534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *SubStmt; 817534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation AttrLoc; 8184990890fc9428f98bef90ba349203a648c592778Alexander Kornienko unsigned NumAttrs; 8194990890fc9428f98bef90ba349203a648c592778Alexander Kornienko const Attr *Attrs[1]; 820534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 821534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith friend class ASTStmtReader; 822534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8234990890fc9428f98bef90ba349203a648c592778Alexander Kornienko AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt) 8244990890fc9428f98bef90ba349203a648c592778Alexander Kornienko : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc), 8254990890fc9428f98bef90ba349203a648c592778Alexander Kornienko NumAttrs(Attrs.size()) { 8264990890fc9428f98bef90ba349203a648c592778Alexander Kornienko memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*)); 827534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 828534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8294990890fc9428f98bef90ba349203a648c592778Alexander Kornienko explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) 8304990890fc9428f98bef90ba349203a648c592778Alexander Kornienko : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) { 8314990890fc9428f98bef90ba349203a648c592778Alexander Kornienko memset(Attrs, 0, NumAttrs * sizeof(Attr*)); 832534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 833534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8344990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic: 8350b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc, 8364990890fc9428f98bef90ba349203a648c592778Alexander Kornienko ArrayRef<const Attr*> Attrs, Stmt *SubStmt); 8374990890fc9428f98bef90ba349203a648c592778Alexander Kornienko // \brief Build an empty attributed statement. 8380b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs); 8394990890fc9428f98bef90ba349203a648c592778Alexander Kornienko 840534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation getAttrLoc() const { return AttrLoc; } 8414990890fc9428f98bef90ba349203a648c592778Alexander Kornienko ArrayRef<const Attr*> getAttrs() const { 8424990890fc9428f98bef90ba349203a648c592778Alexander Kornienko return ArrayRef<const Attr*>(Attrs, NumAttrs); 8434990890fc9428f98bef90ba349203a648c592778Alexander Kornienko } 844534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *getSubStmt() { return SubStmt; } 845534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith const Stmt *getSubStmt() const { return SubStmt; } 846534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 84765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; } 84865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} 84965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 850534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith child_range children() { return child_range(&SubStmt, &SubStmt + 1); } 851534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 852534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith static bool classof(const Stmt *T) { 853534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return T->getStmtClass() == AttributedStmtClass; 854534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 855534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith}; 856534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 857534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else. 8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt { 86143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, THEN, ELSE, END_EXPR }; 8628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 8638cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor 864b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IfLoc; 865d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation ElseLoc; 866ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8680b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, 86944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0); 870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 871025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty if/then/else statement 872025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { } 873025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 8748cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \brief Retrieve the variable declared in this "if" statement, if any. 8758cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// 8768cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// In the following example, "x" is the condition variable. 8778cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \code 8788cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// if (int x = foo()) { 8798cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// printf("x is %d", x); 8808cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// } 8818cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \endcode 88243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 8830b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void setConditionVariable(const ASTContext &C, VarDecl *V); 884ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 885d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this IfStmt has a condition variable, return the faux DeclStmt 886d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 887d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 888d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 889d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 890ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8918297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 892025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 8938297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getThen() const { return SubExprs[THEN]; } 8941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setThen(Stmt *S) { SubExprs[THEN] = S; } 8958297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getElse() const { return SubExprs[ELSE]; } 896025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setElse(Stmt *S) { SubExprs[ELSE] = S; } 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8988297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 8998297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getThen() { return SubExprs[THEN]; } 9008297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getElse() { return SubExprs[ELSE]; } 901b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 902025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getIfLoc() const { return IfLoc; } 903025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setIfLoc(SourceLocation L) { IfLoc = L; } 904d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation getElseLoc() const { return ElseLoc; } 905d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor void setElseLoc(SourceLocation L) { ElseLoc = L; } 906025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 90765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; } 90865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 909b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff if (SubExprs[ELSE]) 91065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[ELSE]->getLocEnd(); 911b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff else 91265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[THEN]->getLocEnd(); 913b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators over subexpressions. The iterators will include iterating 91663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // over the initialization expression referenced by the condition variable. 91763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 91863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 91963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 92063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IfStmtClass; 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt. 9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt { 92943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 931c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // This points to a linked list of case and default statements. 932c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *FirstCase; 9339dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SourceLocation SwitchLoc; 9341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 935559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// If the SwitchStmt is a switch on an enum value, this records whether 936559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// all the enum values were covered by CaseStmts. This value is meant to 937559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// be a hint for possible clients. 938559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek unsigned AllEnumCasesCovered : 1; 939559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9410b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond); 9421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 943025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build a empty switch statement. 944025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { } 945025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 946d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \brief Retrieve the variable declared in this "switch" statement, if any. 947d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// 948d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// In the following example, "x" is the condition variable. 949d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \code 950d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// switch (int x = foo()) { 951d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// case 0: break; 952d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// // ... 953d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// } 954d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \endcode 95543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 9560b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void setConditionVariable(const ASTContext &C, VarDecl *V); 957ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 958d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this SwitchStmt has a condition variable, return the faux DeclStmt 959d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 960d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 961d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 962d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 963d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor 9648297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 9658297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 966c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getSwitchCaseList() const { return FirstCase; } 967c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 9688297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 969025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 9708297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 971025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 972c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getSwitchCaseList() { return FirstCase; } 9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 97443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Set the case list for this switch statement. 975025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } 976025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 977025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getSwitchLoc() const { return SwitchLoc; } 978025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchLoc(SourceLocation L) { SwitchLoc = L; } 979c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 9801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setBody(Stmt *S, SourceLocation SL) { 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SubExprs[BODY] = S; 9829dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SwitchLoc = SL; 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 984c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void addSwitchCase(SwitchCase *SC) { 985ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(!SC->getNextSwitchCase() 986ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie && "case/default already added to a switch"); 987c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor SC->setNextSwitchCase(FirstCase); 988c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson FirstCase = SC; 989c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 990559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 991559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a 992559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// switch over an enum value then all cases have been explicitly covered. 993559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek void setAllEnumCasesCovered() { 994559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek AllEnumCasesCovered = 1; 995559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 996559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 997559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Returns true if the SwitchStmt is a switch of an enum value and all cases 998559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// have been explicitly covered. 999559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek bool isAllEnumCasesCovered() const { 1000559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek return (bool) AllEnumCasesCovered; 1001559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 1002559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 100365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; } 100465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 100565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BODY]->getLocEnd(); 10069dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff } 100765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 100863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators 100963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 101063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 101163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 101263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 10131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SwitchStmtClass; 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt. 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt { 102243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 10238297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 1024b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation WhileLoc; 10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10260b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 102743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SourceLocation WL); 10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1029d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty while statement. 1030d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { } 1031d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 10325656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Retrieve the variable declared in this "while" statement, if any. 10335656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// 10345656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// In the following example, "x" is the condition variable. 10355656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \code 10365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// while (int x = random()) { 10375656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// // ... 10385656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// } 10395656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \endcode 104043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 10410b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void setConditionVariable(const ASTContext &C, VarDecl *V); 10425656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 1043d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this WhileStmt has a condition variable, return the faux DeclStmt 1044d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 1045d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 1046d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 1047d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 1048d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 10498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 10508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 1051d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 10528297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 10538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 1054d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 1055d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1056d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 1057d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1058b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 105965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; } 106065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 106165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BODY]->getLocEnd(); 1062b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 106365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == WhileStmtClass; 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10688297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 106963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 107063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 107163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt. 10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt { 1077c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor enum { BODY, COND, END_EXPR }; 10788297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 1079b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation DoLoc; 10809f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation WhileLoc; 1081989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RParenLoc; // Location of final ')' in do stmt condition. 10829f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor 10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1084989135901c750af61ef012b6b0a0368be415bc46Chris Lattner DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL, 1085989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RP) 1086989135901c750af61ef012b6b0a0368be415bc46Chris Lattner : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) { 10878297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 10888297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[BODY] = body; 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 109067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 109167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty do-while statement. 109267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { } 10931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10948297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 10958297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 109667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 10978297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Stmt *getBody() const { return SubExprs[BODY]; } 109967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 110067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 110167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getDoLoc() const { return DoLoc; } 110267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setDoLoc(SourceLocation L) { DoLoc = L; } 11039f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 11049f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1105b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 1106989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 1107989135901c750af61ef012b6b0a0368be415bc46Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1108989135901c750af61ef012b6b0a0368be415bc46Chris Lattner 110965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; } 111065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 111165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DoStmtClass; 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11158297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 11168297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 111763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 111863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 111963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source. 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt { 112843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; 11298297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 1130b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation ForLoc; 11315831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation LParenLoc, RParenLoc; 11325831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11340b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, 11350b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, 11360b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper SourceLocation RP); 11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty for statement. 113967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { } 114067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 11418297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getInit() { return SubExprs[INIT]; } 1142ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 114399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \brief Retrieve the variable declared in this "for" statement, if any. 114499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// 114599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// In the following example, "y" is the condition variable. 114699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \code 114799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// for (int x = random(); int y = mangle(x); ++x) { 114899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// // ... 114999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// } 115099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \endcode 115143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 11520b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void setConditionVariable(const ASTContext &C, VarDecl *V); 1153ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1154d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this ForStmt has a condition variable, return the faux DeclStmt 1155d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 1156d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 1157d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]); 1158d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 1159d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 11608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 11618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 11628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 11638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 11648297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getInit() const { return SubExprs[INIT]; } 11658297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 11668297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 11678297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 1168b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 116967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInit(Stmt *S) { SubExprs[INIT] = S; } 117067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 117167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } 117267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 117367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 117467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getForLoc() const { return ForLoc; } 117567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setForLoc(SourceLocation L) { ForLoc = L; } 11765831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 11775831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 11785831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 11795831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 118067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 118165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; } 118265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 118365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BODY]->getLocEnd(); 1184b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 118565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ForStmtClass; 11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11908297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 119163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 119263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 119363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto. 11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt { 1199ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 1200507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation GotoLoc; 120161f62165220e75694fe333179c78815e2e48d71fTed Kremenek SourceLocation LabelLoc; 12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1203ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL) 120461f62165220e75694fe333179c78815e2e48d71fTed Kremenek : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 12051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12061de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor /// \brief Build an empty goto statement. 12071de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { } 12081de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 1209ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 1210ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *D) { Label = D; } 12111de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 12121de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getGotoLoc() const { return GotoLoc; } 12131de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setGotoLoc(SourceLocation L) { GotoLoc = L; } 12141de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 12151de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 1216b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 121765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; } 121865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; } 121965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 12201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GotoStmtClass; 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12248297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 122563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto. 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt { 1231ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation GotoLoc; 12325f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation StarLoc; 12331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Target; 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, 12365f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Expr *target) 12375f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc), 12385f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Target((Stmt*)target) {} 12397d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 12407d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty indirect goto statement. 12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IndirectGotoStmt(EmptyShell Empty) 12427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Stmt(IndirectGotoStmtClass, Empty) { } 12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1244ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner void setGotoLoc(SourceLocation L) { GotoLoc = L; } 1245ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation getGotoLoc() const { return GotoLoc; } 12465f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor void setStarLoc(SourceLocation L) { StarLoc = L; } 12475f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation getStarLoc() const { return StarLoc; } 12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 124995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall Expr *getTarget() { return reinterpret_cast<Expr*>(Target); } 125095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);} 12517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); } 1252b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 125395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// getConstantTarget - Returns the fixed target of this indirect 125495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// goto, if one exists. 1255ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getConstantTarget(); 1256ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner const LabelDecl *getConstantTarget() const { 125795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall return const_cast<IndirectGotoStmt*>(this)->getConstantTarget(); 125895c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall } 125995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall 126065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; } 126165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); } 12621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IndirectGotoStmtClass; 12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12678297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 126863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Target, &Target+1); } 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue. 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt { 1275507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation ContinueLoc; 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1277507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {} 12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1279d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty continue statement. 1280d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { } 1281d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1282d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getContinueLoc() const { return ContinueLoc; } 1283d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setContinueLoc(SourceLocation L) { ContinueLoc = L; } 1284d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 128565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; } 128665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; } 1287861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor 12881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ContinueStmtClass; 12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12928297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 129363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break. 12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt { 1299507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation BreakLoc; 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1301507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1303025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty break statement. 1304025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { } 1305025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1306025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getBreakLoc() const { return BreakLoc; } 1307025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBreakLoc(SourceLocation L) { BreakLoc = L; } 1308025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 130965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; } 131065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; } 1311b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 13121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BreakStmtClass; 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13168297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 131763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1321c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression: 1322c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return; 1323c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return 4; 1324c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// 1325c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to 1326c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to 1327c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void. We explicitly model this in the AST, which means you can't 1328c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument. 13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt { 13311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *RetExpr; 1332507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation RetLoc; 13335077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *NRVOCandidate; 1334ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13365077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL) 133725a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { } 13385077c3876beeaed32280af88244e8050078619a8Douglas Gregor 13395077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) 13405077c3876beeaed32280af88244e8050078619a8Douglas Gregor : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL), 13415077c3876beeaed32280af88244e8050078619a8Douglas Gregor NRVOCandidate(NRVOCandidate) {} 13420de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13430de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor /// \brief Build an empty return expression. 13440de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { } 13450de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getRetValue() const; 13471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getRetValue(); 13480de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); } 13490de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13500de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor SourceLocation getReturnLoc() const { return RetLoc; } 13510de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setReturnLoc(SourceLocation L) { RetLoc = L; } 1352b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 13535077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// \brief Retrieve the variable that might be used for the named return 13545077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// value optimization. 13555077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// 13565077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// The optimization itself can only be performed if the variable is 13575077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// also marked as an NRVO object. 13585077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *getNRVOCandidate() const { return NRVOCandidate; } 13595077c3876beeaed32280af88244e8050078619a8Douglas Gregor void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; } 1360ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 136165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; } 136265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 136365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return RetExpr ? RetExpr->getLocEnd() : RetLoc; 136465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ReturnStmtClass; 13685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13708297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 137163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 137263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (RetExpr) return child_range(&RetExpr, &RetExpr+1); 137363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 137463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1377728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt. 1378728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// 1379728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass AsmStmt : public Stmt { 1380728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierprotected: 1381066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier SourceLocation AsmLoc; 138212b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// \brief True if the assembly statement does not have any input or output 138312b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// operands. 1384728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool IsSimple; 138512b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier 138612b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// \brief If true, treat this inline assembly as having side effects. 138712b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// This assembly statement should not be optimized, deleted or moved. 1388728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool IsVolatile; 1389728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1390066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned NumOutputs; 1391066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned NumInputs; 1392066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned NumClobbers; 1393066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 139419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier Stmt **Exprs; 1395066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1396066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile, 1397066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned numoutputs, unsigned numinputs, unsigned numclobbers) : 1398066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile), 1399066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { } 1400728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1401aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall friend class ASTStmtReader; 1402aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1403728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierpublic: 1404728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier /// \brief Build an empty inline-assembly statement. 1405728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier explicit AsmStmt(StmtClass SC, EmptyShell Empty) : 1406aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall Stmt(SC, Empty), Exprs(0) { } 140729760b452876548f59804e8c02c3276bc7281d5dMatt Beaumont-Gay 1408066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier SourceLocation getAsmLoc() const { return AsmLoc; } 1409066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier void setAsmLoc(SourceLocation L) { AsmLoc = L; } 1410728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1411728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool isSimple() const { return IsSimple; } 1412728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier void setSimple(bool V) { IsSimple = V; } 1413728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1414728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool isVolatile() const { return IsVolatile; } 1415728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier void setVolatile(bool V) { IsVolatile = V; } 1416728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 141765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } 141865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } 1419728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1420da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier //===--- Asm String Analysis ---===// 1421da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier 1422da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier /// Assemble final IR asm string. 14238b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper std::string generateAsmString(const ASTContext &C) const; 1424da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier 1425066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier //===--- Output operands ---===// 1426066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1427066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned getNumOutputs() const { return NumOutputs; } 1428066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1429c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// getOutputConstraint - Return the constraint string for the specified 1430c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// output operand. All output constraints are known to be non-empty (either 1431c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// '=' or '+'). 1432aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier StringRef getOutputConstraint(unsigned i) const; 1433c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1434c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// isOutputPlusConstraint - Return true if the specified output constraint 1435c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// is a "+" constraint (which is both an input and an output) or false if it 1436c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// is an "=" constraint (just an output). 1437c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier bool isOutputPlusConstraint(unsigned i) const { 1438c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier return getOutputConstraint(i)[0] == '+'; 1439c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier } 1440c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1441aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier const Expr *getOutputExpr(unsigned i) const; 1442c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1443c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// getNumPlusOperands - Return the number of output operands that have a "+" 1444c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// constraint. 1445c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier unsigned getNumPlusOperands() const; 1446c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1447066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier //===--- Input operands ---===// 1448066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1449066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned getNumInputs() const { return NumInputs; } 1450066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1451c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// getInputConstraint - Return the specified input constraint. Unlike output 1452c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// constraints, these can be empty. 1453aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier StringRef getInputConstraint(unsigned i) const; 1454aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier 1455aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier const Expr *getInputExpr(unsigned i) const; 1456c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1457066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier //===--- Other ---===// 1458066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 14592fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier unsigned getNumClobbers() const { return NumClobbers; } 1460aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier StringRef getClobber(unsigned i) const; 14612fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier 1462728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier static bool classof(const Stmt *T) { 1463728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier return T->getStmtClass() == GCCAsmStmtClass || 1464728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier T->getStmtClass() == MSAsmStmtClass; 1465728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier } 146619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 146719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier // Input expr iterators. 146819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 146919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ExprIterator inputs_iterator; 147019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ConstExprIterator const_inputs_iterator; 147119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 147219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier inputs_iterator begin_inputs() { 147319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 147419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 147519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 147619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier inputs_iterator end_inputs() { 147719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs + NumInputs; 147819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 147919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 148019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_inputs_iterator begin_inputs() const { 148119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 148219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 148319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 148419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_inputs_iterator end_inputs() const { 148519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs + NumInputs; 148619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 148719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 148819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier // Output expr iterators. 148919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 149019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ExprIterator outputs_iterator; 149119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ConstExprIterator const_outputs_iterator; 149219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 149319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier outputs_iterator begin_outputs() { 149419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0]; 149519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 149619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier outputs_iterator end_outputs() { 149719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 149819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 149919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 150019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_outputs_iterator begin_outputs() const { 150119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0]; 150219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 150319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_outputs_iterator end_outputs() const { 150419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 150519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 150619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 150719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier child_range children() { 150819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); 150919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 1510728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier}; 1511728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 15127d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a GCC inline-assembly statement extension. 1513fe795956194141c91ae555985c9b930595bff43fChris Lattner/// 1514728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass GCCAsmStmt : public AsmStmt { 1515066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier SourceLocation RParenLoc; 15166a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson StringLiteral *AsmStr; 1517b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1518966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson // FIXME: If we wanted to, we could allocate all of these in one big array. 1519966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Constraints; 1520966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Clobbers; 1521aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall IdentifierInfo **Names; 1522aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1523aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall friend class ASTStmtReader; 1524ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1525fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic: 15260b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple, 1527df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier bool isvolatile, unsigned numoutputs, unsigned numinputs, 1528df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier IdentifierInfo **names, StringLiteral **constraints, Expr **exprs, 1529df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier StringLiteral *asmstr, unsigned numclobbers, 1530df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier StringLiteral **clobbers, SourceLocation rparenloc); 1531b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1532cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor /// \brief Build an empty inline-assembly statement. 1533728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty), 1534aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall Constraints(0), Clobbers(0), Names(0) { } 1535cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1536cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 1537cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1538cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1539458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner //===--- Asm String Analysis ---===// 1540458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1541458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const StringLiteral *getAsmString() const { return AsmStr; } 1542458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner StringLiteral *getAsmString() { return AsmStr; } 1543cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmString(StringLiteral *E) { AsmStr = E; } 1544cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1545458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AsmStringPiece - this is part of a decomposed asm string specification 1546458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// (for use with the AnalyzeAsmString function below). An asm string is 1547458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// considered to be a concatenation of these parts. 1548458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner class AsmStringPiece { 1549458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1550458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner enum Kind { 1551458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". 1552458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Operand // Operand reference, with optional modifier %c4. 1553458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 1554458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner private: 1555458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Kind MyKind; 1556458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner std::string Str; 1557458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned OperandNo; 1558458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1559458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} 1560458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(unsigned OpNo, char Modifier) 1561458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner : MyKind(Operand), Str(), OperandNo(OpNo) { 1562458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Str += Modifier; 1563458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1565458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isString() const { return MyKind == String; } 1566458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isOperand() const { return MyKind == Operand; } 15671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1568458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const std::string &getString() const { 1569458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isString()); 1570458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str; 1571458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1572458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1573458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned getOperandNo() const { 1574458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1575458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return OperandNo; 1576458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1578458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// getModifier - Get the modifier for this operand, if present. This 1579458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// returns '\0' if there was no modifier. 1580458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner char getModifier() const { 1581458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1582458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str[0]; 1583458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1584458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1586458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 1587458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// it into pieces. If the asm string is erroneous, emit errors and return 1588458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// true, otherwise return false. This handles canonicalization and 1589458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// translation of strings from GCC syntax to LLVM IR syntax, and handles 15901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump //// flattening of named references like %[foo] to Operand AsmStringPiece's. 1591686775deca8b8685eb90801495880e3abdd844c2Chris Lattner unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces, 15928b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper const ASTContext &C, unsigned &DiagOffs) const; 15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1594da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier /// Assemble final IR asm string. 15958b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper std::string generateAsmString(const ASTContext &C) const; 15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1597b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Output operands ---===// 1598b327793860737d1c103a73aeda8057dd628a101dChris Lattner 1599aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall IdentifierInfo *getOutputIdentifier(unsigned i) const { 1600aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return Names[i]; 1601aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1602aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1603aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef getOutputName(unsigned i) const { 1604aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall if (IdentifierInfo *II = getOutputIdentifier(i)) 1605aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return II->getName(); 1606aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1607aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return StringRef(); 1608aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1609aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1610686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getOutputConstraint(unsigned i) const; 16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1612b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getOutputConstraintLiteral(unsigned i) const { 1613ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i]; 1614ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1615b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getOutputConstraintLiteral(unsigned i) { 1616b327793860737d1c103a73aeda8057dd628a101dChris Lattner return Constraints[i]; 1617b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1619ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getOutputExpr(unsigned i); 16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1621b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getOutputExpr(unsigned i) const { 1622df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i); 1623b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1625b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Input operands ---===// 16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1627aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall IdentifierInfo *getInputIdentifier(unsigned i) const { 1628aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return Names[i + NumOutputs]; 1629aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1630aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1631aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef getInputName(unsigned i) const { 1632aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall if (IdentifierInfo *II = getInputIdentifier(i)) 1633aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return II->getName(); 1634aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1635aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return StringRef(); 1636aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1637aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1638686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getInputConstraint(unsigned i) const; 16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1640b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getInputConstraintLiteral(unsigned i) const { 1641ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1642ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1643b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getInputConstraintLiteral(unsigned i) { 1644ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1645ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 16461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1647ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getInputExpr(unsigned i); 1648935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner void setInputExpr(unsigned i, Expr *E); 1649ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1650b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getInputExpr(unsigned i) const { 1651df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier return const_cast<GCCAsmStmt*>(this)->getInputExpr(i); 1652b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 1653cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1654aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate: 16558b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper void setOutputsAndInputsAndClobbers(const ASTContext &C, 1656ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1657fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Constraints, 1658fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson Stmt **Exprs, 1659fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumOutputs, 1660ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie unsigned NumInputs, 1661fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Clobbers, 1662fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumClobbers); 1663aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic: 1664cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 166510ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner //===--- Other ---===// 16661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 166710ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// getNamedOperand - Given a symbolic operand reference like %[foo], 166810ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// translate this into a numeric value needed to reference the same operand. 166910ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// This returns -1 if the operand name is invalid. 1670686775deca8b8685eb90801495880e3abdd844c2Chris Lattner int getNamedOperand(StringRef SymbolicName) const; 167110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner 167233f0558f75f70061707d1388e305b8f92f4e55deChad Rosier StringRef getClobber(unsigned i) const; 16735c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; } 16745c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier const StringLiteral *getClobberStringLiteral(unsigned i) const { 16755c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier return Clobbers[i]; 16765c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier } 1677cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 167865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; } 167965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1681df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier static bool classof(const Stmt *T) { 1682df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier return T->getStmtClass() == GCCAsmStmtClass; 1683df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier } 1684fe795956194141c91ae555985c9b930595bff43fChris Lattner}; 168578492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek 16867d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a Microsoft inline-assembly statement extension. 16878cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier/// 1688728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass MSAsmStmt : public AsmStmt { 1689c4cca7b2408bdfd99ea0f63fec1421c1327593b2Enea Zaffanella SourceLocation LBraceLoc, EndLoc; 1690aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef AsmStr; 16918cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 169279efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier unsigned NumAsmToks; 169379efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier 169479efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier Token *AsmToks; 169589fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier StringRef *Constraints; 169633c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier StringRef *Clobbers; 16978cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1698aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall friend class ASTStmtReader; 1699aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 17008cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic: 17010b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper MSAsmStmt(const ASTContext &C, SourceLocation asmloc, 17020b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper SourceLocation lbraceloc, bool issimple, bool isvolatile, 17030b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs, 1704aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall ArrayRef<StringRef> constraints, 1705e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier ArrayRef<Expr*> exprs, StringRef asmstr, 170689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier ArrayRef<StringRef> clobbers, SourceLocation endloc); 17078cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1708cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier /// \brief Build an empty MS-style inline-assembly statement. 1709728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty), 171089fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { } 1711cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier 17127bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier SourceLocation getLBraceLoc() const { return LBraceLoc; } 17137bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier void setLBraceLoc(SourceLocation L) { LBraceLoc = L; } 17148cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier SourceLocation getEndLoc() const { return EndLoc; } 17158cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier void setEndLoc(SourceLocation L) { EndLoc = L; } 17168cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 17177bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier bool hasBraces() const { return LBraceLoc.isValid(); } 17187bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier 171979efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier unsigned getNumAsmToks() { return NumAsmToks; } 172079efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier Token *getAsmToks() { return AsmToks; } 17218f726de55412870ef70e788b852c6cc50873e15bChad Rosier 17228cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier //===--- Asm String Analysis ---===// 1723aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef getAsmString() const { return AsmStr; } 17248cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1725da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier /// Assemble final IR asm string. 17268b4b98b7cb18cc4a99cca0aefa515cc8756dc06dCraig Topper std::string generateAsmString(const ASTContext &C) const; 1727da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier 17282603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier //===--- Output operands ---===// 17292603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 173089fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier StringRef getOutputConstraint(unsigned i) const { 1731aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall assert(i < NumOutputs); 173289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier return Constraints[i]; 173389fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier } 1734c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1735633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier Expr *getOutputExpr(unsigned i); 1736633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier 17372603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier const Expr *getOutputExpr(unsigned i) const { 17382603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier return const_cast<MSAsmStmt*>(this)->getOutputExpr(i); 17392603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier } 17402603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 17412603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier //===--- Input operands ---===// 17422603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 174389fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier StringRef getInputConstraint(unsigned i) const { 1744aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall assert(i < NumInputs); 174589fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier return Constraints[i + NumOutputs]; 174689fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier } 1747c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1748633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier Expr *getInputExpr(unsigned i); 1749633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier void setInputExpr(unsigned i, Expr *E); 1750633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier 17512603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier const Expr *getInputExpr(unsigned i) const { 17522603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier return const_cast<MSAsmStmt*>(this)->getInputExpr(i); 17532603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier } 17542603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 17558cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier //===--- Other ---===// 17568cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1757aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall ArrayRef<StringRef> getAllConstraints() const { 1758aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return ArrayRef<StringRef>(Constraints, NumInputs + NumOutputs); 1759aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1760aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall ArrayRef<StringRef> getClobbers() const { 1761aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return ArrayRef<StringRef>(Clobbers, NumClobbers); 1762aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1763aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall ArrayRef<Expr*> getAllExprs() const { 1764aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall return ArrayRef<Expr*>(reinterpret_cast<Expr**>(Exprs), 1765aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall NumInputs + NumOutputs); 1766aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall } 1767aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1768aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall StringRef getClobber(unsigned i) const { return getClobbers()[i]; } 1769aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 1770aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallprivate: 17710b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper void initialize(const ASTContext &C, StringRef AsmString, 17720b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints, 17730b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers); 1774aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCallpublic: 17754399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier 177665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; } 177765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; } 177865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 17798cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier static bool classof(const Stmt *T) { 17808cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return T->getStmtClass() == MSAsmStmtClass; 17818cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 17828cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 17838cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier child_range children() { 1784651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]); 17858cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 17868cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier}; 17878cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 178828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt { 178928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 179028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 179128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 179228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { FILTER_EXPR, BLOCK }; 179328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 179428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt(SourceLocation Loc, 179528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 179628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 179728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 17987110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 17997110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 18007110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { } 18017110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 180228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 18030b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static SEHExceptStmt* Create(const ASTContext &C, 180428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation ExceptLoc, 180528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 180628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 180765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 180865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); } 180965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 181028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 181128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getExceptLoc() const { return Loc; } 181228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); } 181328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1814ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr *getFilterExpr() const { 1815ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); 1816ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 1817ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1818ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CompoundStmt *getBlock() const { 1819cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko return cast<CompoundStmt>(Children[BLOCK]); 1820ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 182128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 182228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 182328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 182428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 182528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 182628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 182728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHExceptStmtClass; 182828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 182928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 183028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 183128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 183228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt { 183328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 183428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block; 183528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 183628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt(SourceLocation Loc, 183728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 183828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 18397110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 18407110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 18417110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { } 18427110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 184328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 18440b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static SEHFinallyStmt* Create(const ASTContext &C, 184528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation FinallyLoc, 184628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 184728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 184865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); } 184965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 185028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 185128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getFinallyLoc() const { return Loc; } 185228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Block->getLocEnd(); } 185328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1854cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); } 185528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 185628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 185728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(&Block,&Block+1); 185828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 185928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 186028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 186128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHFinallyStmtClass; 186228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 186328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 186428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 186528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 186628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt { 186728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool IsCXXTry; 186828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc; 186928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 187028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 187128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { TRY = 0, HANDLER = 1 }; 187228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 187328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try' 187428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 187528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 187628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 187728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 18787110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 18797110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 18807110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { } 18817110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 188228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 18830b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry, 18840b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper SourceLocation TryLoc, Stmt *TryBlock, 188528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 188628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 188765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); } 188865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 188928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 189028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getTryLoc() const { return TryLoc; } 189128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); } 189228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 189328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool getIsCXXTry() const { return IsCXXTry; } 1894ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1895ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CompoundStmt* getTryBlock() const { 1896cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko return cast<CompoundStmt>(Children[TRY]); 1897ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 1898ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 189928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *getHandler() const { return Children[HANDLER]; } 190028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 190128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// Returns 0 if not defined 190228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt *getExceptHandler() const; 190328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt *getFinallyHandler() const; 190428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 190528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 190628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 190728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 190828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 190928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 191028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHTryStmtClass; 191128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 191228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 1913ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1914051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// \brief This captures a statement into a function. For example, the following 1915051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// pragma annotated compound statement can be represented as a CapturedStmt, 1916051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// and this compound statement is the body of an anonymous outlined function. 1917051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @code 1918051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// #pragma omp parallel 1919051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// { 1920051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// compute(); 1921051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// } 1922051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @endcode 1923051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajclass CapturedStmt : public Stmt { 1924051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic: 1925051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The different capture forms: by 'this' or by reference, etc. 1926051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj enum VariableCaptureKind { 1927051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VCK_This, 1928051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VCK_ByRef 1929051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj }; 1930051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1931051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Describes the capture of either a variable or 'this'. 1932051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj class Capture { 19333a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir llvm::PointerIntPair<VarDecl *, 1, VariableCaptureKind> VarAndKind; 1934051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation Loc; 1935051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1936051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj public: 1937051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Create a new capture. 1938051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1939051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \param Loc The source location associated with this capture. 1940051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1941051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \param Kind The kind of capture (this, ByRef, ...). 1942051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1943051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \param Var The variable being captured, or null if capturing this. 1944051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1945051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var = 0) 19463a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir : VarAndKind(Var, Kind), Loc(Loc) { 1947051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj switch (Kind) { 1948051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj case VCK_This: 1949051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj assert(Var == 0 && "'this' capture cannot have a variable!"); 1950051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj break; 1951051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj case VCK_ByRef: 1952051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj assert(Var && "capturing by reference must have a variable!"); 1953051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj break; 1954051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1955051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1956051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1957051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Determine the kind of capture. 19583a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir VariableCaptureKind getCaptureKind() const { return VarAndKind.getInt(); } 1959051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1960051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the source location at which the variable or 'this' was 1961051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// first used. 1962051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation getLocation() const { return Loc; } 1963051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1964051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Determine whether this capture handles the C++ 'this' pointer. 19653a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir bool capturesThis() const { return getCaptureKind() == VCK_This; } 1966051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1967051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Determine whether this capture handles a variable. 19683a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir bool capturesVariable() const { return getCaptureKind() != VCK_This; } 1969051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1970051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the declaration of the variable being captured. 1971051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1972051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// This operation is only valid if this capture does not capture 'this'. 1973051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VarDecl *getCapturedVar() const { 1974051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj assert(!capturesThis() && "No variable available for 'this' capture"); 19753a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir return VarAndKind.getPointer(); 1976051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1977dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir friend class ASTStmtReader; 1978051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj }; 1979051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1980051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajprivate: 1981051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The number of variable captured, including 'this'. 1982051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj unsigned NumCaptures; 1983051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 19849fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief The pointer part is the implicit the outlined function and the 19859fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// int part is the captured region kind, 'CR_Default' etc. 19869fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind; 1987051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1988051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl. 1989051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj RecordDecl *TheRecordDecl; 1990051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1991051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Construct a captured statement. 19929fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures, 19939fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD); 1994051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1995051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Construct an empty captured statement. 1996051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj CapturedStmt(EmptyShell Empty, unsigned NumCaptures); 1997051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1998051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Stmt **getStoredStmts() const { 1999051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1); 2000051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2001051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2002051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Capture *getStoredCaptures() const; 2003051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2004dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; } 2005dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir 2006051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic: 20070b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static CapturedStmt *Create(const ASTContext &Context, Stmt *S, 20089fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapturedRegionKind Kind, 2009051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj ArrayRef<Capture> Captures, 2010051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj ArrayRef<Expr *> CaptureInits, 20116afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj CapturedDecl *CD, RecordDecl *RD); 2012051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 20130b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper static CapturedStmt *CreateDeserialized(const ASTContext &Context, 2014051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj unsigned NumCaptures); 2015051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2016051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the statement being captured. 2017051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; } 2018051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj const Stmt *getCapturedStmt() const { 2019051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return const_cast<CapturedStmt *>(this)->getCapturedStmt(); 2020051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2021051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2022051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the outlined function declaration. 20239fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapturedDecl *getCapturedDecl() { return CapDeclAndKind.getPointer(); } 20249fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan const CapturedDecl *getCapturedDecl() const { 20259fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan return const_cast<CapturedStmt *>(this)->getCapturedDecl(); 20269fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 20279fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan 20289fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief Set the outlined function declaration. 20299fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan void setCapturedDecl(CapturedDecl *D) { 20309fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan assert(D && "null CapturedDecl"); 20319fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapDeclAndKind.setPointer(D); 20329fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 20339fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan 20349fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief Retrieve the captured region kind. 20359fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapturedRegionKind getCapturedRegionKind() const { 20369fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan return CapDeclAndKind.getInt(); 20379fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 20389fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan 20399fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief Set the captured region kind. 20409fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan void setCapturedRegionKind(CapturedRegionKind Kind) { 20419fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan CapDeclAndKind.setInt(Kind); 20429fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 2043051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2044051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the record declaration for captured variables. 2045051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; } 2046051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 20479fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan /// \brief Set the record declaration for captured variables. 20489fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan void setCapturedRecordDecl(RecordDecl *D) { 20499fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan assert(D && "null RecordDecl"); 20509fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan TheRecordDecl = D; 20519fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan } 20529fd6b8f5a73788f288edd01fa99d434d1e6588adWei Pan 2053051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief True if this variable has been captured. 2054051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj bool capturesVariable(const VarDecl *Var) const; 2055051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2056051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief An iterator that walks over the captures. 2057dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir typedef Capture *capture_iterator; 2058dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir typedef const Capture *const_capture_iterator; 2059651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<capture_iterator> capture_range; 2060651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<const_capture_iterator> capture_const_range; 2061651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2062651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines capture_range captures() { 2063651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return capture_range(capture_begin(), capture_end()); 2064651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 2065651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines capture_const_range captures() const { 2066651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return capture_const_range(capture_begin(), capture_end()); 2067651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 2068051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2069051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve an iterator pointing to the first capture. 2070dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir capture_iterator capture_begin() { return getStoredCaptures(); } 2071dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir const_capture_iterator capture_begin() const { return getStoredCaptures(); } 2072051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2073051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve an iterator pointing past the end of the sequence of 2074051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// captures. 2075051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_iterator capture_end() const { 2076051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getStoredCaptures() + NumCaptures; 2077051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2078051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2079051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the number of captures, including 'this'. 2080051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj unsigned capture_size() const { return NumCaptures; } 2081051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2082051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Iterator that walks over the capture initialization arguments. 2083051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj typedef Expr **capture_init_iterator; 2084651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<capture_init_iterator> capture_init_range; 2085651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2086651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines capture_init_range capture_inits() const { 2087651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return capture_init_range(capture_init_begin(), capture_init_end()); 2088651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 2089051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2090051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the first initialization argument. 2091051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_init_iterator capture_init_begin() const { 2092051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return reinterpret_cast<Expr **>(getStoredStmts()); 2093051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2094051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2095051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the iterator pointing one past the last initialization 2096051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// argument. 2097051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_init_iterator capture_init_end() const { 2098051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return capture_init_begin() + NumCaptures; 2099051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2100051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2101051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation getLocStart() const LLVM_READONLY { 2102051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getCapturedStmt()->getLocStart(); 2103051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2104051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation getLocEnd() const LLVM_READONLY { 2105051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getCapturedStmt()->getLocEnd(); 2106051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2107051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceRange getSourceRange() const LLVM_READONLY { 2108051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getCapturedStmt()->getSourceRange(); 2109051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2110051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2111051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj static bool classof(const Stmt *T) { 2112051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return T->getStmtClass() == CapturedStmtClass; 2113051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2114051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2115051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj child_range children(); 2116dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir 2117dc5be4f54d6415cb88b2f8a7c5bc9011e332b9b8Ben Langmuir friend class ASTStmtReader; 2118051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj}; 2119051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 21205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 21215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2123