Stmt.h revision 3aa8140bde5b9bedf13e46ec0a668daa54814196
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 177573098b83e780d1c5bea13b384b610d8f155676Steve Naroff#include "llvm/Support/Casting.h" 18a95d3750441ac8ad03e36af8e6e74039c9a3109dTed Kremenek#include "llvm/Support/raw_ostream.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/SourceLocation.h" 20d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h" 219caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h" 228ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek#include "clang/AST/DeclGroup.h" 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h" 248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek#include "clang/AST/ASTContext.h" 256e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string> 267573098b83e780d1c5bea13b384b610d8f155676Steve Naroffusing llvm::dyn_cast_or_null; 277573098b83e780d1c5bea13b384b610d8f155676Steve Naroff 2841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm { 2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor class FoldingSetNodeID; 3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor} 3141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 33e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop class ASTContext; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 367ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff class ParmVarDecl; 374b07b2968f87f3cd5a3d8c76145f1cbfd718d42dSebastian Redl class QualType; 385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class IdentifierInfo; 390c727a35718556866a978f64ac549d9798735f08Chris Lattner class SourceManager; 406a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson class StringLiteral; 416c36be5b383875b490684bcf439d6d427298c1afChris Lattner class SwitchStmt; 421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek //===----------------------------------------------------------------------===// 44ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // ExprIterator - Iterators for iterating over Stmt* arrays that contain 45ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // only Expr*. This is needed because AST nodes use Stmt* arrays to store 46ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // references to children (to be compatible with StmtIterator). 47ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek //===----------------------------------------------------------------------===// 481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Stmt; 50ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Expr; 511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ExprIterator { 53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Stmt** I; 54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator(Stmt** i) : I(i) {} 561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExprIterator() : I(0) {} 57ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator& operator++() { ++I; return *this; } 58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator-(size_t i) { return I-i; } 59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator+(size_t i) { return I+i; } 60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator[](size_t idx); 61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // FIXME: Verify that this will correctly return a signed distance. 62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ExprIterator& R) const { return I - R.I; } 63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator*() const; 64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator->() const; 65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator==(const ExprIterator& R) const { return I == R.I; } 66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator!=(const ExprIterator& R) const { return I != R.I; } 67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>(const ExprIterator& R) const { return I > R.I; } 68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>=(const ExprIterator& R) const { return I >= R.I; } 69ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek }; 701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ConstExprIterator { 721705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer const Stmt * const *I; 73ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 741705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator(const Stmt * const *i) : I(i) {} 751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ConstExprIterator() : I(0) {} 76ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ConstExprIterator& operator++() { ++I; return *this; } 771705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator+(size_t i) const { return I+i; } 781705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator-(size_t i) const { return I-i; } 79ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator[](size_t idx) const; 80ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ConstExprIterator& R) const { return I - R.I; } 81ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator*() const; 82ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator->() const; 83ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator==(const ConstExprIterator& R) const { return I == R.I; } 84ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator!=(const ConstExprIterator& R) const { return I != R.I; } 85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>(const ConstExprIterator& R) const { return I > R.I; } 86ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>=(const ConstExprIterator& R) const { return I >= R.I; } 871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }; 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements. 91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement. 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt { 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum StmtClass { 98f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor NoStmtClass = 0, 99f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class, 1007381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \ 1019a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class, 1027381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \ 1039a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class 1047381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT) 1054bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 1068e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1088189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Make vanilla 'new' and 'delete' illegal for Stmts. 1098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected: 1108189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes) throw() { 1118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek assert(0 && "Stmts cannot be allocated with regular 'new'."); 1128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return 0; 1138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void operator delete(void* data) throw() { 1158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek assert(0 && "Stmts cannot be released with regular 'delete'."); 1168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class StmtBitfields { 1198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Stmt; 1208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall /// \brief The statement class. 1228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned sClass : 8; 1238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall enum { NumStmtBits = 8 }; 1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CompoundStmtBitfields { 1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CompoundStmt; 1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned NumStmts : 32 - NumStmtBits; 1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class ExprBitfields { 1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Expr; 1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DeclRefExpr; // computeDependence 1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class InitListExpr; // ctor 1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DesignatedInitExpr; // ctor 138d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor friend class BlockDeclRefExpr; // ctor 139bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ASTStmtReader; // deserialization 140bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXNewExpr; // ctor 141bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class DependentScopeDeclRefExpr; // ctor 142bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXConstructExpr; // ctor 143bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CallExpr; // ctor 144bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OffsetOfExpr; // ctor 145bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ObjCMessageExpr; // ctor 146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ShuffleVectorExpr; // ctor 147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ParenListExpr; // ctor 148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXUnresolvedConstructExpr; // ctor 149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXDependentScopeMemberExpr; // ctor 150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OverloadExpr; // ctor 1518e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1528e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueKind : 2; 154f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall unsigned ObjectKind : 2; 1558e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned TypeDependent : 1; 1568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueDependent : 1; 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned ContainsUnexpandedParameterPack : 1; 1588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor enum { NumExprBits = 15 }; 1608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 161cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth class DeclRefExprBitfields { 162cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth friend class DeclRefExpr; 163cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth friend class ASTStmtReader; // deserialization 164cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth unsigned : NumExprBits; 165cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 166cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth unsigned HasQualifier : 1; 167cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth unsigned HasExplicitTemplateArgs : 1; 1683aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth unsigned HasFoundDecl : 1; 169cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth }; 170cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 1718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CastExprBitfields { 1728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CastExpr; 1738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumExprBits; 1748e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1752bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned Kind : 6; 1762bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned BasePathSize : 32 - 6 - NumExprBits; 1778e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 179cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne class CallExprBitfields { 180cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne friend class CallExpr; 181cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned : NumExprBits; 182cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 183cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs : 1; 184cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne }; 185cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1868e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall union { 18763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // FIXME: this is wasteful on 64-bit platforms. 18863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall void *Aligner; 18963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 1908e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBitfields StmtBits; 1918e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBitfields CompoundStmtBits; 1928e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBitfields ExprBits; 193cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBitfields DeclRefExprBits; 1948e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBitfields CastExprBits; 195cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBitfields CallExprBits; 1968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 198d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor friend class ASTStmtReader; 199d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2008189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic: 2018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Only allow allocation of Stmts using the allocator in ASTContext 2021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // or by doing a placement new. 2038189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext& C, 204f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor unsigned alignment = 8) throw() { 2058189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return ::operator new(bytes, C, alignment); 2068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 2071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2088189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext* C, 209f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor unsigned alignment = 8) throw() { 2108189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return ::operator new(bytes, *C, alignment); 2118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 2121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, void* mem) throw() { 2148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return mem; 2158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 216e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 217fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext&, unsigned) throw() { } 218fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext*, unsigned) throw() { } 219e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor void operator delete(void*, std::size_t) throw() { } 220fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, void*) throw() { } 221e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 222025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic: 223025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief A placeholder type used to construct an empty shell of a 224025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// type, that will be filled in later (e.g., by some 225025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// de-serialization). 226025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor struct EmptyShell { }; 227025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 2289c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected: 229025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Construct an empty statement. 2308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall explicit Stmt(StmtClass SC, EmptyShell) { 2318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 232025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); 233025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor } 234025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt(StmtClass SC) { 2378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 241c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt StmtClass getStmtClass() const { 2428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall return static_cast<StmtClass>(StmtBits.sClass); 243b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor } 2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStmtClassName() const; 2451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 246b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// SourceLocation tokens are not useful in isolation - they are low level 247b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// value objects created/interpreted by SourceManager. We assume AST 248b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// clients will have a pointer to the respective SourceManager. 24963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 25063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 251311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner SourceLocation getLocStart() const { return getSourceRange().getBegin(); } 252311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // global temp stats (until we have a per-module visitor) 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void addStmtClass(const StmtClass s); 2562024f4d4b0d57616f79ea742fa782d633d414462Kovarththanan Rajaratnam static bool CollectingStats(bool Enable = false); 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void PrintStats(); 2586000dace22f110d8768476989313e9d981d690d0Chris Lattner 2596000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dump - This does a local dump of the specified AST fragment. It dumps the 2606000dace22f110d8768476989313e9d981d690d0Chris Lattner /// specified node and a few nodes underneath it, but not the whole subtree. 2616000dace22f110d8768476989313e9d981d690d0Chris Lattner /// This is useful in a debugger. 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void dump() const; 263e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner void dump(SourceManager &SM) const; 2649668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis void dump(llvm::raw_ostream &OS, SourceManager &SM) const; 2656000dace22f110d8768476989313e9d981d690d0Chris Lattner 2666000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpAll - This does a dump of the specified AST fragment and all subtrees. 2676000dace22f110d8768476989313e9d981d690d0Chris Lattner void dumpAll() const; 268e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner void dumpAll(SourceManager &SM) const; 2696000dace22f110d8768476989313e9d981d690d0Chris Lattner 2706000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST 2716000dace22f110d8768476989313e9d981d690d0Chris Lattner /// back to its original source language syntax. 27248d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman void dumpPretty(ASTContext& Context) const; 2731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void printPretty(llvm::raw_ostream &OS, PrinterHelper *Helper, 274e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 27548d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman unsigned Indentation = 0) const { 27648d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation); 27748d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman } 278e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void printPretty(llvm::raw_ostream &OS, ASTContext &Context, 2791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PrinterHelper *Helper, 280e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 281d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned Indentation = 0) const; 2821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 283d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only 284d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// works on systems with GraphViz (Mac OS X) or dot+gv installed. 285d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek void viewAST() const; 2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Implement isa<T> support. 2881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *) { return true; } 2891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 290d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// hasImplicitControlFlow - Some statements (e.g. short circuited operations) 291d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// contain implicit control-flow in the order their subexpressions 292d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// are evaluated. This predicate returns true if this statement has 293d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// such implicit control-flow. Such statements are also specially handled 294d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// within CFGs. 295d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek bool hasImplicitControlFlow() const; 296d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek 29763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// Child Iterators: All subclasses must implement 'children' 29863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// to permit easy iteration over the substatements/subexpessions of an 29963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// AST node. This permits easy iteration over all nodes in the AST. 3009caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef StmtIterator child_iterator; 3019caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef ConstStmtIterator const_child_iterator; 3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef StmtRange child_range; 30463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef ConstStmtRange const_child_range; 3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 30763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_range children() const { 30863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return const_cast<Stmt*>(this)->children(); 30977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 3101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_begin() { return children().first; } 31263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_end() { return children().second; } 31363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 31463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_begin() const { return children().first; } 31563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_end() const { return children().second; } 31641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 31741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Produce a unique representation of the given statement. 31841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 31941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief ID once the profiling operation is complete, will contain 32041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// the unique representation of the given statement. 32141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 32241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Context the AST context in which the statement resides 32341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 32441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Canonical whether the profile should be based on the canonical 32541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// representation of this statement (e.g., where non-type template 3261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// parameters are identified by index/level rather than their 32741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// declaration pointers) or the exact representation of the statement as 32841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// written in the source. 3294ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 33041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor bool Canonical); 3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions 3351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where 3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration. 3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt { 3399653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor DeclGroupRef DG; 34081c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation StartLoc, EndLoc; 3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 3448ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg), 3458ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek StartLoc(startLoc), EndLoc(endLoc) {} 3461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor /// \brief Build an empty declaration statement. 34884f2170062014d268951902164bed0d8bdea0e82Douglas Gregor explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { } 34984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 3507e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner /// isSingleDecl - This method returns true if this DeclStmt refers 351fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner /// to a single Decl. 3527e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner bool isSingleDecl() const { 353fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner return DG.isSingleDecl(); 3548ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek } 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3567e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner const Decl *getSingleDecl() const { return DG.getSingleDecl(); } 3571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl *getSingleDecl() { return DG.getSingleDecl(); } 3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 359e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner const DeclGroupRef getDeclGroup() const { return DG; } 360e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner DeclGroupRef getDeclGroup() { return DG; } 36184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setDeclGroup(DeclGroupRef DGR) { DG = DGR; } 362b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 36381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getStartLoc() const { return StartLoc; } 36484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setStartLoc(SourceLocation L) { StartLoc = L; } 36581c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getEndLoc() const { return EndLoc; } 36684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setEndLoc(SourceLocation L) { EndLoc = L; } 36784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 3688ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek SourceRange getSourceRange() const { 36981c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner return SourceRange(StartLoc, EndLoc); 37081c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner } 3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DeclStmtClass; 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclStmt *) { return true; } 3761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37714f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek // Iterators over subexpressions. 37863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 37963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(DG.begin(), DG.end()), 38063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator(DG.end(), DG.end())); 38163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3830632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::iterator decl_iterator; 3840632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::const_iterator const_decl_iterator; 3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3868ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_begin() { return DG.begin(); } 3878ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_end() { return DG.end(); } 3888ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_begin() const { return DG.begin(); } 3898ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_end() const { return DG.end(); } 3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3. 3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt { 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation SemiLoc; 39644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 397b7d98d35ea723624345f06e5895ddce2e0388ef0Argyrios Kyrtzidis /// \brief If the null statement was preceded by an empty macro this is 398b7d98d35ea723624345f06e5895ddce2e0388ef0Argyrios Kyrtzidis /// its instantiation source location, e.g: 39944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @code 40044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// #define CALL(x) 40144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// CALL(0); 40244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @endcode 403b7d98d35ea723624345f06e5895ddce2e0388ef0Argyrios Kyrtzidis SourceLocation LeadingEmptyMacro; 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 405b7d98d35ea723624345f06e5895ddce2e0388ef0Argyrios Kyrtzidis NullStmt(SourceLocation L, SourceLocation LeadingEmptyMacro =SourceLocation()) 40644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis : Stmt(NullStmtClass), SemiLoc(L), LeadingEmptyMacro(LeadingEmptyMacro) {} 4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 408025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty null statement. 409025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) { } 410025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getSemiLoc() const { return SemiLoc; } 412025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSemiLoc(SourceLocation L) { SemiLoc = L; } 413b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 414b7d98d35ea723624345f06e5895ddce2e0388ef0Argyrios Kyrtzidis bool hasLeadingEmptyMacro() const { return LeadingEmptyMacro.isValid(); } 415b7d98d35ea723624345f06e5895ddce2e0388ef0Argyrios Kyrtzidis SourceLocation getLeadingEmptyMacroLoc() const { return LeadingEmptyMacro; } 41644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(SemiLoc); } 4181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == NullStmtClass; 4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const NullStmt *) { return true; } 4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 42544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 42644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtReader; 42744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtWriter; 4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }. 4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt { 4338189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek Stmt** Body; 434b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation LBracLoc, RBracLoc; 4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned NumStmts, 4378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall SourceLocation LB, SourceLocation RB) 4388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { 4398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = NumStmts; 440654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis assert(CompoundStmtBits.NumStmts == NumStmts && 441654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); 4428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 443026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (NumStmts == 0) { 444026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Body = 0; 445026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return; 446026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 448026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Body = new (C) Stmt*[NumStmts]; 4498e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall memcpy(Body, StmtStart, NumStmts * sizeof(*Body)); 4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 451025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 452025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor // \brief Build an empty compound statement. 453025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CompoundStmt(EmptyShell Empty) 4548e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass, Empty), Body(0) { 4558e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = 0; 4568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 457025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 458025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts); 4591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } 4618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned size() const { return CompoundStmtBits.NumStmts; } 462025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 4638189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt** body_iterator; 4648189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek body_iterator body_begin() { return Body; } 4658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall body_iterator body_end() { return Body + size(); } 4668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; } 467e946fc833d8592aa2890bfd9839f1ad839b3d284Fariborz Jahanian 4688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setLastStmt(Stmt *S) { 4698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall assert(!body_empty() && "setLastStmt"); 4708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Body[size()-1] = S; 4718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4738189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt* const * const_body_iterator; 4748189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_body_iterator body_begin() const { return Body; } 4758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const_body_iterator body_end() const { return Body + size(); } 4768e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; } 4778189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek 4788189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<body_iterator> reverse_body_iterator; 4798189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rbegin() { 4808189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_end()); 4818189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4828189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rend() { 4838189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_begin()); 4848189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4854ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 4868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<const_body_iterator> 4878189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator; 4884ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 4898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rbegin() const { 4908189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_end()); 4918189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4938189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rend() const { 4948189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_begin()); 4958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(LBracLoc, RBracLoc); 499b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 5001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 501cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getLBracLoc() const { return LBracLoc; } 502025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setLBracLoc(SourceLocation L) { LBracLoc = L; } 503cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getRBracLoc() const { return RBracLoc; } 504025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setRBracLoc(SourceLocation L) { RBracLoc = L; } 5051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundStmtClass; 5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundStmt *) { return true; } 5101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 51263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 51363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 51463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 517c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt, 518c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt { 519103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected: 520c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // A pointer to the following CaseStmt or DefaultStmt class, 521c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // used by SwitchStmt. 522c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *NextSwitchCase; 523103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek 524d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {} 5251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 526c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic: 527c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } 528c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 529c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getNextSwitchCase() { return NextSwitchCase; } 530c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 531c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } 532d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek 53363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt *getSubStmt(); 534702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner const Stmt *getSubStmt() const { 535702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner return const_cast<SwitchCase*>(this)->getSubStmt(); 536702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner } 537b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 53863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(); } 5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass || 54263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall T->getStmtClass() == DefaultStmtClass; 543c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 544c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson static bool classof(const SwitchCase *) { return true; } 545c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson}; 546c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 547c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase { 5480a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor enum { LHS, RHS, SUBSTMT, END_EXPR }; 5491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 550d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // GNU "case 1 ... 4" extension 551b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation CaseLoc; 552dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation EllipsisLoc; 553dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation ColonLoc; 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 555dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, 5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation ellipsisLoc, SourceLocation colonLoc) 557d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek : SwitchCase(CaseStmtClass) { 55824e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner SubExprs[SUBSTMT] = 0; 559d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 560d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 561b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff CaseLoc = caseLoc; 562dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor EllipsisLoc = ellipsisLoc; 563dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor ColonLoc = colonLoc; 564d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek } 565025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 566025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty switch case statement. 567025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { } 568025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 569764a7ce5217f9569e100a3445f47496ee82daf86Chris Lattner SourceLocation getCaseLoc() const { return CaseLoc; } 570025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCaseLoc(SourceLocation L) { CaseLoc = L; } 571dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 572dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } 573dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 574dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 575025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 576d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 577d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 578d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 579025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getLHS() const { 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[LHS]); 58251b09f2c528c8460b5465c676173324e44176d62Devang Patel } 5831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getRHS() const { 5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[RHS]); 58551b09f2c528c8460b5465c676173324e44176d62Devang Patel } 58651b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 58820dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; } 58920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } 59020dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } 5911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 5943fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner // Handle deeply nested case statements with iteration instead of recursion. 5953fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner const CaseStmt *CS = this; 59691ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) 5973fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner CS = CS2; 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd()); 600b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 6011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass; 6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CaseStmt *) { return true; } 6051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 606d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 60763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 60863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[END_EXPR]); 60963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 612c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase { 613d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt* SubStmt; 6146c36be5b383875b490684bcf439d6d427298c1afChris Lattner SourceLocation DefaultLoc; 615dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation ColonLoc; 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : 618dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL), 619dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor ColonLoc(CL) {} 620025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 621025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty default statement. 622025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { } 623025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 624d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubStmt; } 62551b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubStmt; } 626025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSubStmt(Stmt *S) { SubStmt = S; } 627025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 6286c36be5b383875b490684bcf439d6d427298c1afChris Lattner SourceLocation getDefaultLoc() const { return DefaultLoc; } 629025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setDefaultLoc(SourceLocation L) { DefaultLoc = L; } 630dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 631dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 63363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 6341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(DefaultLoc, SubStmt->getLocEnd()); 635b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 6361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DefaultStmtClass; 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DefaultStmt *) { return true; } 6401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 641d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 64263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 645ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner 646ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement. For example: 647ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// foo: return; 648ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt { 650ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *TheDecl; 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *SubStmt; 652b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IdentLoc; 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 654ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt) 655ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) { 6568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 6571de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 6581de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor // \brief Build an empty label statement. 6591de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { } 6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getIdentLoc() const { return IdentLoc; } 662ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getDecl() const { return TheDecl; } 663ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setDecl(LabelDecl *D) { TheDecl = D; } 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *getSubStmt() { return SubStmt; } 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Stmt *getSubStmt() const { return SubStmt; } 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setIdentLoc(SourceLocation L) { IdentLoc = L; } 6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setSubStmt(Stmt *SS) { SubStmt = SS; } 669b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 67063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(IdentLoc, SubStmt->getLocEnd()); 6721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 67363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 67463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == LabelStmtClass; 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const LabelStmt *) { return true; } 6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else. 6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt { 68543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, THEN, ELSE, END_EXPR }; 6868297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 6878cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor 688b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IfLoc; 689d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation ElseLoc; 69044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 69243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, 69344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0); 69443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor 695025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty if/then/else statement 696025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { } 697025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 6988cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \brief Retrieve the variable declared in this "if" statement, if any. 6998cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// 7008cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// In the following example, "x" is the condition variable. 7018cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \code 7028cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// if (int x = foo()) { 7038cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// printf("x is %d", x); 7048cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// } 7058cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \endcode 70643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 70743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 708c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 709d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this IfStmt has a condition variable, return the faux DeclStmt 710d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 711d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 712d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 713d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 714d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 7158297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 716025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 7178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getThen() const { return SubExprs[THEN]; } 7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setThen(Stmt *S) { SubExprs[THEN] = S; } 7198297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getElse() const { return SubExprs[ELSE]; } 720025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setElse(Stmt *S) { SubExprs[ELSE] = S; } 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7228297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 7238297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getThen() { return SubExprs[THEN]; } 7248297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getElse() { return SubExprs[ELSE]; } 725b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 726025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getIfLoc() const { return IfLoc; } 727025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setIfLoc(SourceLocation L) { IfLoc = L; } 728d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation getElseLoc() const { return ElseLoc; } 729d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor void setElseLoc(SourceLocation L) { ElseLoc = L; } 730025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 73163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 732b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff if (SubExprs[ELSE]) 733b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd()); 734b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff else 735b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd()); 736b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators over subexpressions. The iterators will include iterating 73963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // over the initialization expression referenced by the condition variable. 74063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 74163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 74263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 74363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 7441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IfStmtClass; 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IfStmt *) { return true; } 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt. 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt { 75343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 755c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // This points to a linked list of case and default statements. 756c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *FirstCase; 7579dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SourceLocation SwitchLoc; 7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 759559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// If the SwitchStmt is a switch on an enum value, this records whether 760559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// all the enum values were covered by CaseStmts. This value is meant to 761559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// be a hint for possible clients. 762559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek unsigned AllEnumCasesCovered : 1; 763559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 76543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond); 7661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 767025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build a empty switch statement. 768025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { } 769025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 770d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \brief Retrieve the variable declared in this "switch" statement, if any. 771d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// 772d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// In the following example, "x" is the condition variable. 773d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \code 774d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// switch (int x = foo()) { 775d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// case 0: break; 776d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// // ... 777d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// } 778d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \endcode 77943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 78043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 781d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 782d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this SwitchStmt has a condition variable, return the faux DeclStmt 783d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 784d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 785d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 786d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 787d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor 7888297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 7898297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 790c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getSwitchCaseList() const { return FirstCase; } 791c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 7928297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 793025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 7948297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 795025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 796c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getSwitchCaseList() { return FirstCase; } 7971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Set the case list for this switch statement. 79943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// 80043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// The caller is responsible for incrementing the retain counts on 80143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// all of the SwitchCase statements in this list. 802025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } 803025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 804025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getSwitchLoc() const { return SwitchLoc; } 805025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchLoc(SourceLocation L) { SwitchLoc = L; } 806c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 8071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setBody(Stmt *S, SourceLocation SL) { 8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SubExprs[BODY] = S; 8099dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SwitchLoc = SL; 8101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 811c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void addSwitchCase(SwitchCase *SC) { 812c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor assert(!SC->getNextSwitchCase() && "case/default already added to a switch"); 813c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor SC->setNextSwitchCase(FirstCase); 814c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson FirstCase = SC; 815c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 816559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 817559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a 818559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// switch over an enum value then all cases have been explicitly covered. 819559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek void setAllEnumCasesCovered() { 820559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek AllEnumCasesCovered = 1; 821559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 822559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 823559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Returns true if the SwitchStmt is a switch of an enum value and all cases 824559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// have been explicitly covered. 825559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek bool isAllEnumCasesCovered() const { 826559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek return (bool) AllEnumCasesCovered; 827559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 828559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 82963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 8301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd()); 8319dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff } 83263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators 83363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 83463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 83563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 83663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SwitchStmtClass; 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const SwitchStmt *) { return true; } 8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt. 8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt { 84743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 8488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 849b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation WhileLoc; 8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 85143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 85243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SourceLocation WL); 8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 854d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty while statement. 855d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { } 856d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 8575656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Retrieve the variable declared in this "while" statement, if any. 8585656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// 8595656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// In the following example, "x" is the condition variable. 8605656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \code 8615656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// while (int x = random()) { 8625656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// // ... 8635656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// } 8645656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \endcode 86543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 86643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 8675656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 868d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this WhileStmt has a condition variable, return the faux DeclStmt 869d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 870d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 871d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 872d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 873d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 8748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 8758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 876d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 8778297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 8788297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 879d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 880d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 881d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 882d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 883b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 88463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 8851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd()); 886b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 8871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == WhileStmtClass; 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const WhileStmt *) { return true; } 8911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8928297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 89363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 89463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 89563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt. 8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt { 901c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor enum { BODY, COND, END_EXPR }; 9028297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 903b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation DoLoc; 9049f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation WhileLoc; 905989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RParenLoc; // Location of final ')' in do stmt condition. 9069f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor 9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 908989135901c750af61ef012b6b0a0368be415bc46Chris Lattner DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL, 909989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RP) 910989135901c750af61ef012b6b0a0368be415bc46Chris Lattner : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) { 9118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 9128297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[BODY] = body; 9131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 91467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 91567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty do-while statement. 91667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { } 9171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9188297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 9198297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 92067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 9218297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Stmt *getBody() const { return SubExprs[BODY]; } 92367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 92467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 92567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getDoLoc() const { return DoLoc; } 92667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setDoLoc(SourceLocation L) { DoLoc = L; } 9279f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 9289f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 929b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 930989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 931989135901c750af61ef012b6b0a0368be415bc46Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 932989135901c750af61ef012b6b0a0368be415bc46Chris Lattner 93363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 9341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(DoLoc, RParenLoc); 935b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DoStmtClass; 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DoStmt *) { return true; } 9408297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 9418297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 94263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 94363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 94463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not 9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source. 9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt { 95343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; 9548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 955b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation ForLoc; 9565831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation LParenLoc, RParenLoc; 9575831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor 9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 95943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, 96043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP); 9611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty for statement. 96367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { } 96467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 9658297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getInit() { return SubExprs[INIT]; } 966c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 96799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \brief Retrieve the variable declared in this "for" statement, if any. 96899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// 96999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// In the following example, "y" is the condition variable. 97099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \code 97199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// for (int x = random(); int y = mangle(x); ++x) { 97299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// // ... 97399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// } 97499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \endcode 97543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 97643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 977c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 978d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this ForStmt has a condition variable, return the faux DeclStmt 979d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 980d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 981d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]); 982d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 983d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 9848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 9858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 9868297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 9878297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 9888297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getInit() const { return SubExprs[INIT]; } 9898297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 9908297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 9918297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 992b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 99367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInit(Stmt *S) { SubExprs[INIT] = S; } 99467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 99567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } 99667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 99767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 99867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getForLoc() const { return ForLoc; } 99967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setForLoc(SourceLocation L) { ForLoc = L; } 10005831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 10015831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 10025831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 10035831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 100467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 100563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd()); 1007b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ForStmtClass; 10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ForStmt *) { return true; } 10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10138297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 101463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 101563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 101663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto. 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt { 1022ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 1023507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation GotoLoc; 102461f62165220e75694fe333179c78815e2e48d71fTed Kremenek SourceLocation LabelLoc; 10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1026ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL) 102761f62165220e75694fe333179c78815e2e48d71fTed Kremenek : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10291de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor /// \brief Build an empty goto statement. 10301de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { } 10311de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 1032ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 1033ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *D) { Label = D; } 10341de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 10351de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getGotoLoc() const { return GotoLoc; } 10361de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setGotoLoc(SourceLocation L) { GotoLoc = L; } 10371de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 10381de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 1039b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 104063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(GotoLoc, LabelLoc); 1042507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff } 10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GotoStmtClass; 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const GotoStmt *) { return true; } 10471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 104963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto. 10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt { 1055ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation GotoLoc; 10565f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation StarLoc; 10571060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Target; 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, 10605f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Expr *target) 10615f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc), 10625f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Target((Stmt*)target) {} 10637d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 10647d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty indirect goto statement. 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IndirectGotoStmt(EmptyShell Empty) 10667d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Stmt(IndirectGotoStmtClass, Empty) { } 10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1068ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner void setGotoLoc(SourceLocation L) { GotoLoc = L; } 1069ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation getGotoLoc() const { return GotoLoc; } 10705f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor void setStarLoc(SourceLocation L) { StarLoc = L; } 10715f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation getStarLoc() const { return StarLoc; } 10721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall Expr *getTarget() { return reinterpret_cast<Expr*>(Target); } 107495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);} 10757d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); } 1076b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 107795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// getConstantTarget - Returns the fixed target of this indirect 107895c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// goto, if one exists. 1079ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getConstantTarget(); 1080ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner const LabelDecl *getConstantTarget() const { 108195c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall return const_cast<IndirectGotoStmt*>(this)->getConstantTarget(); 108295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall } 108395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall 108463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1085ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner return SourceRange(GotoLoc, Target->getLocEnd()); 1086ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner } 10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IndirectGotoStmtClass; 10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IndirectGotoStmt *) { return true; } 10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10938297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 109463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Target, &Target+1); } 10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue. 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt { 1101507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation ContinueLoc; 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1103507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {} 11041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1105d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty continue statement. 1106d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { } 1107d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1108d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getContinueLoc() const { return ContinueLoc; } 1109d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setContinueLoc(SourceLocation L) { ContinueLoc = L; } 1110d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 111163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(ContinueLoc); 1113507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff } 1114861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor 11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ContinueStmtClass; 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ContinueStmt *) { return true; } 11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 112163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break. 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt { 1127507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation BreakLoc; 11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1129507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1131025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty break statement. 1132025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { } 1133025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1134025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getBreakLoc() const { return BreakLoc; } 1135025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBreakLoc(SourceLocation L) { BreakLoc = L; } 1136025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 113763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(BreakLoc); } 1138b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BreakStmtClass; 11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BreakStmt *) { return true; } 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11448297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 114563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1149c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression: 1150c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return; 1151c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return 4; 1152c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// 1153c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to 1154c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to 1155c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void. We explicitly model this in the AST, which means you can't 1156c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument. 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt { 11591060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *RetExpr; 1160507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation RetLoc; 11615077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *NRVOCandidate; 11625077c3876beeaed32280af88244e8050078619a8Douglas Gregor 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11645077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL) 116525a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { } 11665077c3876beeaed32280af88244e8050078619a8Douglas Gregor 11675077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) 11685077c3876beeaed32280af88244e8050078619a8Douglas Gregor : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL), 11695077c3876beeaed32280af88244e8050078619a8Douglas Gregor NRVOCandidate(NRVOCandidate) {} 11700de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 11710de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor /// \brief Build an empty return expression. 11720de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { } 11730de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 11741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getRetValue() const; 11751060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getRetValue(); 11760de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); } 11770de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 11780de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor SourceLocation getReturnLoc() const { return RetLoc; } 11790de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setReturnLoc(SourceLocation L) { RetLoc = L; } 1180b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 11815077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// \brief Retrieve the variable that might be used for the named return 11825077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// value optimization. 11835077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// 11845077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// The optimization itself can only be performed if the variable is 11855077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// also marked as an NRVO object. 11865077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *getNRVOCandidate() const { return NRVOCandidate; } 11875077c3876beeaed32280af88244e8050078619a8Douglas Gregor void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; } 11885077c3876beeaed32280af88244e8050078619a8Douglas Gregor 118963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 11901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ReturnStmtClass; 11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReturnStmt *) { return true; } 11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11968297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 119763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 119863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (RetExpr) return child_range(&RetExpr, &RetExpr+1); 119963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 120063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 12015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1203fe795956194141c91ae555985c9b930595bff43fChris Lattner/// AsmStmt - This represents a GNU inline-assembly statement extension. 1204fe795956194141c91ae555985c9b930595bff43fChris Lattner/// 1205fe795956194141c91ae555985c9b930595bff43fChris Lattnerclass AsmStmt : public Stmt { 1206fe795956194141c91ae555985c9b930595bff43fChris Lattner SourceLocation AsmLoc, RParenLoc; 12076a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson StringLiteral *AsmStr; 1208b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1209dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson bool IsSimple; 121039c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson bool IsVolatile; 12113b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump bool MSAsm; 12121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1213b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned NumOutputs; 1214b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned NumInputs; 1215966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson unsigned NumClobbers; 12161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1217966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson // FIXME: If we wanted to, we could allocate all of these in one big array. 1218966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson IdentifierInfo **Names; 1219966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Constraints; 1220966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson Stmt **Exprs; 1221966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Clobbers; 1222c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1223fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic: 1224c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, 1225966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson bool msasm, unsigned numoutputs, unsigned numinputs, 1226ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **names, StringLiteral **constraints, 1227db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, 1228db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner StringLiteral **clobbers, SourceLocation rparenloc); 1229b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1230cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor /// \brief Build an empty inline-assembly statement. 1231c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty), 1232966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson Names(0), Constraints(0), Exprs(0), Clobbers(0) { } 1233cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1234cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getAsmLoc() const { return AsmLoc; } 1235cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmLoc(SourceLocation L) { AsmLoc = L; } 1236cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 1237cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1238cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 123939c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson bool isVolatile() const { return IsVolatile; } 1240cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setVolatile(bool V) { IsVolatile = V; } 1241dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson bool isSimple() const { return IsSimple; } 12426ffe643322949dd776285a6df60d3578f3918be4Chris Lattner void setSimple(bool V) { IsSimple = V; } 12433b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump bool isMSAsm() const { return MSAsm; } 12443b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump void setMSAsm(bool V) { MSAsm = V; } 1245dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson 1246458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner //===--- Asm String Analysis ---===// 1247458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1248458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const StringLiteral *getAsmString() const { return AsmStr; } 1249458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner StringLiteral *getAsmString() { return AsmStr; } 1250cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmString(StringLiteral *E) { AsmStr = E; } 1251cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1252458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AsmStringPiece - this is part of a decomposed asm string specification 1253458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// (for use with the AnalyzeAsmString function below). An asm string is 1254458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// considered to be a concatenation of these parts. 1255458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner class AsmStringPiece { 1256458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1257458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner enum Kind { 1258458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". 1259458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Operand // Operand reference, with optional modifier %c4. 1260458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 1261458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner private: 1262458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Kind MyKind; 1263458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner std::string Str; 1264458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned OperandNo; 1265458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1266458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} 1267458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(unsigned OpNo, char Modifier) 1268458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner : MyKind(Operand), Str(), OperandNo(OpNo) { 1269458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Str += Modifier; 1270458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1272458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isString() const { return MyKind == String; } 1273458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isOperand() const { return MyKind == Operand; } 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1275458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const std::string &getString() const { 1276458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isString()); 1277458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str; 1278458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1279458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1280458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned getOperandNo() const { 1281458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1282458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return OperandNo; 1283458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1285458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// getModifier - Get the modifier for this operand, if present. This 1286458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// returns '\0' if there was no modifier. 1287458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner char getModifier() const { 1288458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1289458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str[0]; 1290458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1291458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1293458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 1294458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// it into pieces. If the asm string is erroneous, emit errors and return 1295458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// true, otherwise return false. This handles canonicalization and 1296458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// translation of strings from GCC syntax to LLVM IR syntax, and handles 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump //// flattening of named references like %[foo] to Operand AsmStringPiece's. 1298fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner unsigned AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece> &Pieces, 1299fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner ASTContext &C, unsigned &DiagOffs) const; 13001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1302b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Output operands ---===// 1303b327793860737d1c103a73aeda8057dd628a101dChris Lattner 1304b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned getNumOutputs() const { return NumOutputs; } 1305ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1306ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo *getOutputIdentifier(unsigned i) const { 1307ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Names[i]; 1308ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1309ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1310ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::StringRef getOutputName(unsigned i) const { 1311ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson if (IdentifierInfo *II = getOutputIdentifier(i)) 1312ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return II->getName(); 1313c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1314ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return llvm::StringRef(); 1315ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson } 1316ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1317b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// getOutputConstraint - Return the constraint string for the specified 1318b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// output operand. All output constraints are known to be non-empty (either 1319b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// '=' or '+'). 1320acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson llvm::StringRef getOutputConstraint(unsigned i) const; 13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1322b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getOutputConstraintLiteral(unsigned i) const { 1323ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i]; 1324ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1325b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getOutputConstraintLiteral(unsigned i) { 1326b327793860737d1c103a73aeda8057dd628a101dChris Lattner return Constraints[i]; 1327b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1329ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getOutputExpr(unsigned i); 13301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1331b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getOutputExpr(unsigned i) const { 1332b327793860737d1c103a73aeda8057dd628a101dChris Lattner return const_cast<AsmStmt*>(this)->getOutputExpr(i); 1333b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 13341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1335b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// isOutputPlusConstraint - Return true if the specified output constraint 1336b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// is a "+" constraint (which is both an input and an output) or false if it 1337b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// is an "=" constraint (just an output). 1338b327793860737d1c103a73aeda8057dd628a101dChris Lattner bool isOutputPlusConstraint(unsigned i) const { 1339b327793860737d1c103a73aeda8057dd628a101dChris Lattner return getOutputConstraint(i)[0] == '+'; 1340b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134285759278332404e96d4bb89d0e976e46158cd026Chris Lattner /// getNumPlusOperands - Return the number of output operands that have a "+" 134385759278332404e96d4bb89d0e976e46158cd026Chris Lattner /// constraint. 134485759278332404e96d4bb89d0e976e46158cd026Chris Lattner unsigned getNumPlusOperands() const; 13451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1346b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Input operands ---===// 13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumInputs() const { return NumInputs; } 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1350ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo *getInputIdentifier(unsigned i) const { 1351ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Names[i + NumOutputs]; 1352ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1354ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::StringRef getInputName(unsigned i) const { 1355ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson if (IdentifierInfo *II = getInputIdentifier(i)) 1356ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return II->getName(); 1357ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1358ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return llvm::StringRef(); 1359ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson } 1360ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1361b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// getInputConstraint - Return the specified input constraint. Unlike output 1362b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// constraints, these can be empty. 1363acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson llvm::StringRef getInputConstraint(unsigned i) const; 13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1365b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getInputConstraintLiteral(unsigned i) const { 1366ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1367ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1368b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getInputConstraintLiteral(unsigned i) { 1369ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1370ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1372ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getInputExpr(unsigned i); 1373935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner void setInputExpr(unsigned i, Expr *E); 1374935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner 1375b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getInputExpr(unsigned i) const { 1376b327793860737d1c103a73aeda8057dd628a101dChris Lattner return const_cast<AsmStmt*>(this)->getInputExpr(i); 1377b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 1378cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1379acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson void setOutputsAndInputsAndClobbers(ASTContext &C, 1380ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1381fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Constraints, 1382fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson Stmt **Exprs, 1383fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumOutputs, 1384c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned NumInputs, 1385fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Clobbers, 1386fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumClobbers); 1387cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 138810ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner //===--- Other ---===// 13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 139010ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// getNamedOperand - Given a symbolic operand reference like %[foo], 139110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// translate this into a numeric value needed to reference the same operand. 139210ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// This returns -1 if the operand name is invalid. 1393acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson int getNamedOperand(llvm::StringRef SymbolicName) const; 139410ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner 1395966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson unsigned getNumClobbers() const { return NumClobbers; } 1396b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson StringLiteral *getClobber(unsigned i) { return Clobbers[i]; } 1397d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; } 1398cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 139963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1400fe795956194141c91ae555985c9b930595bff43fChris Lattner return SourceRange(AsmLoc, RParenLoc); 1401fe795956194141c91ae555985c9b930595bff43fChris Lattner } 14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1403fe795956194141c91ae555985c9b930595bff43fChris Lattner static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;} 1404fe795956194141c91ae555985c9b930595bff43fChris Lattner static bool classof(const AsmStmt *) { return true; } 14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1406ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek // Input expr iterators. 14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1408ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ExprIterator inputs_iterator; 1409ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ConstExprIterator const_inputs_iterator; 14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1411ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek inputs_iterator begin_inputs() { 1412966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1413ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1415ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek inputs_iterator end_inputs() { 1416966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs + NumInputs; 1417ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1419ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const_inputs_iterator begin_inputs() const { 1420966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1421ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 14221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1423ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const_inputs_iterator end_inputs() const { 1424966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs + NumInputs; 1425d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 14261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1427ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek // Output expr iterators. 14281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1429ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ExprIterator outputs_iterator; 1430ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ConstExprIterator const_outputs_iterator; 14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1432d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek outputs_iterator begin_outputs() { 1433966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0]; 1434d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 1435d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek outputs_iterator end_outputs() { 1436966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1437d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 14381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1439d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek const_outputs_iterator begin_outputs() const { 1440966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0]; 1441d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 1442d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek const_outputs_iterator end_outputs() const { 1443966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1444d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 144663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 144763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); 144863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 1449fe795956194141c91ae555985c9b930595bff43fChris Lattner}; 145078492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek 145128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt { 145228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 145328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 145428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 145528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { FILTER_EXPR, BLOCK }; 145628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 145728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt(SourceLocation Loc, 145828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 145928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 146028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 146128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 146228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static SEHExceptStmt* Create(ASTContext &C, 146328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation ExceptLoc, 146428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 146528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 146628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceRange getSourceRange() const { 146728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SourceRange(getExceptLoc(), getEndLoc()); 146828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 146928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 147028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getExceptLoc() const { return Loc; } 147128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); } 147228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 147328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *getFilterExpr() const { return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); } 147428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Children[BLOCK]); } 147528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 147628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 147728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 147828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 147928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 148028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 148128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHExceptStmtClass; 148228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 148328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 148428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(SEHExceptStmt *) { return true; } 148528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 148628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 148728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 148828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt { 148928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 149028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block; 149128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 149228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt(SourceLocation Loc, 149328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 149428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 149528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 149628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static SEHFinallyStmt* Create(ASTContext &C, 149728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation FinallyLoc, 149828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 149928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 150028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceRange getSourceRange() const { 150128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SourceRange(getFinallyLoc(), getEndLoc()); 150228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 150328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 150428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getFinallyLoc() const { return Loc; } 150528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Block->getLocEnd(); } 150628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 150728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); } 150828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 150928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 151028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(&Block,&Block+1); 151128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 151228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 151328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 151428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHFinallyStmtClass; 151528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 151628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 151728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(SEHFinallyStmt *) { return true; } 151828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 151928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 152028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 152128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt { 152228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool IsCXXTry; 152328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc; 152428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 152528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 152628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { TRY = 0, HANDLER = 1 }; 152728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 152828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try' 152928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 153028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 153128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 153228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 153328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 153428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static SEHTryStmt* Create(ASTContext &C, 153528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool isCXXTry, 153628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 153728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 153828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 153928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 154028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceRange getSourceRange() const { 154128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SourceRange(getTryLoc(), getEndLoc()); 154228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 154328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 154428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getTryLoc() const { return TryLoc; } 154528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); } 154628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 154728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool getIsCXXTry() const { return IsCXXTry; } 154828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley CompoundStmt* getTryBlock() const { return llvm::cast<CompoundStmt>(Children[TRY]); } 154928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *getHandler() const { return Children[HANDLER]; } 155028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 155128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// Returns 0 if not defined 155228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt *getExceptHandler() const; 155328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt *getFinallyHandler() const; 155428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 155528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 155628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 155728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 155828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 155928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 156028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHTryStmtClass; 156128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 156228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 156328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(SEHTryStmt *) { return true; } 156428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 156528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 156628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 15675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 15685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1570