Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Stmt class and statement subclasses. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | a93d0f2 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/ASTDiagnostic.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | #include "clang/AST/ExprCXX.h" |
Steve Naroff | f494b57 | 2008-05-29 21:12:08 +0000 | [diff] [blame] | 17 | #include "clang/AST/ExprObjC.h" |
Benjamin Kramer | a93d0f2 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 18 | #include "clang/AST/Stmt.h" |
Chris Lattner | 16f0049 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 19 | #include "clang/AST/StmtCXX.h" |
| 20 | #include "clang/AST/StmtObjC.h" |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 21 | #include "clang/AST/Type.h" |
Jordan Rose | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 22 | #include "clang/Basic/CharInfo.h" |
Chris Lattner | 9bffb07 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 23 | #include "clang/Basic/TargetInfo.h" |
Benjamin Kramer | a93d0f2 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 24 | #include "clang/Lex/Token.h" |
Chad Rosier | be3ace8 | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
Chandler Carruth | b43c8ec | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 27 | using namespace clang; |
| 28 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 29 | static struct StmtClassNameTable { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 30 | const char *Name; |
| 31 | unsigned Counter; |
| 32 | unsigned Size; |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 33 | } StmtClassInfo[Stmt::lastStmtConstant+1]; |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 34 | |
| 35 | static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { |
| 36 | static bool Initialized = false; |
| 37 | if (Initialized) |
| 38 | return StmtClassInfo[E]; |
| 39 | |
| 40 | // Intialize the table on the first use. |
| 41 | Initialized = true; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 42 | #define ABSTRACT_STMT(STMT) |
Douglas Gregor | f2cad86 | 2008-11-14 12:46:07 +0000 | [diff] [blame] | 43 | #define STMT(CLASS, PARENT) \ |
| 44 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ |
| 45 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 46 | #include "clang/AST/StmtNodes.inc" |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 48 | return StmtClassInfo[E]; |
| 49 | } |
| 50 | |
Benjamin Kramer | 2fa67ef | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 51 | void *Stmt::operator new(size_t bytes, ASTContext& C, |
| 52 | unsigned alignment) throw() { |
| 53 | return ::operator new(bytes, C, alignment); |
| 54 | } |
| 55 | |
| 56 | void *Stmt::operator new(size_t bytes, ASTContext* C, |
| 57 | unsigned alignment) throw() { |
| 58 | return ::operator new(bytes, *C, alignment); |
| 59 | } |
| 60 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 61 | const char *Stmt::getStmtClassName() const { |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 62 | return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void Stmt::PrintStats() { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 66 | // Ensure the table is primed. |
| 67 | getStmtInfoTableEntry(Stmt::NullStmtClass); |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 68 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 69 | unsigned sum = 0; |
Chandler Carruth | b43c8ec | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 70 | llvm::errs() << "\n*** Stmt/Expr Stats:\n"; |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 71 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 72 | if (StmtClassInfo[i].Name == 0) continue; |
| 73 | sum += StmtClassInfo[i].Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 74 | } |
Chandler Carruth | b43c8ec | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 75 | llvm::errs() << " " << sum << " stmts/exprs total.\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 76 | sum = 0; |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 77 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 78 | if (StmtClassInfo[i].Name == 0) continue; |
Douglas Gregor | dbe833d | 2009-05-26 14:40:08 +0000 | [diff] [blame] | 79 | if (StmtClassInfo[i].Counter == 0) continue; |
Chandler Carruth | b43c8ec | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 80 | llvm::errs() << " " << StmtClassInfo[i].Counter << " " |
| 81 | << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size |
| 82 | << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size |
| 83 | << " bytes)\n"; |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 84 | sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 85 | } |
Chandler Carruth | b43c8ec | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 86 | |
| 87 | llvm::errs() << "Total bytes = " << sum << "\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void Stmt::addStmtClass(StmtClass s) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 91 | ++getStmtInfoTableEntry(s).Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Daniel Dunbar | 02892a6 | 2012-03-05 21:42:49 +0000 | [diff] [blame] | 94 | bool Stmt::StatisticsEnabled = false; |
| 95 | void Stmt::EnableStatistics() { |
| 96 | StatisticsEnabled = true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 97 | } |
| 98 | |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 99 | Stmt *Stmt::IgnoreImplicit() { |
| 100 | Stmt *s = this; |
| 101 | |
| 102 | if (ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(s)) |
| 103 | s = ewc->getSubExpr(); |
| 104 | |
| 105 | while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(s)) |
| 106 | s = ice->getSubExpr(); |
| 107 | |
| 108 | return s; |
| 109 | } |
| 110 | |
Chandler Carruth | a1364be | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 111 | /// \brief Strip off all label-like statements. |
| 112 | /// |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 113 | /// This will strip off label statements, case statements, attributed |
| 114 | /// statements and default statements recursively. |
Chandler Carruth | a1364be | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 115 | const Stmt *Stmt::stripLabelLikeStatements() const { |
| 116 | const Stmt *S = this; |
| 117 | while (true) { |
| 118 | if (const LabelStmt *LS = dyn_cast<LabelStmt>(S)) |
| 119 | S = LS->getSubStmt(); |
| 120 | else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S)) |
| 121 | S = SC->getSubStmt(); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 122 | else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S)) |
| 123 | S = AS->getSubStmt(); |
Chandler Carruth | a1364be | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 124 | else |
| 125 | return S; |
| 126 | } |
| 127 | } |
| 128 | |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 129 | namespace { |
| 130 | struct good {}; |
| 131 | struct bad {}; |
John McCall | f8c7fdb | 2011-02-09 08:31:17 +0000 | [diff] [blame] | 132 | |
| 133 | // These silly little functions have to be static inline to suppress |
| 134 | // unused warnings, and they have to be defined to suppress other |
| 135 | // warnings. |
Nick Lewycky | 086eb9f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 136 | static inline good is_good(good) { return good(); } |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 137 | |
| 138 | typedef Stmt::child_range children_t(); |
Nick Lewycky | 086eb9f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 139 | template <class T> good implements_children(children_t T::*) { |
| 140 | return good(); |
| 141 | } |
| 142 | static inline bad implements_children(children_t Stmt::*) { |
| 143 | return bad(); |
| 144 | } |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 145 | |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 146 | typedef SourceLocation getLocStart_t() const; |
| 147 | template <class T> good implements_getLocStart(getLocStart_t T::*) { |
Nick Lewycky | 086eb9f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 148 | return good(); |
| 149 | } |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 150 | static inline bad implements_getLocStart(getLocStart_t Stmt::*) { |
| 151 | return bad(); |
| 152 | } |
| 153 | |
| 154 | typedef SourceLocation getLocEnd_t() const; |
| 155 | template <class T> good implements_getLocEnd(getLocEnd_t T::*) { |
| 156 | return good(); |
| 157 | } |
| 158 | static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) { |
Nick Lewycky | 086eb9f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 159 | return bad(); |
| 160 | } |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 161 | |
| 162 | #define ASSERT_IMPLEMENTS_children(type) \ |
| 163 | (void) sizeof(is_good(implements_children(&type::children))) |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 164 | #define ASSERT_IMPLEMENTS_getLocStart(type) \ |
| 165 | (void) sizeof(is_good(implements_getLocStart(&type::getLocStart))) |
| 166 | #define ASSERT_IMPLEMENTS_getLocEnd(type) \ |
| 167 | (void) sizeof(is_good(implements_getLocEnd(&type::getLocEnd))) |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /// Check whether the various Stmt classes implement their member |
| 171 | /// functions. |
| 172 | static inline void check_implementations() { |
| 173 | #define ABSTRACT_STMT(type) |
| 174 | #define STMT(type, base) \ |
| 175 | ASSERT_IMPLEMENTS_children(type); \ |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 176 | ASSERT_IMPLEMENTS_getLocStart(type); \ |
| 177 | ASSERT_IMPLEMENTS_getLocEnd(type); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 178 | #include "clang/AST/StmtNodes.inc" |
| 179 | } |
| 180 | |
| 181 | Stmt::child_range Stmt::children() { |
| 182 | switch (getStmtClass()) { |
| 183 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 184 | #define ABSTRACT_STMT(type) |
| 185 | #define STMT(type, base) \ |
| 186 | case Stmt::type##Class: \ |
| 187 | return static_cast<type*>(this)->children(); |
| 188 | #include "clang/AST/StmtNodes.inc" |
| 189 | } |
| 190 | llvm_unreachable("unknown statement kind!"); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 193 | // Amusing macro metaprogramming hack: check whether a class provides |
| 194 | // a more specific implementation of getSourceRange. |
| 195 | // |
| 196 | // See also Expr.cpp:getExprLoc(). |
| 197 | namespace { |
| 198 | /// This implementation is used when a class provides a custom |
| 199 | /// implementation of getSourceRange. |
| 200 | template <class S, class T> |
| 201 | SourceRange getSourceRangeImpl(const Stmt *stmt, |
| 202 | SourceRange (T::*v)() const) { |
| 203 | return static_cast<const S*>(stmt)->getSourceRange(); |
| 204 | } |
| 205 | |
| 206 | /// This implementation is used when a class doesn't provide a custom |
| 207 | /// implementation of getSourceRange. Overload resolution should pick it over |
| 208 | /// the implementation above because it's more specialized according to |
| 209 | /// function template partial ordering. |
| 210 | template <class S> |
| 211 | SourceRange getSourceRangeImpl(const Stmt *stmt, |
| 212 | SourceRange (Stmt::*v)() const) { |
| 213 | return SourceRange(static_cast<const S*>(stmt)->getLocStart(), |
| 214 | static_cast<const S*>(stmt)->getLocEnd()); |
| 215 | } |
| 216 | } |
| 217 | |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 218 | SourceRange Stmt::getSourceRange() const { |
| 219 | switch (getStmtClass()) { |
| 220 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 221 | #define ABSTRACT_STMT(type) |
| 222 | #define STMT(type, base) \ |
| 223 | case Stmt::type##Class: \ |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 224 | return getSourceRangeImpl<type>(this, &type::getSourceRange); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 225 | #include "clang/AST/StmtNodes.inc" |
| 226 | } |
| 227 | llvm_unreachable("unknown statement kind!"); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Daniel Dunbar | 90e25a8 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 230 | SourceLocation Stmt::getLocStart() const { |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 231 | // llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n"; |
Daniel Dunbar | 90e25a8 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 232 | switch (getStmtClass()) { |
| 233 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 234 | #define ABSTRACT_STMT(type) |
| 235 | #define STMT(type, base) \ |
| 236 | case Stmt::type##Class: \ |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 237 | return static_cast<const type*>(this)->getLocStart(); |
Daniel Dunbar | 90e25a8 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 238 | #include "clang/AST/StmtNodes.inc" |
| 239 | } |
| 240 | llvm_unreachable("unknown statement kind"); |
| 241 | } |
| 242 | |
| 243 | SourceLocation Stmt::getLocEnd() const { |
| 244 | switch (getStmtClass()) { |
| 245 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 246 | #define ABSTRACT_STMT(type) |
| 247 | #define STMT(type, base) \ |
| 248 | case Stmt::type##Class: \ |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 249 | return static_cast<const type*>(this)->getLocEnd(); |
Daniel Dunbar | 90e25a8 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 250 | #include "clang/AST/StmtNodes.inc" |
| 251 | } |
| 252 | llvm_unreachable("unknown statement kind"); |
| 253 | } |
| 254 | |
Nico Weber | d36aa35 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 255 | CompoundStmt::CompoundStmt(ASTContext &C, ArrayRef<Stmt*> Stmts, |
Benjamin Kramer | 3a2d0fb | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 256 | SourceLocation LB, SourceLocation RB) |
| 257 | : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { |
Nico Weber | d36aa35 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 258 | CompoundStmtBits.NumStmts = Stmts.size(); |
| 259 | assert(CompoundStmtBits.NumStmts == Stmts.size() && |
Benjamin Kramer | 3a2d0fb | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 260 | "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); |
| 261 | |
Nico Weber | d36aa35 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 262 | if (Stmts.size() == 0) { |
Benjamin Kramer | 3a2d0fb | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 263 | Body = 0; |
| 264 | return; |
| 265 | } |
| 266 | |
Nico Weber | d36aa35 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 267 | Body = new (C) Stmt*[Stmts.size()]; |
| 268 | std::copy(Stmts.begin(), Stmts.end(), Body); |
Benjamin Kramer | 3a2d0fb | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 271 | void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) { |
| 272 | if (this->Body) |
| 273 | C.Deallocate(Body); |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 274 | this->CompoundStmtBits.NumStmts = NumStmts; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 275 | |
| 276 | Body = new (C) Stmt*[NumStmts]; |
| 277 | memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts); |
| 278 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 279 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 280 | const char *LabelStmt::getName() const { |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 281 | return getDecl()->getIdentifier()->getNameStart(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 284 | AttributedStmt *AttributedStmt::Create(ASTContext &C, SourceLocation Loc, |
| 285 | ArrayRef<const Attr*> Attrs, |
| 286 | Stmt *SubStmt) { |
| 287 | void *Mem = C.Allocate(sizeof(AttributedStmt) + |
| 288 | sizeof(Attr*) * (Attrs.size() - 1), |
| 289 | llvm::alignOf<AttributedStmt>()); |
| 290 | return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); |
| 291 | } |
| 292 | |
| 293 | AttributedStmt *AttributedStmt::CreateEmpty(ASTContext &C, unsigned NumAttrs) { |
| 294 | assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); |
| 295 | void *Mem = C.Allocate(sizeof(AttributedStmt) + |
| 296 | sizeof(Attr*) * (NumAttrs - 1), |
| 297 | llvm::alignOf<AttributedStmt>()); |
| 298 | return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); |
| 299 | } |
| 300 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 301 | bool Stmt::hasImplicitControlFlow() const { |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 302 | switch (StmtBits.sClass) { |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 303 | default: |
| 304 | return false; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 305 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 306 | case CallExprClass: |
| 307 | case ConditionalOperatorClass: |
| 308 | case ChooseExprClass: |
| 309 | case StmtExprClass: |
| 310 | case DeclStmtClass: |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 311 | return true; |
| 312 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 313 | case Stmt::BinaryOperatorClass: { |
| 314 | const BinaryOperator* B = cast<BinaryOperator>(this); |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 315 | if (B->isLogicalOp() || B->getOpcode() == BO_Comma) |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 316 | return true; |
| 317 | else |
| 318 | return false; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
Chad Rosier | aba59aa | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 323 | std::string AsmStmt::generateAsmString(ASTContext &C) const { |
Chad Rosier | 9252701 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 324 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 325 | return gccAsmStmt->generateAsmString(C); |
| 326 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 327 | return msAsmStmt->generateAsmString(C); |
Chad Rosier | aba59aa | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 328 | llvm_unreachable("unknown asm statement kind!"); |
| 329 | } |
| 330 | |
| 331 | StringRef AsmStmt::getOutputConstraint(unsigned i) const { |
Chad Rosier | 9252701 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 332 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 333 | return gccAsmStmt->getOutputConstraint(i); |
| 334 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 335 | return msAsmStmt->getOutputConstraint(i); |
Chad Rosier | aba59aa | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 336 | llvm_unreachable("unknown asm statement kind!"); |
| 337 | } |
| 338 | |
| 339 | const Expr *AsmStmt::getOutputExpr(unsigned i) const { |
Chad Rosier | 9252701 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 340 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 341 | return gccAsmStmt->getOutputExpr(i); |
| 342 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 343 | return msAsmStmt->getOutputExpr(i); |
Chad Rosier | aba59aa | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 344 | llvm_unreachable("unknown asm statement kind!"); |
| 345 | } |
| 346 | |
| 347 | StringRef AsmStmt::getInputConstraint(unsigned i) const { |
Chad Rosier | 9252701 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 348 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 349 | return gccAsmStmt->getInputConstraint(i); |
| 350 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 351 | return msAsmStmt->getInputConstraint(i); |
Chad Rosier | aba59aa | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 352 | llvm_unreachable("unknown asm statement kind!"); |
| 353 | } |
| 354 | |
| 355 | const Expr *AsmStmt::getInputExpr(unsigned i) const { |
Chad Rosier | 9252701 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 356 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 357 | return gccAsmStmt->getInputExpr(i); |
| 358 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 359 | return msAsmStmt->getInputExpr(i); |
Chad Rosier | aba59aa | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 360 | llvm_unreachable("unknown asm statement kind!"); |
| 361 | } |
| 362 | |
| 363 | StringRef AsmStmt::getClobber(unsigned i) const { |
Chad Rosier | 9252701 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 364 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 365 | return gccAsmStmt->getClobber(i); |
| 366 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 367 | return msAsmStmt->getClobber(i); |
Chad Rosier | aba59aa | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 368 | llvm_unreachable("unknown asm statement kind!"); |
| 369 | } |
| 370 | |
Chad Rosier | c4fb221 | 2012-08-28 00:24:05 +0000 | [diff] [blame] | 371 | /// getNumPlusOperands - Return the number of output operands that have a "+" |
| 372 | /// constraint. |
| 373 | unsigned AsmStmt::getNumPlusOperands() const { |
| 374 | unsigned Res = 0; |
| 375 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) |
| 376 | if (isOutputPlusConstraint(i)) |
| 377 | ++Res; |
| 378 | return Res; |
| 379 | } |
| 380 | |
Chad Rosier | 33f0558 | 2012-08-27 23:47:56 +0000 | [diff] [blame] | 381 | StringRef GCCAsmStmt::getClobber(unsigned i) const { |
| 382 | return getClobberStringLiteral(i)->getString(); |
| 383 | } |
| 384 | |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 385 | Expr *GCCAsmStmt::getOutputExpr(unsigned i) { |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 386 | return cast<Expr>(Exprs[i]); |
| 387 | } |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 388 | |
| 389 | /// getOutputConstraint - Return the constraint string for the specified |
| 390 | /// output operand. All output constraints are known to be non-empty (either |
| 391 | /// '=' or '+'). |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 392 | StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const { |
Anders Carlsson | acb6bcb | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 393 | return getOutputConstraintLiteral(i)->getString(); |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 394 | } |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 395 | |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 396 | Expr *GCCAsmStmt::getInputExpr(unsigned i) { |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 397 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 398 | } |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 399 | void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) { |
Chris Lattner | 935f0f0 | 2011-02-21 22:09:29 +0000 | [diff] [blame] | 400 | Exprs[i + NumOutputs] = E; |
| 401 | } |
| 402 | |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 403 | /// getInputConstraint - Return the specified input constraint. Unlike output |
| 404 | /// constraints, these can be empty. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 405 | StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { |
Anders Carlsson | acb6bcb | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 406 | return getInputConstraintLiteral(i)->getString(); |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 409 | void GCCAsmStmt::setOutputsAndInputsAndClobbers(ASTContext &C, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 410 | IdentifierInfo **Names, |
Anders Carlsson | fdba9c0 | 2010-01-30 19:34:25 +0000 | [diff] [blame] | 411 | StringLiteral **Constraints, |
| 412 | Stmt **Exprs, |
| 413 | unsigned NumOutputs, |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 414 | unsigned NumInputs, |
Anders Carlsson | fdba9c0 | 2010-01-30 19:34:25 +0000 | [diff] [blame] | 415 | StringLiteral **Clobbers, |
| 416 | unsigned NumClobbers) { |
Douglas Gregor | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 417 | this->NumOutputs = NumOutputs; |
| 418 | this->NumInputs = NumInputs; |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 419 | this->NumClobbers = NumClobbers; |
| 420 | |
| 421 | unsigned NumExprs = NumOutputs + NumInputs; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 422 | |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 423 | C.Deallocate(this->Names); |
| 424 | this->Names = new (C) IdentifierInfo*[NumExprs]; |
| 425 | std::copy(Names, Names + NumExprs, this->Names); |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 426 | |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 427 | C.Deallocate(this->Exprs); |
| 428 | this->Exprs = new (C) Stmt*[NumExprs]; |
| 429 | std::copy(Exprs, Exprs + NumExprs, this->Exprs); |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 430 | |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 431 | C.Deallocate(this->Constraints); |
| 432 | this->Constraints = new (C) StringLiteral*[NumExprs]; |
| 433 | std::copy(Constraints, Constraints + NumExprs, this->Constraints); |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 434 | |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 435 | C.Deallocate(this->Clobbers); |
| 436 | this->Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 437 | std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers); |
Douglas Gregor | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 440 | /// getNamedOperand - Given a symbolic operand reference like %[foo], |
| 441 | /// translate this into a numeric value needed to reference the same operand. |
| 442 | /// This returns -1 if the operand name is invalid. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 443 | int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 444 | unsigned NumPlusOperands = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 445 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 446 | // Check if this is an output operand. |
| 447 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { |
| 448 | if (getOutputName(i) == SymbolicName) |
| 449 | return i; |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 450 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 451 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 452 | for (unsigned i = 0, e = getNumInputs(); i != e; ++i) |
| 453 | if (getInputName(i) == SymbolicName) |
| 454 | return getNumOutputs() + NumPlusOperands + i; |
| 455 | |
| 456 | // Not found. |
| 457 | return -1; |
| 458 | } |
| 459 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 460 | /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing |
| 461 | /// it into pieces. If the asm string is erroneous, emit errors and return |
| 462 | /// true, otherwise return false. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 463 | unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, |
Chris Lattner | fb5058e | 2009-03-10 23:41:04 +0000 | [diff] [blame] | 464 | ASTContext &C, unsigned &DiagOffs) const { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 465 | StringRef Str = getAsmString()->getString(); |
Benjamin Kramer | 2f4eaef | 2010-08-17 12:54:38 +0000 | [diff] [blame] | 466 | const char *StrStart = Str.begin(); |
| 467 | const char *StrEnd = Str.end(); |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 468 | const char *CurPtr = StrStart; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 470 | // "Simple" inline asms have no constraints or operands, just convert the asm |
| 471 | // string to escape $'s. |
| 472 | if (isSimple()) { |
| 473 | std::string Result; |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 474 | for (; CurPtr != StrEnd; ++CurPtr) { |
| 475 | switch (*CurPtr) { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 476 | case '$': |
| 477 | Result += "$$"; |
| 478 | break; |
| 479 | default: |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 480 | Result += *CurPtr; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 481 | break; |
| 482 | } |
| 483 | } |
| 484 | Pieces.push_back(AsmStringPiece(Result)); |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 485 | return 0; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | // CurStringPiece - The current string that we are building up as we scan the |
| 489 | // asm string. |
| 490 | std::string CurStringPiece; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 491 | |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 492 | bool HasVariants = !C.getTargetInfo().hasNoAsmVariants(); |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 493 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 494 | while (1) { |
| 495 | // Done with the string? |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 496 | if (CurPtr == StrEnd) { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 497 | if (!CurStringPiece.empty()) |
| 498 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 499 | return 0; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 500 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 502 | char CurChar = *CurPtr++; |
Chris Lattner | 018b54e | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 503 | switch (CurChar) { |
| 504 | case '$': CurStringPiece += "$$"; continue; |
Chris Lattner | 9bffb07 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 505 | case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue; |
| 506 | case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue; |
| 507 | case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue; |
Chris Lattner | 018b54e | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 508 | case '%': |
| 509 | break; |
| 510 | default: |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 511 | CurStringPiece += CurChar; |
| 512 | continue; |
| 513 | } |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 514 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 515 | // Escaped "%" character in asm string. |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 516 | if (CurPtr == StrEnd) { |
| 517 | // % at end of string is invalid (no escape). |
| 518 | DiagOffs = CurPtr-StrStart-1; |
| 519 | return diag::err_asm_invalid_escape; |
| 520 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 522 | char EscapedChar = *CurPtr++; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 523 | if (EscapedChar == '%') { // %% -> % |
| 524 | // Escaped percentage sign. |
| 525 | CurStringPiece += '%'; |
| 526 | continue; |
| 527 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 529 | if (EscapedChar == '=') { // %= -> Generate an unique ID. |
| 530 | CurStringPiece += "${:uid}"; |
| 531 | continue; |
| 532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 534 | // Otherwise, we have an operand. If we have accumulated a string so far, |
| 535 | // add it to the Pieces list. |
| 536 | if (!CurStringPiece.empty()) { |
| 537 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
| 538 | CurStringPiece.clear(); |
| 539 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 540 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 541 | // Handle %x4 and %x[foo] by capturing x as the modifier character. |
| 542 | char Modifier = '\0'; |
Jordan Rose | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 543 | if (isLetter(EscapedChar)) { |
Benjamin Kramer | bc57f3c | 2011-07-05 11:13:37 +0000 | [diff] [blame] | 544 | if (CurPtr == StrEnd) { // Premature end. |
| 545 | DiagOffs = CurPtr-StrStart-1; |
| 546 | return diag::err_asm_invalid_escape; |
| 547 | } |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 548 | Modifier = EscapedChar; |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 549 | EscapedChar = *CurPtr++; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 550 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | |
Jordan Rose | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 552 | if (isDigit(EscapedChar)) { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 553 | // %n - Assembler operand n |
Chris Lattner | cafc222 | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 554 | unsigned N = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 555 | |
Chris Lattner | cafc222 | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 556 | --CurPtr; |
Jordan Rose | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 557 | while (CurPtr != StrEnd && isDigit(*CurPtr)) |
Chris Lattner | 32a47ed | 2009-03-11 23:09:16 +0000 | [diff] [blame] | 558 | N = N*10 + ((*CurPtr++)-'0'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | |
Chris Lattner | 8575927 | 2009-03-11 00:23:13 +0000 | [diff] [blame] | 560 | unsigned NumOperands = |
| 561 | getNumOutputs() + getNumPlusOperands() + getNumInputs(); |
| 562 | if (N >= NumOperands) { |
| 563 | DiagOffs = CurPtr-StrStart-1; |
| 564 | return diag::err_asm_invalid_operand_number; |
| 565 | } |
| 566 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 567 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
| 568 | continue; |
| 569 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 570 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 571 | // Handle %[foo], a symbolic operand reference. |
| 572 | if (EscapedChar == '[') { |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 573 | DiagOffs = CurPtr-StrStart-1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 574 | |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 575 | // Find the ']'. |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 576 | const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 577 | if (NameEnd == 0) |
| 578 | return diag::err_asm_unterminated_symbolic_operand_name; |
| 579 | if (NameEnd == CurPtr) |
| 580 | return diag::err_asm_empty_symbolic_operand_name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 581 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 582 | StringRef SymbolicName(CurPtr, NameEnd - CurPtr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 583 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 584 | int N = getNamedOperand(SymbolicName); |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 585 | if (N == -1) { |
| 586 | // Verify that an operand with that name exists. |
| 587 | DiagOffs = CurPtr-StrStart; |
| 588 | return diag::err_asm_unknown_symbolic_operand_name; |
| 589 | } |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 590 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 591 | |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 592 | CurPtr = NameEnd+1; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 593 | continue; |
| 594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 595 | |
Chris Lattner | 2ff0f42 | 2009-03-10 23:57:07 +0000 | [diff] [blame] | 596 | DiagOffs = CurPtr-StrStart-1; |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 597 | return diag::err_asm_invalid_escape; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 598 | } |
| 599 | } |
Chad Rosier | da083b2 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 600 | |
| 601 | /// Assemble final IR asm string (GCC-style). |
| 602 | std::string GCCAsmStmt::generateAsmString(ASTContext &C) const { |
Chad Rosier | be3ace8 | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 603 | // Analyze the asm string to decompose it into its pieces. We know that Sema |
| 604 | // has already done this, so it is guaranteed to be successful. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 605 | SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces; |
Chad Rosier | be3ace8 | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 606 | unsigned DiagOffs; |
| 607 | AnalyzeAsmString(Pieces, C, DiagOffs); |
| 608 | |
| 609 | std::string AsmString; |
| 610 | for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { |
| 611 | if (Pieces[i].isString()) |
| 612 | AsmString += Pieces[i].getString(); |
| 613 | else if (Pieces[i].getModifier() == '\0') |
| 614 | AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); |
| 615 | else |
| 616 | AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + |
| 617 | Pieces[i].getModifier() + '}'; |
| 618 | } |
| 619 | return AsmString; |
| 620 | } |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 621 | |
Chad Rosier | da083b2 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 622 | /// Assemble final IR asm string (MS-style). |
| 623 | std::string MSAsmStmt::generateAsmString(ASTContext &C) const { |
| 624 | // FIXME: This needs to be translated into the IR string representation. |
Chad Rosier | 00d1637 | 2012-08-28 20:33:49 +0000 | [diff] [blame] | 625 | return AsmStr; |
Chad Rosier | da083b2 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Chad Rosier | 633abb0 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 628 | Expr *MSAsmStmt::getOutputExpr(unsigned i) { |
| 629 | return cast<Expr>(Exprs[i]); |
| 630 | } |
| 631 | |
| 632 | Expr *MSAsmStmt::getInputExpr(unsigned i) { |
| 633 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 634 | } |
| 635 | void MSAsmStmt::setInputExpr(unsigned i, Expr *E) { |
| 636 | Exprs[i + NumOutputs] = E; |
| 637 | } |
| 638 | |
Sam Weinig | b0e4cb6 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 639 | QualType CXXCatchStmt::getCaughtType() const { |
| 640 | if (ExceptionDecl) |
| 641 | return ExceptionDecl->getType(); |
| 642 | return QualType(); |
| 643 | } |
| 644 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 645 | //===----------------------------------------------------------------------===// |
| 646 | // Constructors |
| 647 | //===----------------------------------------------------------------------===// |
| 648 | |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 649 | GCCAsmStmt::GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, |
| 650 | bool isvolatile, unsigned numoutputs, unsigned numinputs, |
| 651 | IdentifierInfo **names, StringLiteral **constraints, |
| 652 | Expr **exprs, StringLiteral *asmstr, |
| 653 | unsigned numclobbers, StringLiteral **clobbers, |
| 654 | SourceLocation rparenloc) |
Chad Rosier | 066ef86 | 2012-08-27 19:38:01 +0000 | [diff] [blame] | 655 | : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
| 656 | numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) { |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 657 | |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 658 | unsigned NumExprs = NumOutputs + NumInputs; |
| 659 | |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 660 | Names = new (C) IdentifierInfo*[NumExprs]; |
| 661 | std::copy(names, names + NumExprs, Names); |
| 662 | |
| 663 | Exprs = new (C) Stmt*[NumExprs]; |
| 664 | std::copy(exprs, exprs + NumExprs, Exprs); |
| 665 | |
| 666 | Constraints = new (C) StringLiteral*[NumExprs]; |
| 667 | std::copy(constraints, constraints + NumExprs, Constraints); |
| 668 | |
| 669 | Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 670 | std::copy(clobbers, clobbers + NumClobbers, Clobbers); |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Chad Rosier | 058ab17 | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 673 | MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc, |
| 674 | SourceLocation lbraceloc, bool issimple, bool isvolatile, |
Chad Rosier | e54cba1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 675 | ArrayRef<Token> asmtoks, unsigned numoutputs, |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 676 | unsigned numinputs, |
Chad Rosier | e54cba1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 677 | ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs, |
| 678 | StringRef asmstr, ArrayRef<StringRef> clobbers, |
| 679 | SourceLocation endloc) |
| 680 | : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
| 681 | numinputs, clobbers.size()), LBraceLoc(lbraceloc), |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 682 | EndLoc(endloc), NumAsmToks(asmtoks.size()) { |
Chad Rosier | 058ab17 | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 683 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 684 | initialize(C, asmstr, asmtoks, constraints, exprs, clobbers); |
| 685 | } |
Chad Rosier | 058ab17 | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 686 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 687 | static StringRef copyIntoContext(ASTContext &C, StringRef str) { |
| 688 | size_t size = str.size(); |
| 689 | char *buffer = new (C) char[size]; |
| 690 | memcpy(buffer, str.data(), size); |
| 691 | return StringRef(buffer, size); |
| 692 | } |
| 693 | |
| 694 | void MSAsmStmt::initialize(ASTContext &C, |
| 695 | StringRef asmstr, |
| 696 | ArrayRef<Token> asmtoks, |
| 697 | ArrayRef<StringRef> constraints, |
| 698 | ArrayRef<Expr*> exprs, |
| 699 | ArrayRef<StringRef> clobbers) { |
| 700 | assert(NumAsmToks == asmtoks.size()); |
| 701 | assert(NumClobbers == clobbers.size()); |
| 702 | |
| 703 | unsigned NumExprs = exprs.size(); |
| 704 | assert(NumExprs == NumOutputs + NumInputs); |
| 705 | assert(NumExprs == constraints.size()); |
| 706 | |
| 707 | AsmStr = copyIntoContext(C, asmstr); |
Chad Rosier | 79efe24 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 708 | |
Chad Rosier | 633abb0 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 709 | Exprs = new (C) Stmt*[NumExprs]; |
Chad Rosier | e54cba1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 710 | for (unsigned i = 0, e = NumExprs; i != e; ++i) |
| 711 | Exprs[i] = exprs[i]; |
Chad Rosier | 633abb0 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 712 | |
Chad Rosier | 79efe24 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 713 | AsmToks = new (C) Token[NumAsmToks]; |
| 714 | for (unsigned i = 0, e = NumAsmToks; i != e; ++i) |
| 715 | AsmToks[i] = asmtoks[i]; |
Chad Rosier | 62f22b8 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 716 | |
Chad Rosier | 89fb6d7 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 717 | Constraints = new (C) StringRef[NumExprs]; |
| 718 | for (unsigned i = 0, e = NumExprs; i != e; ++i) { |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 719 | Constraints[i] = copyIntoContext(C, constraints[i]); |
Chad Rosier | 89fb6d7 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Chad Rosier | 33c72e1 | 2012-08-10 21:36:25 +0000 | [diff] [blame] | 722 | Clobbers = new (C) StringRef[NumClobbers]; |
Chad Rosier | e790bc3 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 723 | for (unsigned i = 0, e = NumClobbers; i != e; ++i) { |
| 724 | // FIXME: Avoid the allocation/copy if at all possible. |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 725 | Clobbers[i] = copyIntoContext(C, clobbers[i]); |
Chad Rosier | e790bc3 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 726 | } |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 729 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 730 | Stmt *Body, SourceLocation FCL, |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 731 | SourceLocation RPL) |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 732 | : Stmt(ObjCForCollectionStmtClass) { |
| 733 | SubExprs[ELEM] = Elem; |
| 734 | SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect); |
| 735 | SubExprs[BODY] = Body; |
| 736 | ForLoc = FCL; |
| 737 | RParenLoc = RPL; |
| 738 | } |
| 739 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 740 | ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, |
| 741 | Stmt **CatchStmts, unsigned NumCatchStmts, |
| 742 | Stmt *atFinallyStmt) |
| 743 | : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc), |
| 744 | NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != 0) |
| 745 | { |
| 746 | Stmt **Stmts = getStmts(); |
| 747 | Stmts[0] = atTryStmt; |
| 748 | for (unsigned I = 0; I != NumCatchStmts; ++I) |
| 749 | Stmts[I + 1] = CatchStmts[I]; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 750 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 751 | if (HasFinally) |
| 752 | Stmts[NumCatchStmts + 1] = atFinallyStmt; |
| 753 | } |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 754 | |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 755 | ObjCAtTryStmt *ObjCAtTryStmt::Create(ASTContext &Context, |
| 756 | SourceLocation atTryLoc, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 757 | Stmt *atTryStmt, |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 758 | Stmt **CatchStmts, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 759 | unsigned NumCatchStmts, |
| 760 | Stmt *atFinallyStmt) { |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 761 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 762 | (1 + NumCatchStmts + (atFinallyStmt != 0)) * sizeof(Stmt *); |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 763 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 764 | return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts, |
| 765 | atFinallyStmt); |
| 766 | } |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 767 | |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 768 | ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(ASTContext &Context, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 769 | unsigned NumCatchStmts, |
| 770 | bool HasFinally) { |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 771 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 772 | (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *); |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 773 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 774 | return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 775 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 776 | |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 777 | SourceLocation ObjCAtTryStmt::getLocEnd() const { |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 778 | if (HasFinally) |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 779 | return getFinallyStmt()->getLocEnd(); |
| 780 | if (NumCatchStmts) |
| 781 | return getCatchStmt(NumCatchStmts - 1)->getLocEnd(); |
| 782 | return getTryBody()->getLocEnd(); |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 785 | CXXTryStmt *CXXTryStmt::Create(ASTContext &C, SourceLocation tryLoc, |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 786 | Stmt *tryBlock, ArrayRef<Stmt*> handlers) { |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 787 | std::size_t Size = sizeof(CXXTryStmt); |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 788 | Size += ((handlers.size() + 1) * sizeof(Stmt)); |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 789 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 790 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 791 | return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Argyrios Kyrtzidis | 7cb45e3 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 794 | CXXTryStmt *CXXTryStmt::Create(ASTContext &C, EmptyShell Empty, |
| 795 | unsigned numHandlers) { |
| 796 | std::size_t Size = sizeof(CXXTryStmt); |
| 797 | Size += ((numHandlers + 1) * sizeof(Stmt)); |
| 798 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 799 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Argyrios Kyrtzidis | 7cb45e3 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 800 | return new (Mem) CXXTryStmt(Empty, numHandlers); |
| 801 | } |
| 802 | |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 803 | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 804 | ArrayRef<Stmt*> handlers) |
| 805 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 806 | Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); |
Sam Weinig | b0e4cb6 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 807 | Stmts[0] = tryBlock; |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 808 | std::copy(handlers.begin(), handlers.end(), Stmts + 1); |
Sam Weinig | b0e4cb6 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 809 | } |
| 810 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 811 | CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt, |
| 812 | Expr *Cond, Expr *Inc, DeclStmt *LoopVar, |
| 813 | Stmt *Body, SourceLocation FL, |
| 814 | SourceLocation CL, SourceLocation RPL) |
| 815 | : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) { |
| 816 | SubExprs[RANGE] = Range; |
| 817 | SubExprs[BEGINEND] = BeginEndStmt; |
| 818 | SubExprs[COND] = reinterpret_cast<Stmt*>(Cond); |
| 819 | SubExprs[INC] = reinterpret_cast<Stmt*>(Inc); |
| 820 | SubExprs[LOOPVAR] = LoopVar; |
| 821 | SubExprs[BODY] = Body; |
| 822 | } |
| 823 | |
| 824 | Expr *CXXForRangeStmt::getRangeInit() { |
| 825 | DeclStmt *RangeStmt = getRangeStmt(); |
| 826 | VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl()); |
| 827 | assert(RangeDecl &&& "for-range should have a single var decl"); |
| 828 | return RangeDecl->getInit(); |
| 829 | } |
| 830 | |
| 831 | const Expr *CXXForRangeStmt::getRangeInit() const { |
| 832 | return const_cast<CXXForRangeStmt*>(this)->getRangeInit(); |
| 833 | } |
| 834 | |
| 835 | VarDecl *CXXForRangeStmt::getLoopVariable() { |
| 836 | Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl(); |
| 837 | assert(LV && "No loop variable in CXXForRangeStmt"); |
| 838 | return cast<VarDecl>(LV); |
| 839 | } |
| 840 | |
| 841 | const VarDecl *CXXForRangeStmt::getLoopVariable() const { |
| 842 | return const_cast<CXXForRangeStmt*>(this)->getLoopVariable(); |
| 843 | } |
| 844 | |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 845 | IfStmt::IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 846 | Stmt *then, SourceLocation EL, Stmt *elsev) |
| 847 | : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL) |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 848 | { |
| 849 | setConditionVariable(C, var); |
| 850 | SubExprs[COND] = reinterpret_cast<Stmt*>(cond); |
| 851 | SubExprs[THEN] = then; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 852 | SubExprs[ELSE] = elsev; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | VarDecl *IfStmt::getConditionVariable() const { |
| 856 | if (!SubExprs[VAR]) |
| 857 | return 0; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 858 | |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 859 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 860 | return cast<VarDecl>(DS->getSingleDecl()); |
| 861 | } |
| 862 | |
| 863 | void IfStmt::setConditionVariable(ASTContext &C, VarDecl *V) { |
| 864 | if (!V) { |
| 865 | SubExprs[VAR] = 0; |
| 866 | return; |
| 867 | } |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 868 | |
Daniel Dunbar | 96a0014 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 869 | SourceRange VarRange = V->getSourceRange(); |
| 870 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 871 | VarRange.getEnd()); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 874 | ForStmt::ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, |
| 875 | Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 876 | SourceLocation RP) |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 877 | : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP) |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 878 | { |
| 879 | SubExprs[INIT] = Init; |
| 880 | setConditionVariable(C, condVar); |
| 881 | SubExprs[COND] = reinterpret_cast<Stmt*>(Cond); |
| 882 | SubExprs[INC] = reinterpret_cast<Stmt*>(Inc); |
| 883 | SubExprs[BODY] = Body; |
| 884 | } |
| 885 | |
| 886 | VarDecl *ForStmt::getConditionVariable() const { |
| 887 | if (!SubExprs[CONDVAR]) |
| 888 | return 0; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 889 | |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 890 | DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]); |
| 891 | return cast<VarDecl>(DS->getSingleDecl()); |
| 892 | } |
| 893 | |
| 894 | void ForStmt::setConditionVariable(ASTContext &C, VarDecl *V) { |
| 895 | if (!V) { |
| 896 | SubExprs[CONDVAR] = 0; |
| 897 | return; |
| 898 | } |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 899 | |
Daniel Dunbar | 96a0014 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 900 | SourceRange VarRange = V->getSourceRange(); |
| 901 | SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 902 | VarRange.getEnd()); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 905 | SwitchStmt::SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond) |
| 906 | : Stmt(SwitchStmtClass), FirstCase(0), AllEnumCasesCovered(0) |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 907 | { |
| 908 | setConditionVariable(C, Var); |
| 909 | SubExprs[COND] = reinterpret_cast<Stmt*>(cond); |
| 910 | SubExprs[BODY] = NULL; |
| 911 | } |
| 912 | |
| 913 | VarDecl *SwitchStmt::getConditionVariable() const { |
| 914 | if (!SubExprs[VAR]) |
| 915 | return 0; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 916 | |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 917 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 918 | return cast<VarDecl>(DS->getSingleDecl()); |
| 919 | } |
| 920 | |
| 921 | void SwitchStmt::setConditionVariable(ASTContext &C, VarDecl *V) { |
| 922 | if (!V) { |
| 923 | SubExprs[VAR] = 0; |
| 924 | return; |
| 925 | } |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 926 | |
Daniel Dunbar | 96a0014 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 927 | SourceRange VarRange = V->getSourceRange(); |
| 928 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 929 | VarRange.getEnd()); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 930 | } |
| 931 | |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 932 | Stmt *SwitchCase::getSubStmt() { |
Chris Lattner | c4002c7 | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 933 | if (isa<CaseStmt>(this)) |
| 934 | return cast<CaseStmt>(this)->getSubStmt(); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 935 | return cast<DefaultStmt>(this)->getSubStmt(); |
| 936 | } |
| 937 | |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 938 | WhileStmt::WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 939 | SourceLocation WL) |
Chris Lattner | c4002c7 | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 940 | : Stmt(WhileStmtClass) { |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 941 | setConditionVariable(C, Var); |
| 942 | SubExprs[COND] = reinterpret_cast<Stmt*>(cond); |
| 943 | SubExprs[BODY] = body; |
| 944 | WhileLoc = WL; |
| 945 | } |
| 946 | |
| 947 | VarDecl *WhileStmt::getConditionVariable() const { |
| 948 | if (!SubExprs[VAR]) |
| 949 | return 0; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 950 | |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 951 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 952 | return cast<VarDecl>(DS->getSingleDecl()); |
| 953 | } |
| 954 | |
| 955 | void WhileStmt::setConditionVariable(ASTContext &C, VarDecl *V) { |
| 956 | if (!V) { |
| 957 | SubExprs[VAR] = 0; |
| 958 | return; |
| 959 | } |
Daniel Dunbar | 96a0014 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 960 | |
| 961 | SourceRange VarRange = V->getSourceRange(); |
| 962 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 963 | VarRange.getEnd()); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 964 | } |
| 965 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 966 | // IndirectGotoStmt |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 967 | LabelDecl *IndirectGotoStmt::getConstantTarget() { |
John McCall | 95c225d | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 968 | if (AddrLabelExpr *E = |
| 969 | dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts())) |
| 970 | return E->getLabel(); |
| 971 | return 0; |
| 972 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 973 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 974 | // ReturnStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 975 | const Expr* ReturnStmt::getRetValue() const { |
| 976 | return cast_or_null<Expr>(RetExpr); |
| 977 | } |
| 978 | Expr* ReturnStmt::getRetValue() { |
| 979 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 980 | } |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 981 | |
| 982 | SEHTryStmt::SEHTryStmt(bool IsCXXTry, |
| 983 | SourceLocation TryLoc, |
| 984 | Stmt *TryBlock, |
| 985 | Stmt *Handler) |
| 986 | : Stmt(SEHTryStmtClass), |
| 987 | IsCXXTry(IsCXXTry), |
| 988 | TryLoc(TryLoc) |
| 989 | { |
| 990 | Children[TRY] = TryBlock; |
| 991 | Children[HANDLER] = Handler; |
| 992 | } |
| 993 | |
| 994 | SEHTryStmt* SEHTryStmt::Create(ASTContext &C, |
| 995 | bool IsCXXTry, |
| 996 | SourceLocation TryLoc, |
| 997 | Stmt *TryBlock, |
| 998 | Stmt *Handler) { |
| 999 | return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1000 | } |
| 1001 | |
| 1002 | SEHExceptStmt* SEHTryStmt::getExceptHandler() const { |
| 1003 | return dyn_cast<SEHExceptStmt>(getHandler()); |
| 1004 | } |
| 1005 | |
| 1006 | SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const { |
| 1007 | return dyn_cast<SEHFinallyStmt>(getHandler()); |
| 1008 | } |
| 1009 | |
| 1010 | SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, |
| 1011 | Expr *FilterExpr, |
| 1012 | Stmt *Block) |
| 1013 | : Stmt(SEHExceptStmtClass), |
| 1014 | Loc(Loc) |
| 1015 | { |
| 1016 | Children[FILTER_EXPR] = reinterpret_cast<Stmt*>(FilterExpr); |
| 1017 | Children[BLOCK] = Block; |
| 1018 | } |
| 1019 | |
| 1020 | SEHExceptStmt* SEHExceptStmt::Create(ASTContext &C, |
| 1021 | SourceLocation Loc, |
| 1022 | Expr *FilterExpr, |
| 1023 | Stmt *Block) { |
| 1024 | return new(C) SEHExceptStmt(Loc,FilterExpr,Block); |
| 1025 | } |
| 1026 | |
| 1027 | SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, |
| 1028 | Stmt *Block) |
| 1029 | : Stmt(SEHFinallyStmtClass), |
| 1030 | Loc(Loc), |
| 1031 | Block(Block) |
| 1032 | {} |
| 1033 | |
| 1034 | SEHFinallyStmt* SEHFinallyStmt::Create(ASTContext &C, |
| 1035 | SourceLocation Loc, |
| 1036 | Stmt *Block) { |
| 1037 | return new(C)SEHFinallyStmt(Loc,Block); |
| 1038 | } |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1039 | |
| 1040 | CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const { |
| 1041 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1042 | |
| 1043 | // Offset of the first Capture object. |
| 1044 | unsigned FirstCaptureOffset = |
| 1045 | llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1046 | |
| 1047 | return reinterpret_cast<Capture *>( |
| 1048 | reinterpret_cast<char *>(const_cast<CapturedStmt *>(this)) |
| 1049 | + FirstCaptureOffset); |
| 1050 | } |
| 1051 | |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1052 | CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind, |
| 1053 | ArrayRef<Capture> Captures, |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1054 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1055 | CapturedDecl *CD, |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1056 | RecordDecl *RD) |
| 1057 | : Stmt(CapturedStmtClass), NumCaptures(Captures.size()), |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1058 | CapDeclAndKind(CD, Kind), TheRecordDecl(RD) { |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1059 | assert( S && "null captured statement"); |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1060 | assert(CD && "null captured declaration for captured statement"); |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1061 | assert(RD && "null record declaration for captured statement"); |
| 1062 | |
| 1063 | // Copy initialization expressions. |
| 1064 | Stmt **Stored = getStoredStmts(); |
| 1065 | for (unsigned I = 0, N = NumCaptures; I != N; ++I) |
| 1066 | *Stored++ = CaptureInits[I]; |
| 1067 | |
| 1068 | // Copy the statement being captured. |
| 1069 | *Stored = S; |
| 1070 | |
| 1071 | // Copy all Capture objects. |
| 1072 | Capture *Buffer = getStoredCaptures(); |
| 1073 | std::copy(Captures.begin(), Captures.end(), Buffer); |
| 1074 | } |
| 1075 | |
| 1076 | CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures) |
| 1077 | : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures), |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1078 | CapDeclAndKind(0, CR_Default), TheRecordDecl(0) { |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1079 | getStoredStmts()[NumCaptures] = 0; |
| 1080 | } |
| 1081 | |
| 1082 | CapturedStmt *CapturedStmt::Create(ASTContext &Context, Stmt *S, |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1083 | CapturedRegionKind Kind, |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1084 | ArrayRef<Capture> Captures, |
| 1085 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1086 | CapturedDecl *CD, |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1087 | RecordDecl *RD) { |
| 1088 | // The layout is |
| 1089 | // |
| 1090 | // ----------------------------------------------------------- |
| 1091 | // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture | |
| 1092 | // ----------------^-------------------^---------------------- |
| 1093 | // getStoredStmts() getStoredCaptures() |
| 1094 | // |
| 1095 | // where S is the statement being captured. |
| 1096 | // |
| 1097 | assert(CaptureInits.size() == Captures.size() && "wrong number of arguments"); |
| 1098 | |
| 1099 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1); |
| 1100 | if (!Captures.empty()) { |
| 1101 | // Realign for the following Capture array. |
| 1102 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1103 | Size += sizeof(Capture) * Captures.size(); |
| 1104 | } |
| 1105 | |
| 1106 | void *Mem = Context.Allocate(Size); |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1107 | return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD); |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | CapturedStmt *CapturedStmt::CreateDeserialized(ASTContext &Context, |
| 1111 | unsigned NumCaptures) { |
| 1112 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1113 | if (NumCaptures > 0) { |
| 1114 | // Realign for the following Capture array. |
| 1115 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1116 | Size += sizeof(Capture) * NumCaptures; |
| 1117 | } |
| 1118 | |
| 1119 | void *Mem = Context.Allocate(Size); |
| 1120 | return new (Mem) CapturedStmt(EmptyShell(), NumCaptures); |
| 1121 | } |
| 1122 | |
| 1123 | Stmt::child_range CapturedStmt::children() { |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1124 | // Children are captured field initilizers. |
| 1125 | return child_range(getStoredStmts(), getStoredStmts() + NumCaptures); |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | bool CapturedStmt::capturesVariable(const VarDecl *Var) const { |
Ben Langmuir | dc5be4f | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 1129 | for (const_capture_iterator I = capture_begin(), |
| 1130 | E = capture_end(); I != E; ++I) { |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame^] | 1131 | if (!I->capturesVariable()) |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1132 | continue; |
| 1133 | |
| 1134 | // This does not handle variable redeclarations. This should be |
| 1135 | // extended to capture variables with redeclarations, for example |
| 1136 | // a thread-private variable in OpenMP. |
| 1137 | if (I->getCapturedVar() == Var) |
| 1138 | return true; |
| 1139 | } |
| 1140 | |
| 1141 | return false; |
| 1142 | } |