Stmt.h revision 8e6285af719adc6f86d6faa235d22a08eb68ee3a
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" 235ee56e95c3905d2e7bc403631b03865cdbdd8a42Anders Carlsson#include "clang/AST/FullExpr.h" 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h" 258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek#include "clang/AST/ASTContext.h" 266e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string> 277573098b83e780d1c5bea13b384b610d8f155676Steve Naroffusing llvm::dyn_cast_or_null; 287573098b83e780d1c5bea13b384b610d8f155676Steve Naroff 2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm { 3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor class FoldingSetNodeID; 3141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor} 3241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 34e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop class ASTContext; 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 377ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff class ParmVarDecl; 384b07b2968f87f3cd5a3d8c76145f1cbfd718d42dSebastian Redl class QualType; 395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class IdentifierInfo; 400c727a35718556866a978f64ac549d9798735f08Chris Lattner class SourceManager; 416a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson class StringLiteral; 426c36be5b383875b490684bcf439d6d427298c1afChris Lattner class SwitchStmt; 431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 44ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek //===----------------------------------------------------------------------===// 45ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // ExprIterator - Iterators for iterating over Stmt* arrays that contain 46ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // only Expr*. This is needed because AST nodes use Stmt* arrays to store 47ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // references to children (to be compatible with StmtIterator). 48ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek //===----------------------------------------------------------------------===// 491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Stmt; 51ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Expr; 521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ExprIterator { 54ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Stmt** I; 55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 56ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator(Stmt** i) : I(i) {} 571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExprIterator() : I(0) {} 58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator& operator++() { ++I; return *this; } 59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator-(size_t i) { return I-i; } 60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator+(size_t i) { return I+i; } 61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator[](size_t idx); 62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // FIXME: Verify that this will correctly return a signed distance. 63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ExprIterator& R) const { return I - R.I; } 64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator*() const; 65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator->() const; 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 bool operator>=(const ExprIterator& R) const { return I >= R.I; } 70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek }; 711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ConstExprIterator { 731705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer const Stmt * const *I; 74ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 751705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator(const Stmt * const *i) : I(i) {} 761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ConstExprIterator() : I(0) {} 77ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ConstExprIterator& operator++() { ++I; return *this; } 781705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator+(size_t i) const { return I+i; } 791705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator-(size_t i) const { return I-i; } 80ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator[](size_t idx) const; 81ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ConstExprIterator& R) const { return I - R.I; } 82ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator*() const; 83ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator->() const; 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; } 87ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>=(const ConstExprIterator& R) const { return I >= R.I; } 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }; 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements. 92ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement. 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt { 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum StmtClass { 99f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor NoStmtClass = 0, 100f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class, 1017381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \ 1029a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class, 1037381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \ 1049a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class 1057381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT) 1064bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 1078e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Make vanilla 'new' and 'delete' illegal for Stmts. 1108189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected: 1118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes) throw() { 1128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek assert(0 && "Stmts cannot be allocated with regular 'new'."); 1138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return 0; 1148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void operator delete(void* data) throw() { 1168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek assert(0 && "Stmts cannot be released with regular 'delete'."); 1178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class StmtBitfields { 1208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Stmt; 1218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall /// \brief The statement class. 1238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned sClass : 8; 1248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall enum { NumStmtBits = 8 }; 1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CompoundStmtBitfields { 1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CompoundStmt; 1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned NumStmts : 32 - NumStmtBits; 1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class LabelStmtBitfields { 1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class LabelStmt; 1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned Used : 1; 1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned HasUnusedAttr : 1; 1408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class ExprBitfields { 1438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Expr; 1448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DeclRefExpr; // computeDependence 1458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class InitListExpr; // ctor 1468e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DesignatedInitExpr; // ctor 1478e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1488e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1498e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueKind : 2; 1508e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned TypeDependent : 1; 1518e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueDependent : 1; 1528e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall enum { NumExprBits = 12 }; 1548e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1558e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CastExprBitfields { 1568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CastExpr; 1578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumExprBits; 1588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned Kind : 5; 1608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned BasePathSize : 32 - NumExprBits - 5; 1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall union { 1648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBitfields StmtBits; 1658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBitfields CompoundStmtBits; 1668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall LabelStmtBitfields LabelStmtBits; 1678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBitfields ExprBits; 1688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBitfields CastExprBits; 1698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1718189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic: 1728189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Only allow allocation of Stmts using the allocator in ASTContext 1731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // or by doing a placement new. 1748189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext& C, 175f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor unsigned alignment = 8) throw() { 1768189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return ::operator new(bytes, C, alignment); 1778189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1798189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext* C, 180f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor unsigned alignment = 8) throw() { 1818189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return ::operator new(bytes, *C, alignment); 1828189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1848189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, void* mem) throw() { 1858189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return mem; 1868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 187e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 188fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext&, unsigned) throw() { } 189fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext*, unsigned) throw() { } 190e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor void operator delete(void*, std::size_t) throw() { } 191fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, void*) throw() { } 192e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 193025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic: 194025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief A placeholder type used to construct an empty shell of a 195025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// type, that will be filled in later (e.g., by some 196025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// de-serialization). 197025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor struct EmptyShell { }; 198025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1999c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected: 200025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Construct an empty statement. 2018e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall explicit Stmt(StmtClass SC, EmptyShell) { 2028e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 203025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); 204025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor } 205025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2078e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt(StmtClass SC) { 2088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual ~Stmt() {} 2121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 213c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt StmtClass getStmtClass() const { 2148e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall return static_cast<StmtClass>(StmtBits.sClass); 215b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor } 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStmtClassName() const; 2171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 218b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// SourceLocation tokens are not useful in isolation - they are low level 219b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// value objects created/interpreted by SourceManager. We assume AST 220b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// clients will have a pointer to the respective SourceManager. 221b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff virtual SourceRange getSourceRange() const = 0; 222311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner SourceLocation getLocStart() const { return getSourceRange().getBegin(); } 223311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // global temp stats (until we have a per-module visitor) 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void addStmtClass(const StmtClass s); 2272024f4d4b0d57616f79ea742fa782d633d414462Kovarththanan Rajaratnam static bool CollectingStats(bool Enable = false); 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void PrintStats(); 2296000dace22f110d8768476989313e9d981d690d0Chris Lattner 2306000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dump - This does a local dump of the specified AST fragment. It dumps the 2316000dace22f110d8768476989313e9d981d690d0Chris Lattner /// specified node and a few nodes underneath it, but not the whole subtree. 2326000dace22f110d8768476989313e9d981d690d0Chris Lattner /// This is useful in a debugger. 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void dump() const; 234e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner void dump(SourceManager &SM) const; 2359668033ee4c25efd019e6c7e6dd96aa2e6364a46Argyrios Kyrtzidis void dump(llvm::raw_ostream &OS, SourceManager &SM) const; 2366000dace22f110d8768476989313e9d981d690d0Chris Lattner 2376000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpAll - This does a dump of the specified AST fragment and all subtrees. 2386000dace22f110d8768476989313e9d981d690d0Chris Lattner void dumpAll() const; 239e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner void dumpAll(SourceManager &SM) const; 2406000dace22f110d8768476989313e9d981d690d0Chris Lattner 2416000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST 2426000dace22f110d8768476989313e9d981d690d0Chris Lattner /// back to its original source language syntax. 24348d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman void dumpPretty(ASTContext& Context) const; 2441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void printPretty(llvm::raw_ostream &OS, PrinterHelper *Helper, 245e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 24648d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman unsigned Indentation = 0) const { 24748d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation); 24848d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman } 249e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void printPretty(llvm::raw_ostream &OS, ASTContext &Context, 2501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PrinterHelper *Helper, 251e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 252d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned Indentation = 0) const; 2531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 254d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only 255d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// works on systems with GraphViz (Mac OS X) or dot+gv installed. 256d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek void viewAST() const; 2571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Implement isa<T> support. 2591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *) { return true; } 2601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 261d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// hasImplicitControlFlow - Some statements (e.g. short circuited operations) 262d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// contain implicit control-flow in the order their subexpressions 263d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// are evaluated. This predicate returns true if this statement has 264d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// such implicit control-flow. Such statements are also specially handled 265d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// within CFGs. 266d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek bool hasImplicitControlFlow() const; 267d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek 26877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek /// Child Iterators: All subclasses must implement child_begin and child_end 26977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek /// to permit easy iteration over the substatements/subexpessions of an 27077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek /// AST node. This permits easy iteration over all nodes in the AST. 2719caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef StmtIterator child_iterator; 2729caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef ConstStmtIterator const_child_iterator; 2731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin() = 0; 2758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end() = 0; 2761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const_child_iterator child_begin() const { 2789caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek return const_child_iterator(const_cast<Stmt*>(this)->child_begin()); 27977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 2801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const_child_iterator child_end() const { 2829caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek return const_child_iterator(const_cast<Stmt*>(this)->child_end()); 28377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 28441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 28541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Produce a unique representation of the given statement. 28641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 28741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief ID once the profiling operation is complete, will contain 28841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// the unique representation of the given statement. 28941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 29041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Context the AST context in which the statement resides 29141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 29241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Canonical whether the profile should be based on the canonical 29341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// representation of this statement (e.g., where non-type template 2941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// parameters are identified by index/level rather than their 29541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// declaration pointers) or the exact representation of the statement as 29641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// written in the source. 29741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 29841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor bool Canonical); 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions 3031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration. 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt { 3079653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor DeclGroupRef DG; 30881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation StartLoc, EndLoc; 3091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 3128ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg), 3138ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek StartLoc(startLoc), EndLoc(endLoc) {} 3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor /// \brief Build an empty declaration statement. 31684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { } 31784f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 3187e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner /// isSingleDecl - This method returns true if this DeclStmt refers 319fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner /// to a single Decl. 3207e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner bool isSingleDecl() const { 321fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner return DG.isSingleDecl(); 3228ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek } 3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3247e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner const Decl *getSingleDecl() const { return DG.getSingleDecl(); } 3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl *getSingleDecl() { return DG.getSingleDecl(); } 3261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 327e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner const DeclGroupRef getDeclGroup() const { return DG; } 328e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner DeclGroupRef getDeclGroup() { return DG; } 32984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setDeclGroup(DeclGroupRef DGR) { DG = DGR; } 330b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 33181c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getStartLoc() const { return StartLoc; } 33284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setStartLoc(SourceLocation L) { StartLoc = L; } 33381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getEndLoc() const { return EndLoc; } 33484f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setEndLoc(SourceLocation L) { EndLoc = L; } 33584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 3368ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek SourceRange getSourceRange() const { 33781c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner return SourceRange(StartLoc, EndLoc); 33881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner } 3391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DeclStmtClass; 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclStmt *) { return true; } 3441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34514f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek // Iterators over subexpressions. 3468297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 3478297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 3481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3490632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::iterator decl_iterator; 3500632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::const_iterator const_decl_iterator; 3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3528ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_begin() { return DG.begin(); } 3538ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_end() { return DG.end(); } 3548ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_begin() const { return DG.begin(); } 3558ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_end() const { return DG.end(); } 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3. 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt { 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation SemiLoc; 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer NullStmt(SourceLocation L) : Stmt(NullStmtClass), SemiLoc(L) {} 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 365025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty null statement. 366025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) { } 367025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getSemiLoc() const { return SemiLoc; } 369025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSemiLoc(SourceLocation L) { SemiLoc = L; } 370b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 371507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff virtual SourceRange getSourceRange() const { return SourceRange(SemiLoc); } 3721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == NullStmtClass; 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const NullStmt *) { return true; } 3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3788297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 3798297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 3808297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }. 3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt { 3868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek Stmt** Body; 387b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation LBracLoc, RBracLoc; 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned NumStmts, 3908e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall SourceLocation LB, SourceLocation RB) 3918e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { 3928e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = NumStmts; 3938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 394026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (NumStmts == 0) { 395026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Body = 0; 396026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return; 397026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 399026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Body = new (C) Stmt*[NumStmts]; 4008e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall memcpy(Body, StmtStart, NumStmts * sizeof(*Body)); 4011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 402025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 403025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor // \brief Build an empty compound statement. 404025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CompoundStmt(EmptyShell Empty) 4058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass, Empty), Body(0) { 4068e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = 0; 4078e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 408025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 409025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts); 4101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4118e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } 4128e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned size() const { return CompoundStmtBits.NumStmts; } 413025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 4148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt** body_iterator; 4158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek body_iterator body_begin() { return Body; } 4168e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall body_iterator body_end() { return Body + size(); } 4178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; } 418e946fc833d8592aa2890bfd9839f1ad839b3d284Fariborz Jahanian 4198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setLastStmt(Stmt *S) { 4208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall assert(!body_empty() && "setLastStmt"); 4218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Body[size()-1] = S; 4228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt* const * const_body_iterator; 4258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_body_iterator body_begin() const { return Body; } 4268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const_body_iterator body_end() const { return Body + size(); } 4278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; } 4288189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek 4298189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<body_iterator> reverse_body_iterator; 4308189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rbegin() { 4318189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_end()); 4328189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4338189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rend() { 4348189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_begin()); 4358189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4364ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 4378189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<const_body_iterator> 4388189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator; 4394ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 4408189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rbegin() const { 4418189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_end()); 4428189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4448189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rend() const { 4458189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_begin()); 4468189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(LBracLoc, RBracLoc); 450b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 452cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getLBracLoc() const { return LBracLoc; } 453025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setLBracLoc(SourceLocation L) { LBracLoc = L; } 454cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getRBracLoc() const { return RBracLoc; } 455025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setRBracLoc(SourceLocation L) { RBracLoc = L; } 4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundStmtClass; 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundStmt *) { return true; } 4611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 4638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 4648297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 467c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt, 468c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt { 469103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected: 470c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // A pointer to the following CaseStmt or DefaultStmt class, 471c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // used by SwitchStmt. 472c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *NextSwitchCase; 473103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek 474d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {} 4751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 476c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic: 477c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } 478c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 479c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getNextSwitchCase() { return NextSwitchCase; } 480c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 481c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } 482d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek 483d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return v_getSubStmt(); } 484b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 485b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(); } 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass || 489c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson T->getStmtClass() == DefaultStmtClass; 490c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 491c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson static bool classof(const SwitchCase *) { return true; } 4923fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattnerprotected: 4931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual Stmt* v_getSubStmt() = 0; 494c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson}; 495c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 496c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase { 497d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek enum { SUBSTMT, LHS, RHS, END_EXPR }; 4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 499d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // GNU "case 1 ... 4" extension 500b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation CaseLoc; 501dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation EllipsisLoc; 502dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation ColonLoc; 503dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor 5043fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner virtual Stmt* v_getSubStmt() { return getSubStmt(); } 5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 506dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, 5071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation ellipsisLoc, SourceLocation colonLoc) 508d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek : SwitchCase(CaseStmtClass) { 50924e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner SubExprs[SUBSTMT] = 0; 510d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 511d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 512b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff CaseLoc = caseLoc; 513dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor EllipsisLoc = ellipsisLoc; 514dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor ColonLoc = colonLoc; 515d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek } 516025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 517025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty switch case statement. 518025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { } 519025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 520764a7ce5217f9569e100a3445f47496ee82daf86Chris Lattner SourceLocation getCaseLoc() const { return CaseLoc; } 521025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCaseLoc(SourceLocation L) { CaseLoc = L; } 522dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 523dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } 524dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 525dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 526025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 527d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 528d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 529d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 530025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getLHS() const { 5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[LHS]); 53351b09f2c528c8460b5465c676173324e44176d62Devang Patel } 5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getRHS() const { 5351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[RHS]); 53651b09f2c528c8460b5465c676173324e44176d62Devang Patel } 53751b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 53920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; } 54020dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } 54120dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } 5421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5443fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner virtual SourceRange getSourceRange() const { 5453fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner // Handle deeply nested case statements with iteration instead of recursion. 5463fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner const CaseStmt *CS = this; 54791ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) 5483fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner CS = CS2; 5491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd()); 551b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass; 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CaseStmt *) { return true; } 5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 557d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 558d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek virtual child_iterator child_begin(); 559d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek virtual child_iterator child_end(); 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 562c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase { 563d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt* SubStmt; 5646c36be5b383875b490684bcf439d6d427298c1afChris Lattner SourceLocation DefaultLoc; 565dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation ColonLoc; 5663fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner virtual Stmt* v_getSubStmt() { return getSubStmt(); } 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : 569dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL), 570dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor ColonLoc(CL) {} 571025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 572025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty default statement. 573025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { } 574025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 575d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubStmt; } 57651b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubStmt; } 577025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSubStmt(Stmt *S) { SubStmt = S; } 578025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5796c36be5b383875b490684bcf439d6d427298c1afChris Lattner SourceLocation getDefaultLoc() const { return DefaultLoc; } 580025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setDefaultLoc(SourceLocation L) { DefaultLoc = L; } 581dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 582dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(DefaultLoc, SubStmt->getLocEnd()); 586b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 5871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DefaultStmtClass; 5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DefaultStmt *) { return true; } 5911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 592d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 593d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek virtual child_iterator child_begin(); 594d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek virtual child_iterator child_end(); 5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt { 5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Label; 5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *SubStmt; 600b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IdentLoc; 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6021a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis LabelStmt(SourceLocation IL, IdentifierInfo *label, Stmt *substmt, 6031a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis bool hasUnusedAttr = false) 6048e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(LabelStmtClass), Label(label), SubStmt(substmt), IdentLoc(IL) { 6058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall LabelStmtBits.Used = false; 6068e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall LabelStmtBits.HasUnusedAttr = hasUnusedAttr; 6078e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 6081de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 6091de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor // \brief Build an empty label statement. 6101de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { } 6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getIdentLoc() const { return IdentLoc; } 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *getID() const { return Label; } 6141de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setID(IdentifierInfo *II) { Label = II; } 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *getSubStmt() { return SubStmt; } 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Stmt *getSubStmt() const { return SubStmt; } 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setIdentLoc(SourceLocation L) { IdentLoc = L; } 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setSubStmt(Stmt *SS) { SubStmt = SS; } 620b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 621355a9fe26a6dec89680ddf713dd5bc7a671b298aArgyrios Kyrtzidis /// \brief Whether this label was used. 6221a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis bool isUsed(bool CheckUnusedAttr = true) const { 6238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall return LabelStmtBits.Used || 6248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall (CheckUnusedAttr && LabelStmtBits.HasUnusedAttr); 6251a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis } 6268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setUsed(bool U = true) { LabelStmtBits.Used = U; } 627355a9fe26a6dec89680ddf713dd5bc7a671b298aArgyrios Kyrtzidis 6288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool HasUnusedAttribute() const { return LabelStmtBits.HasUnusedAttr; } 6298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setUnusedAttribute(bool U) { LabelStmtBits.HasUnusedAttr = U; } 6301a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis 6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 6321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(IdentLoc, SubStmt->getLocEnd()); 6331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 6341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == LabelStmtClass; 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const LabelStmt *) { return true; } 6381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6398297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 6408297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 6418297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else. 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt { 64843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, THEN, ELSE, END_EXPR }; 6498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 6508cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor 651b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IfLoc; 652d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation ElseLoc; 653c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 65543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, 65643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0); 65743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor 658025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty if/then/else statement 659025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { } 660025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 6618cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \brief Retrieve the variable declared in this "if" statement, if any. 6628cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// 6638cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// In the following example, "x" is the condition variable. 6648cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \code 6658cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// if (int x = foo()) { 6668cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// printf("x is %d", x); 6678cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// } 6688cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \endcode 66943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 67043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 671c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6728297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 673025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 6748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getThen() const { return SubExprs[THEN]; } 6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setThen(Stmt *S) { SubExprs[THEN] = S; } 6768297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getElse() const { return SubExprs[ELSE]; } 677025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setElse(Stmt *S) { SubExprs[ELSE] = S; } 6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6798297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 6808297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getThen() { return SubExprs[THEN]; } 6818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getElse() { return SubExprs[ELSE]; } 682b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 683025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getIfLoc() const { return IfLoc; } 684025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setIfLoc(SourceLocation L) { IfLoc = L; } 685d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation getElseLoc() const { return ElseLoc; } 686d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor void setElseLoc(SourceLocation L) { ElseLoc = L; } 687025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 6881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 689b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff if (SubExprs[ELSE]) 690b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd()); 691b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff else 692b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd()); 693b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IfStmtClass; 6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IfStmt *) { return true; } 6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70035628d1f17c817f8c240208db7ba490e3109981bTed Kremenek // Iterators over subexpressions. The iterators will include iterating 70135628d1f17c817f8c240208db7ba490e3109981bTed Kremenek // over the initialization expression referenced by the condition variable. 7028297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 7038297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt. 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt { 70943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 711c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // This points to a linked list of case and default statements. 712c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *FirstCase; 7139dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SourceLocation SwitchLoc; 7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 715559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// If the SwitchStmt is a switch on an enum value, this records whether 716559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// all the enum values were covered by CaseStmts. This value is meant to 717559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// be a hint for possible clients. 718559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek unsigned AllEnumCasesCovered : 1; 719559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 72143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond); 7221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 723025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build a empty switch statement. 724025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { } 725025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 726d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \brief Retrieve the variable declared in this "switch" statement, if any. 727d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// 728d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// In the following example, "x" is the condition variable. 729d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \code 730d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// switch (int x = foo()) { 731d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// case 0: break; 732d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// // ... 733d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// } 734d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \endcode 73543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 73643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 737d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor 7388297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 7398297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 740c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getSwitchCaseList() const { return FirstCase; } 741c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 7428297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 743025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 7448297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 745025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 746c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getSwitchCaseList() { return FirstCase; } 7471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Set the case list for this switch statement. 74943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// 75043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// The caller is responsible for incrementing the retain counts on 75143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// all of the SwitchCase statements in this list. 752025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } 753025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 754025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getSwitchLoc() const { return SwitchLoc; } 755025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchLoc(SourceLocation L) { SwitchLoc = L; } 756c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setBody(Stmt *S, SourceLocation SL) { 7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SubExprs[BODY] = S; 7599dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SwitchLoc = SL; 7601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 761c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void addSwitchCase(SwitchCase *SC) { 762c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor assert(!SC->getNextSwitchCase() && "case/default already added to a switch"); 763c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor SC->setNextSwitchCase(FirstCase); 764c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson FirstCase = SC; 765c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 766559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 767559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a 768559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// switch over an enum value then all cases have been explicitly covered. 769559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek void setAllEnumCasesCovered() { 770559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek AllEnumCasesCovered = 1; 771559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 772559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 773559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Returns true if the SwitchStmt is a switch of an enum value and all cases 774559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// have been explicitly covered. 775559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek bool isAllEnumCasesCovered() const { 776559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek return (bool) AllEnumCasesCovered; 777559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 778559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 7791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 7801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd()); 7819dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff } 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SwitchStmtClass; 7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const SwitchStmt *) { return true; } 7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7878297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 7888297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 7898297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt. 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt { 79643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 7978297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 798b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation WhileLoc; 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 80043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 80143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SourceLocation WL); 8021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 803d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty while statement. 804d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { } 805d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 8065656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Retrieve the variable declared in this "while" statement, if any. 8075656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// 8085656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// In the following example, "x" is the condition variable. 8095656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \code 8105656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// while (int x = random()) { 8115656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// // ... 8125656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// } 8135656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \endcode 81443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 81543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 8165656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 8178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 8188297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 819d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 8208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 8218297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 822d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 823d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 824d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 825d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 826b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 8271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 8281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd()); 829b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 8301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == WhileStmtClass; 8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const WhileStmt *) { return true; } 8341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8358297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 8368297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 8378297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt. 8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt { 8438297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek enum { COND, BODY, END_EXPR }; 8448297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 845b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation DoLoc; 8469f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation WhileLoc; 847989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RParenLoc; // Location of final ')' in do stmt condition. 8489f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 850989135901c750af61ef012b6b0a0368be415bc46Chris Lattner DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL, 851989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RP) 852989135901c750af61ef012b6b0a0368be415bc46Chris Lattner : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) { 8538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 8548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[BODY] = body; 8551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 85667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 85767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty do-while statement. 85867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { } 8591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 8618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 86267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 8638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 8641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Stmt *getBody() const { return SubExprs[BODY]; } 86567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 86667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 86767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getDoLoc() const { return DoLoc; } 86867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setDoLoc(SourceLocation L) { DoLoc = L; } 8699f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 8709f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 871b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 872989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 873989135901c750af61ef012b6b0a0368be415bc46Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 874989135901c750af61ef012b6b0a0368be415bc46Chris Lattner 8751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 8761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(DoLoc, RParenLoc); 877b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 8781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DoStmtClass; 8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DoStmt *) { return true; } 8828297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 8838297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 8848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 8858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not 8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source. 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt { 89443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; 8958297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 896b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation ForLoc; 8975831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation LParenLoc, RParenLoc; 8985831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor 8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 90043dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, 90143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP); 9021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 90367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty for statement. 90467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { } 90567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 9068297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getInit() { return SubExprs[INIT]; } 907c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 90899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \brief Retrieve the variable declared in this "for" statement, if any. 90999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// 91099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// In the following example, "y" is the condition variable. 91199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \code 91299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// for (int x = random(); int y = mangle(x); ++x) { 91399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// // ... 91499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// } 91599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \endcode 91643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 91743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 918c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 9198297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 9208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 9218297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 9228297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 9238297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getInit() const { return SubExprs[INIT]; } 9248297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 9258297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 9268297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 927b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 92867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInit(Stmt *S) { SubExprs[INIT] = S; } 92967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 93067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } 93167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 93267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 93367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getForLoc() const { return ForLoc; } 93467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setForLoc(SourceLocation L) { ForLoc = L; } 9355831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 9365831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 9375831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 9385831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 93967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 9401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd()); 942b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ForStmtClass; 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ForStmt *) { return true; } 9471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 9498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 9508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto. 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt { 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 957507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation GotoLoc; 95861f62165220e75694fe333179c78815e2e48d71fTed Kremenek SourceLocation LabelLoc; 9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GotoStmt(LabelStmt *label, SourceLocation GL, SourceLocation LL) 96161f62165220e75694fe333179c78815e2e48d71fTed Kremenek : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9631de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor /// \brief Build an empty goto statement. 9641de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { } 9651de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 9671de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setLabel(LabelStmt *S) { Label = S; } 9681de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 9691de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getGotoLoc() const { return GotoLoc; } 9701de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setGotoLoc(SourceLocation L) { GotoLoc = L; } 9711de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 9721de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 973b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(GotoLoc, LabelLoc); 976507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff } 9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GotoStmtClass; 9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const GotoStmt *) { return true; } 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9828297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 9838297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 9848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto. 9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt { 990ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation GotoLoc; 9915f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation StarLoc; 9921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Target; 9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, 9955f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Expr *target) 9965f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc), 9975f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Target((Stmt*)target) {} 9987d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 9997d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty indirect goto statement. 10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IndirectGotoStmt(EmptyShell Empty) 10017d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Stmt(IndirectGotoStmtClass, Empty) { } 10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1003ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner void setGotoLoc(SourceLocation L) { GotoLoc = L; } 1004ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation getGotoLoc() const { return GotoLoc; } 10055f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor void setStarLoc(SourceLocation L) { StarLoc = L; } 10065f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation getStarLoc() const { return StarLoc; } 10071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getTarget(); 10091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getTarget() const; 10107d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); } 1011b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 1012ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner virtual SourceRange getSourceRange() const { 1013ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner return SourceRange(GotoLoc, Target->getLocEnd()); 1014ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner } 10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IndirectGotoStmtClass; 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IndirectGotoStmt *) { return true; } 10201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10218297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 10228297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 10238297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue. 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt { 1030507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation ContinueLoc; 10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1032507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {} 10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1034d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty continue statement. 1035d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { } 1036d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1037d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getContinueLoc() const { return ContinueLoc; } 1038d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setContinueLoc(SourceLocation L) { ContinueLoc = L; } 1039d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(ContinueLoc); 1042507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff } 1043861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor 10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ContinueStmtClass; 10465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ContinueStmt *) { return true; } 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 10508297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 10518297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break. 10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt { 1057507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation BreakLoc; 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1059507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 10601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1061025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty break statement. 1062025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { } 1063025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1064025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getBreakLoc() const { return BreakLoc; } 1065025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBreakLoc(SourceLocation L) { BreakLoc = L; } 1066025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1067507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff virtual SourceRange getSourceRange() const { return SourceRange(BreakLoc); } 1068b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BreakStmtClass; 10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BreakStmt *) { return true; } 10731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 10758297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 10768297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1080c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression: 1081c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return; 1082c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return 4; 1083c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// 1084c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to 1085c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to 1086c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void. We explicitly model this in the AST, which means you can't 1087c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument. 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt { 10901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *RetExpr; 1091507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation RetLoc; 10925077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *NRVOCandidate; 10935077c3876beeaed32280af88244e8050078619a8Douglas Gregor 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10955077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL) 109625a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { } 10975077c3876beeaed32280af88244e8050078619a8Douglas Gregor 10985077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) 10995077c3876beeaed32280af88244e8050078619a8Douglas Gregor : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL), 11005077c3876beeaed32280af88244e8050078619a8Douglas Gregor NRVOCandidate(NRVOCandidate) {} 11010de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 11020de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor /// \brief Build an empty return expression. 11030de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { } 11040de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 11051060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getRetValue() const; 11061060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getRetValue(); 11070de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); } 11080de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 11090de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor SourceLocation getReturnLoc() const { return RetLoc; } 11100de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setReturnLoc(SourceLocation L) { RetLoc = L; } 1111b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 11125077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// \brief Retrieve the variable that might be used for the named return 11135077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// value optimization. 11145077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// 11155077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// The optimization itself can only be performed if the variable is 11165077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// also marked as an NRVO object. 11175077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *getNRVOCandidate() const { return NRVOCandidate; } 11185077c3876beeaed32280af88244e8050078619a8Douglas Gregor void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; } 11195077c3876beeaed32280af88244e8050078619a8Douglas Gregor 1120507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff virtual SourceRange getSourceRange() const; 11211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ReturnStmtClass; 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReturnStmt *) { return true; } 11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11278297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 11288297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_begin(); 11298297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek virtual child_iterator child_end(); 11305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1132fe795956194141c91ae555985c9b930595bff43fChris Lattner/// AsmStmt - This represents a GNU inline-assembly statement extension. 1133fe795956194141c91ae555985c9b930595bff43fChris Lattner/// 1134fe795956194141c91ae555985c9b930595bff43fChris Lattnerclass AsmStmt : public Stmt { 1135fe795956194141c91ae555985c9b930595bff43fChris Lattner SourceLocation AsmLoc, RParenLoc; 11366a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson StringLiteral *AsmStr; 1137b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1138dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson bool IsSimple; 113939c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson bool IsVolatile; 11403b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump bool MSAsm; 11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1142b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned NumOutputs; 1143b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned NumInputs; 1144966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson unsigned NumClobbers; 11451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1146966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson // FIXME: If we wanted to, we could allocate all of these in one big array. 1147966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson IdentifierInfo **Names; 1148966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Constraints; 1149966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson Stmt **Exprs; 1150966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Clobbers; 1151c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1152fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic: 1153c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, 1154966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson bool msasm, unsigned numoutputs, unsigned numinputs, 1155ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **names, StringLiteral **constraints, 1156db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, 1157db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner StringLiteral **clobbers, SourceLocation rparenloc); 1158b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1159cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor /// \brief Build an empty inline-assembly statement. 1160c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty), 1161966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson Names(0), Constraints(0), Exprs(0), Clobbers(0) { } 1162cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1163cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getAsmLoc() const { return AsmLoc; } 1164cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmLoc(SourceLocation L) { AsmLoc = L; } 1165cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 1166cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1167cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 116839c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson bool isVolatile() const { return IsVolatile; } 1169cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setVolatile(bool V) { IsVolatile = V; } 1170dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson bool isSimple() const { return IsSimple; } 11716ffe643322949dd776285a6df60d3578f3918be4Chris Lattner void setSimple(bool V) { IsSimple = V; } 11723b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump bool isMSAsm() const { return MSAsm; } 11733b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump void setMSAsm(bool V) { MSAsm = V; } 1174dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson 1175458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner //===--- Asm String Analysis ---===// 1176458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1177458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const StringLiteral *getAsmString() const { return AsmStr; } 1178458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner StringLiteral *getAsmString() { return AsmStr; } 1179cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmString(StringLiteral *E) { AsmStr = E; } 1180cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1181458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AsmStringPiece - this is part of a decomposed asm string specification 1182458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// (for use with the AnalyzeAsmString function below). An asm string is 1183458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// considered to be a concatenation of these parts. 1184458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner class AsmStringPiece { 1185458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1186458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner enum Kind { 1187458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". 1188458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Operand // Operand reference, with optional modifier %c4. 1189458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 1190458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner private: 1191458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Kind MyKind; 1192458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner std::string Str; 1193458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned OperandNo; 1194458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1195458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} 1196458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(unsigned OpNo, char Modifier) 1197458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner : MyKind(Operand), Str(), OperandNo(OpNo) { 1198458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Str += Modifier; 1199458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1201458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isString() const { return MyKind == String; } 1202458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isOperand() const { return MyKind == Operand; } 12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1204458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const std::string &getString() const { 1205458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isString()); 1206458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str; 1207458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1208458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1209458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned getOperandNo() const { 1210458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1211458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return OperandNo; 1212458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1214458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// getModifier - Get the modifier for this operand, if present. This 1215458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// returns '\0' if there was no modifier. 1216458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner char getModifier() const { 1217458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1218458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str[0]; 1219458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1220458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1222458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 1223458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// it into pieces. If the asm string is erroneous, emit errors and return 1224458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// true, otherwise return false. This handles canonicalization and 1225458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// translation of strings from GCC syntax to LLVM IR syntax, and handles 12261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump //// flattening of named references like %[foo] to Operand AsmStringPiece's. 1227fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner unsigned AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece> &Pieces, 1228fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner ASTContext &C, unsigned &DiagOffs) const; 12291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1231b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Output operands ---===// 1232b327793860737d1c103a73aeda8057dd628a101dChris Lattner 1233b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned getNumOutputs() const { return NumOutputs; } 1234ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1235ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo *getOutputIdentifier(unsigned i) const { 1236ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Names[i]; 1237ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1238ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1239ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::StringRef getOutputName(unsigned i) const { 1240ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson if (IdentifierInfo *II = getOutputIdentifier(i)) 1241ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return II->getName(); 1242c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1243ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return llvm::StringRef(); 1244ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson } 1245ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1246b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// getOutputConstraint - Return the constraint string for the specified 1247b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// output operand. All output constraints are known to be non-empty (either 1248b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// '=' or '+'). 1249acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson llvm::StringRef getOutputConstraint(unsigned i) const; 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1251b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getOutputConstraintLiteral(unsigned i) const { 1252ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i]; 1253ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1254b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getOutputConstraintLiteral(unsigned i) { 1255b327793860737d1c103a73aeda8057dd628a101dChris Lattner return Constraints[i]; 1256b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1258ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getOutputExpr(unsigned i); 12591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1260b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getOutputExpr(unsigned i) const { 1261b327793860737d1c103a73aeda8057dd628a101dChris Lattner return const_cast<AsmStmt*>(this)->getOutputExpr(i); 1262b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1264b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// isOutputPlusConstraint - Return true if the specified output constraint 1265b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// is a "+" constraint (which is both an input and an output) or false if it 1266b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// is an "=" constraint (just an output). 1267b327793860737d1c103a73aeda8057dd628a101dChris Lattner bool isOutputPlusConstraint(unsigned i) const { 1268b327793860737d1c103a73aeda8057dd628a101dChris Lattner return getOutputConstraint(i)[0] == '+'; 1269b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 12701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127185759278332404e96d4bb89d0e976e46158cd026Chris Lattner /// getNumPlusOperands - Return the number of output operands that have a "+" 127285759278332404e96d4bb89d0e976e46158cd026Chris Lattner /// constraint. 127385759278332404e96d4bb89d0e976e46158cd026Chris Lattner unsigned getNumPlusOperands() const; 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1275b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Input operands ---===// 12761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumInputs() const { return NumInputs; } 12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1279ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo *getInputIdentifier(unsigned i) const { 1280ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Names[i + NumOutputs]; 1281ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1283ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::StringRef getInputName(unsigned i) const { 1284ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson if (IdentifierInfo *II = getInputIdentifier(i)) 1285ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return II->getName(); 1286ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1287ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return llvm::StringRef(); 1288ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson } 1289ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1290b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// getInputConstraint - Return the specified input constraint. Unlike output 1291b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// constraints, these can be empty. 1292acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson llvm::StringRef getInputConstraint(unsigned i) const; 12931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1294b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getInputConstraintLiteral(unsigned i) const { 1295ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1296ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1297b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getInputConstraintLiteral(unsigned i) { 1298ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1299ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1301ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getInputExpr(unsigned i); 13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1303b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getInputExpr(unsigned i) const { 1304b327793860737d1c103a73aeda8057dd628a101dChris Lattner return const_cast<AsmStmt*>(this)->getInputExpr(i); 1305b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 1306cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1307acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson void setOutputsAndInputsAndClobbers(ASTContext &C, 1308ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1309fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Constraints, 1310fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson Stmt **Exprs, 1311fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumOutputs, 1312c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned NumInputs, 1313fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Clobbers, 1314fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumClobbers); 1315cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 131610ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner //===--- Other ---===// 13171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 131810ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// getNamedOperand - Given a symbolic operand reference like %[foo], 131910ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// translate this into a numeric value needed to reference the same operand. 132010ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// This returns -1 if the operand name is invalid. 1321acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson int getNamedOperand(llvm::StringRef SymbolicName) const; 132210ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner 1323966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson unsigned getNumClobbers() const { return NumClobbers; } 1324b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson StringLiteral *getClobber(unsigned i) { return Clobbers[i]; } 1325d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; } 1326cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1327fe795956194141c91ae555985c9b930595bff43fChris Lattner virtual SourceRange getSourceRange() const { 1328fe795956194141c91ae555985c9b930595bff43fChris Lattner return SourceRange(AsmLoc, RParenLoc); 1329fe795956194141c91ae555985c9b930595bff43fChris Lattner } 13301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1331fe795956194141c91ae555985c9b930595bff43fChris Lattner static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;} 1332fe795956194141c91ae555985c9b930595bff43fChris Lattner static bool classof(const AsmStmt *) { return true; } 13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1334ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek // Input expr iterators. 13351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1336ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ExprIterator inputs_iterator; 1337ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ConstExprIterator const_inputs_iterator; 13381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1339ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek inputs_iterator begin_inputs() { 1340966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1341ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1343ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek inputs_iterator end_inputs() { 1344966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs + NumInputs; 1345ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1347ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const_inputs_iterator begin_inputs() const { 1348966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1349ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1351ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const_inputs_iterator end_inputs() const { 1352966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs + NumInputs; 1353d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1355ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek // Output expr iterators. 13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1357ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ExprIterator outputs_iterator; 1358ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ConstExprIterator const_outputs_iterator; 13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1360d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek outputs_iterator begin_outputs() { 1361966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0]; 1362d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 1363d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek outputs_iterator end_outputs() { 1364966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1365d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 13661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1367d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek const_outputs_iterator begin_outputs() const { 1368966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0]; 1369d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 1370d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek const_outputs_iterator end_outputs() const { 1371966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1372d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 13731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Child iterators 13751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1376fe795956194141c91ae555985c9b930595bff43fChris Lattner virtual child_iterator child_begin(); 1377fe795956194141c91ae555985c9b930595bff43fChris Lattner virtual child_iterator child_end(); 1378fe795956194141c91ae555985c9b930595bff43fChris Lattner}; 137978492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek 13805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 13815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1383