Stmt.h revision 63c00d7f35fa060c0a446c9df3a4402d9c7757fe
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 LabelStmtBitfields { 1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class LabelStmt; 1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned Used : 1; 1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned HasUnusedAttr : 1; 1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class ExprBitfields { 1428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Expr; 1438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DeclRefExpr; // computeDependence 1448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class InitListExpr; // ctor 1458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DesignatedInitExpr; // ctor 146d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor friend class BlockDeclRefExpr; // ctor 147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ASTStmtReader; // deserialization 148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXNewExpr; // ctor 149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class DependentScopeDeclRefExpr; // ctor 150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXConstructExpr; // ctor 151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CallExpr; // ctor 152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OffsetOfExpr; // ctor 153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ObjCMessageExpr; // ctor 154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ShuffleVectorExpr; // ctor 155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ParenListExpr; // ctor 156bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXUnresolvedConstructExpr; // ctor 157bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXDependentScopeMemberExpr; // ctor 158bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OverloadExpr; // ctor 1598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueKind : 2; 162f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall unsigned ObjectKind : 2; 1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned TypeDependent : 1; 1648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueDependent : 1; 165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned ContainsUnexpandedParameterPack : 1; 1668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 167d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor enum { NumExprBits = 15 }; 1688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CastExprBitfields { 1708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CastExpr; 1718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumExprBits; 1728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1732bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned Kind : 6; 1742bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned BasePathSize : 32 - 6 - NumExprBits; 1758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1768e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 177cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne class CallExprBitfields { 178cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne friend class CallExpr; 179cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned : NumExprBits; 180cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 181cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs : 1; 182cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne }; 183cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1848e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall union { 18563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // FIXME: this is wasteful on 64-bit platforms. 18663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall void *Aligner; 18763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 1888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBitfields StmtBits; 1898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBitfields CompoundStmtBits; 1908e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall LabelStmtBitfields LabelStmtBits; 1918e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBitfields ExprBits; 1928e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBitfields CastExprBits; 193cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBitfields CallExprBits; 1948e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1958e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 196d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor friend class ASTStmtReader; 197d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1988189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic: 1998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Only allow allocation of Stmts using the allocator in ASTContext 2001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // or by doing a placement new. 2018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext& C, 202f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor unsigned alignment = 8) throw() { 2038189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return ::operator new(bytes, C, alignment); 2048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 2051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext* C, 207f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor unsigned alignment = 8) throw() { 2088189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return ::operator new(bytes, *C, alignment); 2098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 2101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, void* mem) throw() { 2128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return mem; 2138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 214e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 215fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext&, unsigned) throw() { } 216fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext*, unsigned) throw() { } 217e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor void operator delete(void*, std::size_t) throw() { } 218fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, void*) throw() { } 219e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 220025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic: 221025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief A placeholder type used to construct an empty shell of a 222025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// type, that will be filled in later (e.g., by some 223025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// de-serialization). 224025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor struct EmptyShell { }; 225025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 2269c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected: 227025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Construct an empty statement. 2288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall explicit Stmt(StmtClass SC, EmptyShell) { 2298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 230025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); 231025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor } 232025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt(StmtClass SC) { 2358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 239c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt StmtClass getStmtClass() const { 2408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall return static_cast<StmtClass>(StmtBits.sClass); 241b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor } 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStmtClassName() const; 2431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 244b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// SourceLocation tokens are not useful in isolation - they are low level 245b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// value objects created/interpreted by SourceManager. We assume AST 246b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// clients will have a pointer to the respective SourceManager. 24763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 24863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 249311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner SourceLocation getLocStart() const { return getSourceRange().getBegin(); } 250311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // global temp stats (until we have a per-module visitor) 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void addStmtClass(const StmtClass s); 2542024f4d4b0d57616f79ea742fa782d633d414462Kovarththanan Rajaratnam static bool CollectingStats(bool Enable = false); 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void PrintStats(); 2566000dace22f110d8768476989313e9d981d690d0Chris Lattner 2576000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dump - This does a local dump of the specified AST fragment. It dumps the 2586000dace22f110d8768476989313e9d981d690d0Chris Lattner /// specified node and a few nodes underneath it, but not the whole subtree. 2596000dace22f110d8768476989313e9d981d690d0Chris Lattner /// This is useful in a debugger. 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void dump() const; 261e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner void dump(SourceManager &SM) const; 2629668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis void dump(llvm::raw_ostream &OS, SourceManager &SM) const; 2636000dace22f110d8768476989313e9d981d690d0Chris Lattner 2646000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpAll - This does a dump of the specified AST fragment and all subtrees. 2656000dace22f110d8768476989313e9d981d690d0Chris Lattner void dumpAll() const; 266e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner void dumpAll(SourceManager &SM) const; 2676000dace22f110d8768476989313e9d981d690d0Chris Lattner 2686000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST 2696000dace22f110d8768476989313e9d981d690d0Chris Lattner /// back to its original source language syntax. 27048d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman void dumpPretty(ASTContext& Context) const; 2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void printPretty(llvm::raw_ostream &OS, PrinterHelper *Helper, 272e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 27348d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman unsigned Indentation = 0) const { 27448d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation); 27548d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman } 276e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void printPretty(llvm::raw_ostream &OS, ASTContext &Context, 2771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PrinterHelper *Helper, 278e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 279d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned Indentation = 0) const; 2801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 281d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only 282d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// works on systems with GraphViz (Mac OS X) or dot+gv installed. 283d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek void viewAST() const; 2841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Implement isa<T> support. 2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *) { return true; } 2871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 288d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// hasImplicitControlFlow - Some statements (e.g. short circuited operations) 289d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// contain implicit control-flow in the order their subexpressions 290d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// are evaluated. This predicate returns true if this statement has 291d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// such implicit control-flow. Such statements are also specially handled 292d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// within CFGs. 293d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek bool hasImplicitControlFlow() const; 294d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek 29563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// Child Iterators: All subclasses must implement 'children' 29663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// to permit easy iteration over the substatements/subexpessions of an 29763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// AST node. This permits easy iteration over all nodes in the AST. 2989caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef StmtIterator child_iterator; 2999caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef ConstStmtIterator const_child_iterator; 3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef StmtRange child_range; 30263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef ConstStmtRange const_child_range; 3031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 30563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_range children() const { 30663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return const_cast<Stmt*>(this)->children(); 30777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_begin() { return children().first; } 31063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_end() { return children().second; } 31163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 31263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_begin() const { return children().first; } 31363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_end() const { return children().second; } 31441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 31541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Produce a unique representation of the given statement. 31641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 31741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief ID once the profiling operation is complete, will contain 31841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// the unique representation of the given statement. 31941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 32041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Context the AST context in which the statement resides 32141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 32241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Canonical whether the profile should be based on the canonical 32341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// representation of this statement (e.g., where non-type template 3241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// parameters are identified by index/level rather than their 32541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// declaration pointers) or the exact representation of the statement as 32641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// written in the source. 3274ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 32841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor bool Canonical); 3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and 3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions 3331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration. 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt { 3379653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor DeclGroupRef DG; 33881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation StartLoc, EndLoc; 3391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 3428ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg), 3438ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek StartLoc(startLoc), EndLoc(endLoc) {} 3441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor /// \brief Build an empty declaration statement. 34684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { } 34784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 3487e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner /// isSingleDecl - This method returns true if this DeclStmt refers 349fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner /// to a single Decl. 3507e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner bool isSingleDecl() const { 351fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner return DG.isSingleDecl(); 3528ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek } 3531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3547e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner const Decl *getSingleDecl() const { return DG.getSingleDecl(); } 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl *getSingleDecl() { return DG.getSingleDecl(); } 3561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 357e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner const DeclGroupRef getDeclGroup() const { return DG; } 358e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner DeclGroupRef getDeclGroup() { return DG; } 35984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setDeclGroup(DeclGroupRef DGR) { DG = DGR; } 360b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 36181c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getStartLoc() const { return StartLoc; } 36284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setStartLoc(SourceLocation L) { StartLoc = L; } 36381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getEndLoc() const { return EndLoc; } 36484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setEndLoc(SourceLocation L) { EndLoc = L; } 36584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 3668ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek SourceRange getSourceRange() const { 36781c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner return SourceRange(StartLoc, EndLoc); 36881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner } 3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DeclStmtClass; 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclStmt *) { return true; } 3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37514f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek // Iterators over subexpressions. 37663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 37763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(DG.begin(), DG.end()), 37863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator(DG.end(), DG.end())); 37963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3810632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::iterator decl_iterator; 3820632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::const_iterator const_decl_iterator; 3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3848ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_begin() { return DG.begin(); } 3858ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_end() { return DG.end(); } 3868ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_begin() const { return DG.begin(); } 3878ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_end() const { return DG.end(); } 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3. 3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt { 3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation SemiLoc; 39444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 39544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// \brief Whether the null statement was preceded by an empty macro, e.g: 39644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @code 39744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// #define CALL(x) 39844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// CALL(0); 39944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @endcode 40044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis bool LeadingEmptyMacro; 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 40244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis NullStmt(SourceLocation L, bool LeadingEmptyMacro = false) 40344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis : Stmt(NullStmtClass), SemiLoc(L), LeadingEmptyMacro(LeadingEmptyMacro) {} 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 405025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty null statement. 406025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) { } 407025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getSemiLoc() const { return SemiLoc; } 409025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSemiLoc(SourceLocation L) { SemiLoc = L; } 410b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 41144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis bool hasLeadingEmptyMacro() const { return LeadingEmptyMacro; } 41244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 41363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(SemiLoc); } 4141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == NullStmtClass; 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const NullStmt *) { return true; } 4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 42144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 42244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtReader; 42344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtWriter; 4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }. 4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt { 4298189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek Stmt** Body; 430b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation LBracLoc, RBracLoc; 4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned NumStmts, 4338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall SourceLocation LB, SourceLocation RB) 4348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { 4358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = NumStmts; 4368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 437026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (NumStmts == 0) { 438026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Body = 0; 439026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return; 440026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 4411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 442026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Body = new (C) Stmt*[NumStmts]; 4438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall memcpy(Body, StmtStart, NumStmts * sizeof(*Body)); 4441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 445025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 446025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor // \brief Build an empty compound statement. 447025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CompoundStmt(EmptyShell Empty) 4488e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass, Empty), Body(0) { 4498e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = 0; 4508e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 451025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 452025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts); 4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4548e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } 4558e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned size() const { return CompoundStmtBits.NumStmts; } 456025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 4578189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt** body_iterator; 4588189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek body_iterator body_begin() { return Body; } 4598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall body_iterator body_end() { return Body + size(); } 4608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; } 461e946fc833d8592aa2890bfd9839f1ad839b3d284Fariborz Jahanian 4628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setLastStmt(Stmt *S) { 4638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall assert(!body_empty() && "setLastStmt"); 4648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Body[size()-1] = S; 4658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4678189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt* const * const_body_iterator; 4688189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_body_iterator body_begin() const { return Body; } 4698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const_body_iterator body_end() const { return Body + size(); } 4708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; } 4718189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek 4728189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<body_iterator> reverse_body_iterator; 4738189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rbegin() { 4748189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_end()); 4758189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4768189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rend() { 4778189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_begin()); 4788189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4794ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 4808189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<const_body_iterator> 4818189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator; 4824ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 4838189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rbegin() const { 4848189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_end()); 4858189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4878189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rend() const { 4888189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_begin()); 4898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(LBracLoc, RBracLoc); 493b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 4941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 495cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getLBracLoc() const { return LBracLoc; } 496025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setLBracLoc(SourceLocation L) { LBracLoc = L; } 497cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getRBracLoc() const { return RBracLoc; } 498025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setRBracLoc(SourceLocation L) { RBracLoc = L; } 4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundStmtClass; 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundStmt *) { return true; } 5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5058297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 50663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 50763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 50863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 511c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt, 512c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt { 513103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected: 514c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // A pointer to the following CaseStmt or DefaultStmt class, 515c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // used by SwitchStmt. 516c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *NextSwitchCase; 517103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek 518d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {} 5191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 520c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic: 521c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } 522c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 523c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getNextSwitchCase() { return NextSwitchCase; } 524c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 525c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } 526d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek 52763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt *getSubStmt(); 528b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 52963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(); } 5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass || 53363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall T->getStmtClass() == DefaultStmtClass; 534c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 535c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson static bool classof(const SwitchCase *) { return true; } 536c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson}; 537c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 538c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase { 539d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek enum { SUBSTMT, LHS, RHS, END_EXPR }; 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 541d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // GNU "case 1 ... 4" extension 542b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation CaseLoc; 543dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation EllipsisLoc; 544dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation ColonLoc; 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 546dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, 5471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation ellipsisLoc, SourceLocation colonLoc) 548d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek : SwitchCase(CaseStmtClass) { 54924e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner SubExprs[SUBSTMT] = 0; 550d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 551d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 552b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff CaseLoc = caseLoc; 553dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor EllipsisLoc = ellipsisLoc; 554dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor ColonLoc = colonLoc; 555d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek } 556025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 557025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty switch case statement. 558025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { } 559025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 560764a7ce5217f9569e100a3445f47496ee82daf86Chris Lattner SourceLocation getCaseLoc() const { return CaseLoc; } 561025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCaseLoc(SourceLocation L) { CaseLoc = L; } 562dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 563dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } 564dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 565dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 566025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 567d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 568d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 569d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 570025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getLHS() const { 5721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[LHS]); 57351b09f2c528c8460b5465c676173324e44176d62Devang Patel } 5741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getRHS() const { 5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[RHS]); 57651b09f2c528c8460b5465c676173324e44176d62Devang Patel } 57751b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 57920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; } 58020dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } 58120dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } 5821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 5853fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner // Handle deeply nested case statements with iteration instead of recursion. 5863fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner const CaseStmt *CS = this; 58791ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) 5883fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner CS = CS2; 5891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd()); 591b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass; 5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CaseStmt *) { return true; } 5961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 597d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 59863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 59963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[END_EXPR]); 60063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 603c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase { 604d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt* SubStmt; 6056c36be5b383875b490684bcf439d6d427298c1afChris Lattner SourceLocation DefaultLoc; 606dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation ColonLoc; 6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : 609dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL), 610dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor ColonLoc(CL) {} 611025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 612025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty default statement. 613025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { } 614025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 615d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubStmt; } 61651b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubStmt; } 617025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSubStmt(Stmt *S) { SubStmt = S; } 618025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 6196c36be5b383875b490684bcf439d6d427298c1afChris Lattner SourceLocation getDefaultLoc() const { return DefaultLoc; } 620025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setDefaultLoc(SourceLocation L) { DefaultLoc = L; } 621dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 622dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 62463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(DefaultLoc, SubStmt->getLocEnd()); 626b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 6271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DefaultStmtClass; 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DefaultStmt *) { return true; } 6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 632d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 63363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt { 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Label; 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *SubStmt; 639b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IdentLoc; 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6411a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis LabelStmt(SourceLocation IL, IdentifierInfo *label, Stmt *substmt, 6421a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis bool hasUnusedAttr = false) 6438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(LabelStmtClass), Label(label), SubStmt(substmt), IdentLoc(IL) { 6448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall LabelStmtBits.Used = false; 6458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall LabelStmtBits.HasUnusedAttr = hasUnusedAttr; 6468e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 6471de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 6481de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor // \brief Build an empty label statement. 6491de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { } 6501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getIdentLoc() const { return IdentLoc; } 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *getID() const { return Label; } 6531de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setID(IdentifierInfo *II) { Label = II; } 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *getSubStmt() { return SubStmt; } 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Stmt *getSubStmt() const { return SubStmt; } 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setIdentLoc(SourceLocation L) { IdentLoc = L; } 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setSubStmt(Stmt *SS) { SubStmt = SS; } 659b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 660355a9fe26a6dec89680ddf713dd5bc7a671b298aArgyrios Kyrtzidis /// \brief Whether this label was used. 6611a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis bool isUsed(bool CheckUnusedAttr = true) const { 6628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall return LabelStmtBits.Used || 6638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall (CheckUnusedAttr && LabelStmtBits.HasUnusedAttr); 6641a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis } 6658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setUsed(bool U = true) { LabelStmtBits.Used = U; } 666355a9fe26a6dec89680ddf713dd5bc7a671b298aArgyrios Kyrtzidis 6678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool HasUnusedAttribute() const { return LabelStmtBits.HasUnusedAttr; } 6688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setUnusedAttribute(bool U) { LabelStmtBits.HasUnusedAttr = U; } 6691a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis 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 7098297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 710025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 7118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getThen() const { return SubExprs[THEN]; } 7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setThen(Stmt *S) { SubExprs[THEN] = S; } 7138297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getElse() const { return SubExprs[ELSE]; } 714025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setElse(Stmt *S) { SubExprs[ELSE] = S; } 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7168297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 7178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getThen() { return SubExprs[THEN]; } 7188297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getElse() { return SubExprs[ELSE]; } 719b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 720025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getIfLoc() const { return IfLoc; } 721025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setIfLoc(SourceLocation L) { IfLoc = L; } 722d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation getElseLoc() const { return ElseLoc; } 723d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor void setElseLoc(SourceLocation L) { ElseLoc = L; } 724025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 72563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 726b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff if (SubExprs[ELSE]) 727b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd()); 728b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff else 729b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd()); 730b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators over subexpressions. The iterators will include iterating 73363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // over the initialization expression referenced by the condition variable. 73463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 73563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 73663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 73763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 7381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IfStmtClass; 7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IfStmt *) { return true; } 7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt. 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt { 74743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 749c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // This points to a linked list of case and default statements. 750c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *FirstCase; 7519dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SourceLocation SwitchLoc; 7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 753559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// If the SwitchStmt is a switch on an enum value, this records whether 754559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// all the enum values were covered by CaseStmts. This value is meant to 755559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// be a hint for possible clients. 756559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek unsigned AllEnumCasesCovered : 1; 757559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 75943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond); 7601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 761025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build a empty switch statement. 762025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { } 763025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 764d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \brief Retrieve the variable declared in this "switch" statement, if any. 765d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// 766d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// In the following example, "x" is the condition variable. 767d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \code 768d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// switch (int x = foo()) { 769d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// case 0: break; 770d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// // ... 771d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// } 772d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \endcode 77343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 77443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 775d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor 7768297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 7778297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 778c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getSwitchCaseList() const { return FirstCase; } 779c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 7808297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 781025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 7828297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 783025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 784c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getSwitchCaseList() { return FirstCase; } 7851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Set the case list for this switch statement. 78743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// 78843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// The caller is responsible for incrementing the retain counts on 78943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// all of the SwitchCase statements in this list. 790025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } 791025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 792025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getSwitchLoc() const { return SwitchLoc; } 793025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchLoc(SourceLocation L) { SwitchLoc = L; } 794c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setBody(Stmt *S, SourceLocation SL) { 7961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SubExprs[BODY] = S; 7979dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SwitchLoc = SL; 7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 799c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void addSwitchCase(SwitchCase *SC) { 800c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor assert(!SC->getNextSwitchCase() && "case/default already added to a switch"); 801c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor SC->setNextSwitchCase(FirstCase); 802c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson FirstCase = SC; 803c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 804559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 805559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a 806559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// switch over an enum value then all cases have been explicitly covered. 807559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek void setAllEnumCasesCovered() { 808559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek AllEnumCasesCovered = 1; 809559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 810559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 811559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Returns true if the SwitchStmt is a switch of an enum value and all cases 812559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// have been explicitly covered. 813559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek bool isAllEnumCasesCovered() const { 814559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek return (bool) AllEnumCasesCovered; 815559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 816559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 81763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 8181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd()); 8199dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff } 82063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators 82163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 82263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 82363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 82463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 8251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SwitchStmtClass; 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const SwitchStmt *) { return true; } 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt. 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt { 83543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 8368297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 837b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation WhileLoc; 8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 83943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 84043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SourceLocation WL); 8411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 842d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty while statement. 843d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { } 844d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 8455656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Retrieve the variable declared in this "while" statement, if any. 8465656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// 8475656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// In the following example, "x" is the condition variable. 8485656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \code 8495656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// while (int x = random()) { 8505656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// // ... 8515656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// } 8525656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \endcode 85343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 85443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 8555656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 8568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 8578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 858d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 8598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 8608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 861d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 862d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 863d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 864d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 865b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 86663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 8671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd()); 868b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 8691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == WhileStmtClass; 8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const WhileStmt *) { return true; } 8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 87563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 87663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 87763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt. 8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt { 883c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor enum { BODY, COND, END_EXPR }; 8848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 885b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation DoLoc; 8869f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation WhileLoc; 887989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RParenLoc; // Location of final ')' in do stmt condition. 8889f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 890989135901c750af61ef012b6b0a0368be415bc46Chris Lattner DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL, 891989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RP) 892989135901c750af61ef012b6b0a0368be415bc46Chris Lattner : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) { 8938297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 8948297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[BODY] = body; 8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 89667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 89767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty do-while statement. 89867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { } 8991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9008297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 9018297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 90267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 9038297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 9041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Stmt *getBody() const { return SubExprs[BODY]; } 90567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 90667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 90767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getDoLoc() const { return DoLoc; } 90867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setDoLoc(SourceLocation L) { DoLoc = L; } 9099f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 9109f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 911b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 912989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 913989135901c750af61ef012b6b0a0368be415bc46Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 914989135901c750af61ef012b6b0a0368be415bc46Chris Lattner 91563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(DoLoc, RParenLoc); 917b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 9181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DoStmtClass; 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DoStmt *) { return true; } 9228297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 9238297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 92463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 92563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 92663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source. 9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt { 93543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; 9368297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 937b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation ForLoc; 9385831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation LParenLoc, RParenLoc; 9395831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 94143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, 94243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP); 9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 94467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty for statement. 94567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { } 94667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 9478297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getInit() { return SubExprs[INIT]; } 948c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 94999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \brief Retrieve the variable declared in this "for" statement, if any. 95099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// 95199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// In the following example, "y" is the condition variable. 95299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \code 95399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// for (int x = random(); int y = mangle(x); ++x) { 95499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// // ... 95599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// } 95699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \endcode 95743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 95843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 959c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 9608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 9618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 9628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 9638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 9648297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getInit() const { return SubExprs[INIT]; } 9658297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 9668297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 9678297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 968b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 96967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInit(Stmt *S) { SubExprs[INIT] = S; } 97067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 97167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } 97267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 97367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 97467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getForLoc() const { return ForLoc; } 97567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setForLoc(SourceLocation L) { ForLoc = L; } 9765831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 9775831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 9785831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 9795831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 98067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 98163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd()); 983b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 9841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ForStmtClass; 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ForStmt *) { return true; } 9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9898297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 99063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 99163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 99263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto. 9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt { 9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 999507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation GotoLoc; 100061f62165220e75694fe333179c78815e2e48d71fTed Kremenek SourceLocation LabelLoc; 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GotoStmt(LabelStmt *label, SourceLocation GL, SourceLocation LL) 100361f62165220e75694fe333179c78815e2e48d71fTed Kremenek : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10051de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor /// \brief Build an empty goto statement. 10061de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { } 10071de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 10091de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setLabel(LabelStmt *S) { Label = S; } 10101de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 10111de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getGotoLoc() const { return GotoLoc; } 10121de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setGotoLoc(SourceLocation L) { GotoLoc = L; } 10131de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 10141de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 1015b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 101663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(GotoLoc, LabelLoc); 1018507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff } 10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GotoStmtClass; 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const GotoStmt *) { return true; } 10231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10248297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 102563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto. 10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt { 1031ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation GotoLoc; 10325f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation StarLoc; 10331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Target; 10345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, 10365f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Expr *target) 10375f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc), 10385f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Target((Stmt*)target) {} 10397d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 10407d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty indirect goto statement. 10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IndirectGotoStmt(EmptyShell Empty) 10427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Stmt(IndirectGotoStmtClass, Empty) { } 10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1044ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner void setGotoLoc(SourceLocation L) { GotoLoc = L; } 1045ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation getGotoLoc() const { return GotoLoc; } 10465f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor void setStarLoc(SourceLocation L) { StarLoc = L; } 10475f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation getStarLoc() const { return StarLoc; } 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall Expr *getTarget() { return reinterpret_cast<Expr*>(Target); } 105095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);} 10517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); } 1052b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 105395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// getConstantTarget - Returns the fixed target of this indirect 105495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// goto, if one exists. 105595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall LabelStmt *getConstantTarget(); 105695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall const LabelStmt *getConstantTarget() const { 105795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall return const_cast<IndirectGotoStmt*>(this)->getConstantTarget(); 105895c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall } 105995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall 106063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1061ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner return SourceRange(GotoLoc, Target->getLocEnd()); 1062ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner } 10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IndirectGotoStmtClass; 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IndirectGotoStmt *) { return true; } 10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10698297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 107063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Target, &Target+1); } 10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue. 10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt { 1077507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation ContinueLoc; 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1079507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {} 10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1081d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty continue statement. 1082d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { } 1083d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1084d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getContinueLoc() const { return ContinueLoc; } 1085d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setContinueLoc(SourceLocation L) { ContinueLoc = L; } 1086d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 108763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(ContinueLoc); 1089507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff } 1090861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor 10911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ContinueStmtClass; 10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ContinueStmt *) { return true; } 10951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10968297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 109763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break. 11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt { 1103507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation BreakLoc; 11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1105507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1107025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty break statement. 1108025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { } 1109025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1110025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getBreakLoc() const { return BreakLoc; } 1111025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBreakLoc(SourceLocation L) { BreakLoc = L; } 1112025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 111363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(BreakLoc); } 1114b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BreakStmtClass; 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BreakStmt *) { return true; } 11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 112163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1125c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression: 1126c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return; 1127c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return 4; 1128c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// 1129c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to 1130c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to 1131c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void. We explicitly model this in the AST, which means you can't 1132c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument. 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt { 11351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *RetExpr; 1136507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation RetLoc; 11375077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *NRVOCandidate; 11385077c3876beeaed32280af88244e8050078619a8Douglas Gregor 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11405077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL) 114125a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { } 11425077c3876beeaed32280af88244e8050078619a8Douglas Gregor 11435077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) 11445077c3876beeaed32280af88244e8050078619a8Douglas Gregor : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL), 11455077c3876beeaed32280af88244e8050078619a8Douglas Gregor NRVOCandidate(NRVOCandidate) {} 11460de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 11470de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor /// \brief Build an empty return expression. 11480de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { } 11490de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 11501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getRetValue() const; 11511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getRetValue(); 11520de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); } 11530de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 11540de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor SourceLocation getReturnLoc() const { return RetLoc; } 11550de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setReturnLoc(SourceLocation L) { RetLoc = L; } 1156b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 11575077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// \brief Retrieve the variable that might be used for the named return 11585077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// value optimization. 11595077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// 11605077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// The optimization itself can only be performed if the variable is 11615077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// also marked as an NRVO object. 11625077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *getNRVOCandidate() const { return NRVOCandidate; } 11635077c3876beeaed32280af88244e8050078619a8Douglas Gregor void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; } 11645077c3876beeaed32280af88244e8050078619a8Douglas Gregor 116563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ReturnStmtClass; 11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReturnStmt *) { return true; } 11711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11728297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 117363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 117463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (RetExpr) return child_range(&RetExpr, &RetExpr+1); 117563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 117663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1179fe795956194141c91ae555985c9b930595bff43fChris Lattner/// AsmStmt - This represents a GNU inline-assembly statement extension. 1180fe795956194141c91ae555985c9b930595bff43fChris Lattner/// 1181fe795956194141c91ae555985c9b930595bff43fChris Lattnerclass AsmStmt : public Stmt { 1182fe795956194141c91ae555985c9b930595bff43fChris Lattner SourceLocation AsmLoc, RParenLoc; 11836a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson StringLiteral *AsmStr; 1184b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1185dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson bool IsSimple; 118639c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson bool IsVolatile; 11873b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump bool MSAsm; 11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1189b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned NumOutputs; 1190b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned NumInputs; 1191966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson unsigned NumClobbers; 11921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1193966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson // FIXME: If we wanted to, we could allocate all of these in one big array. 1194966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson IdentifierInfo **Names; 1195966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Constraints; 1196966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson Stmt **Exprs; 1197966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Clobbers; 1198c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1199fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic: 1200c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, 1201966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson bool msasm, unsigned numoutputs, unsigned numinputs, 1202ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **names, StringLiteral **constraints, 1203db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, 1204db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner StringLiteral **clobbers, SourceLocation rparenloc); 1205b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1206cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor /// \brief Build an empty inline-assembly statement. 1207c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty), 1208966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson Names(0), Constraints(0), Exprs(0), Clobbers(0) { } 1209cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1210cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getAsmLoc() const { return AsmLoc; } 1211cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmLoc(SourceLocation L) { AsmLoc = L; } 1212cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 1213cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1214cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 121539c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson bool isVolatile() const { return IsVolatile; } 1216cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setVolatile(bool V) { IsVolatile = V; } 1217dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson bool isSimple() const { return IsSimple; } 12186ffe643322949dd776285a6df60d3578f3918be4Chris Lattner void setSimple(bool V) { IsSimple = V; } 12193b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump bool isMSAsm() const { return MSAsm; } 12203b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump void setMSAsm(bool V) { MSAsm = V; } 1221dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson 1222458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner //===--- Asm String Analysis ---===// 1223458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1224458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const StringLiteral *getAsmString() const { return AsmStr; } 1225458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner StringLiteral *getAsmString() { return AsmStr; } 1226cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmString(StringLiteral *E) { AsmStr = E; } 1227cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1228458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AsmStringPiece - this is part of a decomposed asm string specification 1229458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// (for use with the AnalyzeAsmString function below). An asm string is 1230458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// considered to be a concatenation of these parts. 1231458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner class AsmStringPiece { 1232458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1233458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner enum Kind { 1234458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". 1235458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Operand // Operand reference, with optional modifier %c4. 1236458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 1237458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner private: 1238458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Kind MyKind; 1239458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner std::string Str; 1240458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned OperandNo; 1241458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1242458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} 1243458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(unsigned OpNo, char Modifier) 1244458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner : MyKind(Operand), Str(), OperandNo(OpNo) { 1245458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Str += Modifier; 1246458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 12471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1248458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isString() const { return MyKind == String; } 1249458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isOperand() const { return MyKind == Operand; } 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1251458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const std::string &getString() const { 1252458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isString()); 1253458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str; 1254458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1255458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1256458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned getOperandNo() const { 1257458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1258458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return OperandNo; 1259458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1261458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// getModifier - Get the modifier for this operand, if present. This 1262458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// returns '\0' if there was no modifier. 1263458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner char getModifier() const { 1264458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1265458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str[0]; 1266458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1267458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1269458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 1270458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// it into pieces. If the asm string is erroneous, emit errors and return 1271458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// true, otherwise return false. This handles canonicalization and 1272458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// translation of strings from GCC syntax to LLVM IR syntax, and handles 12731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump //// flattening of named references like %[foo] to Operand AsmStringPiece's. 1274fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner unsigned AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece> &Pieces, 1275fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner ASTContext &C, unsigned &DiagOffs) const; 12761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1278b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Output operands ---===// 1279b327793860737d1c103a73aeda8057dd628a101dChris Lattner 1280b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned getNumOutputs() const { return NumOutputs; } 1281ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1282ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo *getOutputIdentifier(unsigned i) const { 1283ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Names[i]; 1284ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1285ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1286ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::StringRef getOutputName(unsigned i) const { 1287ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson if (IdentifierInfo *II = getOutputIdentifier(i)) 1288ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return II->getName(); 1289c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1290ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return llvm::StringRef(); 1291ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson } 1292ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1293b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// getOutputConstraint - Return the constraint string for the specified 1294b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// output operand. All output constraints are known to be non-empty (either 1295b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// '=' or '+'). 1296acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson llvm::StringRef getOutputConstraint(unsigned i) const; 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1298b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getOutputConstraintLiteral(unsigned i) const { 1299ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i]; 1300ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1301b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getOutputConstraintLiteral(unsigned i) { 1302b327793860737d1c103a73aeda8057dd628a101dChris Lattner return Constraints[i]; 1303b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 13041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1305ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getOutputExpr(unsigned i); 13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1307b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getOutputExpr(unsigned i) const { 1308b327793860737d1c103a73aeda8057dd628a101dChris Lattner return const_cast<AsmStmt*>(this)->getOutputExpr(i); 1309b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1311b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// isOutputPlusConstraint - Return true if the specified output constraint 1312b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// is a "+" constraint (which is both an input and an output) or false if it 1313b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// is an "=" constraint (just an output). 1314b327793860737d1c103a73aeda8057dd628a101dChris Lattner bool isOutputPlusConstraint(unsigned i) const { 1315b327793860737d1c103a73aeda8057dd628a101dChris Lattner return getOutputConstraint(i)[0] == '+'; 1316b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 13171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 131885759278332404e96d4bb89d0e976e46158cd026Chris Lattner /// getNumPlusOperands - Return the number of output operands that have a "+" 131985759278332404e96d4bb89d0e976e46158cd026Chris Lattner /// constraint. 132085759278332404e96d4bb89d0e976e46158cd026Chris Lattner unsigned getNumPlusOperands() const; 13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1322b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Input operands ---===// 13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumInputs() const { return NumInputs; } 13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1326ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo *getInputIdentifier(unsigned i) const { 1327ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Names[i + NumOutputs]; 1328ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1330ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::StringRef getInputName(unsigned i) const { 1331ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson if (IdentifierInfo *II = getInputIdentifier(i)) 1332ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return II->getName(); 1333ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1334ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return llvm::StringRef(); 1335ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson } 1336ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1337b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// getInputConstraint - Return the specified input constraint. Unlike output 1338b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// constraints, these can be empty. 1339acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson llvm::StringRef getInputConstraint(unsigned i) const; 13401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1341b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getInputConstraintLiteral(unsigned i) const { 1342ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1343ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1344b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getInputConstraintLiteral(unsigned i) { 1345ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1346ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1348ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getInputExpr(unsigned i); 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1350b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getInputExpr(unsigned i) const { 1351b327793860737d1c103a73aeda8057dd628a101dChris Lattner return const_cast<AsmStmt*>(this)->getInputExpr(i); 1352b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 1353cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1354acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson void setOutputsAndInputsAndClobbers(ASTContext &C, 1355ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1356fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Constraints, 1357fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson Stmt **Exprs, 1358fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumOutputs, 1359c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned NumInputs, 1360fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Clobbers, 1361fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumClobbers); 1362cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 136310ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner //===--- Other ---===// 13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136510ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// getNamedOperand - Given a symbolic operand reference like %[foo], 136610ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// translate this into a numeric value needed to reference the same operand. 136710ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// This returns -1 if the operand name is invalid. 1368acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson int getNamedOperand(llvm::StringRef SymbolicName) const; 136910ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner 1370966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson unsigned getNumClobbers() const { return NumClobbers; } 1371b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson StringLiteral *getClobber(unsigned i) { return Clobbers[i]; } 1372d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; } 1373cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 137463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1375fe795956194141c91ae555985c9b930595bff43fChris Lattner return SourceRange(AsmLoc, RParenLoc); 1376fe795956194141c91ae555985c9b930595bff43fChris Lattner } 13771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1378fe795956194141c91ae555985c9b930595bff43fChris Lattner static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;} 1379fe795956194141c91ae555985c9b930595bff43fChris Lattner static bool classof(const AsmStmt *) { return true; } 13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1381ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek // Input expr iterators. 13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1383ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ExprIterator inputs_iterator; 1384ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ConstExprIterator const_inputs_iterator; 13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1386ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek inputs_iterator begin_inputs() { 1387966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1388ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1390ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek inputs_iterator end_inputs() { 1391966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs + NumInputs; 1392ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1394ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const_inputs_iterator begin_inputs() const { 1395966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1396ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1398ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const_inputs_iterator end_inputs() const { 1399966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs + NumInputs; 1400d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1402ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek // Output expr iterators. 14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1404ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ExprIterator outputs_iterator; 1405ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ConstExprIterator const_outputs_iterator; 14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1407d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek outputs_iterator begin_outputs() { 1408966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0]; 1409d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 1410d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek outputs_iterator end_outputs() { 1411966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1412d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1414d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek const_outputs_iterator begin_outputs() const { 1415966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0]; 1416d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 1417d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek const_outputs_iterator end_outputs() const { 1418966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1419d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 142163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 142263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); 142363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 1424fe795956194141c91ae555985c9b930595bff43fChris Lattner}; 142578492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek 14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1429