Stmt.h revision 7bd092b054444e9800e8de1d8d71c408dbdc8ead
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 179594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "clang/Basic/LLVM.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/SourceLocation.h" 19d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h" 209caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h" 218ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek#include "clang/AST/DeclGroup.h" 22534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith#include "clang/AST/Attr.h" 238f726de55412870ef70e788b852c6cc50873e15bChad Rosier#include "clang/Lex/Token.h" 249594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "llvm/ADT/SmallVector.h" 25aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 26aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/raw_ostream.h" 276e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string> 287573098b83e780d1c5bea13b384b610d8f155676Steve Naroff 2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm { 3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor class FoldingSetNodeID; 3141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor} 3241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 34e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop class ASTContext; 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 377ba138abd329e591a8f6d5001f60dd7082f71b3bSteve Naroff class ParmVarDecl; 384b07b2968f87f3cd5a3d8c76145f1cbfd718d42dSebastian Redl class QualType; 395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class IdentifierInfo; 40478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer class LabelDecl; 410c727a35718556866a978f64ac549d9798735f08Chris Lattner class SourceManager; 426a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson class StringLiteral; 436c36be5b383875b490684bcf439d6d427298c1afChris Lattner class SwitchStmt; 44478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer class VarDecl; 451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 46ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie //===--------------------------------------------------------------------===// 47ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // ExprIterator - Iterators for iterating over Stmt* arrays that contain 48ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // only Expr*. This is needed because AST nodes use Stmt* arrays to store 49ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // references to children (to be compatible with StmtIterator). 50ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie //===--------------------------------------------------------------------===// 511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Stmt; 53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Expr; 541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 55ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ExprIterator { 56ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Stmt** I; 57ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 58ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator(Stmt** i) : I(i) {} 591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExprIterator() : I(0) {} 60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator& operator++() { ++I; return *this; } 61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator-(size_t i) { return I-i; } 62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator+(size_t i) { return I+i; } 63ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator[](size_t idx); 64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // FIXME: Verify that this will correctly return a signed distance. 65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ExprIterator& R) const { return I - R.I; } 66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator*() const; 67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator->() const; 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 bool operator>(const ExprIterator& R) const { return I > R.I; } 71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>=(const ExprIterator& R) const { return I >= R.I; } 72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek }; 731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ConstExprIterator { 751705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer const Stmt * const *I; 76ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 771705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator(const Stmt * const *i) : I(i) {} 781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ConstExprIterator() : I(0) {} 79ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ConstExprIterator& operator++() { ++I; return *this; } 801705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator+(size_t i) const { return I+i; } 811705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator-(size_t i) const { return I-i; } 82ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator[](size_t idx) const; 83ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ConstExprIterator& R) const { return I - R.I; } 84ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator*() const; 85ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator->() const; 86ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator==(const ConstExprIterator& R) const { return I == R.I; } 87ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator!=(const ConstExprIterator& R) const { return I != R.I; } 88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>(const ConstExprIterator& R) const { return I > R.I; } 89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>=(const ConstExprIterator& R) const { return I >= R.I; } 901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }; 911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 93ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements. 94ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement. 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt { 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum StmtClass { 101f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor NoStmtClass = 0, 102f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class, 1037381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \ 1049a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class, 1057381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \ 1069a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class 1077381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT) 1084bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 1098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Make vanilla 'new' and 'delete' illegal for Stmts. 1128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected: 1138189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes) throw() { 114b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Stmts cannot be allocated with regular 'new'."); 1158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void operator delete(void* data) throw() { 117b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Stmts cannot be released with regular 'delete'."); 1188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class StmtBitfields { 1218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Stmt; 1228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall /// \brief The statement class. 1248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned sClass : 8; 1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall enum { NumStmtBits = 8 }; 1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CompoundStmtBitfields { 1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CompoundStmt; 1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned NumStmts : 32 - NumStmtBits; 1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class ExprBitfields { 1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Expr; 1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DeclRefExpr; // computeDependence 1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class InitListExpr; // ctor 1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DesignatedInitExpr; // ctor 140d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor friend class BlockDeclRefExpr; // ctor 141bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ASTStmtReader; // deserialization 142bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXNewExpr; // ctor 143bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class DependentScopeDeclRefExpr; // ctor 144bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXConstructExpr; // ctor 145bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CallExpr; // ctor 146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OffsetOfExpr; // ctor 147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ObjCMessageExpr; // ctor 148ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ObjCArrayLiteral; // ctor 149ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ObjCDictionaryLiteral; // ctor 150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ShuffleVectorExpr; // ctor 151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ParenListExpr; // ctor 152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXUnresolvedConstructExpr; // ctor 153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXDependentScopeMemberExpr; // ctor 154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OverloadExpr; // ctor 1554b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class PseudoObjectExpr; // ctor 156dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman friend class AtomicExpr; // ctor 1578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueKind : 2; 160f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall unsigned ObjectKind : 2; 1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned TypeDependent : 1; 1628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueDependent : 1; 163561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor unsigned InstantiationDependent : 1; 164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned ContainsUnexpandedParameterPack : 1; 1658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 166561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor enum { NumExprBits = 16 }; 1678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 168bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer class CharacterLiteralBitfields { 169bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer friend class CharacterLiteral; 170bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned : NumExprBits; 171bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 172bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned Kind : 2; 173bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer }; 174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer class FloatingLiteralBitfields { 176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer friend class FloatingLiteral; 177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned : NumExprBits; 178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 179bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned IsIEEE : 1; // Distinguishes between PPC128 and IEEE128. 180bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned IsExact : 1; 181bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer }; 182bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 183bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer class UnaryExprOrTypeTraitExprBitfields { 184bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer friend class UnaryExprOrTypeTraitExpr; 185bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned : NumExprBits; 186bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 187bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned Kind : 2; 188bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned IsType : 1; // true if operand is a type, false if an expression. 189bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer }; 190bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 191cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth class DeclRefExprBitfields { 192cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth friend class DeclRefExpr; 193cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth friend class ASTStmtReader; // deserialization 194cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth unsigned : NumExprBits; 195cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 196cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth unsigned HasQualifier : 1; 197e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara unsigned HasTemplateKWAndArgsInfo : 1; 1983aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth unsigned HasFoundDecl : 1; 1997cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara unsigned HadMultipleCandidates : 1; 200f4b88a45902af1802a1cb42ba48b1c474474f228John McCall unsigned RefersToEnclosingLocal : 1; 201cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth }; 202cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 2038e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CastExprBitfields { 2048e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CastExpr; 2058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumExprBits; 2068e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 2072bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned Kind : 6; 2082bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned BasePathSize : 32 - 6 - NumExprBits; 2098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 2108e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 211cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne class CallExprBitfields { 212cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne friend class CallExpr; 213cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned : NumExprBits; 214cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 215cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs : 1; 216cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne }; 217cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 21880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall class ExprWithCleanupsBitfields { 21980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ExprWithCleanups; 22080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ASTStmtReader; // deserialization 22180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 22280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned : NumExprBits; 22380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 22480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned NumObjects : 32 - NumExprBits; 22580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall }; 22680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 2274b9c2d235fb9449e249d74f48ecfec601650de93John McCall class PseudoObjectExprBitfields { 2284b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class PseudoObjectExpr; 2294b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class ASTStmtReader; // deserialization 2304b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2314b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned : NumExprBits; 2324b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2334b9c2d235fb9449e249d74f48ecfec601650de93John McCall // These don't need to be particularly wide, because they're 2344b9c2d235fb9449e249d74f48ecfec601650de93John McCall // strictly limited by the forms of expressions we permit. 2354b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned NumSubExprs : 8; 2364b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned ResultIndex : 32 - 8 - NumExprBits; 2374b9c2d235fb9449e249d74f48ecfec601650de93John McCall }; 2384b9c2d235fb9449e249d74f48ecfec601650de93John McCall 239f85e193739c953358c865005855253af4f68a497John McCall class ObjCIndirectCopyRestoreExprBitfields { 240f85e193739c953358c865005855253af4f68a497John McCall friend class ObjCIndirectCopyRestoreExpr; 241f85e193739c953358c865005855253af4f68a497John McCall unsigned : NumExprBits; 242f85e193739c953358c865005855253af4f68a497John McCall 243f85e193739c953358c865005855253af4f68a497John McCall unsigned ShouldCopy : 1; 244f85e193739c953358c865005855253af4f68a497John McCall }; 245f85e193739c953358c865005855253af4f68a497John McCall 24632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl class InitListExprBitfields { 24732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl friend class InitListExpr; 24832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 24932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl unsigned : NumExprBits; 25032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 25132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// Whether this initializer list originally had a GNU array-range 25232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// designator in it. This is a temporary marker used by CodeGen. 25332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl unsigned HadArrayRangeDesignator : 1; 25432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 25532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// Whether this initializer list initializes a std::initializer_list 25632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// object. 25732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl unsigned InitializesStdInitializerList : 1; 25832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl }; 25932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 2604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor class TypeTraitExprBitfields { 2614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class TypeTraitExpr; 2624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtReader; 2634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtWriter; 2644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned : NumExprBits; 2664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The kind of type trait, which is a value of a TypeTrait enumerator. 2684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned Kind : 8; 2694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief If this expression is not value-dependent, this indicates whether 2714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// the trait evaluated true or false. 2724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned Value : 1; 2734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The number of arguments to this type trait. 2754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned NumArgs : 32 - 8 - 1 - NumExprBits; 2764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor }; 2774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall union { 27963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // FIXME: this is wasteful on 64-bit platforms. 28063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall void *Aligner; 28163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 2828e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBitfields StmtBits; 2838e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBitfields CompoundStmtBits; 2848e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBitfields ExprBits; 285bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer CharacterLiteralBitfields CharacterLiteralBits; 286bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer FloatingLiteralBitfields FloatingLiteralBits; 287bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits; 288cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBitfields DeclRefExprBits; 2898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBitfields CastExprBits; 290cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBitfields CallExprBits; 29180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanupsBitfields ExprWithCleanupsBits; 2924b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBitfields PseudoObjectExprBits; 293f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits; 29432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl InitListExprBitfields InitListExprBits; 2954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTraitExprBitfields TypeTraitExprBits; 2968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 2978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 298d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor friend class ASTStmtReader; 2994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtWriter; 300d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 3018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic: 3028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Only allow allocation of Stmts using the allocator in ASTContext 3031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // or by doing a placement new. 3048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext& C, 305f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor unsigned alignment = 8) throw() { 3068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return ::operator new(bytes, C, alignment); 3078189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext* C, 310f4e689b8528770001f4792f1f4ebdfb09d859e3dDouglas Gregor unsigned alignment = 8) throw() { 3118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return ::operator new(bytes, *C, alignment); 3128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, void* mem) throw() { 3158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return mem; 3168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 317e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 318fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext&, unsigned) throw() { } 319fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext*, unsigned) throw() { } 320e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor void operator delete(void*, std::size_t) throw() { } 321fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, void*) throw() { } 322e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 323025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic: 324025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief A placeholder type used to construct an empty shell of a 325025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// type, that will be filled in later (e.g., by some 326025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// de-serialization). 327025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor struct EmptyShell { }; 328025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 32902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate: 33002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar /// \brief Whether statistic collection is enabled. 33102892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static bool StatisticsEnabled; 33202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar 3339c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected: 334025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Construct an empty statement. 3358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall explicit Stmt(StmtClass SC, EmptyShell) { 3368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 33702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) Stmt::addStmtClass(SC); 338025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor } 339025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt(StmtClass SC) { 3428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 34302892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) Stmt::addStmtClass(SC); 3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 346ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie StmtClass getStmtClass() const { 3478e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall return static_cast<StmtClass>(StmtBits.sClass); 348b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor } 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStmtClassName() const; 3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 351b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// SourceLocation tokens are not useful in isolation - they are low level 352b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// value objects created/interpreted by SourceManager. We assume AST 353b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// clients will have a pointer to the respective SourceManager. 354aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 355aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY; 356aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY; 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // global temp stats (until we have a per-module visitor) 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void addStmtClass(const StmtClass s); 36002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static void EnableStatistics(); 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void PrintStats(); 3626000dace22f110d8768476989313e9d981d690d0Chris Lattner 3636000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dump - This does a local dump of the specified AST fragment. It dumps the 3646000dace22f110d8768476989313e9d981d690d0Chris Lattner /// specified node and a few nodes underneath it, but not the whole subtree. 3656000dace22f110d8768476989313e9d981d690d0Chris Lattner /// This is useful in a debugger. 366f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis LLVM_ATTRIBUTE_USED void dump() const; 367f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const; 3688cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void dump(raw_ostream &OS, SourceManager &SM) const; 3696000dace22f110d8768476989313e9d981d690d0Chris Lattner 3706000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpAll - This does a dump of the specified AST fragment and all subtrees. 3716000dace22f110d8768476989313e9d981d690d0Chris Lattner void dumpAll() const; 372e300c870f08d08badf2ebcb53ded49f304af37fcChris Lattner void dumpAll(SourceManager &SM) const; 3736000dace22f110d8768476989313e9d981d690d0Chris Lattner 3746000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST 3756000dace22f110d8768476989313e9d981d690d0Chris Lattner /// back to its original source language syntax. 37648d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman void dumpPretty(ASTContext& Context) const; 3778cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void printPretty(raw_ostream &OS, PrinterHelper *Helper, 378e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 37948d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman unsigned Indentation = 0) const { 38048d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation); 38148d14a222276fad5279e994d1a062f36ae6fcbceEli Friedman } 3828cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void printPretty(raw_ostream &OS, ASTContext &Context, 3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PrinterHelper *Helper, 384e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 385d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned Indentation = 0) const; 3861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 387d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only 388d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// works on systems with GraphViz (Mac OS X) or dot+gv installed. 389d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek void viewAST() const; 3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3917e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// Skip past any implicit AST nodes which might surround this 3927e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes. 3937e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall Stmt *IgnoreImplicit(); 3947e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 395a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth const Stmt *stripLabelLikeStatements() const; 396a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth Stmt *stripLabelLikeStatements() { 397a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth return const_cast<Stmt*>( 398a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth const_cast<const Stmt*>(this)->stripLabelLikeStatements()); 399a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth } 400a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Implement isa<T> support. 4021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *) { return true; } 4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 404d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// hasImplicitControlFlow - Some statements (e.g. short circuited operations) 405d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// contain implicit control-flow in the order their subexpressions 406d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// are evaluated. This predicate returns true if this statement has 407d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// such implicit control-flow. Such statements are also specially handled 408d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// within CFGs. 409d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek bool hasImplicitControlFlow() const; 410d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek 41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// Child Iterators: All subclasses must implement 'children' 41263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// to permit easy iteration over the substatements/subexpessions of an 41363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// AST node. This permits easy iteration over all nodes in the AST. 4149caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef StmtIterator child_iterator; 4159caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef ConstStmtIterator const_child_iterator; 4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef StmtRange child_range; 41863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef ConstStmtRange const_child_range; 4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 42163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_range children() const { 42263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return const_cast<Stmt*>(this)->children(); 42377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 4241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_begin() { return children().first; } 42663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_end() { return children().second; } 42763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 42863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_begin() const { return children().first; } 42963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_end() const { return children().second; } 43041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 43141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Produce a unique representation of the given statement. 43241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 43341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief ID once the profiling operation is complete, will contain 43441ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// the unique representation of the given statement. 43541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 43641ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Context the AST context in which the statement resides 43741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 43841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Canonical whether the profile should be based on the canonical 43941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// representation of this statement (e.g., where non-type template 4401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// parameters are identified by index/level rather than their 44141ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// declaration pointers) or the exact representation of the statement as 44241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// written in the source. 4434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 444b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth bool Canonical) const; 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions 4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration. 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt { 4539653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor DeclGroupRef DG; 45481c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation StartLoc, EndLoc; 4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 4588ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg), 4598ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek StartLoc(startLoc), EndLoc(endLoc) {} 4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 46184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor /// \brief Build an empty declaration statement. 46284f2170062014d268951902164bed0d8bdea0e82Douglas Gregor explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { } 46384f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 4647e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner /// isSingleDecl - This method returns true if this DeclStmt refers 465fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner /// to a single Decl. 4667e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner bool isSingleDecl() const { 467fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner return DG.isSingleDecl(); 4688ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek } 4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4707e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner const Decl *getSingleDecl() const { return DG.getSingleDecl(); } 4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl *getSingleDecl() { return DG.getSingleDecl(); } 4721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 473e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner const DeclGroupRef getDeclGroup() const { return DG; } 474e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner DeclGroupRef getDeclGroup() { return DG; } 47584f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setDeclGroup(DeclGroupRef DGR) { DG = DGR; } 476b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 47781c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getStartLoc() const { return StartLoc; } 47884f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setStartLoc(SourceLocation L) { StartLoc = L; } 47981c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getEndLoc() const { return EndLoc; } 48084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setEndLoc(SourceLocation L) { EndLoc = L; } 48184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 482aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 48381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner return SourceRange(StartLoc, EndLoc); 48481c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner } 4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DeclStmtClass; 4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclStmt *) { return true; } 4901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49114f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek // Iterators over subexpressions. 49263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 49363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(DG.begin(), DG.end()), 49463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator(DG.end(), DG.end())); 49563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 4961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4970632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::iterator decl_iterator; 4980632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::const_iterator const_decl_iterator; 4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5008ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_begin() { return DG.begin(); } 5018ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_end() { return DG.end(); } 5028ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_begin() const { return DG.begin(); } 5038ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_end() const { return DG.end(); } 504fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose 505fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator; 506fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose reverse_decl_iterator decl_rbegin() { 507fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose return reverse_decl_iterator(decl_end()); 508fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose } 509fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose reverse_decl_iterator decl_rend() { 510fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose return reverse_decl_iterator(decl_begin()); 511fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose } 5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3. 5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt { 5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation SemiLoc; 51844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 519e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis /// \brief True if the null statement was preceded by an empty macro, e.g: 52044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @code 52144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// #define CALL(x) 52244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// CALL(0); 52344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @endcode 524e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis bool HasLeadingEmptyMacro; 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 526e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false) 527e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis : Stmt(NullStmtClass), SemiLoc(L), 528e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis HasLeadingEmptyMacro(hasLeadingEmptyMacro) {} 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 530025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty null statement. 531e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty), 532e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis HasLeadingEmptyMacro(false) { } 533025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getSemiLoc() const { return SemiLoc; } 535025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSemiLoc(SourceLocation L) { SemiLoc = L; } 536b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 537e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; } 53844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 539aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(SemiLoc); } 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == NullStmtClass; 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const NullStmt *) { return true; } 5451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 54744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 54844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtReader; 54944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtWriter; 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }. 5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt { 5558189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek Stmt** Body; 556b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation LBracLoc, RBracLoc; 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5583a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts, 5593a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer SourceLocation LB, SourceLocation RB); 5603a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer 5613a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer // \brief Build an empty compound statment with a location. 5623a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer explicit CompoundStmt(SourceLocation Loc) 5633a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) { 5643a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer CompoundStmtBits.NumStmts = 0; 5651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 566025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 567025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor // \brief Build an empty compound statement. 568025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CompoundStmt(EmptyShell Empty) 5698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass, Empty), Body(0) { 5708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = 0; 5718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 572025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 573025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts); 5741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } 5768e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned size() const { return CompoundStmtBits.NumStmts; } 577025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5788189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt** body_iterator; 5798189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek body_iterator body_begin() { return Body; } 5808e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall body_iterator body_end() { return Body + size(); } 5818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; } 582ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5838e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setLastStmt(Stmt *S) { 5848e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall assert(!body_empty() && "setLastStmt"); 5858e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Body[size()-1] = S; 5868e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5888189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt* const * const_body_iterator; 5898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_body_iterator body_begin() const { return Body; } 5908e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const_body_iterator body_end() const { return Body + size(); } 5918e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; } 5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek 5938189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<body_iterator> reverse_body_iterator; 5948189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rbegin() { 5958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_end()); 5968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 5978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rend() { 5988189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_begin()); 5998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6004ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 6018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<const_body_iterator> 6028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator; 6034ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 6048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rbegin() const { 6058189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_end()); 6068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6088189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rend() const { 6098189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_begin()); 6108189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 612aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 6131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(LBracLoc, RBracLoc); 614b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 616cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getLBracLoc() const { return LBracLoc; } 617025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setLBracLoc(SourceLocation L) { LBracLoc = L; } 618cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getRBracLoc() const { return RBracLoc; } 619025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setRBracLoc(SourceLocation L) { RBracLoc = L; } 6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundStmtClass; 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundStmt *) { return true; } 6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6268297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 62763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 62863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 62963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 630ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6318ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek const_child_range children() const { 6328ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 6338ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek } 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 636c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt, 637c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt { 638103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected: 639c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // A pointer to the following CaseStmt or DefaultStmt class, 640c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // used by SwitchStmt. 641c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *NextSwitchCase; 642103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek 643d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {} 6441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 645c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonpublic: 646c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } 647c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 648c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getNextSwitchCase() { return NextSwitchCase; } 649c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 650c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } 651d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek 65263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt *getSubStmt(); 653702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner const Stmt *getSubStmt() const { 654702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner return const_cast<SwitchCase*>(this)->getSubStmt(); 655702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner } 656b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 657aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); } 6581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass || 66163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall T->getStmtClass() == DefaultStmtClass; 662c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 663c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson static bool classof(const SwitchCase *) { return true; } 664c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson}; 665c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 666c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase { 6670a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor enum { LHS, RHS, SUBSTMT, END_EXPR }; 6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 669d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // GNU "case 1 ... 4" extension 670b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation CaseLoc; 671dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation EllipsisLoc; 672dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation ColonLoc; 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 674dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, 6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation ellipsisLoc, SourceLocation colonLoc) 676d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek : SwitchCase(CaseStmtClass) { 67724e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner SubExprs[SUBSTMT] = 0; 678d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 679d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 680b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff CaseLoc = caseLoc; 681dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor EllipsisLoc = ellipsisLoc; 682dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor ColonLoc = colonLoc; 683d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek } 684025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 685025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty switch case statement. 686025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { } 687025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 688764a7ce5217f9569e100a3445f47496ee82daf86Chris Lattner SourceLocation getCaseLoc() const { return CaseLoc; } 689025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCaseLoc(SourceLocation L) { CaseLoc = L; } 690dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 691dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } 692dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 693dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 694025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 695d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 696d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 697d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 698025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getLHS() const { 7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[LHS]); 70151b09f2c528c8460b5465c676173324e44176d62Devang Patel } 7021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getRHS() const { 7031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[RHS]); 70451b09f2c528c8460b5465c676173324e44176d62Devang Patel } 70551b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 70720dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; } 70820dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } 70920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 712aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 7133fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner // Handle deeply nested case statements with iteration instead of recursion. 7143fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner const CaseStmt *CS = this; 71591ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) 7163fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner CS = CS2; 7171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd()); 719b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass; 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CaseStmt *) { return true; } 7241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 725d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 72663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 72763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[END_EXPR]); 72863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 731c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase { 732d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt* SubStmt; 7336c36be5b383875b490684bcf439d6d427298c1afChris Lattner SourceLocation DefaultLoc; 734dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation ColonLoc; 7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : 737dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL), 738dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor ColonLoc(CL) {} 739025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 740025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty default statement. 741025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { } 742025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 743d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubStmt; } 74451b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubStmt; } 745025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSubStmt(Stmt *S) { SubStmt = S; } 746025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 7476c36be5b383875b490684bcf439d6d427298c1afChris Lattner SourceLocation getDefaultLoc() const { return DefaultLoc; } 748025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setDefaultLoc(SourceLocation L) { DefaultLoc = L; } 749dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 750dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 752aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(DefaultLoc, SubStmt->getLocEnd()); 754b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 7551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DefaultStmtClass; 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DefaultStmt *) { return true; } 7591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 760d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 76163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 764ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 765ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement. For example: 766ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// foo: return; 767ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt { 769ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *TheDecl; 7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *SubStmt; 771b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IdentLoc; 7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 773ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt) 774ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) { 7758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 7761de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 7771de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor // \brief Build an empty label statement. 7781de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { } 7791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getIdentLoc() const { return IdentLoc; } 781ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getDecl() const { return TheDecl; } 782ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setDecl(LabelDecl *D) { TheDecl = D; } 7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *getSubStmt() { return SubStmt; } 7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Stmt *getSubStmt() const { return SubStmt; } 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setIdentLoc(SourceLocation L) { IdentLoc = L; } 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setSubStmt(Stmt *SS) { SubStmt = SS; } 788b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 789aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 7901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(IdentLoc, SubStmt->getLocEnd()); 7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 79263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 79363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 7941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == LabelStmtClass; 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const LabelStmt *) { return true; } 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 801534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement. 802534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// 803534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example: 804534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// [[omp::for(...)]] for (...) { ... } 805534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// 806534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt { 807534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *SubStmt; 808534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation AttrLoc; 8094990890fc9428f98bef90ba349203a648c592778Alexander Kornienko unsigned NumAttrs; 8104990890fc9428f98bef90ba349203a648c592778Alexander Kornienko const Attr *Attrs[1]; 811534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 812534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith friend class ASTStmtReader; 813534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8144990890fc9428f98bef90ba349203a648c592778Alexander Kornienko AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt) 8154990890fc9428f98bef90ba349203a648c592778Alexander Kornienko : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc), 8164990890fc9428f98bef90ba349203a648c592778Alexander Kornienko NumAttrs(Attrs.size()) { 8174990890fc9428f98bef90ba349203a648c592778Alexander Kornienko memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*)); 818534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 819534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8204990890fc9428f98bef90ba349203a648c592778Alexander Kornienko explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) 8214990890fc9428f98bef90ba349203a648c592778Alexander Kornienko : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) { 8224990890fc9428f98bef90ba349203a648c592778Alexander Kornienko memset(Attrs, 0, NumAttrs * sizeof(Attr*)); 823534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 824534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8254990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic: 8264990890fc9428f98bef90ba349203a648c592778Alexander Kornienko static AttributedStmt *Create(ASTContext &C, SourceLocation Loc, 8274990890fc9428f98bef90ba349203a648c592778Alexander Kornienko ArrayRef<const Attr*> Attrs, Stmt *SubStmt); 8284990890fc9428f98bef90ba349203a648c592778Alexander Kornienko // \brief Build an empty attributed statement. 8294990890fc9428f98bef90ba349203a648c592778Alexander Kornienko static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs); 8304990890fc9428f98bef90ba349203a648c592778Alexander Kornienko 831534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation getAttrLoc() const { return AttrLoc; } 8324990890fc9428f98bef90ba349203a648c592778Alexander Kornienko ArrayRef<const Attr*> getAttrs() const { 8334990890fc9428f98bef90ba349203a648c592778Alexander Kornienko return ArrayRef<const Attr*>(Attrs, NumAttrs); 8344990890fc9428f98bef90ba349203a648c592778Alexander Kornienko } 835534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *getSubStmt() { return SubStmt; } 836534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith const Stmt *getSubStmt() const { return SubStmt; } 837534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 838534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceRange getSourceRange() const LLVM_READONLY { 839534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return SourceRange(AttrLoc, SubStmt->getLocEnd()); 840534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 841534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith child_range children() { return child_range(&SubStmt, &SubStmt + 1); } 842534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 843534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith static bool classof(const Stmt *T) { 844534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return T->getStmtClass() == AttributedStmtClass; 845534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 846534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith static bool classof(const AttributedStmt *) { return true; } 847534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith}; 848534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 849534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else. 8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt { 85343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, THEN, ELSE, END_EXPR }; 8548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 8558cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor 856b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IfLoc; 857d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation ElseLoc; 858ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 860ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, 86144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0); 862ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 863025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty if/then/else statement 864025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { } 865025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 8668cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \brief Retrieve the variable declared in this "if" statement, if any. 8678cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// 8688cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// In the following example, "x" is the condition variable. 8698cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \code 8708cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// if (int x = foo()) { 8718cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// printf("x is %d", x); 8728cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// } 8738cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \endcode 87443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 87543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 876ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 877d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this IfStmt has a condition variable, return the faux DeclStmt 878d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 879d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 880d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 881d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 882ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8838297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 884025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 8858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getThen() const { return SubExprs[THEN]; } 8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setThen(Stmt *S) { SubExprs[THEN] = S; } 8878297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getElse() const { return SubExprs[ELSE]; } 888025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setElse(Stmt *S) { SubExprs[ELSE] = S; } 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8908297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 8918297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getThen() { return SubExprs[THEN]; } 8928297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getElse() { return SubExprs[ELSE]; } 893b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 894025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getIfLoc() const { return IfLoc; } 895025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setIfLoc(SourceLocation L) { IfLoc = L; } 896d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation getElseLoc() const { return ElseLoc; } 897d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor void setElseLoc(SourceLocation L) { ElseLoc = L; } 898025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 899aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 900b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff if (SubExprs[ELSE]) 901b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd()); 902b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff else 903b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd()); 904b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 9051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 90663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators over subexpressions. The iterators will include iterating 90763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // over the initialization expression referenced by the condition variable. 90863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 90963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 91063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 91163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IfStmtClass; 9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IfStmt *) { return true; } 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt. 9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt { 92143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 923c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // This points to a linked list of case and default statements. 924c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *FirstCase; 9259dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SourceLocation SwitchLoc; 9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 927559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// If the SwitchStmt is a switch on an enum value, this records whether 928559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// all the enum values were covered by CaseStmts. This value is meant to 929559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// be a hint for possible clients. 930559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek unsigned AllEnumCasesCovered : 1; 931559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 93343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond); 9341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 935025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build a empty switch statement. 936025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { } 937025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 938d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \brief Retrieve the variable declared in this "switch" statement, if any. 939d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// 940d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// In the following example, "x" is the condition variable. 941d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \code 942d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// switch (int x = foo()) { 943d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// case 0: break; 944d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// // ... 945d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// } 946d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \endcode 94743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 94843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 949ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 950d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this SwitchStmt has a condition variable, return the faux DeclStmt 951d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 952d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 953d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 954d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 955d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor 9568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 9578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 958c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getSwitchCaseList() const { return FirstCase; } 959c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 9608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 961025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 9628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 963025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 964c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getSwitchCaseList() { return FirstCase; } 9651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Set the case list for this switch statement. 96743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// 96843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// The caller is responsible for incrementing the retain counts on 96943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// all of the SwitchCase statements in this list. 970025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } 971025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 972025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getSwitchLoc() const { return SwitchLoc; } 973025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchLoc(SourceLocation L) { SwitchLoc = L; } 974c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setBody(Stmt *S, SourceLocation SL) { 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SubExprs[BODY] = S; 9779dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SwitchLoc = SL; 9781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 979c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void addSwitchCase(SwitchCase *SC) { 980ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(!SC->getNextSwitchCase() 981ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie && "case/default already added to a switch"); 982c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor SC->setNextSwitchCase(FirstCase); 983c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson FirstCase = SC; 984c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 985559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 986559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a 987559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// switch over an enum value then all cases have been explicitly covered. 988559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek void setAllEnumCasesCovered() { 989559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek AllEnumCasesCovered = 1; 990559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 991559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 992559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Returns true if the SwitchStmt is a switch of an enum value and all cases 993559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// have been explicitly covered. 994559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek bool isAllEnumCasesCovered() const { 995559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek return (bool) AllEnumCasesCovered; 996559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 997559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 998aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd()); 10009dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff } 100163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators 100263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 100363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 100463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 100563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SwitchStmtClass; 10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const SwitchStmt *) { return true; } 10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt. 10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt { 101643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 10178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 1018b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation WhileLoc; 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1020ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 102143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SourceLocation WL); 10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1023d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty while statement. 1024d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { } 1025d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 10265656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Retrieve the variable declared in this "while" statement, if any. 10275656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// 10285656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// In the following example, "x" is the condition variable. 10295656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \code 10305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// while (int x = random()) { 10315656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// // ... 10325656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// } 10335656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \endcode 103443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 103543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 10365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 1037d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this WhileStmt has a condition variable, return the faux DeclStmt 1038d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 1039d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 1040d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 1041d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 1042d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 10438297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 10448297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 1045d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 10468297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 10478297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 1048d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 1049d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1050d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 1051d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1052b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 1053aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 10541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd()); 1055b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 10561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == WhileStmtClass; 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const WhileStmt *) { return true; } 10601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 106263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 106363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 106463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt. 10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt { 1070c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor enum { BODY, COND, END_EXPR }; 10718297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 1072b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation DoLoc; 10739f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation WhileLoc; 1074989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RParenLoc; // Location of final ')' in do stmt condition. 10759f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1077989135901c750af61ef012b6b0a0368be415bc46Chris Lattner DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL, 1078989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RP) 1079989135901c750af61ef012b6b0a0368be415bc46Chris Lattner : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) { 10808297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 10818297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[BODY] = body; 10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 108367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 108467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty do-while statement. 108567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { } 10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10878297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 10888297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 108967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 10908297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 10911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Stmt *getBody() const { return SubExprs[BODY]; } 109267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 109367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 109467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getDoLoc() const { return DoLoc; } 109567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setDoLoc(SourceLocation L) { DoLoc = L; } 10969f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 10979f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1098b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 1099989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 1100989135901c750af61ef012b6b0a0368be415bc46Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1101989135901c750af61ef012b6b0a0368be415bc46Chris Lattner 1102aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(DoLoc, RParenLoc); 1104b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 11051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DoStmtClass; 11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DoStmt *) { return true; } 11098297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 11108297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 111163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 111263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 111363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not 11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source. 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt { 112243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; 11238297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 1124b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation ForLoc; 11255831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation LParenLoc, RParenLoc; 11265831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor 11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1128ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, 112943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP); 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113167d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty for statement. 113267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { } 113367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 11348297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getInit() { return SubExprs[INIT]; } 1135ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 113699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \brief Retrieve the variable declared in this "for" statement, if any. 113799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// 113899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// In the following example, "y" is the condition variable. 113999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \code 114099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// for (int x = random(); int y = mangle(x); ++x) { 114199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// // ... 114299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// } 114399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \endcode 114443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 114543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 1146ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1147d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this ForStmt has a condition variable, return the faux DeclStmt 1148d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 1149d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 1150d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]); 1151d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 1152d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 11538297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 11548297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 11558297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 11568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 11578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getInit() const { return SubExprs[INIT]; } 11588297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 11598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 11608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 1161b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 116267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInit(Stmt *S) { SubExprs[INIT] = S; } 116367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 116467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } 116567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 116667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 116767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getForLoc() const { return ForLoc; } 116867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setForLoc(SourceLocation L) { ForLoc = L; } 11695831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 11705831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 11715831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 11725831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 117367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 1174aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 11751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd()); 1176b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 11771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ForStmtClass; 11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ForStmt *) { return true; } 11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11828297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 118363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 118463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 118563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto. 11895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt { 1191ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 1192507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation GotoLoc; 119361f62165220e75694fe333179c78815e2e48d71fTed Kremenek SourceLocation LabelLoc; 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1195ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL) 119661f62165220e75694fe333179c78815e2e48d71fTed Kremenek : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11981de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor /// \brief Build an empty goto statement. 11991de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { } 12001de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 1201ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 1202ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *D) { Label = D; } 12031de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 12041de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getGotoLoc() const { return GotoLoc; } 12051de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setGotoLoc(SourceLocation L) { GotoLoc = L; } 12061de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 12071de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 1208b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 1209aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(GotoLoc, LabelLoc); 1211507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff } 12121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GotoStmtClass; 12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const GotoStmt *) { return true; } 12161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12178297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 121863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto. 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt { 1224ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation GotoLoc; 12255f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation StarLoc; 12261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Target; 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, 12295f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Expr *target) 12305f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc), 12315f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Target((Stmt*)target) {} 12327d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 12337d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty indirect goto statement. 12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IndirectGotoStmt(EmptyShell Empty) 12357d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Stmt(IndirectGotoStmtClass, Empty) { } 12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1237ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner void setGotoLoc(SourceLocation L) { GotoLoc = L; } 1238ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation getGotoLoc() const { return GotoLoc; } 12395f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor void setStarLoc(SourceLocation L) { StarLoc = L; } 12405f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation getStarLoc() const { return StarLoc; } 12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 124295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall Expr *getTarget() { return reinterpret_cast<Expr*>(Target); } 124395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);} 12447d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); } 1245b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 124695c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// getConstantTarget - Returns the fixed target of this indirect 124795c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// goto, if one exists. 1248ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getConstantTarget(); 1249ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner const LabelDecl *getConstantTarget() const { 125095c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall return const_cast<IndirectGotoStmt*>(this)->getConstantTarget(); 125195c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall } 125295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall 1253aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 1254ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner return SourceRange(GotoLoc, Target->getLocEnd()); 1255ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner } 12561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IndirectGotoStmtClass; 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IndirectGotoStmt *) { return true; } 12611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 126363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Target, &Target+1); } 12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ContinueStmt - This represents a continue. 12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ContinueStmt : public Stmt { 1270507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation ContinueLoc; 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1272507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {} 12731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1274d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty continue statement. 1275d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { } 1276d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1277d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getContinueLoc() const { return ContinueLoc; } 1278d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setContinueLoc(SourceLocation L) { ContinueLoc = L; } 1279d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1280aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(ContinueLoc); 1282507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff } 1283861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ContinueStmtClass; 12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ContinueStmt *) { return true; } 12881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12898297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 129063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break. 12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt { 1296507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation BreakLoc; 12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1298507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1300025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty break statement. 1301025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { } 1302025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1303025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getBreakLoc() const { return BreakLoc; } 1304025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBreakLoc(SourceLocation L) { BreakLoc = L; } 1305025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1306aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(BreakLoc); } 1307b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BreakStmtClass; 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BreakStmt *) { return true; } 13121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13138297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 131463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1318c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression: 1319c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return; 1320c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return 4; 1321c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// 1322c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to 1323c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to 1324c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void. We explicitly model this in the AST, which means you can't 1325c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument. 13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt { 13281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *RetExpr; 1329507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation RetLoc; 13305077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *NRVOCandidate; 1331ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13335077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL) 133425a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { } 13355077c3876beeaed32280af88244e8050078619a8Douglas Gregor 13365077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) 13375077c3876beeaed32280af88244e8050078619a8Douglas Gregor : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL), 13385077c3876beeaed32280af88244e8050078619a8Douglas Gregor NRVOCandidate(NRVOCandidate) {} 13390de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13400de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor /// \brief Build an empty return expression. 13410de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { } 13420de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13431060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getRetValue() const; 13441060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getRetValue(); 13450de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); } 13460de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13470de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor SourceLocation getReturnLoc() const { return RetLoc; } 13480de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setReturnLoc(SourceLocation L) { RetLoc = L; } 1349b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 13505077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// \brief Retrieve the variable that might be used for the named return 13515077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// value optimization. 13525077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// 13535077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// The optimization itself can only be performed if the variable is 13545077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// also marked as an NRVO object. 13555077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *getNRVOCandidate() const { return NRVOCandidate; } 13565077c3876beeaed32280af88244e8050078619a8Douglas Gregor void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; } 1357ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1358aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ReturnStmtClass; 13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReturnStmt *) { return true; } 13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13658297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 136663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 136763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (RetExpr) return child_range(&RetExpr, &RetExpr+1); 136863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 136963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 13705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1372fe795956194141c91ae555985c9b930595bff43fChris Lattner/// AsmStmt - This represents a GNU inline-assembly statement extension. 1373fe795956194141c91ae555985c9b930595bff43fChris Lattner/// 1374fe795956194141c91ae555985c9b930595bff43fChris Lattnerclass AsmStmt : public Stmt { 1375fe795956194141c91ae555985c9b930595bff43fChris Lattner SourceLocation AsmLoc, RParenLoc; 13766a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson StringLiteral *AsmStr; 1377b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1378dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson bool IsSimple; 137939c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson bool IsVolatile; 13803b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump bool MSAsm; 13811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1382b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned NumOutputs; 1383b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned NumInputs; 1384966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson unsigned NumClobbers; 13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1386966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson // FIXME: If we wanted to, we could allocate all of these in one big array. 1387966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson IdentifierInfo **Names; 1388966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Constraints; 1389966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson Stmt **Exprs; 1390966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Clobbers; 1391ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1392fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic: 1393ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, 1394966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson bool msasm, unsigned numoutputs, unsigned numinputs, 1395ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **names, StringLiteral **constraints, 1396db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, 1397db6ed1786bf460e1143f67d14bf2d71ad9856f81Chris Lattner StringLiteral **clobbers, SourceLocation rparenloc); 1398b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1399cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor /// \brief Build an empty inline-assembly statement. 1400ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty), 1401966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson Names(0), Constraints(0), Exprs(0), Clobbers(0) { } 1402cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1403cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getAsmLoc() const { return AsmLoc; } 1404cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmLoc(SourceLocation L) { AsmLoc = L; } 1405cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 1406cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1407cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 140839c47b56f45437bbc49c9568b7308a400234a730Anders Carlsson bool isVolatile() const { return IsVolatile; } 1409cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setVolatile(bool V) { IsVolatile = V; } 1410dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson bool isSimple() const { return IsSimple; } 14116ffe643322949dd776285a6df60d3578f3918be4Chris Lattner void setSimple(bool V) { IsSimple = V; } 14123b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump bool isMSAsm() const { return MSAsm; } 14133b11fd3b52e7b88233c602407c151d07cb093e75Mike Stump void setMSAsm(bool V) { MSAsm = V; } 1414dfab34a696d1dba8622248c31aaf605906cb6109Anders Carlsson 1415458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner //===--- Asm String Analysis ---===// 1416458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1417458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const StringLiteral *getAsmString() const { return AsmStr; } 1418458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner StringLiteral *getAsmString() { return AsmStr; } 1419cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmString(StringLiteral *E) { AsmStr = E; } 1420cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1421458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AsmStringPiece - this is part of a decomposed asm string specification 1422458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// (for use with the AnalyzeAsmString function below). An asm string is 1423458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// considered to be a concatenation of these parts. 1424458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner class AsmStringPiece { 1425458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1426458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner enum Kind { 1427458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". 1428458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Operand // Operand reference, with optional modifier %c4. 1429458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 1430458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner private: 1431458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Kind MyKind; 1432458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner std::string Str; 1433458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned OperandNo; 1434458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1435458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} 1436458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(unsigned OpNo, char Modifier) 1437458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner : MyKind(Operand), Str(), OperandNo(OpNo) { 1438458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Str += Modifier; 1439458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 14401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1441458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isString() const { return MyKind == String; } 1442458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isOperand() const { return MyKind == Operand; } 14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1444458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const std::string &getString() const { 1445458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isString()); 1446458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str; 1447458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1448458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1449458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned getOperandNo() const { 1450458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1451458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return OperandNo; 1452458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1454458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// getModifier - Get the modifier for this operand, if present. This 1455458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// returns '\0' if there was no modifier. 1456458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner char getModifier() const { 1457458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1458458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str[0]; 1459458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1460458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1462458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 1463458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// it into pieces. If the asm string is erroneous, emit errors and return 1464458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// true, otherwise return false. This handles canonicalization and 1465458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// translation of strings from GCC syntax to LLVM IR syntax, and handles 14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump //// flattening of named references like %[foo] to Operand AsmStringPiece's. 1467686775deca8b8685eb90801495880e3abdd844c2Chris Lattner unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces, 1468fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner ASTContext &C, unsigned &DiagOffs) const; 14691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1471b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Output operands ---===// 1472b327793860737d1c103a73aeda8057dd628a101dChris Lattner 1473b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson unsigned getNumOutputs() const { return NumOutputs; } 1474ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1475ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo *getOutputIdentifier(unsigned i) const { 1476ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Names[i]; 1477ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1478ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1479686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getOutputName(unsigned i) const { 1480ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson if (IdentifierInfo *II = getOutputIdentifier(i)) 1481ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return II->getName(); 1482ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1483686775deca8b8685eb90801495880e3abdd844c2Chris Lattner return StringRef(); 1484ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson } 1485ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1486b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// getOutputConstraint - Return the constraint string for the specified 1487b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// output operand. All output constraints are known to be non-empty (either 1488b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// '=' or '+'). 1489686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getOutputConstraint(unsigned i) const; 14901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1491b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getOutputConstraintLiteral(unsigned i) const { 1492ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i]; 1493ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1494b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getOutputConstraintLiteral(unsigned i) { 1495b327793860737d1c103a73aeda8057dd628a101dChris Lattner return Constraints[i]; 1496b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1498ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getOutputExpr(unsigned i); 14991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1500b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getOutputExpr(unsigned i) const { 1501b327793860737d1c103a73aeda8057dd628a101dChris Lattner return const_cast<AsmStmt*>(this)->getOutputExpr(i); 1502b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 15031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1504b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// isOutputPlusConstraint - Return true if the specified output constraint 1505b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// is a "+" constraint (which is both an input and an output) or false if it 1506b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// is an "=" constraint (just an output). 1507b327793860737d1c103a73aeda8057dd628a101dChris Lattner bool isOutputPlusConstraint(unsigned i) const { 1508b327793860737d1c103a73aeda8057dd628a101dChris Lattner return getOutputConstraint(i)[0] == '+'; 1509b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 15101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 151185759278332404e96d4bb89d0e976e46158cd026Chris Lattner /// getNumPlusOperands - Return the number of output operands that have a "+" 151285759278332404e96d4bb89d0e976e46158cd026Chris Lattner /// constraint. 151385759278332404e96d4bb89d0e976e46158cd026Chris Lattner unsigned getNumPlusOperands() const; 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1515b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Input operands ---===// 15161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumInputs() const { return NumInputs; } 15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1519ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo *getInputIdentifier(unsigned i) const { 1520ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Names[i + NumOutputs]; 1521ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1523686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getInputName(unsigned i) const { 1524ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson if (IdentifierInfo *II = getInputIdentifier(i)) 1525ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson return II->getName(); 1526ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1527686775deca8b8685eb90801495880e3abdd844c2Chris Lattner return StringRef(); 1528ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson } 1529ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson 1530b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// getInputConstraint - Return the specified input constraint. Unlike output 1531b327793860737d1c103a73aeda8057dd628a101dChris Lattner /// constraints, these can be empty. 1532686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getInputConstraint(unsigned i) const; 15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1534b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getInputConstraintLiteral(unsigned i) const { 1535ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1536ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1537b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getInputConstraintLiteral(unsigned i) { 1538ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1539ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1541ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getInputExpr(unsigned i); 1542935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner void setInputExpr(unsigned i, Expr *E); 1543ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1544b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getInputExpr(unsigned i) const { 1545b327793860737d1c103a73aeda8057dd628a101dChris Lattner return const_cast<AsmStmt*>(this)->getInputExpr(i); 1546b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 1547cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1548acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson void setOutputsAndInputsAndClobbers(ASTContext &C, 1549ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1550fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Constraints, 1551fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson Stmt **Exprs, 1552fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumOutputs, 1553ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie unsigned NumInputs, 1554fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Clobbers, 1555fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumClobbers); 1556cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 155710ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner //===--- Other ---===// 15581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 155910ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// getNamedOperand - Given a symbolic operand reference like %[foo], 156010ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// translate this into a numeric value needed to reference the same operand. 156110ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// This returns -1 if the operand name is invalid. 1562686775deca8b8685eb90801495880e3abdd844c2Chris Lattner int getNamedOperand(StringRef SymbolicName) const; 156310ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner 1564966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson unsigned getNumClobbers() const { return NumClobbers; } 1565b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson StringLiteral *getClobber(unsigned i) { return Clobbers[i]; } 1566d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; } 1567cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1568aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 1569fe795956194141c91ae555985c9b930595bff43fChris Lattner return SourceRange(AsmLoc, RParenLoc); 1570fe795956194141c91ae555985c9b930595bff43fChris Lattner } 15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1572fe795956194141c91ae555985c9b930595bff43fChris Lattner static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;} 1573fe795956194141c91ae555985c9b930595bff43fChris Lattner static bool classof(const AsmStmt *) { return true; } 15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1575ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek // Input expr iterators. 15761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1577ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ExprIterator inputs_iterator; 1578ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ConstExprIterator const_inputs_iterator; 15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1580ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek inputs_iterator begin_inputs() { 1581966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1582ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 15831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1584ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek inputs_iterator end_inputs() { 1585966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs + NumInputs; 1586ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1588ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const_inputs_iterator begin_inputs() const { 1589966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1590ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 15911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1592ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const_inputs_iterator end_inputs() const { 1593966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs + NumInputs; 1594d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 15951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1596ec2f7dccb1f30ae137f74e764e44c2332b0a2ec0Ted Kremenek // Output expr iterators. 15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1598ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ExprIterator outputs_iterator; 1599ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek typedef ConstExprIterator const_outputs_iterator; 16001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1601d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek outputs_iterator begin_outputs() { 1602966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0]; 1603d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 1604d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek outputs_iterator end_outputs() { 1605966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1606d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1608d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek const_outputs_iterator begin_outputs() const { 1609966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0]; 1610d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 1611d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek const_outputs_iterator end_outputs() const { 1612966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson return &Exprs[0] + NumOutputs; 1613d59a5bd0ab7821a643c540df8c84c70fef76a1c2Ted Kremenek } 16141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 161563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 161663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); 161763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 1618fe795956194141c91ae555985c9b930595bff43fChris Lattner}; 161978492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek 16208cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier/// MSAsmStmt - This represents a MS inline-assembly statement extension. 16218cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier/// 16228cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierclass MSAsmStmt : public Stmt { 16237bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier SourceLocation AsmLoc, LBraceLoc, EndLoc; 16248cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier std::string AsmStr; 16258cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16268cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier bool IsSimple; 16278cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier bool IsVolatile; 16288cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 162979efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier unsigned NumAsmToks; 16304399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier unsigned NumClobbers; 163179efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier 163279efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier Token *AsmToks; 16338cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier Stmt **Exprs; 163433c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier StringRef *Clobbers; 16358cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16368cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic: 16377bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, 16387bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier bool issimple, bool isvolatile, ArrayRef<Token> asmtoks, 16397bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier StringRef asmstr, ArrayRef<StringRef> clobbers, 16407bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier SourceLocation endloc); 16418cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16428cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier SourceLocation getAsmLoc() const { return AsmLoc; } 16438cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier void setAsmLoc(SourceLocation L) { AsmLoc = L; } 16447bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier SourceLocation getLBraceLoc() const { return LBraceLoc; } 16457bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier void setLBraceLoc(SourceLocation L) { LBraceLoc = L; } 16468cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier SourceLocation getEndLoc() const { return EndLoc; } 16478cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier void setEndLoc(SourceLocation L) { EndLoc = L; } 16488cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16497bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier bool hasBraces() const { return LBraceLoc.isValid(); } 16507bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier 165179efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier unsigned getNumAsmToks() { return NumAsmToks; } 165279efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier Token *getAsmToks() { return AsmToks; } 16538f726de55412870ef70e788b852c6cc50873e15bChad Rosier 16548cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier bool isVolatile() const { return IsVolatile; } 16558cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier void setVolatile(bool V) { IsVolatile = V; } 16568cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier bool isSimple() const { return IsSimple; } 16578cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier void setSimple(bool V) { IsSimple = V; } 16588cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16598cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier //===--- Asm String Analysis ---===// 16608cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16618cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier const std::string *getAsmString() const { return &AsmStr; } 16628cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier std::string *getAsmString() { return &AsmStr; } 16638cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier void setAsmString(StringRef &E) { AsmStr = E.str(); } 16648cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16658cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier //===--- Other ---===// 16668cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16674399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier unsigned getNumClobbers() const { return NumClobbers; } 16681e059da457ba65062448f24975db386efa0d51f8Chad Rosier StringRef getClobber(unsigned i) const { return Clobbers[i]; } 16694399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier 16708cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier SourceRange getSourceRange() const LLVM_READONLY { 16718cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return SourceRange(AsmLoc, EndLoc); 16728cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 16738cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier static bool classof(const Stmt *T) { 16748cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return T->getStmtClass() == MSAsmStmtClass; 16758cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 16768cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier static bool classof(const MSAsmStmt *) { return true; } 16778cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16788cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier child_range children() { 16798cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return child_range(&Exprs[0], &Exprs[0]); 16808cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 16818cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier}; 16828cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 168328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt { 168428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 168528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 168628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 168728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { FILTER_EXPR, BLOCK }; 168828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 168928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt(SourceLocation Loc, 169028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 169128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 169228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 16937110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 16947110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 16957110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { } 16967110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 169728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 169828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static SEHExceptStmt* Create(ASTContext &C, 169928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation ExceptLoc, 170028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 170128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 1702aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 170328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SourceRange(getExceptLoc(), getEndLoc()); 170428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 170528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 170628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getExceptLoc() const { return Loc; } 170728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); } 170828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1709ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr *getFilterExpr() const { 1710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); 1711ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 1712ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1713ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CompoundStmt *getBlock() const { 1714ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return llvm::cast<CompoundStmt>(Children[BLOCK]); 1715ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 171628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 171728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 171828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 171928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 172028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 172128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 172228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHExceptStmtClass; 172328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 172428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 172528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(SEHExceptStmt *) { return true; } 172628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 172728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 172828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 172928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt { 173028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 173128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block; 173228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 173328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt(SourceLocation Loc, 173428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 173528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 17367110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 17377110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 17387110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { } 17397110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 174028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 174128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static SEHFinallyStmt* Create(ASTContext &C, 174228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation FinallyLoc, 174328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 174428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1745aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 174628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SourceRange(getFinallyLoc(), getEndLoc()); 174728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 174828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 174928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getFinallyLoc() const { return Loc; } 175028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Block->getLocEnd(); } 175128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 175228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); } 175328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 175428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 175528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(&Block,&Block+1); 175628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 175728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 175828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 175928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHFinallyStmtClass; 176028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 176128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 176228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(SEHFinallyStmt *) { return true; } 176328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 176428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 176528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 176628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt { 176728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool IsCXXTry; 176828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc; 176928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 177028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 177128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { TRY = 0, HANDLER = 1 }; 177228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 177328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try' 177428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 177528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 177628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 177728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 17787110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 17797110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 17807110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { } 17817110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 178228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 178328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static SEHTryStmt* Create(ASTContext &C, 178428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool isCXXTry, 178528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 178628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 178728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 178828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1789aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 179028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SourceRange(getTryLoc(), getEndLoc()); 179128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 179228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 179328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getTryLoc() const { return TryLoc; } 179428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); } 179528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 179628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool getIsCXXTry() const { return IsCXXTry; } 1797ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1798ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CompoundStmt* getTryBlock() const { 1799ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return llvm::cast<CompoundStmt>(Children[TRY]); 1800ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 1801ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 180228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *getHandler() const { return Children[HANDLER]; } 180328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 180428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// Returns 0 if not defined 180528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt *getExceptHandler() const; 180628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt *getFinallyHandler() const; 180728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 180828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 180928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 181028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 181128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 181228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 181328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHTryStmtClass; 181428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 181528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 181628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(SEHTryStmt *) { return true; } 181728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 1818ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 18205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1822