Stmt.h revision 051303ce09291dfbed537fa33b0d8a4d92c82b75
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Stmt interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_STMT_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_STMT_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 172fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/DeclGroup.h" 189caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek#include "clang/AST/StmtIterator.h" 192fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/IdentifierTable.h" 202fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/LLVM.h" 212fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Basic/SourceLocation.h" 222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "llvm/ADT/ArrayRef.h" 23aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 24a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer#include "llvm/Support/ErrorHandling.h" 256e340496341a4704be0ede9c1ff4f8eacea7ee2cChris Lattner#include <string> 267573098b83e780d1c5bea13b384b610d8f155676Steve Naroff 2741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregornamespace llvm { 2841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor class FoldingSetNodeID; 2941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor} 3041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 32e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop class ASTContext; 332fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer class Attr; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 352fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer class Expr; 36051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj class FunctionDecl; 375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class IdentifierInfo; 38478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer class LabelDecl; 392fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer class ParmVarDecl; 40a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer class PrinterHelper; 41a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer struct PrintingPolicy; 422fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer class QualType; 43051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj class RecordDecl; 440c727a35718556866a978f64ac549d9798735f08Chris Lattner class SourceManager; 456a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson class StringLiteral; 466c36be5b383875b490684bcf439d6d427298c1afChris Lattner class SwitchStmt; 47a93d0f280693b8418bc88cf7a8c93325f7fcf4c6Benjamin Kramer class Token; 48478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer class VarDecl; 491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie //===--------------------------------------------------------------------===// 51ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // ExprIterator - Iterators for iterating over Stmt* arrays that contain 52ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // only Expr*. This is needed because AST nodes use Stmt* arrays to store 53ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // references to children (to be compatible with StmtIterator). 54ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie //===--------------------------------------------------------------------===// 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Stmt; 57ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class Expr; 581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ExprIterator { 60ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Stmt** I; 61ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 62ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator(Stmt** i) : I(i) {} 631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExprIterator() : I(0) {} 64ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator& operator++() { ++I; return *this; } 65ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator-(size_t i) { return I-i; } 66ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ExprIterator operator+(size_t i) { return I+i; } 67ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator[](size_t idx); 68ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek // FIXME: Verify that this will correctly return a signed distance. 69ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ExprIterator& R) const { return I - R.I; } 70ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator*() const; 71ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr* operator->() const; 72ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator==(const ExprIterator& R) const { return I == R.I; } 73ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator!=(const ExprIterator& R) const { return I != R.I; } 74ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>(const ExprIterator& R) const { return I > R.I; } 75ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>=(const ExprIterator& R) const { return I >= R.I; } 76ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek }; 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek class ConstExprIterator { 791705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer const Stmt * const *I; 80ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek public: 811705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator(const Stmt * const *i) : I(i) {} 821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ConstExprIterator() : I(0) {} 83ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek ConstExprIterator& operator++() { ++I; return *this; } 841705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator+(size_t i) const { return I+i; } 851705fe9ec0efb65f77a46e669e48302923204fe8Benjamin Kramer ConstExprIterator operator-(size_t i) const { return I-i; } 86ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator[](size_t idx) const; 87ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek signed operator-(const ConstExprIterator& R) const { return I - R.I; } 88ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator*() const; 89ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek const Expr * operator->() const; 90ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator==(const ConstExprIterator& R) const { return I == R.I; } 91ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator!=(const ConstExprIterator& R) const { return I != R.I; } 92ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>(const ConstExprIterator& R) const { return I > R.I; } 93ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek bool operator>=(const ConstExprIterator& R) const { return I >= R.I; } 941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }; 951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 97ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// AST classes for statements. 98ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt - This represents one statement. 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Stmt { 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum StmtClass { 105f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor NoStmtClass = 0, 106f2cad8633e46cce12fc3d77c0bd451ffd7264bafDouglas Gregor#define STMT(CLASS, PARENT) CLASS##Class, 1077381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define STMT_RANGE(BASE, FIRST, LAST) \ 1089a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class, 1097381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define LAST_STMT_RANGE(BASE, FIRST, LAST) \ 1109a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class 1117381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(STMT) 1124bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 1138e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Make vanilla 'new' and 'delete' illegal for Stmts. 1168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekprotected: 1178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes) throw() { 118b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Stmts cannot be allocated with regular 'new'."); 1198189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1208189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void operator delete(void* data) throw() { 121b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Stmts cannot be released with regular 'delete'."); 1228189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class StmtBitfields { 1258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Stmt; 1268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall /// \brief The statement class. 1288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned sClass : 8; 1298e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall enum { NumStmtBits = 8 }; 1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CompoundStmtBitfields { 1338e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CompoundStmt; 1348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned NumStmts : 32 - NumStmtBits; 1378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 1388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class ExprBitfields { 1408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class Expr; 1418e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DeclRefExpr; // computeDependence 1428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class InitListExpr; // ctor 1438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class DesignatedInitExpr; // ctor 144d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor friend class BlockDeclRefExpr; // ctor 145bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ASTStmtReader; // deserialization 146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXNewExpr; // ctor 147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class DependentScopeDeclRefExpr; // ctor 148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXConstructExpr; // ctor 149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CallExpr; // ctor 150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OffsetOfExpr; // ctor 151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ObjCMessageExpr; // ctor 152ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ObjCArrayLiteral; // ctor 153ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ObjCDictionaryLiteral; // ctor 154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ShuffleVectorExpr; // ctor 155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class ParenListExpr; // ctor 156bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXUnresolvedConstructExpr; // ctor 157bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CXXDependentScopeMemberExpr; // ctor 158bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class OverloadExpr; // ctor 1594b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class PseudoObjectExpr; // ctor 160dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman friend class AtomicExpr; // ctor 1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumStmtBits; 1628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueKind : 2; 164f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall unsigned ObjectKind : 2; 1658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned TypeDependent : 1; 1668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned ValueDependent : 1; 167561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor unsigned InstantiationDependent : 1; 168d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned ContainsUnexpandedParameterPack : 1; 1698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 170561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor enum { NumExprBits = 16 }; 1718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 172bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer class CharacterLiteralBitfields { 173bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer friend class CharacterLiteral; 174bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned : NumExprBits; 175bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 176bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned Kind : 2; 177bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer }; 178bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 1799ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover enum APFloatSemantics { 1809ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover IEEEhalf, 1819ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover IEEEsingle, 1829ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover IEEEdouble, 1839ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover x87DoubleExtended, 1849ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover IEEEquad, 1859ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover PPCDoubleDouble 1869ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover }; 1879ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 188bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer class FloatingLiteralBitfields { 189bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer friend class FloatingLiteral; 190bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned : NumExprBits; 191bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 1929ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover unsigned Semantics : 3; // Provides semantics for APFloat construction 193bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned IsExact : 1; 194bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer }; 195bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 196bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer class UnaryExprOrTypeTraitExprBitfields { 197bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer friend class UnaryExprOrTypeTraitExpr; 198bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned : NumExprBits; 199bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 200bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned Kind : 2; 201bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer unsigned IsType : 1; // true if operand is a type, false if an expression. 202bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer }; 203bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer 204cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth class DeclRefExprBitfields { 205cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth friend class DeclRefExpr; 206cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth friend class ASTStmtReader; // deserialization 207cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth unsigned : NumExprBits; 208cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 209cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth unsigned HasQualifier : 1; 210e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara unsigned HasTemplateKWAndArgsInfo : 1; 2113aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth unsigned HasFoundDecl : 1; 2127cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara unsigned HadMultipleCandidates : 1; 213f4b88a45902af1802a1cb42ba48b1c474474f228John McCall unsigned RefersToEnclosingLocal : 1; 214cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth }; 215cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 2168e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall class CastExprBitfields { 2178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall friend class CastExpr; 2188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned : NumExprBits; 2198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 2202bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned Kind : 6; 2212bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall unsigned BasePathSize : 32 - 6 - NumExprBits; 2228e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 2238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 224cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne class CallExprBitfields { 225cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne friend class CallExpr; 226cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned : NumExprBits; 227cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 228cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs : 1; 229cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne }; 230cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 23180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall class ExprWithCleanupsBitfields { 23280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ExprWithCleanups; 23380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ASTStmtReader; // deserialization 23480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 23580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned : NumExprBits; 23680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 23780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned NumObjects : 32 - NumExprBits; 23880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall }; 23980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 2404b9c2d235fb9449e249d74f48ecfec601650de93John McCall class PseudoObjectExprBitfields { 2414b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class PseudoObjectExpr; 2424b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class ASTStmtReader; // deserialization 2434b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2444b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned : NumExprBits; 2454b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2464b9c2d235fb9449e249d74f48ecfec601650de93John McCall // These don't need to be particularly wide, because they're 2474b9c2d235fb9449e249d74f48ecfec601650de93John McCall // strictly limited by the forms of expressions we permit. 2484b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned NumSubExprs : 8; 2494b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned ResultIndex : 32 - 8 - NumExprBits; 2504b9c2d235fb9449e249d74f48ecfec601650de93John McCall }; 2514b9c2d235fb9449e249d74f48ecfec601650de93John McCall 252f85e193739c953358c865005855253af4f68a497John McCall class ObjCIndirectCopyRestoreExprBitfields { 253f85e193739c953358c865005855253af4f68a497John McCall friend class ObjCIndirectCopyRestoreExpr; 254f85e193739c953358c865005855253af4f68a497John McCall unsigned : NumExprBits; 255f85e193739c953358c865005855253af4f68a497John McCall 256f85e193739c953358c865005855253af4f68a497John McCall unsigned ShouldCopy : 1; 257f85e193739c953358c865005855253af4f68a497John McCall }; 258f85e193739c953358c865005855253af4f68a497John McCall 25932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl class InitListExprBitfields { 26032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl friend class InitListExpr; 26132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 26232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl unsigned : NumExprBits; 26332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 26432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// Whether this initializer list originally had a GNU array-range 26532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// designator in it. This is a temporary marker used by CodeGen. 26632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl unsigned HadArrayRangeDesignator : 1; 26732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 26832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// Whether this initializer list initializes a std::initializer_list 26932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl /// object. 27032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl unsigned InitializesStdInitializerList : 1; 27132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl }; 27232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 2734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor class TypeTraitExprBitfields { 2744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class TypeTraitExpr; 2754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtReader; 2764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtWriter; 2774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned : NumExprBits; 2794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The kind of type trait, which is a value of a TypeTrait enumerator. 2814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned Kind : 8; 2824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief If this expression is not value-dependent, this indicates whether 2844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// the trait evaluated true or false. 2854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned Value : 1; 2864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The number of arguments to this type trait. 2884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned NumArgs : 32 - 8 - 1 - NumExprBits; 2894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor }; 2904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2918e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall union { 29263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // FIXME: this is wasteful on 64-bit platforms. 29363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall void *Aligner; 29463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 2958e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBitfields StmtBits; 2968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBitfields CompoundStmtBits; 2978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBitfields ExprBits; 298bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer CharacterLiteralBitfields CharacterLiteralBits; 299bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer FloatingLiteralBitfields FloatingLiteralBits; 300bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits; 301cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBitfields DeclRefExprBits; 3028e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBitfields CastExprBits; 303cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBitfields CallExprBits; 30480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanupsBitfields ExprWithCleanupsBits; 3054b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBitfields PseudoObjectExprBits; 306f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits; 30732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl InitListExprBitfields InitListExprBits; 3084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTraitExprBitfields TypeTraitExprBits; 3098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall }; 3108e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 311d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor friend class ASTStmtReader; 3124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtWriter; 313d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 3148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekpublic: 3158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek // Only allow allocation of Stmts using the allocator in ASTContext 3161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // or by doing a placement new. 3178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext& C, 3182fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer unsigned alignment = 8) throw(); 3191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3208189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, ASTContext* C, 3212fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer unsigned alignment = 8) throw(); 3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3238189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void* operator new(size_t bytes, void* mem) throw() { 3248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return mem; 3258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 326e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 327fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext&, unsigned) throw() { } 328fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, ASTContext*, unsigned) throw() { } 329e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor void operator delete(void*, std::size_t) throw() { } 330fb523e16dd1f860ff02a3ae03e5e3e25327a5860Chris Lattner void operator delete(void*, void*) throw() { } 331e2dedf8f61b8f306f704781456b482eb61871e8eDouglas Gregor 332025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorpublic: 333025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief A placeholder type used to construct an empty shell of a 334025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// type, that will be filled in later (e.g., by some 335025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// de-serialization). 336025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor struct EmptyShell { }; 337025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 33802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbarprivate: 33902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar /// \brief Whether statistic collection is enabled. 34002892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static bool StatisticsEnabled; 34102892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar 3429c1863ef36a74e8203f00289d19856ad956f48b9Ted Kremenekprotected: 343025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Construct an empty statement. 3448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall explicit Stmt(StmtClass SC, EmptyShell) { 3458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 34602892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) Stmt::addStmtClass(SC); 347025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor } 348025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3508e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt(StmtClass SC) { 3518e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall StmtBits.sClass = SC; 35202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) Stmt::addStmtClass(SC); 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 355ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie StmtClass getStmtClass() const { 3568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall return static_cast<StmtClass>(StmtBits.sClass); 357b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor } 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStmtClassName() const; 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 360b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// SourceLocation tokens are not useful in isolation - they are low level 361b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// value objects created/interpreted by SourceManager. We assume AST 362b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff /// clients will have a pointer to the respective SourceManager. 363aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 364aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY; 365aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY; 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // global temp stats (until we have a per-module visitor) 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void addStmtClass(const StmtClass s); 36902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static void EnableStatistics(); 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void PrintStats(); 3716000dace22f110d8768476989313e9d981d690d0Chris Lattner 37295f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko /// \brief Dumps the specified AST fragment and all subtrees to 37395f6190acb664b345b1395abaea84ee451740c5bDmitri Gribenko /// \c llvm::errs(). 374f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis LLVM_ATTRIBUTE_USED void dump() const; 375f775c7b0575446920d03366abd1f5b5188a7eadeArgyrios Kyrtzidis LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const; 3768cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void dump(raw_ostream &OS, SourceManager &SM) const; 3776000dace22f110d8768476989313e9d981d690d0Chris Lattner 3787ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu /// dumpColor - same as dump(), but forces color highlighting. 3797ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu LLVM_ATTRIBUTE_USED void dumpColor() const; 3807ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu 3816000dace22f110d8768476989313e9d981d690d0Chris Lattner /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST 3826000dace22f110d8768476989313e9d981d690d0Chris Lattner /// back to its original source language syntax. 383d1420c6fa788669e49f21e184927c7833881e399Richard Smith void dumpPretty(ASTContext &Context) const; 3848cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void printPretty(raw_ostream &OS, PrinterHelper *Helper, 385e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy, 386d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned Indentation = 0) const; 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only 389d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek /// works on systems with GraphViz (Mac OS X) or dot+gv installed. 390d2a4a1af1088fca80e2dc76eb3369db0fbbfdefdTed Kremenek void viewAST() const; 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3927e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// Skip past any implicit AST nodes which might surround this 3937e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes. 3947e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall Stmt *IgnoreImplicit(); 3957e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 396a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth const Stmt *stripLabelLikeStatements() const; 397a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth Stmt *stripLabelLikeStatements() { 398a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth return const_cast<Stmt*>( 399a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth const_cast<const Stmt*>(this)->stripLabelLikeStatements()); 400a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth } 401a1364be341550d71dff27dd8de0c6872ba6c707eChandler Carruth 402d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// hasImplicitControlFlow - Some statements (e.g. short circuited operations) 403d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// contain implicit control-flow in the order their subexpressions 404d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// are evaluated. This predicate returns true if this statement has 405d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// such implicit control-flow. Such statements are also specially handled 406d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek /// within CFGs. 407d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek bool hasImplicitControlFlow() const; 408d48ade633d96b94cb435d73e2c935ea457152decTed Kremenek 40963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// Child Iterators: All subclasses must implement 'children' 41063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// to permit easy iteration over the substatements/subexpessions of an 41163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// AST node. This permits easy iteration over all nodes in the AST. 4129caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef StmtIterator child_iterator; 4139caf8b1ca6beb254f420dada3c0e94d5ef027f58Ted Kremenek typedef ConstStmtIterator const_child_iterator; 4141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef StmtRange child_range; 41663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall typedef ConstStmtRange const_child_range; 4171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 41963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_range children() const { 42063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return const_cast<Stmt*>(this)->children(); 42177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 4221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_begin() { return children().first; } 42463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator child_end() { return children().second; } 42563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 42663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_begin() const { return children().first; } 42763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall const_child_iterator child_end() const { return children().second; } 42841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor 42941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// \brief Produce a unique representation of the given statement. 43041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 43170517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko /// \param ID once the profiling operation is complete, will contain 43241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// the unique representation of the given statement. 43341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 43470517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko /// \param Context the AST context in which the statement resides 43541ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// 43670517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko /// \param Canonical whether the profile should be based on the canonical 43741ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// representation of this statement (e.g., where non-type template 4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// parameters are identified by index/level rather than their 43941ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// declaration pointers) or the exact representation of the statement as 44041ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor /// written in the source. 4414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 442b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth bool Canonical) const; 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclStmt - Adaptor class for mixing declarations with statements and 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions. For example, CompoundStmt mixes statements, expressions 4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// and declarations (variables, types). Another example is ForStmt, where 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the first statement can be an expression or a declaration. 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclStmt : public Stmt { 4519653db7bd0e3665b955a0445859285f2e1e7dacdDouglas Gregor DeclGroupRef DG; 45281c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation StartLoc, EndLoc; 4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 4568ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg), 4578ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek StartLoc(startLoc), EndLoc(endLoc) {} 4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 45984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor /// \brief Build an empty declaration statement. 46084f2170062014d268951902164bed0d8bdea0e82Douglas Gregor explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { } 46184f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 4627e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner /// isSingleDecl - This method returns true if this DeclStmt refers 463fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner /// to a single Decl. 4647e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner bool isSingleDecl() const { 465fe95deaf66e4fbd82d44b5f6afa8162fa69cb85cChris Lattner return DG.isSingleDecl(); 4668ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek } 4671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4687e24e82a70a2c681f4291a3397bcd1e1005f251aChris Lattner const Decl *getSingleDecl() const { return DG.getSingleDecl(); } 4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl *getSingleDecl() { return DG.getSingleDecl(); } 4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 471e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner const DeclGroupRef getDeclGroup() const { return DG; } 472e66a8cf9117e5fb95a05ff76ec06615e63dd5adeChris Lattner DeclGroupRef getDeclGroup() { return DG; } 47384f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setDeclGroup(DeclGroupRef DGR) { DG = DGR; } 474b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 47581c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getStartLoc() const { return StartLoc; } 47684f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setStartLoc(SourceLocation L) { StartLoc = L; } 47781c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceLocation getEndLoc() const { return EndLoc; } 47884f2170062014d268951902164bed0d8bdea0e82Douglas Gregor void setEndLoc(SourceLocation L) { EndLoc = L; } 47984f2170062014d268951902164bed0d8bdea0e82Douglas Gregor 48065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; } 48165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; } 4821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DeclStmtClass; 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48714f8b4ff660bcaa763974b8d0fae81857c594495Ted Kremenek // Iterators over subexpressions. 48863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 48963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(DG.begin(), DG.end()), 49063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_iterator(DG.end(), DG.end())); 49163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4930632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::iterator decl_iterator; 4940632dd6fe068011af5710c0d6a745724021ff620Chris Lattner typedef DeclGroupRef::const_iterator const_decl_iterator; 4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4968ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_begin() { return DG.begin(); } 4978ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek decl_iterator decl_end() { return DG.end(); } 4988ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_begin() const { return DG.begin(); } 4998ffb159441e923322bef6b5dee1aaf24c738d75eTed Kremenek const_decl_iterator decl_end() const { return DG.end(); } 500fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose 501fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator; 502fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose reverse_decl_iterator decl_rbegin() { 503fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose return reverse_decl_iterator(decl_end()); 504fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose } 505fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose reverse_decl_iterator decl_rend() { 506fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose return reverse_decl_iterator(decl_begin()); 507fd8b43596478b779b6777cb3a595e69d7856c378Jordan Rose } 5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// NullStmt - This is the null statement ";": C99 6.8.3p3. 5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass NullStmt : public Stmt { 5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation SemiLoc; 51444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 515e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis /// \brief True if the null statement was preceded by an empty macro, e.g: 51644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @code 51744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// #define CALL(x) 51844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// CALL(0); 51944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis /// @endcode 520e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis bool HasLeadingEmptyMacro; 5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 522e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false) 523e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis : Stmt(NullStmtClass), SemiLoc(L), 524e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis HasLeadingEmptyMacro(hasLeadingEmptyMacro) {} 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 526025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty null statement. 527e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty), 528e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis HasLeadingEmptyMacro(false) { } 529025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getSemiLoc() const { return SemiLoc; } 531025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSemiLoc(SourceLocation L) { SemiLoc = L; } 532b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 533e2ca828119b8bff4a5c25c6db8ee4fec558451e7Argyrios Kyrtzidis bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; } 53444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 53565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; } 53665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; } 5371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == NullStmtClass; 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 54344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis 54444aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtReader; 54544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis friend class ASTStmtWriter; 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundStmt - This represents a group of statements like { stmt stmt }. 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundStmt : public Stmt { 5518189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek Stmt** Body; 552b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation LBracLoc, RBracLoc; 5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 554d36aa359e2f45cd22c7366a015ad94de08044dbbNico Weber CompoundStmt(ASTContext &C, ArrayRef<Stmt*> Stmts, 5553a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer SourceLocation LB, SourceLocation RB); 5563a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer 5573a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer // \brief Build an empty compound statment with a location. 5583a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer explicit CompoundStmt(SourceLocation Loc) 5593a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) { 5603a2d0fb726aca3096b5c1ea9be734417060f34d7Benjamin Kramer CompoundStmtBits.NumStmts = 0; 5611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 562025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 563025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor // \brief Build an empty compound statement. 564025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit CompoundStmt(EmptyShell Empty) 5658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Stmt(CompoundStmtClass, Empty), Body(0) { 5668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CompoundStmtBits.NumStmts = 0; 5678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 568025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 569025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts); 5701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } 5728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned size() const { return CompoundStmtBits.NumStmts; } 573025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 5748189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt** body_iterator; 5758189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek body_iterator body_begin() { return Body; } 5768e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall body_iterator body_end() { return Body + size(); } 5778e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; } 578ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setLastStmt(Stmt *S) { 5808e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall assert(!body_empty() && "setLastStmt"); 5818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Body[size()-1] = S; 5828e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5848189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef Stmt* const * const_body_iterator; 5858189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_body_iterator body_begin() const { return Body; } 5868e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const_body_iterator body_end() const { return Body + size(); } 5878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; } 5888189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek 5898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<body_iterator> reverse_body_iterator; 5908189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rbegin() { 5918189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_end()); 5928189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 5938189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek reverse_body_iterator body_rend() { 5948189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return reverse_body_iterator(body_begin()); 5958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 5964ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 5978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek typedef std::reverse_iterator<const_body_iterator> 5988189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator; 5994ce854736dd196e2304f554ebeac8b43c89cf9e2Ted Kremenek 6008189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rbegin() const { 6018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_end()); 6028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek const_reverse_body_iterator body_rend() const { 6058189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek return const_reverse_body_iterator(body_begin()); 6068189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 6071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; } 60965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; } 6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 611cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getLBracLoc() const { return LBracLoc; } 612025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setLBracLoc(SourceLocation L) { LBracLoc = L; } 613cc326204dd97771c336b9aab3b9963ea30d69c29Ted Kremenek SourceLocation getRBracLoc() const { return RBracLoc; } 614025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setRBracLoc(SourceLocation L) { RBracLoc = L; } 6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundStmtClass; 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6208297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 62163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 62263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 62363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6258ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek const_child_range children() const { 6268ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 6278ed557991fe8d51eb27e6c439030ec6ef93a2b8fTed Kremenek } 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 630c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson// SwitchCase is the base class for CaseStmt and DefaultStmt, 631c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass SwitchCase : public Stmt { 632103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenekprotected: 633c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // A pointer to the following CaseStmt or DefaultStmt class, 634c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // used by SwitchStmt. 635c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *NextSwitchCase; 63681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation KeywordLoc; 63781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation ColonLoc; 63881cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis 63981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc) 64081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {} 641103fc81f12aa635aa0a573c94b1aceb496b4e587Ted Kremenek 64281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SwitchCase(StmtClass SC, EmptyShell) 64381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : 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 65281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getKeywordLoc() const { return KeywordLoc; } 65381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setKeywordLoc(SourceLocation L) { KeywordLoc = L; } 65481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getColonLoc() const { return ColonLoc; } 65581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setColonLoc(SourceLocation L) { ColonLoc = L; } 65681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis 65763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt *getSubStmt(); 658702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner const Stmt *getSubStmt() const { 659702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner return const_cast<SwitchCase*>(this)->getSubStmt(); 660702e5474f570d0b83db9f354619b8ac5bc8ed743Chris Lattner } 661b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 66281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } 66381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocEnd() const LLVM_READONLY; 6641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass || 66763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall T->getStmtClass() == DefaultStmtClass; 668c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 669c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson}; 670c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 671c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass CaseStmt : public SwitchCase { 6720a9beb52baa6c990d45d638a177d9456e650282aDouglas Gregor enum { LHS, RHS, SUBSTMT, END_EXPR }; 6731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 674d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // GNU "case 1 ... 4" extension 675dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation EllipsisLoc; 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 677dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, 6781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation ellipsisLoc, SourceLocation colonLoc) 67981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : SwitchCase(CaseStmtClass, caseLoc, colonLoc) { 68024e1e707b4c362f18e371e2bbf054a8345b57bfaChris Lattner SubExprs[SUBSTMT] = 0; 681d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 682d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 683dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor EllipsisLoc = ellipsisLoc; 684d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek } 685025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 686025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty switch case statement. 68781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { } 688025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 68981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getCaseLoc() const { return KeywordLoc; } 69081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setCaseLoc(SourceLocation L) { KeywordLoc = L; } 691dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 692dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } 693dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 694dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 695025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 696d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 697d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 698d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 699025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getLHS() const { 7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[LHS]); 70251b09f2c528c8460b5465c676173324e44176d62Devang Patel } 7031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getRHS() const { 7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return reinterpret_cast<const Expr*>(SubExprs[RHS]); 70551b09f2c528c8460b5465c676173324e44176d62Devang Patel } 70651b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 70820dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; } 70920dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } 71020dabe8b8ff7ed6d2d0158fee43755a4bc7642c3Chris Lattner void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } 7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } 71365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 7143fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner // Handle deeply nested case statements with iteration instead of recursion. 7153fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner const CaseStmt *CS = this; 71691ee0140ecb60b5c1402edc9e577257636c4ca60Chris Lattner while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) 7173fb94a4918bd427fdb12df997dd87fd1017f0388Chris Lattner CS = CS2; 7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return CS->getSubStmt()->getLocEnd(); 720b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 72165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 7221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CaseStmtClass; 7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 726d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 72763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 72863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[END_EXPR]); 72963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 732c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlssonclass DefaultStmt : public SwitchCase { 733d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt* SubStmt; 7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : 73681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {} 737025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 738025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty default statement. 73981cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis explicit DefaultStmt(EmptyShell Empty) 74081cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis : SwitchCase(DefaultStmtClass, Empty) { } 741025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 742d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek Stmt *getSubStmt() { return SubStmt; } 74351b09f2c528c8460b5465c676173324e44176d62Devang Patel const Stmt *getSubStmt() const { return SubStmt; } 744025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSubStmt(Stmt *S) { SubStmt = S; } 745025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 74681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getDefaultLoc() const { return KeywordLoc; } 74781cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis void setDefaultLoc(SourceLocation L) { KeywordLoc = L; } 748dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 749dbb26db1d426fb6caaaf1b4fa47b46d1947c12c9Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 75181cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } 75265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} 75365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DefaultStmtClass; 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 758d97bb6c1384cb773ba5cdbd198008dec127cebadTed Kremenek // Iterators 75963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 76281cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidisinline SourceLocation SwitchCase::getLocEnd() const { 76381cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis if (const CaseStmt *CS = dyn_cast<CaseStmt>(this)) 76481cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis return CS->getLocEnd(); 76581cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis return cast<DefaultStmt>(this)->getLocEnd(); 76681cc2f1ecd31d8e3bca2c936fb9538a9d9c39695Argyrios Kyrtzidis} 767ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 768ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// LabelStmt - Represents a label, which has a substatement. For example: 769ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// foo: return; 770ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner/// 7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LabelStmt : public Stmt { 772ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *TheDecl; 7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *SubStmt; 774b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IdentLoc; 7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 776ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt) 777ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) { 7788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 7791de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 7801de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor // \brief Build an empty label statement. 7811de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { } 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getIdentLoc() const { return IdentLoc; } 784ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getDecl() const { return TheDecl; } 785ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setDecl(LabelDecl *D) { TheDecl = D; } 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Stmt *getSubStmt() { return SubStmt; } 7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Stmt *getSubStmt() const { return SubStmt; } 7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setIdentLoc(SourceLocation L) { IdentLoc = L; } 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setSubStmt(Stmt *SS) { SubStmt = SS; } 791b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 79265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; } 79365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} 79465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 79563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 79663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 7971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == LabelStmtClass; 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 803534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// \brief Represents an attribute applied to a statement. 804534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// 805534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// Represents an attribute applied to a statement. For example: 806534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// [[omp::for(...)]] for (...) { ... } 807534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith/// 808534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithclass AttributedStmt : public Stmt { 809534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *SubStmt; 810534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation AttrLoc; 8114990890fc9428f98bef90ba349203a648c592778Alexander Kornienko unsigned NumAttrs; 8124990890fc9428f98bef90ba349203a648c592778Alexander Kornienko const Attr *Attrs[1]; 813534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 814534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith friend class ASTStmtReader; 815534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8164990890fc9428f98bef90ba349203a648c592778Alexander Kornienko AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt) 8174990890fc9428f98bef90ba349203a648c592778Alexander Kornienko : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc), 8184990890fc9428f98bef90ba349203a648c592778Alexander Kornienko NumAttrs(Attrs.size()) { 8194990890fc9428f98bef90ba349203a648c592778Alexander Kornienko memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*)); 820534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 821534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8224990890fc9428f98bef90ba349203a648c592778Alexander Kornienko explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) 8234990890fc9428f98bef90ba349203a648c592778Alexander Kornienko : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) { 8244990890fc9428f98bef90ba349203a648c592778Alexander Kornienko memset(Attrs, 0, NumAttrs * sizeof(Attr*)); 825534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 826534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8274990890fc9428f98bef90ba349203a648c592778Alexander Kornienkopublic: 8284990890fc9428f98bef90ba349203a648c592778Alexander Kornienko static AttributedStmt *Create(ASTContext &C, SourceLocation Loc, 8294990890fc9428f98bef90ba349203a648c592778Alexander Kornienko ArrayRef<const Attr*> Attrs, Stmt *SubStmt); 8304990890fc9428f98bef90ba349203a648c592778Alexander Kornienko // \brief Build an empty attributed statement. 8314990890fc9428f98bef90ba349203a648c592778Alexander Kornienko static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs); 8324990890fc9428f98bef90ba349203a648c592778Alexander Kornienko 833534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation getAttrLoc() const { return AttrLoc; } 8344990890fc9428f98bef90ba349203a648c592778Alexander Kornienko ArrayRef<const Attr*> getAttrs() const { 8354990890fc9428f98bef90ba349203a648c592778Alexander Kornienko return ArrayRef<const Attr*>(Attrs, NumAttrs); 8364990890fc9428f98bef90ba349203a648c592778Alexander Kornienko } 837534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *getSubStmt() { return SubStmt; } 838534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith const Stmt *getSubStmt() const { return SubStmt; } 839534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 84065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; } 84165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} 84265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 843534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith child_range children() { return child_range(&SubStmt, &SubStmt + 1); } 844534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 845534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith static bool classof(const Stmt *T) { 846534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return T->getStmtClass() == AttributedStmtClass; 847534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 848534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith}; 849534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 850534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IfStmt - This represents an if/then/else. 8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IfStmt : public Stmt { 85443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, THEN, ELSE, END_EXPR }; 8558297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 8568cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor 857b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation IfLoc; 858d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation ElseLoc; 859ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 861ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, 86244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0); 863ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 864025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty if/then/else statement 865025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { } 866025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 8678cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \brief Retrieve the variable declared in this "if" statement, if any. 8688cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// 8698cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// In the following example, "x" is the condition variable. 8708cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \code 8718cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// if (int x = foo()) { 8728cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// printf("x is %d", x); 8738cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// } 8748cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor /// \endcode 87543dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 87643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 877ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 878d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this IfStmt has a condition variable, return the faux DeclStmt 879d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 880d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 881d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 882d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 883ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 885025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 8868297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getThen() const { return SubExprs[THEN]; } 8871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setThen(Stmt *S) { SubExprs[THEN] = S; } 8888297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getElse() const { return SubExprs[ELSE]; } 889025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setElse(Stmt *S) { SubExprs[ELSE] = S; } 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8918297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 8928297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getThen() { return SubExprs[THEN]; } 8938297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getElse() { return SubExprs[ELSE]; } 894b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 895025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getIfLoc() const { return IfLoc; } 896025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setIfLoc(SourceLocation L) { IfLoc = L; } 897d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor SourceLocation getElseLoc() const { return ElseLoc; } 898d06f6ca61062f85926eb9d409eb3d4f8afcf93c7Douglas Gregor void setElseLoc(SourceLocation L) { ElseLoc = L; } 899025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 90065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; } 90165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 902b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff if (SubExprs[ELSE]) 90365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[ELSE]->getLocEnd(); 904b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff else 90565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[THEN]->getLocEnd(); 906b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 90863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators over subexpressions. The iterators will include iterating 90963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // over the initialization expression referenced by the condition variable. 91063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 91163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 91263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 91363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IfStmtClass; 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SwitchStmt - This represents a 'switch' stmt. 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SwitchStmt : public Stmt { 92243dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 9231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 924c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson // This points to a linked list of case and default statements. 925c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *FirstCase; 9269dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SourceLocation SwitchLoc; 9271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 928559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// If the SwitchStmt is a switch on an enum value, this records whether 929559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// all the enum values were covered by CaseStmts. This value is meant to 930559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// be a hint for possible clients. 931559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek unsigned AllEnumCasesCovered : 1; 932559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 93443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond); 9351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 936025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build a empty switch statement. 937025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { } 938025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 939d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \brief Retrieve the variable declared in this "switch" statement, if any. 940d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// 941d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// In the following example, "x" is the condition variable. 942d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \code 943d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// switch (int x = foo()) { 944d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// case 0: break; 945d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// // ... 946d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// } 947d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor /// \endcode 94843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 94943dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 950ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 951d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this SwitchStmt has a condition variable, return the faux DeclStmt 952d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 953d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 954d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 955d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 956d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor 9578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 9588297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 959c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson const SwitchCase *getSwitchCaseList() const { return FirstCase; } 960c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 9618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 962025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 9638297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 964025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 965c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson SwitchCase *getSwitchCaseList() { return FirstCase; } 9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Set the case list for this switch statement. 96843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// 96943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// The caller is responsible for incrementing the retain counts on 97043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// all of the SwitchCase statements in this list. 971025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } 972025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 973025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getSwitchLoc() const { return SwitchLoc; } 974025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setSwitchLoc(SourceLocation L) { SwitchLoc = L; } 975c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setBody(Stmt *S, SourceLocation SL) { 9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SubExprs[BODY] = S; 9789dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff SwitchLoc = SL; 9791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 980c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson void addSwitchCase(SwitchCase *SC) { 981ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(!SC->getNextSwitchCase() 982ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie && "case/default already added to a switch"); 983c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor SC->setNextSwitchCase(FirstCase); 984c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson FirstCase = SC; 985c1fcb7762673be706b0a40477d5e93411e918f93Anders Carlsson } 986559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 987559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a 988559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// switch over an enum value then all cases have been explicitly covered. 989559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek void setAllEnumCasesCovered() { 990559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek AllEnumCasesCovered = 1; 991559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 992559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 993559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// Returns true if the SwitchStmt is a switch of an enum value and all cases 994559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek /// have been explicitly covered. 995559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek bool isAllEnumCasesCovered() const { 996559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek return (bool) AllEnumCasesCovered; 997559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek } 998559fb554602bedb57dbbf3cc14ac8a38264b4547Ted Kremenek 99965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; } 100065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 100165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BODY]->getLocEnd(); 10029dcbfa450d751bd68fc4af8b75da381d4f6984b9Steve Naroff } 100365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 100463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // Iterators 100563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 100663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 100763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 100863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SwitchStmtClass; 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// WhileStmt - This represents a 'while' stmt. 10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass WhileStmt : public Stmt { 101843dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { VAR, COND, BODY, END_EXPR }; 10198297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 1020b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation WhileLoc; 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1022ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 102343dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor SourceLocation WL); 10241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1025d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor /// \brief Build an empty while statement. 1026d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { } 1027d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 10285656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Retrieve the variable declared in this "while" statement, if any. 10295656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// 10305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// In the following example, "x" is the condition variable. 10315656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \code 10325656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// while (int x = random()) { 10335656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// // ... 10345656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// } 10355656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \endcode 103643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 103743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 10385656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 1039d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this WhileStmt has a condition variable, return the faux DeclStmt 1040d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 1041d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 1042d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 1043d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 1044d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 10458297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 10468297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 1047d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 10488297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 10498297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 1050d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 1051d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor 1052d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 1053d921cf976b4769af8d06d6763a2547dadf7940abDouglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1054b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 105565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; } 105665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 105765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BODY]->getLocEnd(); 1058b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 105965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 10601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == WhileStmtClass; 10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10648297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 106563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 106663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 106763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DoStmt - This represents a 'do/while' stmt. 10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DoStmt : public Stmt { 1073c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48Douglas Gregor enum { BODY, COND, END_EXPR }; 10748297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; 1075b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation DoLoc; 10769f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation WhileLoc; 1077989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RParenLoc; // Location of final ')' in do stmt condition. 10789f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1080989135901c750af61ef012b6b0a0368be415bc46Chris Lattner DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL, 1081989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation RP) 1082989135901c750af61ef012b6b0a0368be415bc46Chris Lattner : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) { 10838297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 10848297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek SubExprs[BODY] = body; 10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 108667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 108767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty do-while statement. 108867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { } 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10908297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 10918297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 109267d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 10938297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 10941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Stmt *getBody() const { return SubExprs[BODY]; } 109567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 109667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 109767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getDoLoc() const { return DoLoc; } 109867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setDoLoc(SourceLocation L) { DoLoc = L; } 10999f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor SourceLocation getWhileLoc() const { return WhileLoc; } 11009f3ca2a7747bd47f14d7693f333103fac29a24d2Douglas Gregor void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1101b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 1102989135901c750af61ef012b6b0a0368be415bc46Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 1103989135901c750af61ef012b6b0a0368be415bc46Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1104989135901c750af61ef012b6b0a0368be415bc46Chris Lattner 110565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; } 110665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 110765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 11081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DoStmtClass; 11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 11128297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 111363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 111463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 111563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the init/cond/inc parts of the ForStmt will be null if they were not 11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified in the source. 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ForStmt : public Stmt { 112443dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; 11258297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 1126b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff SourceLocation ForLoc; 11275831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation LParenLoc, RParenLoc; 11285831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor 11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1130ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, 113143dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP); 11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113367d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor /// \brief Build an empty for statement. 113467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { } 113567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 11368297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getInit() { return SubExprs[INIT]; } 1137ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 113899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \brief Retrieve the variable declared in this "for" statement, if any. 113999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// 114099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// In the following example, "y" is the condition variable. 114199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \code 114299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// for (int x = random(); int y = mangle(x); ++x) { 114399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// // ... 114499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// } 114599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor /// \endcode 114643dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor VarDecl *getConditionVariable() const; 114743dec6bbde2d0a16c35978983761c8b7030c8e18Douglas Gregor void setConditionVariable(ASTContext &C, VarDecl *V); 1148ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1149d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// If this ForStmt has a condition variable, return the faux DeclStmt 1150d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek /// associated with the creation of that condition variable. 1151d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek const DeclStmt *getConditionVariableDeclStmt() const { 1152d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]); 1153d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek } 1154d40066b0fb883839a9100e5455e33190b9b8abacTed Kremenek 11558297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 11568297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 11578297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek Stmt *getBody() { return SubExprs[BODY]; } 11588297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek 11598297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getInit() const { return SubExprs[INIT]; } 11608297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 11618297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 11628297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek const Stmt *getBody() const { return SubExprs[BODY]; } 1163b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 116467d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInit(Stmt *S) { SubExprs[INIT] = S; } 116567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 116667d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } 116767d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setBody(Stmt *S) { SubExprs[BODY] = S; } 116867d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 116967d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor SourceLocation getForLoc() const { return ForLoc; } 117067d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor void setForLoc(SourceLocation L) { ForLoc = L; } 11715831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 11725831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 11735831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 11745831c6a1efc47e6a19d82fe3dd25b5b8fef6979dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 117567d8249924ef38a5375ff9c92cd21c1854d6ababDouglas Gregor 117665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; } 117765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 117865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BODY]->getLocEnd(); 1179b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff } 118065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ForStmtClass; 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11858297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 118663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 118763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 118863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GotoStmt - This represents a direct goto. 11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass GotoStmt : public Stmt { 1194ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 1195507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation GotoLoc; 119661f62165220e75694fe333179c78815e2e48d71fTed Kremenek SourceLocation LabelLoc; 11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1198ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL) 119961f62165220e75694fe333179c78815e2e48d71fTed Kremenek : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12011de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor /// \brief Build an empty goto statement. 12021de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { } 12031de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 1204ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 1205ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *D) { Label = D; } 12061de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor 12071de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getGotoLoc() const { return GotoLoc; } 12081de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setGotoLoc(SourceLocation L) { GotoLoc = L; } 12091de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 12101de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 1211b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 121265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; } 121365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; } 121465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 12151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GotoStmtClass; 12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12198297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 122063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// IndirectGotoStmt - This represents an indirect goto. 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IndirectGotoStmt : public Stmt { 1226ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation GotoLoc; 12275f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation StarLoc; 12281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Target; 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, 12315f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Expr *target) 12325f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc), 12335f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor Target((Stmt*)target) {} 12347d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 12357d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty indirect goto statement. 12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IndirectGotoStmt(EmptyShell Empty) 12377d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Stmt(IndirectGotoStmtClass, Empty) { } 12381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1239ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner void setGotoLoc(SourceLocation L) { GotoLoc = L; } 1240ad56d684259f706b7c0ae5ad9c23adb4f2926817Chris Lattner SourceLocation getGotoLoc() const { return GotoLoc; } 12415f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor void setStarLoc(SourceLocation L) { StarLoc = L; } 12425f1b9e689fa5c101512aef99225f2afea1673449Douglas Gregor SourceLocation getStarLoc() const { return StarLoc; } 12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 124495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall Expr *getTarget() { return reinterpret_cast<Expr*>(Target); } 124595c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);} 12467d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); } 1247b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 124895c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// getConstantTarget - Returns the fixed target of this indirect 124995c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall /// goto, if one exists. 1250ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getConstantTarget(); 1251ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner const LabelDecl *getConstantTarget() const { 125295c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall return const_cast<IndirectGotoStmt*>(this)->getConstantTarget(); 125395c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall } 125495c225de9fa3d79f70ef5008c0279580a7d9dcadJohn McCall 125565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; } 125665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); } 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IndirectGotoStmtClass; 12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 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 128065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; } 128165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; } 1282861ce3178c70cfb0fa50baf685e1ad363538eaa9Douglas Gregor 12831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ContinueStmtClass; 12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12878297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 128863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BreakStmt - This represents a break. 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BreakStmt : public Stmt { 1294507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation BreakLoc; 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1296507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1298025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor /// \brief Build an empty break statement. 1299025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { } 1300025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 1301025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor SourceLocation getBreakLoc() const { return BreakLoc; } 1302025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor void setBreakLoc(SourceLocation L) { BreakLoc = L; } 1303025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor 130465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; } 130565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; } 1306b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 13071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BreakStmtClass; 13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13118297777fbe19c4d39e8a70c55346474868055fa1Ted Kremenek // Iterators 131263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1316c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// ReturnStmt - This represents a return, optionally of an expression: 1317c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return; 1318c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return 4; 1319c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// 1320c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// Note that GCC allows return with no argument in a function declared to 1321c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return a value, and it allows returning a value in functions declared to 1322c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// return void. We explicitly model this in the AST, which means you can't 1323c8edf6bd5f76bf50411d037c83d36847edfa68f0Chris Lattner/// depend on the return type of the function and the presence of an argument. 13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReturnStmt : public Stmt { 13261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *RetExpr; 1327507f2d5811bd7da1a4d9d2f4960f32177dfab9deSteve Naroff SourceLocation RetLoc; 13285077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *NRVOCandidate; 1329ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13315077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL) 133225a0fe2a99aaf2d1bf5bdfdae7ab11e2a5e7622fAbramo Bagnara : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { } 13335077c3876beeaed32280af88244e8050078619a8Douglas Gregor 13345077c3876beeaed32280af88244e8050078619a8Douglas Gregor ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) 13355077c3876beeaed32280af88244e8050078619a8Douglas Gregor : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL), 13365077c3876beeaed32280af88244e8050078619a8Douglas Gregor NRVOCandidate(NRVOCandidate) {} 13370de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13380de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor /// \brief Build an empty return expression. 13390de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { } 13400de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getRetValue() const; 13421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getRetValue(); 13430de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); } 13440de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor 13450de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor SourceLocation getReturnLoc() const { return RetLoc; } 13460de9d8857b715c2f45c987651f4ce06d73330d93Douglas Gregor void setReturnLoc(SourceLocation L) { RetLoc = L; } 1347b5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09Steve Naroff 13485077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// \brief Retrieve the variable that might be used for the named return 13495077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// value optimization. 13505077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// 13515077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// The optimization itself can only be performed if the variable is 13525077c3876beeaed32280af88244e8050078619a8Douglas Gregor /// also marked as an NRVO object. 13535077c3876beeaed32280af88244e8050078619a8Douglas Gregor const VarDecl *getNRVOCandidate() const { return NRVOCandidate; } 13545077c3876beeaed32280af88244e8050078619a8Douglas Gregor void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; } 1355ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 135665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; } 135765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 135865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return RetExpr ? RetExpr->getLocEnd() : RetLoc; 135965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 13601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ReturnStmtClass; 13635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 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 1372728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt. 1373728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier/// 1374728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass AsmStmt : public Stmt { 1375728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierprotected: 1376066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier SourceLocation AsmLoc; 137712b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// \brief True if the assembly statement does not have any input or output 137812b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// operands. 1379728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool IsSimple; 138012b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier 138112b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// \brief If true, treat this inline assembly as having side effects. 138212b95e523c193bac4bdde0b23f2a9777ca956145Chad Rosier /// This assembly statement should not be optimized, deleted or moved. 1383728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool IsVolatile; 1384728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1385066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned NumOutputs; 1386066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned NumInputs; 1387066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned NumClobbers; 1388066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1389066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier IdentifierInfo **Names; 139019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier Stmt **Exprs; 1391066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1392066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile, 1393066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned numoutputs, unsigned numinputs, unsigned numclobbers) : 1394066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile), 1395066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { } 1396728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1397728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierpublic: 1398728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier /// \brief Build an empty inline-assembly statement. 1399728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier explicit AsmStmt(StmtClass SC, EmptyShell Empty) : 140019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier Stmt(SC, Empty), Names(0), Exprs(0) { } 140129760b452876548f59804e8c02c3276bc7281d5dMatt Beaumont-Gay 1402066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier SourceLocation getAsmLoc() const { return AsmLoc; } 1403066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier void setAsmLoc(SourceLocation L) { AsmLoc = L; } 1404728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1405728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool isSimple() const { return IsSimple; } 1406728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier void setSimple(bool V) { IsSimple = V; } 1407728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1408728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier bool isVolatile() const { return IsVolatile; } 1409728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier void setVolatile(bool V) { IsVolatile = V; } 1410728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 141165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } 141265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } 1413728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 1414da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier //===--- Asm String Analysis ---===// 1415da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier 1416da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier /// Assemble final IR asm string. 1417aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier std::string generateAsmString(ASTContext &C) const; 1418da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier 1419066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier //===--- Output operands ---===// 1420066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1421066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned getNumOutputs() const { return NumOutputs; } 1422066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1423066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier IdentifierInfo *getOutputIdentifier(unsigned i) const { 1424066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier return Names[i]; 1425066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier } 1426066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1427066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier StringRef getOutputName(unsigned i) const { 1428066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier if (IdentifierInfo *II = getOutputIdentifier(i)) 1429066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier return II->getName(); 1430066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1431066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier return StringRef(); 1432066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier } 1433066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1434c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// getOutputConstraint - Return the constraint string for the specified 1435c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// output operand. All output constraints are known to be non-empty (either 1436c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// '=' or '+'). 1437aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier StringRef getOutputConstraint(unsigned i) const; 1438c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1439c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// isOutputPlusConstraint - Return true if the specified output constraint 1440c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// is a "+" constraint (which is both an input and an output) or false if it 1441c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// is an "=" constraint (just an output). 1442c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier bool isOutputPlusConstraint(unsigned i) const { 1443c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier return getOutputConstraint(i)[0] == '+'; 1444c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier } 1445c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1446aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier const Expr *getOutputExpr(unsigned i) const; 1447c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1448c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// getNumPlusOperands - Return the number of output operands that have a "+" 1449c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// constraint. 1450c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier unsigned getNumPlusOperands() const; 1451c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1452066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier //===--- Input operands ---===// 1453066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1454066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier unsigned getNumInputs() const { return NumInputs; } 1455066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1456066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier IdentifierInfo *getInputIdentifier(unsigned i) const { 1457066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier return Names[i + NumOutputs]; 1458066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier } 1459066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1460066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier StringRef getInputName(unsigned i) const { 1461066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier if (IdentifierInfo *II = getInputIdentifier(i)) 1462066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier return II->getName(); 1463066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1464066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier return StringRef(); 1465066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier } 1466066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 1467c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// getInputConstraint - Return the specified input constraint. Unlike output 1468c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier /// constraints, these can be empty. 1469aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier StringRef getInputConstraint(unsigned i) const; 1470aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier 1471aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier const Expr *getInputExpr(unsigned i) const; 1472c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1473066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier //===--- Other ---===// 1474066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier 14752fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier unsigned getNumClobbers() const { return NumClobbers; } 1476aba59aafd47ded6d483894cd6ab7bff494eb7587Chad Rosier StringRef getClobber(unsigned i) const; 14772fd559f041d49863a7396d9e330bc9dae95ac8c4Chad Rosier 1478728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier static bool classof(const Stmt *T) { 1479728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier return T->getStmtClass() == GCCAsmStmtClass || 1480728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier T->getStmtClass() == MSAsmStmtClass; 1481728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier } 148219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 148319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier // Input expr iterators. 148419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 148519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ExprIterator inputs_iterator; 148619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ConstExprIterator const_inputs_iterator; 148719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 148819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier inputs_iterator begin_inputs() { 148919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 149019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 149119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 149219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier inputs_iterator end_inputs() { 149319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs + NumInputs; 149419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 149519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 149619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_inputs_iterator begin_inputs() const { 149719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 149819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 149919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 150019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_inputs_iterator end_inputs() const { 150119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs + NumInputs; 150219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 150319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 150419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier // Output expr iterators. 150519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 150619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ExprIterator outputs_iterator; 150719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier typedef ConstExprIterator const_outputs_iterator; 150819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 150919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier outputs_iterator begin_outputs() { 151019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0]; 151119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 151219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier outputs_iterator end_outputs() { 151319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 151419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 151519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 151619c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_outputs_iterator begin_outputs() const { 151719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0]; 151819c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 151919c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier const_outputs_iterator end_outputs() const { 152019c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return &Exprs[0] + NumOutputs; 152119c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 152219c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier 152319c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier child_range children() { 152419c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); 152519c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier } 1526728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier}; 1527728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier 15287d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a GCC inline-assembly statement extension. 1529fe795956194141c91ae555985c9b930595bff43fChris Lattner/// 1530728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass GCCAsmStmt : public AsmStmt { 1531066ef86b435a5c567778c25fc201a2831049ad4bChad Rosier SourceLocation RParenLoc; 15326a0ef4b83c91a6d6d5acb4ed5577c4659fe022a3Anders Carlsson StringLiteral *AsmStr; 1533b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1534966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson // FIXME: If we wanted to, we could allocate all of these in one big array. 1535966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Constraints; 1536966146e89141804ff6492739a2a6e6592ca671c7Anders Carlsson StringLiteral **Clobbers; 1537ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1538fe795956194141c91ae555985c9b930595bff43fChris Lattnerpublic: 1539df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, 1540df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier bool isvolatile, unsigned numoutputs, unsigned numinputs, 1541df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier IdentifierInfo **names, StringLiteral **constraints, Expr **exprs, 1542df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier StringLiteral *asmstr, unsigned numclobbers, 1543df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier StringLiteral **clobbers, SourceLocation rparenloc); 1544b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 1545cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor /// \brief Build an empty inline-assembly statement. 1546728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty), 154719c0134d465a1d9a1edc45ebac51652d8636c68eChad Rosier Constraints(0), Clobbers(0) { } 1548cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1549cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 1550cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1551cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1552458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner //===--- Asm String Analysis ---===// 1553458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1554458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const StringLiteral *getAsmString() const { return AsmStr; } 1555458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner StringLiteral *getAsmString() { return AsmStr; } 1556cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor void setAsmString(StringLiteral *E) { AsmStr = E; } 1557cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1558458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AsmStringPiece - this is part of a decomposed asm string specification 1559458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// (for use with the AnalyzeAsmString function below). An asm string is 1560458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// considered to be a concatenation of these parts. 1561458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner class AsmStringPiece { 1562458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1563458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner enum Kind { 1564458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". 1565458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Operand // Operand reference, with optional modifier %c4. 1566458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 1567458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner private: 1568458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Kind MyKind; 1569458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner std::string Str; 1570458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned OperandNo; 1571458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner public: 1572458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} 1573458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner AsmStringPiece(unsigned OpNo, char Modifier) 1574458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner : MyKind(Operand), Str(), OperandNo(OpNo) { 1575458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner Str += Modifier; 1576458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1578458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isString() const { return MyKind == String; } 1579458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner bool isOperand() const { return MyKind == Operand; } 15801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1581458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner const std::string &getString() const { 1582458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isString()); 1583458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str; 1584458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1585458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner 1586458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner unsigned getOperandNo() const { 1587458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1588458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return OperandNo; 1589458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 15901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1591458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// getModifier - Get the modifier for this operand, if present. This 1592458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// returns '\0' if there was no modifier. 1593458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner char getModifier() const { 1594458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner assert(isOperand()); 1595458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner return Str[0]; 1596458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner } 1597458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner }; 15981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1599458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 1600458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// it into pieces. If the asm string is erroneous, emit errors and return 1601458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// true, otherwise return false. This handles canonicalization and 1602458cd9c8a79b25b87dcea43c9d97a4c59f194799Chris Lattner /// translation of strings from GCC syntax to LLVM IR syntax, and handles 16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump //// flattening of named references like %[foo] to Operand AsmStringPiece's. 1604686775deca8b8685eb90801495880e3abdd844c2Chris Lattner unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces, 1605fb5058ef67c054296c88db18ab1b3717845cb71dChris Lattner ASTContext &C, unsigned &DiagOffs) const; 16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1607da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier /// Assemble final IR asm string. 1608da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier std::string generateAsmString(ASTContext &C) const; 16091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1610b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Output operands ---===// 1611b327793860737d1c103a73aeda8057dd628a101dChris Lattner 1612686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getOutputConstraint(unsigned i) const; 16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1614b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getOutputConstraintLiteral(unsigned i) const { 1615ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i]; 1616ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1617b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getOutputConstraintLiteral(unsigned i) { 1618b327793860737d1c103a73aeda8057dd628a101dChris Lattner return Constraints[i]; 1619b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1621ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getOutputExpr(unsigned i); 16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1623b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getOutputExpr(unsigned i) const { 1624df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i); 1625b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1627b327793860737d1c103a73aeda8057dd628a101dChris Lattner //===--- Input operands ---===// 16281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1629686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getInputConstraint(unsigned i) const; 16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1631b327793860737d1c103a73aeda8057dd628a101dChris Lattner const StringLiteral *getInputConstraintLiteral(unsigned i) const { 1632ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1633ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 1634b327793860737d1c103a73aeda8057dd628a101dChris Lattner StringLiteral *getInputConstraintLiteral(unsigned i) { 1635ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return Constraints[i + NumOutputs]; 1636ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek } 16371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1638ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek Expr *getInputExpr(unsigned i); 1639935f0f01c1ed3c2052b797ac035d57a85b78adc4Chris Lattner void setInputExpr(unsigned i, Expr *E); 1640ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1641b327793860737d1c103a73aeda8057dd628a101dChris Lattner const Expr *getInputExpr(unsigned i) const { 1642df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier return const_cast<GCCAsmStmt*>(this)->getInputExpr(i); 1643b327793860737d1c103a73aeda8057dd628a101dChris Lattner } 1644cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 1645acb6bcb442936f3c14126fdd473307c17647cb84Anders Carlsson void setOutputsAndInputsAndClobbers(ASTContext &C, 1646ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1647fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Constraints, 1648fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson Stmt **Exprs, 1649fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumOutputs, 1650ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie unsigned NumInputs, 1651fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson StringLiteral **Clobbers, 1652fdba9c069023f686e2608affde02c82131ee1cf8Anders Carlsson unsigned NumClobbers); 1653cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 165410ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner //===--- Other ---===// 16551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 165610ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// getNamedOperand - Given a symbolic operand reference like %[foo], 165710ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// translate this into a numeric value needed to reference the same operand. 165810ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner /// This returns -1 if the operand name is invalid. 1659686775deca8b8685eb90801495880e3abdd844c2Chris Lattner int getNamedOperand(StringRef SymbolicName) const; 166010ca96ae9aed6906c3302403ef1a146a8d4c6b74Chris Lattner 166133f0558f75f70061707d1388e305b8f92f4e55deChad Rosier StringRef getClobber(unsigned i) const; 16625c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; } 16635c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier const StringLiteral *getClobberStringLiteral(unsigned i) const { 16645c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier return Clobbers[i]; 16655c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier } 1666cd7d5a9dc558178ed7a66032f888781b3c592e4fDouglas Gregor 166765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; } 166865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1670df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier static bool classof(const Stmt *T) { 1671df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier return T->getStmtClass() == GCCAsmStmtClass; 1672df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier } 1673fe795956194141c91ae555985c9b930595bff43fChris Lattner}; 167478492dae00fb85e0da0f966df4745edafdafb66cTed Kremenek 16757d2c5ca9c3dad400f66aca58eebef321c04cf57eChad Rosier/// This represents a Microsoft inline-assembly statement extension. 16768cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier/// 1677728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosierclass MSAsmStmt : public AsmStmt { 1678c4cca7b2408bdfd99ea0f63fec1421c1327593b2Enea Zaffanella SourceLocation LBraceLoc, EndLoc; 16798cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier std::string AsmStr; 16808cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 168179efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier unsigned NumAsmToks; 168279efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier 168379efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier Token *AsmToks; 168489fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier StringRef *Constraints; 168533c72e1c0bbb477cf36dd7becd933b860c42ed8cChad Rosier StringRef *Clobbers; 16868cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 16878cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosierpublic: 16887bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, 16897bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier bool issimple, bool isvolatile, ArrayRef<Token> asmtoks, 1690e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier unsigned numoutputs, unsigned numinputs, 1691e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier ArrayRef<IdentifierInfo*> names, ArrayRef<StringRef> constraints, 1692e54cba1ec0b0e498ee67d200289035797932e714Chad Rosier ArrayRef<Expr*> exprs, StringRef asmstr, 169389fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier ArrayRef<StringRef> clobbers, SourceLocation endloc); 16948cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1695cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier /// \brief Build an empty MS-style inline-assembly statement. 1696728581e7702cafe32cc9e1b5b61a15f5042ce189Chad Rosier explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty), 169789fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { } 1698cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier 16997bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier SourceLocation getLBraceLoc() const { return LBraceLoc; } 17007bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier void setLBraceLoc(SourceLocation L) { LBraceLoc = L; } 17018cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier SourceLocation getEndLoc() const { return EndLoc; } 17028cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier void setEndLoc(SourceLocation L) { EndLoc = L; } 17038cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 17047bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier bool hasBraces() const { return LBraceLoc.isValid(); } 17057bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier 170679efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier unsigned getNumAsmToks() { return NumAsmToks; } 170779efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier Token *getAsmToks() { return AsmToks; } 17088f726de55412870ef70e788b852c6cc50873e15bChad Rosier 17098cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier //===--- Asm String Analysis ---===// 17108cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 17118cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier const std::string *getAsmString() const { return &AsmStr; } 17128cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier std::string *getAsmString() { return &AsmStr; } 17138cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier void setAsmString(StringRef &E) { AsmStr = E.str(); } 17148cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1715da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier /// Assemble final IR asm string. 1716da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier std::string generateAsmString(ASTContext &C) const; 1717da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9Chad Rosier 17182603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier //===--- Output operands ---===// 17192603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 172089fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier StringRef getOutputConstraint(unsigned i) const { 172189fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier return Constraints[i]; 172289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier } 1723c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1724633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier Expr *getOutputExpr(unsigned i); 1725633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier 17262603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier const Expr *getOutputExpr(unsigned i) const { 17272603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier return const_cast<MSAsmStmt*>(this)->getOutputExpr(i); 17282603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier } 17292603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 17302603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier //===--- Input operands ---===// 17312603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 173289fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier StringRef getInputConstraint(unsigned i) const { 173389fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier return Constraints[i + NumOutputs]; 173489fb6d7eba51c7864ec544e07accd23b24057122Chad Rosier } 1735c4fb221120f2c8b158082d0b2b9daa29d2f65d5bChad Rosier 1736633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier Expr *getInputExpr(unsigned i); 1737633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier void setInputExpr(unsigned i, Expr *E); 1738633abb0ea01d37ab9c8e4ce1ee9e48894a12dfcaChad Rosier 17392603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier const Expr *getInputExpr(unsigned i) const { 17402603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier return const_cast<MSAsmStmt*>(this)->getInputExpr(i); 17412603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier } 17422603fa6c0e0fff904317b525724170ba8ae5bfa8Chad Rosier 17438cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier //===--- Other ---===// 17448cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 17451e059da457ba65062448f24975db386efa0d51f8Chad Rosier StringRef getClobber(unsigned i) const { return Clobbers[i]; } 17464399ea9d473365224d9e4db0cd94aab849eb59b7Chad Rosier 174765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; } 174865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; } 174965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 17508cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier static bool classof(const Stmt *T) { 17518cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return T->getStmtClass() == MSAsmStmtClass; 17528cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 17538cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 17548cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier child_range children() { 17558cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return child_range(&Exprs[0], &Exprs[0]); 17568cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 17578cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier}; 17588cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 175928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHExceptStmt : public Stmt { 176028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 176128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 176228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 176328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { FILTER_EXPR, BLOCK }; 176428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 176528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt(SourceLocation Loc, 176628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 176728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 176828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 17697110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 17707110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 17717110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { } 17727110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 177328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 177428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static SEHExceptStmt* Create(ASTContext &C, 177528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation ExceptLoc, 177628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 177728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 177865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 177965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); } 178065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 178128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 178228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getExceptLoc() const { return Loc; } 178328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); } 178428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr *getFilterExpr() const { 1786ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); 1787ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 1788ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1789ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CompoundStmt *getBlock() const { 1790cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko return cast<CompoundStmt>(Children[BLOCK]); 1791ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 179228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 179328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 179428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 179528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 179628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 179728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 179828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHExceptStmtClass; 179928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 180028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 180128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 180228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 180328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHFinallyStmt : public Stmt { 180428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation Loc; 180528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block; 180628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 180728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt(SourceLocation Loc, 180828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 180928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 18107110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 18117110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 18127110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { } 18137110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 181428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 181528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static SEHFinallyStmt* Create(ASTContext &C, 181628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation FinallyLoc, 181728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block); 181828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 181965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); } 182065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 182128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 182228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getFinallyLoc() const { return Loc; } 182328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Block->getLocEnd(); } 182428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1825cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); } 182628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 182728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 182828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(&Block,&Block+1); 182928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 183028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 183128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 183228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHFinallyStmtClass; 183328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 183428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 183528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 183628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 183728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass SEHTryStmt : public Stmt { 183828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool IsCXXTry; 183928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc; 184028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Children[2]; 184128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 184228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley enum { TRY = 0, HANDLER = 1 }; 184328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 184428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try' 184528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 184628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 184728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 184828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 18497110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 18507110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 18517110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { } 18527110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 185328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic: 185428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static SEHTryStmt* Create(ASTContext &C, 185528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool isCXXTry, 185628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 185728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 185828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler); 185928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 186065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); } 186165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 186228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 186328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getTryLoc() const { return TryLoc; } 186428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); } 186528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 186628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley bool getIsCXXTry() const { return IsCXXTry; } 1867ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1868ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CompoundStmt* getTryBlock() const { 1869cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko return cast<CompoundStmt>(Children[TRY]); 1870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 1871ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 187228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *getHandler() const { return Children[HANDLER]; } 187328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 187428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// Returns 0 if not defined 187528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHExceptStmt *getExceptHandler() const; 187628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SEHFinallyStmt *getFinallyHandler() const; 187728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 187828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley child_range children() { 187928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return child_range(Children,Children+2); 188028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 188128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 188228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley static bool classof(const Stmt *T) { 188328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return T->getStmtClass() == SEHTryStmtClass; 188428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 188528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}; 1886ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1887051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// \brief This captures a statement into a function. For example, the following 1888051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// pragma annotated compound statement can be represented as a CapturedStmt, 1889051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// and this compound statement is the body of an anonymous outlined function. 1890051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @code 1891051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// #pragma omp parallel 1892051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// { 1893051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// compute(); 1894051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// } 1895051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj/// @endcode 1896051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajclass CapturedStmt : public Stmt { 1897051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic: 1898051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The different capture forms: by 'this' or by reference, etc. 1899051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj enum VariableCaptureKind { 1900051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VCK_This, 1901051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VCK_ByRef 1902051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj }; 1903051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1904051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Describes the capture of either a variable or 'this'. 1905051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj class Capture { 1906051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VarDecl *Var; 1907051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation Loc; 1908051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1909051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj public: 1910051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Create a new capture. 1911051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1912051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \param Loc The source location associated with this capture. 1913051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1914051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \param Kind The kind of capture (this, ByRef, ...). 1915051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1916051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \param Var The variable being captured, or null if capturing this. 1917051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1918051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var = 0) 1919051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj : Var(Var), Loc(Loc) { 1920051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj switch (Kind) { 1921051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj case VCK_This: 1922051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj assert(Var == 0 && "'this' capture cannot have a variable!"); 1923051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj break; 1924051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj case VCK_ByRef: 1925051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj assert(Var && "capturing by reference must have a variable!"); 1926051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj break; 1927051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1928051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1929051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1930051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Determine the kind of capture. 1931051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VariableCaptureKind getCaptureKind() const { 1932051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj if (capturesThis()) 1933051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return VCK_This; 1934051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1935051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return VCK_ByRef; 1936051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1937051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1938051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the source location at which the variable or 'this' was 1939051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// first used. 1940051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation getLocation() const { return Loc; } 1941051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1942051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Determine whether this capture handles the C++ 'this' pointer. 1943051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj bool capturesThis() const { return Var == 0; } 1944051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1945051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Determine whether this capture handles a variable. 1946051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj bool capturesVariable() const { return Var != 0; } 1947051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1948051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the declaration of the variable being captured. 1949051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// 1950051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// This operation is only valid if this capture does not capture 'this'. 1951051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj VarDecl *getCapturedVar() const { 1952051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj assert(!capturesThis() && "No variable available for 'this' capture"); 1953051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return Var; 1954051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1955051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj }; 1956051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1957051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajprivate: 1958051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The number of variable captured, including 'this'. 1959051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj unsigned NumCaptures; 1960051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1961051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The implicit outlined function. 1962051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj FunctionDecl *TheFuncDecl; 1963051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1964051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl. 1965051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj RecordDecl *TheRecordDecl; 1966051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1967051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Construct a captured statement. 1968051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj CapturedStmt(Stmt *S, ArrayRef<Capture> Captures, 1969051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj ArrayRef<Expr *> CaptureInits, 1970051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj FunctionDecl *FD, RecordDecl *RD); 1971051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1972051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Construct an empty captured statement. 1973051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj CapturedStmt(EmptyShell Empty, unsigned NumCaptures); 1974051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1975051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Stmt **getStoredStmts() const { 1976051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1); 1977051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1978051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1979051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Capture *getStoredCaptures() const; 1980051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1981051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Sirajpublic: 1982051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj static CapturedStmt *Create(ASTContext &Context, Stmt *S, 1983051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj ArrayRef<Capture> Captures, 1984051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj ArrayRef<Expr *> CaptureInits, 1985051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj FunctionDecl *FD, RecordDecl *RD); 1986051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1987051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj static CapturedStmt *CreateDeserialized(ASTContext &Context, 1988051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj unsigned NumCaptures); 1989051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1990051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the statement being captured. 1991051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; } 1992051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj const Stmt *getCapturedStmt() const { 1993051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return const_cast<CapturedStmt *>(this)->getCapturedStmt(); 1994051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 1995051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1996051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the outlined function declaration. 1997051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj const FunctionDecl *getCapturedFunctionDecl() const { return TheFuncDecl; } 1998051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 1999051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the record declaration for captured variables. 2000051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; } 2001051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2002051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief True if this variable has been captured. 2003051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj bool capturesVariable(const VarDecl *Var) const; 2004051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2005051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief An iterator that walks over the captures. 2006051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj typedef const Capture *capture_iterator; 2007051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2008051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve an iterator pointing to the first capture. 2009051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_iterator capture_begin() const { return getStoredCaptures(); } 2010051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2011051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve an iterator pointing past the end of the sequence of 2012051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// captures. 2013051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_iterator capture_end() const { 2014051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getStoredCaptures() + NumCaptures; 2015051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2016051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2017051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the number of captures, including 'this'. 2018051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj unsigned capture_size() const { return NumCaptures; } 2019051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2020051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Iterator that walks over the capture initialization arguments. 2021051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj typedef Expr **capture_init_iterator; 2022051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2023051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the first initialization argument. 2024051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_init_iterator capture_init_begin() const { 2025051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return reinterpret_cast<Expr **>(getStoredStmts()); 2026051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2027051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2028051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// \brief Retrieve the iterator pointing one past the last initialization 2029051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj /// argument. 2030051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj capture_init_iterator capture_init_end() const { 2031051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return capture_init_begin() + NumCaptures; 2032051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2033051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2034051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation getLocStart() const LLVM_READONLY { 2035051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getCapturedStmt()->getLocStart(); 2036051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2037051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceLocation getLocEnd() const LLVM_READONLY { 2038051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getCapturedStmt()->getLocEnd(); 2039051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2040051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj SourceRange getSourceRange() const LLVM_READONLY { 2041051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return getCapturedStmt()->getSourceRange(); 2042051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2043051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2044051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj static bool classof(const Stmt *T) { 2045051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj return T->getStmtClass() == CapturedStmtClass; 2046051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj } 2047051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 2048051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj child_range children(); 2049051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj}; 2050051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj 20515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 20525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2054