Chris Lattner | f42cce7 | 2006-10-25 04:09:21 +0000 | [diff] [blame] | 1 | //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 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. |
Chris Lattner | f42cce7 | 2006-10-25 04:09:21 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Stmt class and statement subclasses. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 444a130 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/ASTDiagnostic.h" |
Chris Lattner | 2937565 | 2006-12-04 18:06:35 +0000 | [diff] [blame] | 16 | #include "clang/AST/ExprCXX.h" |
Steve Naroff | 021ca18 | 2008-05-29 21:12:08 +0000 | [diff] [blame] | 17 | #include "clang/AST/ExprObjC.h" |
Benjamin Kramer | 444a130 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 18 | #include "clang/AST/Stmt.h" |
Chris Lattner | f0b64d7 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 19 | #include "clang/AST/StmtCXX.h" |
| 20 | #include "clang/AST/StmtObjC.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtOpenMP.h" |
Sebastian Redl | 54c04d4 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 22 | #include "clang/AST/Type.h" |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 23 | #include "clang/Basic/CharInfo.h" |
Chris Lattner | 1a8f394 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 24 | #include "clang/Basic/TargetInfo.h" |
Benjamin Kramer | 444a130 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 25 | #include "clang/Lex/Token.h" |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringExtras.h" |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 27 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | f42cce7 | 2006-10-25 04:09:21 +0000 | [diff] [blame] | 28 | using namespace clang; |
| 29 | |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 30 | static struct StmtClassNameTable { |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 31 | const char *Name; |
| 32 | unsigned Counter; |
| 33 | unsigned Size; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 34 | } StmtClassInfo[Stmt::lastStmtConstant+1]; |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 35 | |
| 36 | static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { |
| 37 | static bool Initialized = false; |
| 38 | if (Initialized) |
| 39 | return StmtClassInfo[E]; |
| 40 | |
| 41 | // Intialize the table on the first use. |
| 42 | Initialized = true; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 43 | #define ABSTRACT_STMT(STMT) |
Douglas Gregor | be35ce9 | 2008-11-14 12:46:07 +0000 | [diff] [blame] | 44 | #define STMT(CLASS, PARENT) \ |
| 45 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ |
| 46 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 47 | #include "clang/AST/StmtNodes.inc" |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 49 | return StmtClassInfo[E]; |
| 50 | } |
| 51 | |
Craig Topper | 3793291 | 2013-08-18 10:09:15 +0000 | [diff] [blame] | 52 | void *Stmt::operator new(size_t bytes, const ASTContext& C, |
Craig Topper | 5a05001 | 2013-08-18 17:45:38 +0000 | [diff] [blame] | 53 | unsigned alignment) { |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 54 | return ::operator new(bytes, C, alignment); |
| 55 | } |
| 56 | |
Steve Naroff | f1e5369 | 2007-03-23 22:27:02 +0000 | [diff] [blame] | 57 | const char *Stmt::getStmtClassName() const { |
John McCall | 925b1662 | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 58 | return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name; |
Steve Naroff | f1e5369 | 2007-03-23 22:27:02 +0000 | [diff] [blame] | 59 | } |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 60 | |
| 61 | void Stmt::PrintStats() { |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 62 | // Ensure the table is primed. |
| 63 | getStmtInfoTableEntry(Stmt::NullStmtClass); |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 64 | |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 65 | unsigned sum = 0; |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 66 | llvm::errs() << "\n*** Stmt/Expr Stats:\n"; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 67 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 68 | if (StmtClassInfo[i].Name == nullptr) continue; |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 69 | sum += StmtClassInfo[i].Counter; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 70 | } |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 71 | llvm::errs() << " " << sum << " stmts/exprs total.\n"; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 72 | sum = 0; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 73 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 74 | if (StmtClassInfo[i].Name == nullptr) continue; |
Douglas Gregor | a30d046 | 2009-05-26 14:40:08 +0000 | [diff] [blame] | 75 | if (StmtClassInfo[i].Counter == 0) continue; |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 76 | llvm::errs() << " " << StmtClassInfo[i].Counter << " " |
| 77 | << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size |
| 78 | << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size |
| 79 | << " bytes)\n"; |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 80 | sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 81 | } |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 82 | |
| 83 | llvm::errs() << "Total bytes = " << sum << "\n"; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void Stmt::addStmtClass(StmtClass s) { |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 87 | ++getStmtInfoTableEntry(s).Counter; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Daniel Dunbar | 6290557 | 2012-03-05 21:42:49 +0000 | [diff] [blame] | 90 | bool Stmt::StatisticsEnabled = false; |
| 91 | void Stmt::EnableStatistics() { |
| 92 | StatisticsEnabled = true; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 93 | } |
| 94 | |
John McCall | 4db5c3c | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 95 | Stmt *Stmt::IgnoreImplicit() { |
| 96 | Stmt *s = this; |
| 97 | |
| 98 | if (ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(s)) |
| 99 | s = ewc->getSubExpr(); |
| 100 | |
| 101 | while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(s)) |
| 102 | s = ice->getSubExpr(); |
| 103 | |
| 104 | return s; |
| 105 | } |
| 106 | |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 107 | /// \brief Strip off all label-like statements. |
| 108 | /// |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 109 | /// This will strip off label statements, case statements, attributed |
| 110 | /// statements and default statements recursively. |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 111 | const Stmt *Stmt::stripLabelLikeStatements() const { |
| 112 | const Stmt *S = this; |
| 113 | while (true) { |
| 114 | if (const LabelStmt *LS = dyn_cast<LabelStmt>(S)) |
| 115 | S = LS->getSubStmt(); |
| 116 | else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S)) |
| 117 | S = SC->getSubStmt(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 118 | else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S)) |
| 119 | S = AS->getSubStmt(); |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 120 | else |
| 121 | return S; |
| 122 | } |
| 123 | } |
| 124 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 125 | namespace { |
| 126 | struct good {}; |
| 127 | struct bad {}; |
John McCall | f75152f | 2011-02-09 08:31:17 +0000 | [diff] [blame] | 128 | |
| 129 | // These silly little functions have to be static inline to suppress |
| 130 | // unused warnings, and they have to be defined to suppress other |
| 131 | // warnings. |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 132 | static inline good is_good(good) { return good(); } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 133 | |
| 134 | typedef Stmt::child_range children_t(); |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 135 | template <class T> good implements_children(children_t T::*) { |
| 136 | return good(); |
| 137 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 138 | LLVM_ATTRIBUTE_UNUSED |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 139 | static inline bad implements_children(children_t Stmt::*) { |
| 140 | return bad(); |
| 141 | } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 142 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 143 | typedef SourceLocation getLocStart_t() const; |
| 144 | template <class T> good implements_getLocStart(getLocStart_t T::*) { |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 145 | return good(); |
| 146 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 147 | LLVM_ATTRIBUTE_UNUSED |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 148 | static inline bad implements_getLocStart(getLocStart_t Stmt::*) { |
| 149 | return bad(); |
| 150 | } |
| 151 | |
| 152 | typedef SourceLocation getLocEnd_t() const; |
| 153 | template <class T> good implements_getLocEnd(getLocEnd_t T::*) { |
| 154 | return good(); |
| 155 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 156 | LLVM_ATTRIBUTE_UNUSED |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 157 | static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) { |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 158 | return bad(); |
| 159 | } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 160 | |
| 161 | #define ASSERT_IMPLEMENTS_children(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 162 | (void) is_good(implements_children(&type::children)) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 163 | #define ASSERT_IMPLEMENTS_getLocStart(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 164 | (void) is_good(implements_getLocStart(&type::getLocStart)) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 165 | #define ASSERT_IMPLEMENTS_getLocEnd(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 166 | (void) is_good(implements_getLocEnd(&type::getLocEnd)) |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /// Check whether the various Stmt classes implement their member |
| 170 | /// functions. |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 171 | LLVM_ATTRIBUTE_UNUSED |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 172 | static inline void check_implementations() { |
| 173 | #define ABSTRACT_STMT(type) |
| 174 | #define STMT(type, base) \ |
| 175 | ASSERT_IMPLEMENTS_children(type); \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 176 | ASSERT_IMPLEMENTS_getLocStart(type); \ |
| 177 | ASSERT_IMPLEMENTS_getLocEnd(type); |
John McCall | bd06678 | 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 | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Erik Verbruggen | 11a2ecc | 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 | bd06678 | 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 | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 224 | return getSourceRangeImpl<type>(this, &type::getSourceRange); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 225 | #include "clang/AST/StmtNodes.inc" |
| 226 | } |
| 227 | llvm_unreachable("unknown statement kind!"); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 230 | SourceLocation Stmt::getLocStart() const { |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 231 | // llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n"; |
Daniel Dunbar | b0ab5e9 | 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 | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 237 | return static_cast<const type*>(this)->getLocStart(); |
Daniel Dunbar | b0ab5e9 | 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 | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 249 | return static_cast<const type*>(this)->getLocEnd(); |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 250 | #include "clang/AST/StmtNodes.inc" |
| 251 | } |
| 252 | llvm_unreachable("unknown statement kind"); |
| 253 | } |
| 254 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 255 | CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 256 | SourceLocation LB, SourceLocation RB) |
| 257 | : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { |
Nico Weber | a2a0eb9 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 258 | CompoundStmtBits.NumStmts = Stmts.size(); |
| 259 | assert(CompoundStmtBits.NumStmts == Stmts.size() && |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 260 | "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); |
| 261 | |
Nico Weber | a2a0eb9 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 262 | if (Stmts.size() == 0) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 263 | Body = nullptr; |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 264 | return; |
| 265 | } |
| 266 | |
Nico Weber | a2a0eb9 | 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 | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 271 | void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts, |
| 272 | unsigned NumStmts) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 273 | if (this->Body) |
| 274 | C.Deallocate(Body); |
John McCall | 925b1662 | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 275 | this->CompoundStmtBits.NumStmts = NumStmts; |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 276 | |
| 277 | Body = new (C) Stmt*[NumStmts]; |
| 278 | memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts); |
| 279 | } |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 280 | |
Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 281 | const char *LabelStmt::getName() const { |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 282 | return getDecl()->getIdentifier()->getNameStart(); |
Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 285 | AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 286 | ArrayRef<const Attr*> Attrs, |
| 287 | Stmt *SubStmt) { |
Aaron Ballman | f3d9b09 | 2014-05-13 14:55:01 +0000 | [diff] [blame] | 288 | assert(!Attrs.empty() && "Attrs should not be empty"); |
| 289 | void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(), |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 290 | llvm::alignOf<AttributedStmt>()); |
| 291 | return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); |
| 292 | } |
| 293 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 294 | AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, |
| 295 | unsigned NumAttrs) { |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 296 | assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); |
Aaron Ballman | f3d9b09 | 2014-05-13 14:55:01 +0000 | [diff] [blame] | 297 | void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs, |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 298 | llvm::alignOf<AttributedStmt>()); |
| 299 | return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); |
| 300 | } |
| 301 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 302 | std::string AsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 303 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 304 | return gccAsmStmt->generateAsmString(C); |
| 305 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 306 | return msAsmStmt->generateAsmString(C); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 307 | llvm_unreachable("unknown asm statement kind!"); |
| 308 | } |
| 309 | |
| 310 | StringRef AsmStmt::getOutputConstraint(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 311 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 312 | return gccAsmStmt->getOutputConstraint(i); |
| 313 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 314 | return msAsmStmt->getOutputConstraint(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 315 | llvm_unreachable("unknown asm statement kind!"); |
| 316 | } |
| 317 | |
| 318 | const Expr *AsmStmt::getOutputExpr(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 319 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 320 | return gccAsmStmt->getOutputExpr(i); |
| 321 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 322 | return msAsmStmt->getOutputExpr(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 323 | llvm_unreachable("unknown asm statement kind!"); |
| 324 | } |
| 325 | |
| 326 | StringRef AsmStmt::getInputConstraint(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 327 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 328 | return gccAsmStmt->getInputConstraint(i); |
| 329 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 330 | return msAsmStmt->getInputConstraint(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 331 | llvm_unreachable("unknown asm statement kind!"); |
| 332 | } |
| 333 | |
| 334 | const Expr *AsmStmt::getInputExpr(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 335 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 336 | return gccAsmStmt->getInputExpr(i); |
| 337 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 338 | return msAsmStmt->getInputExpr(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 339 | llvm_unreachable("unknown asm statement kind!"); |
| 340 | } |
| 341 | |
| 342 | StringRef AsmStmt::getClobber(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 343 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 344 | return gccAsmStmt->getClobber(i); |
| 345 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 346 | return msAsmStmt->getClobber(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 347 | llvm_unreachable("unknown asm statement kind!"); |
| 348 | } |
| 349 | |
Chad Rosier | a1b5c8c | 2012-08-28 00:24:05 +0000 | [diff] [blame] | 350 | /// getNumPlusOperands - Return the number of output operands that have a "+" |
| 351 | /// constraint. |
| 352 | unsigned AsmStmt::getNumPlusOperands() const { |
| 353 | unsigned Res = 0; |
| 354 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) |
| 355 | if (isOutputPlusConstraint(i)) |
| 356 | ++Res; |
| 357 | return Res; |
| 358 | } |
| 359 | |
Chad Rosier | 6100ae1 | 2012-08-27 23:47:56 +0000 | [diff] [blame] | 360 | StringRef GCCAsmStmt::getClobber(unsigned i) const { |
| 361 | return getClobberStringLiteral(i)->getString(); |
| 362 | } |
| 363 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 364 | Expr *GCCAsmStmt::getOutputExpr(unsigned i) { |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 365 | return cast<Expr>(Exprs[i]); |
| 366 | } |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 367 | |
| 368 | /// getOutputConstraint - Return the constraint string for the specified |
| 369 | /// output operand. All output constraints are known to be non-empty (either |
| 370 | /// '=' or '+'). |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 371 | StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const { |
Anders Carlsson | 66de081 | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 372 | return getOutputConstraintLiteral(i)->getString(); |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 373 | } |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 374 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 375 | Expr *GCCAsmStmt::getInputExpr(unsigned i) { |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 376 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 377 | } |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 378 | void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) { |
Chris Lattner | 93ede02 | 2011-02-21 22:09:29 +0000 | [diff] [blame] | 379 | Exprs[i + NumOutputs] = E; |
| 380 | } |
| 381 | |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 382 | /// getInputConstraint - Return the specified input constraint. Unlike output |
| 383 | /// constraints, these can be empty. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 384 | StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { |
Anders Carlsson | 66de081 | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 385 | return getInputConstraintLiteral(i)->getString(); |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 388 | void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C, |
| 389 | IdentifierInfo **Names, |
| 390 | StringLiteral **Constraints, |
| 391 | Stmt **Exprs, |
| 392 | unsigned NumOutputs, |
| 393 | unsigned NumInputs, |
| 394 | StringLiteral **Clobbers, |
| 395 | unsigned NumClobbers) { |
Douglas Gregor | f994f06 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 396 | this->NumOutputs = NumOutputs; |
| 397 | this->NumInputs = NumInputs; |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 398 | this->NumClobbers = NumClobbers; |
| 399 | |
| 400 | unsigned NumExprs = NumOutputs + NumInputs; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 401 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 402 | C.Deallocate(this->Names); |
| 403 | this->Names = new (C) IdentifierInfo*[NumExprs]; |
| 404 | std::copy(Names, Names + NumExprs, this->Names); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 405 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 406 | C.Deallocate(this->Exprs); |
| 407 | this->Exprs = new (C) Stmt*[NumExprs]; |
| 408 | std::copy(Exprs, Exprs + NumExprs, this->Exprs); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 409 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 410 | C.Deallocate(this->Constraints); |
| 411 | this->Constraints = new (C) StringLiteral*[NumExprs]; |
| 412 | std::copy(Constraints, Constraints + NumExprs, this->Constraints); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 413 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 414 | C.Deallocate(this->Clobbers); |
| 415 | this->Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 416 | std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers); |
Douglas Gregor | f994f06 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 419 | /// getNamedOperand - Given a symbolic operand reference like %[foo], |
| 420 | /// translate this into a numeric value needed to reference the same operand. |
| 421 | /// This returns -1 if the operand name is invalid. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 422 | int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 423 | unsigned NumPlusOperands = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 424 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 425 | // Check if this is an output operand. |
| 426 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { |
| 427 | if (getOutputName(i) == SymbolicName) |
| 428 | return i; |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 431 | for (unsigned i = 0, e = getNumInputs(); i != e; ++i) |
| 432 | if (getInputName(i) == SymbolicName) |
| 433 | return getNumOutputs() + NumPlusOperands + i; |
| 434 | |
| 435 | // Not found. |
| 436 | return -1; |
| 437 | } |
| 438 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 439 | /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing |
| 440 | /// it into pieces. If the asm string is erroneous, emit errors and return |
| 441 | /// true, otherwise return false. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 442 | unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 443 | const ASTContext &C, unsigned &DiagOffs) const { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 444 | StringRef Str = getAsmString()->getString(); |
Benjamin Kramer | 35b077e | 2010-08-17 12:54:38 +0000 | [diff] [blame] | 445 | const char *StrStart = Str.begin(); |
| 446 | const char *StrEnd = Str.end(); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 447 | const char *CurPtr = StrStart; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 448 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 449 | // "Simple" inline asms have no constraints or operands, just convert the asm |
| 450 | // string to escape $'s. |
| 451 | if (isSimple()) { |
| 452 | std::string Result; |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 453 | for (; CurPtr != StrEnd; ++CurPtr) { |
| 454 | switch (*CurPtr) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 455 | case '$': |
| 456 | Result += "$$"; |
| 457 | break; |
| 458 | default: |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 459 | Result += *CurPtr; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 460 | break; |
| 461 | } |
| 462 | } |
| 463 | Pieces.push_back(AsmStringPiece(Result)); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 464 | return 0; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | // CurStringPiece - The current string that we are building up as we scan the |
| 468 | // asm string. |
| 469 | std::string CurStringPiece; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 470 | |
Douglas Gregor | e8bbc12 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 471 | bool HasVariants = !C.getTargetInfo().hasNoAsmVariants(); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 472 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 473 | while (1) { |
| 474 | // Done with the string? |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 475 | if (CurPtr == StrEnd) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 476 | if (!CurStringPiece.empty()) |
| 477 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 478 | return 0; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 481 | char CurChar = *CurPtr++; |
Chris Lattner | da081a8 | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 482 | switch (CurChar) { |
| 483 | case '$': CurStringPiece += "$$"; continue; |
Chris Lattner | 1a8f394 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 484 | case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue; |
| 485 | case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue; |
| 486 | case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue; |
Chris Lattner | da081a8 | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 487 | case '%': |
| 488 | break; |
| 489 | default: |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 490 | CurStringPiece += CurChar; |
| 491 | continue; |
| 492 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 493 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 494 | // Escaped "%" character in asm string. |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 495 | if (CurPtr == StrEnd) { |
| 496 | // % at end of string is invalid (no escape). |
| 497 | DiagOffs = CurPtr-StrStart-1; |
| 498 | return diag::err_asm_invalid_escape; |
| 499 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 501 | char EscapedChar = *CurPtr++; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 502 | if (EscapedChar == '%') { // %% -> % |
| 503 | // Escaped percentage sign. |
| 504 | CurStringPiece += '%'; |
| 505 | continue; |
| 506 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 507 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 508 | if (EscapedChar == '=') { // %= -> Generate an unique ID. |
| 509 | CurStringPiece += "${:uid}"; |
| 510 | continue; |
| 511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 513 | // Otherwise, we have an operand. If we have accumulated a string so far, |
| 514 | // add it to the Pieces list. |
| 515 | if (!CurStringPiece.empty()) { |
| 516 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
| 517 | CurStringPiece.clear(); |
| 518 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 520 | // Handle %x4 and %x[foo] by capturing x as the modifier character. |
| 521 | char Modifier = '\0'; |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 522 | if (isLetter(EscapedChar)) { |
Benjamin Kramer | e87c38b | 2011-07-05 11:13:37 +0000 | [diff] [blame] | 523 | if (CurPtr == StrEnd) { // Premature end. |
| 524 | DiagOffs = CurPtr-StrStart-1; |
| 525 | return diag::err_asm_invalid_escape; |
| 526 | } |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 527 | Modifier = EscapedChar; |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 528 | EscapedChar = *CurPtr++; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 529 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 531 | if (isDigit(EscapedChar)) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 532 | // %n - Assembler operand n |
Chris Lattner | 99d892b | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 533 | unsigned N = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 534 | |
Chris Lattner | 99d892b | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 535 | --CurPtr; |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 536 | while (CurPtr != StrEnd && isDigit(*CurPtr)) |
Chris Lattner | 84f3afa | 2009-03-11 23:09:16 +0000 | [diff] [blame] | 537 | N = N*10 + ((*CurPtr++)-'0'); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | |
Chris Lattner | 1431192 | 2009-03-11 00:23:13 +0000 | [diff] [blame] | 539 | unsigned NumOperands = |
| 540 | getNumOutputs() + getNumPlusOperands() + getNumInputs(); |
| 541 | if (N >= NumOperands) { |
| 542 | DiagOffs = CurPtr-StrStart-1; |
| 543 | return diag::err_asm_invalid_operand_number; |
| 544 | } |
| 545 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 546 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
| 547 | continue; |
| 548 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 550 | // Handle %[foo], a symbolic operand reference. |
| 551 | if (EscapedChar == '[') { |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 552 | DiagOffs = CurPtr-StrStart-1; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 553 | |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 554 | // Find the ']'. |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 555 | const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 556 | if (NameEnd == nullptr) |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 557 | return diag::err_asm_unterminated_symbolic_operand_name; |
| 558 | if (NameEnd == CurPtr) |
| 559 | return diag::err_asm_empty_symbolic_operand_name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 560 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 561 | StringRef SymbolicName(CurPtr, NameEnd - CurPtr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 562 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 563 | int N = getNamedOperand(SymbolicName); |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 564 | if (N == -1) { |
| 565 | // Verify that an operand with that name exists. |
| 566 | DiagOffs = CurPtr-StrStart; |
| 567 | return diag::err_asm_unknown_symbolic_operand_name; |
| 568 | } |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 569 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 570 | |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 571 | CurPtr = NameEnd+1; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 572 | continue; |
| 573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 574 | |
Chris Lattner | 0cdaa2e | 2009-03-10 23:57:07 +0000 | [diff] [blame] | 575 | DiagOffs = CurPtr-StrStart-1; |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 576 | return diag::err_asm_invalid_escape; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 577 | } |
| 578 | } |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 579 | |
| 580 | /// Assemble final IR asm string (GCC-style). |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 581 | std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 582 | // Analyze the asm string to decompose it into its pieces. We know that Sema |
| 583 | // has already done this, so it is guaranteed to be successful. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 584 | SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces; |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 585 | unsigned DiagOffs; |
| 586 | AnalyzeAsmString(Pieces, C, DiagOffs); |
| 587 | |
| 588 | std::string AsmString; |
| 589 | for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { |
| 590 | if (Pieces[i].isString()) |
| 591 | AsmString += Pieces[i].getString(); |
| 592 | else if (Pieces[i].getModifier() == '\0') |
| 593 | AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); |
| 594 | else |
| 595 | AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + |
| 596 | Pieces[i].getModifier() + '}'; |
| 597 | } |
| 598 | return AsmString; |
| 599 | } |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 600 | |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 601 | /// Assemble final IR asm string (MS-style). |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 602 | std::string MSAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 603 | // FIXME: This needs to be translated into the IR string representation. |
Chad Rosier | 0bca469 | 2012-08-28 20:33:49 +0000 | [diff] [blame] | 604 | return AsmStr; |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 607 | Expr *MSAsmStmt::getOutputExpr(unsigned i) { |
| 608 | return cast<Expr>(Exprs[i]); |
| 609 | } |
| 610 | |
| 611 | Expr *MSAsmStmt::getInputExpr(unsigned i) { |
| 612 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 613 | } |
| 614 | void MSAsmStmt::setInputExpr(unsigned i, Expr *E) { |
| 615 | Exprs[i + NumOutputs] = E; |
| 616 | } |
| 617 | |
Sam Weinig | ebcea98 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 618 | QualType CXXCatchStmt::getCaughtType() const { |
| 619 | if (ExceptionDecl) |
| 620 | return ExceptionDecl->getType(); |
| 621 | return QualType(); |
| 622 | } |
| 623 | |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 624 | //===----------------------------------------------------------------------===// |
| 625 | // Constructors |
| 626 | //===----------------------------------------------------------------------===// |
| 627 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 628 | GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, |
| 629 | bool issimple, bool isvolatile, unsigned numoutputs, |
| 630 | unsigned numinputs, IdentifierInfo **names, |
| 631 | StringLiteral **constraints, Expr **exprs, |
| 632 | StringLiteral *asmstr, unsigned numclobbers, |
| 633 | StringLiteral **clobbers, SourceLocation rparenloc) |
Chad Rosier | fe3352e | 2012-08-27 19:38:01 +0000 | [diff] [blame] | 634 | : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
| 635 | numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) { |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 636 | |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 637 | unsigned NumExprs = NumOutputs + NumInputs; |
| 638 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 639 | Names = new (C) IdentifierInfo*[NumExprs]; |
| 640 | std::copy(names, names + NumExprs, Names); |
| 641 | |
| 642 | Exprs = new (C) Stmt*[NumExprs]; |
| 643 | std::copy(exprs, exprs + NumExprs, Exprs); |
| 644 | |
| 645 | Constraints = new (C) StringLiteral*[NumExprs]; |
| 646 | std::copy(constraints, constraints + NumExprs, Constraints); |
| 647 | |
| 648 | Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 649 | std::copy(clobbers, clobbers + NumClobbers, Clobbers); |
Anders Carlsson | 94ea8aa | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 652 | MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc, |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 653 | SourceLocation lbraceloc, bool issimple, bool isvolatile, |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 654 | ArrayRef<Token> asmtoks, unsigned numoutputs, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 655 | unsigned numinputs, |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 656 | ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs, |
| 657 | StringRef asmstr, ArrayRef<StringRef> clobbers, |
| 658 | SourceLocation endloc) |
| 659 | : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
| 660 | numinputs, clobbers.size()), LBraceLoc(lbraceloc), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 661 | EndLoc(endloc), NumAsmToks(asmtoks.size()) { |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 662 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 663 | initialize(C, asmstr, asmtoks, constraints, exprs, clobbers); |
| 664 | } |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 665 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 666 | static StringRef copyIntoContext(const ASTContext &C, StringRef str) { |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 667 | size_t size = str.size(); |
| 668 | char *buffer = new (C) char[size]; |
| 669 | memcpy(buffer, str.data(), size); |
| 670 | return StringRef(buffer, size); |
| 671 | } |
| 672 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 673 | void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 674 | ArrayRef<Token> asmtoks, |
| 675 | ArrayRef<StringRef> constraints, |
| 676 | ArrayRef<Expr*> exprs, |
| 677 | ArrayRef<StringRef> clobbers) { |
| 678 | assert(NumAsmToks == asmtoks.size()); |
| 679 | assert(NumClobbers == clobbers.size()); |
| 680 | |
| 681 | unsigned NumExprs = exprs.size(); |
| 682 | assert(NumExprs == NumOutputs + NumInputs); |
| 683 | assert(NumExprs == constraints.size()); |
| 684 | |
| 685 | AsmStr = copyIntoContext(C, asmstr); |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 686 | |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 687 | Exprs = new (C) Stmt*[NumExprs]; |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 688 | for (unsigned i = 0, e = NumExprs; i != e; ++i) |
| 689 | Exprs[i] = exprs[i]; |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 690 | |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 691 | AsmToks = new (C) Token[NumAsmToks]; |
| 692 | for (unsigned i = 0, e = NumAsmToks; i != e; ++i) |
| 693 | AsmToks[i] = asmtoks[i]; |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 694 | |
Chad Rosier | 3dd7bf2 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 695 | Constraints = new (C) StringRef[NumExprs]; |
| 696 | for (unsigned i = 0, e = NumExprs; i != e; ++i) { |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 697 | Constraints[i] = copyIntoContext(C, constraints[i]); |
Chad Rosier | 3dd7bf2 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Chad Rosier | baf53f9 | 2012-08-10 21:36:25 +0000 | [diff] [blame] | 700 | Clobbers = new (C) StringRef[NumClobbers]; |
Chad Rosier | d6ef704 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 701 | for (unsigned i = 0, e = NumClobbers; i != e; ++i) { |
| 702 | // FIXME: Avoid the allocation/copy if at all possible. |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 703 | Clobbers[i] = copyIntoContext(C, clobbers[i]); |
Chad Rosier | d6ef704 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 704 | } |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 707 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 708 | Stmt *Body, SourceLocation FCL, |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 709 | SourceLocation RPL) |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 710 | : Stmt(ObjCForCollectionStmtClass) { |
| 711 | SubExprs[ELEM] = Elem; |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 712 | SubExprs[COLLECTION] = Collect; |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 713 | SubExprs[BODY] = Body; |
| 714 | ForLoc = FCL; |
| 715 | RParenLoc = RPL; |
| 716 | } |
| 717 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 718 | ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, |
| 719 | Stmt **CatchStmts, unsigned NumCatchStmts, |
| 720 | Stmt *atFinallyStmt) |
| 721 | : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 722 | NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 723 | Stmt **Stmts = getStmts(); |
| 724 | Stmts[0] = atTryStmt; |
| 725 | for (unsigned I = 0; I != NumCatchStmts; ++I) |
| 726 | Stmts[I + 1] = CatchStmts[I]; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 727 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 728 | if (HasFinally) |
| 729 | Stmts[NumCatchStmts + 1] = atFinallyStmt; |
| 730 | } |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 731 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 732 | ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 733 | SourceLocation atTryLoc, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 734 | Stmt *atTryStmt, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 735 | Stmt **CatchStmts, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 736 | unsigned NumCatchStmts, |
| 737 | Stmt *atFinallyStmt) { |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 738 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 739 | (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *); |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 740 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 741 | return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts, |
| 742 | atFinallyStmt); |
| 743 | } |
Ted Kremenek | a496584 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 744 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 745 | ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context, |
| 746 | unsigned NumCatchStmts, |
| 747 | bool HasFinally) { |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 748 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 749 | (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *); |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 750 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 751 | return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 752 | } |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 753 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 754 | SourceLocation ObjCAtTryStmt::getLocEnd() const { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 755 | if (HasFinally) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 756 | return getFinallyStmt()->getLocEnd(); |
| 757 | if (NumCatchStmts) |
| 758 | return getCatchStmt(NumCatchStmts - 1)->getLocEnd(); |
| 759 | return getTryBody()->getLocEnd(); |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 762 | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc, |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 763 | Stmt *tryBlock, ArrayRef<Stmt*> handlers) { |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 764 | std::size_t Size = sizeof(CXXTryStmt); |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 765 | Size += ((handlers.size() + 1) * sizeof(Stmt)); |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 766 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 767 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 768 | return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 771 | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, |
Argyrios Kyrtzidis | 47cd7a9 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 772 | unsigned numHandlers) { |
| 773 | std::size_t Size = sizeof(CXXTryStmt); |
| 774 | Size += ((numHandlers + 1) * sizeof(Stmt)); |
| 775 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 776 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Argyrios Kyrtzidis | 47cd7a9 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 777 | return new (Mem) CXXTryStmt(Empty, numHandlers); |
| 778 | } |
| 779 | |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 780 | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 781 | ArrayRef<Stmt*> handlers) |
| 782 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 783 | Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); |
Sam Weinig | ebcea98 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 784 | Stmts[0] = tryBlock; |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 785 | std::copy(handlers.begin(), handlers.end(), Stmts + 1); |
Sam Weinig | ebcea98 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 788 | CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt, |
| 789 | Expr *Cond, Expr *Inc, DeclStmt *LoopVar, |
| 790 | Stmt *Body, SourceLocation FL, |
| 791 | SourceLocation CL, SourceLocation RPL) |
| 792 | : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) { |
| 793 | SubExprs[RANGE] = Range; |
| 794 | SubExprs[BEGINEND] = BeginEndStmt; |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 795 | SubExprs[COND] = Cond; |
| 796 | SubExprs[INC] = Inc; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 797 | SubExprs[LOOPVAR] = LoopVar; |
| 798 | SubExprs[BODY] = Body; |
| 799 | } |
| 800 | |
| 801 | Expr *CXXForRangeStmt::getRangeInit() { |
| 802 | DeclStmt *RangeStmt = getRangeStmt(); |
| 803 | VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl()); |
Richard Trieu | 8673869 | 2014-02-27 23:59:14 +0000 | [diff] [blame] | 804 | assert(RangeDecl && "for-range should have a single var decl"); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 805 | return RangeDecl->getInit(); |
| 806 | } |
| 807 | |
| 808 | const Expr *CXXForRangeStmt::getRangeInit() const { |
| 809 | return const_cast<CXXForRangeStmt*>(this)->getRangeInit(); |
| 810 | } |
| 811 | |
| 812 | VarDecl *CXXForRangeStmt::getLoopVariable() { |
| 813 | Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl(); |
| 814 | assert(LV && "No loop variable in CXXForRangeStmt"); |
| 815 | return cast<VarDecl>(LV); |
| 816 | } |
| 817 | |
| 818 | const VarDecl *CXXForRangeStmt::getLoopVariable() const { |
| 819 | return const_cast<CXXForRangeStmt*>(this)->getLoopVariable(); |
| 820 | } |
| 821 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 822 | IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 823 | Stmt *then, SourceLocation EL, Stmt *elsev) |
| 824 | : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL) |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 825 | { |
| 826 | setConditionVariable(C, var); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 827 | SubExprs[COND] = cond; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 828 | SubExprs[THEN] = then; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 829 | SubExprs[ELSE] = elsev; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | VarDecl *IfStmt::getConditionVariable() const { |
| 833 | if (!SubExprs[VAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 834 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 835 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 836 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 837 | return cast<VarDecl>(DS->getSingleDecl()); |
| 838 | } |
| 839 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 840 | void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 841 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 842 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 843 | return; |
| 844 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 845 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 846 | SourceRange VarRange = V->getSourceRange(); |
| 847 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 848 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 851 | ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 852 | Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 853 | SourceLocation RP) |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 854 | : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP) |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 855 | { |
| 856 | SubExprs[INIT] = Init; |
| 857 | setConditionVariable(C, condVar); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 858 | SubExprs[COND] = Cond; |
| 859 | SubExprs[INC] = Inc; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 860 | SubExprs[BODY] = Body; |
| 861 | } |
| 862 | |
| 863 | VarDecl *ForStmt::getConditionVariable() const { |
| 864 | if (!SubExprs[CONDVAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 865 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 866 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 867 | DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]); |
| 868 | return cast<VarDecl>(DS->getSingleDecl()); |
| 869 | } |
| 870 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 871 | void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 872 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 873 | SubExprs[CONDVAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 874 | return; |
| 875 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 876 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 877 | SourceRange VarRange = V->getSourceRange(); |
| 878 | SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 879 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 880 | } |
| 881 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 882 | SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 883 | : Stmt(SwitchStmtClass), FirstCase(nullptr), AllEnumCasesCovered(0) |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 884 | { |
| 885 | setConditionVariable(C, Var); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 886 | SubExprs[COND] = cond; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 887 | SubExprs[BODY] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | VarDecl *SwitchStmt::getConditionVariable() const { |
| 891 | if (!SubExprs[VAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 892 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 893 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 894 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 895 | return cast<VarDecl>(DS->getSingleDecl()); |
| 896 | } |
| 897 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 898 | void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 899 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 900 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 901 | return; |
| 902 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 903 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 904 | SourceRange VarRange = V->getSourceRange(); |
| 905 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 906 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 907 | } |
| 908 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 909 | Stmt *SwitchCase::getSubStmt() { |
Chris Lattner | 80d51eb | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 910 | if (isa<CaseStmt>(this)) |
| 911 | return cast<CaseStmt>(this)->getSubStmt(); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 912 | return cast<DefaultStmt>(this)->getSubStmt(); |
| 913 | } |
| 914 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 915 | WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 916 | SourceLocation WL) |
Chris Lattner | 80d51eb | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 917 | : Stmt(WhileStmtClass) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 918 | setConditionVariable(C, Var); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 919 | SubExprs[COND] = cond; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 920 | SubExprs[BODY] = body; |
| 921 | WhileLoc = WL; |
| 922 | } |
| 923 | |
| 924 | VarDecl *WhileStmt::getConditionVariable() const { |
| 925 | if (!SubExprs[VAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 926 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 928 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 929 | return cast<VarDecl>(DS->getSingleDecl()); |
| 930 | } |
| 931 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 932 | void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 933 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 934 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 935 | return; |
| 936 | } |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 937 | |
| 938 | SourceRange VarRange = V->getSourceRange(); |
| 939 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 940 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 943 | // IndirectGotoStmt |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 944 | LabelDecl *IndirectGotoStmt::getConstantTarget() { |
John McCall | 9de9160 | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 945 | if (AddrLabelExpr *E = |
| 946 | dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts())) |
| 947 | return E->getLabel(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 948 | return nullptr; |
John McCall | 9de9160 | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 949 | } |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 950 | |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 951 | // ReturnStmt |
Ted Kremenek | c6501db | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 952 | const Expr* ReturnStmt::getRetValue() const { |
| 953 | return cast_or_null<Expr>(RetExpr); |
| 954 | } |
| 955 | Expr* ReturnStmt::getRetValue() { |
| 956 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 957 | } |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 958 | |
| 959 | SEHTryStmt::SEHTryStmt(bool IsCXXTry, |
| 960 | SourceLocation TryLoc, |
| 961 | Stmt *TryBlock, |
| 962 | Stmt *Handler) |
| 963 | : Stmt(SEHTryStmtClass), |
| 964 | IsCXXTry(IsCXXTry), |
| 965 | TryLoc(TryLoc) |
| 966 | { |
| 967 | Children[TRY] = TryBlock; |
| 968 | Children[HANDLER] = Handler; |
| 969 | } |
| 970 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 971 | SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry, |
| 972 | SourceLocation TryLoc, Stmt *TryBlock, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 973 | Stmt *Handler) { |
| 974 | return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler); |
| 975 | } |
| 976 | |
| 977 | SEHExceptStmt* SEHTryStmt::getExceptHandler() const { |
| 978 | return dyn_cast<SEHExceptStmt>(getHandler()); |
| 979 | } |
| 980 | |
| 981 | SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const { |
| 982 | return dyn_cast<SEHFinallyStmt>(getHandler()); |
| 983 | } |
| 984 | |
| 985 | SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, |
| 986 | Expr *FilterExpr, |
| 987 | Stmt *Block) |
| 988 | : Stmt(SEHExceptStmtClass), |
| 989 | Loc(Loc) |
| 990 | { |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 991 | Children[FILTER_EXPR] = FilterExpr; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 992 | Children[BLOCK] = Block; |
| 993 | } |
| 994 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 995 | SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc, |
| 996 | Expr *FilterExpr, Stmt *Block) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 997 | return new(C) SEHExceptStmt(Loc,FilterExpr,Block); |
| 998 | } |
| 999 | |
| 1000 | SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, |
| 1001 | Stmt *Block) |
| 1002 | : Stmt(SEHFinallyStmtClass), |
| 1003 | Loc(Loc), |
| 1004 | Block(Block) |
| 1005 | {} |
| 1006 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1007 | SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1008 | Stmt *Block) { |
| 1009 | return new(C)SEHFinallyStmt(Loc,Block); |
| 1010 | } |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1011 | |
| 1012 | CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const { |
| 1013 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1014 | |
| 1015 | // Offset of the first Capture object. |
| 1016 | unsigned FirstCaptureOffset = |
| 1017 | llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1018 | |
| 1019 | return reinterpret_cast<Capture *>( |
| 1020 | reinterpret_cast<char *>(const_cast<CapturedStmt *>(this)) |
| 1021 | + FirstCaptureOffset); |
| 1022 | } |
| 1023 | |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1024 | CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind, |
| 1025 | ArrayRef<Capture> Captures, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1026 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1027 | CapturedDecl *CD, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1028 | RecordDecl *RD) |
| 1029 | : Stmt(CapturedStmtClass), NumCaptures(Captures.size()), |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1030 | CapDeclAndKind(CD, Kind), TheRecordDecl(RD) { |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1031 | assert( S && "null captured statement"); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1032 | assert(CD && "null captured declaration for captured statement"); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1033 | assert(RD && "null record declaration for captured statement"); |
| 1034 | |
| 1035 | // Copy initialization expressions. |
| 1036 | Stmt **Stored = getStoredStmts(); |
| 1037 | for (unsigned I = 0, N = NumCaptures; I != N; ++I) |
| 1038 | *Stored++ = CaptureInits[I]; |
| 1039 | |
| 1040 | // Copy the statement being captured. |
| 1041 | *Stored = S; |
| 1042 | |
| 1043 | // Copy all Capture objects. |
| 1044 | Capture *Buffer = getStoredCaptures(); |
| 1045 | std::copy(Captures.begin(), Captures.end(), Buffer); |
| 1046 | } |
| 1047 | |
| 1048 | CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures) |
| 1049 | : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1050 | CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) { |
| 1051 | getStoredStmts()[NumCaptures] = nullptr; |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1054 | CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S, |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1055 | CapturedRegionKind Kind, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1056 | ArrayRef<Capture> Captures, |
| 1057 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1058 | CapturedDecl *CD, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1059 | RecordDecl *RD) { |
| 1060 | // The layout is |
| 1061 | // |
| 1062 | // ----------------------------------------------------------- |
| 1063 | // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture | |
| 1064 | // ----------------^-------------------^---------------------- |
| 1065 | // getStoredStmts() getStoredCaptures() |
| 1066 | // |
| 1067 | // where S is the statement being captured. |
| 1068 | // |
| 1069 | assert(CaptureInits.size() == Captures.size() && "wrong number of arguments"); |
| 1070 | |
| 1071 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1); |
| 1072 | if (!Captures.empty()) { |
| 1073 | // Realign for the following Capture array. |
| 1074 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1075 | Size += sizeof(Capture) * Captures.size(); |
| 1076 | } |
| 1077 | |
| 1078 | void *Mem = Context.Allocate(Size); |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1079 | return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1082 | CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1083 | unsigned NumCaptures) { |
| 1084 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1085 | if (NumCaptures > 0) { |
| 1086 | // Realign for the following Capture array. |
| 1087 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1088 | Size += sizeof(Capture) * NumCaptures; |
| 1089 | } |
| 1090 | |
| 1091 | void *Mem = Context.Allocate(Size); |
| 1092 | return new (Mem) CapturedStmt(EmptyShell(), NumCaptures); |
| 1093 | } |
| 1094 | |
| 1095 | Stmt::child_range CapturedStmt::children() { |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1096 | // Children are captured field initilizers. |
| 1097 | return child_range(getStoredStmts(), getStoredStmts() + NumCaptures); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | bool CapturedStmt::capturesVariable(const VarDecl *Var) const { |
Aaron Ballman | c656303a | 2014-03-14 18:08:33 +0000 | [diff] [blame] | 1101 | for (const auto &I : captures()) { |
| 1102 | if (!I.capturesVariable()) |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1103 | continue; |
| 1104 | |
| 1105 | // This does not handle variable redeclarations. This should be |
| 1106 | // extended to capture variables with redeclarations, for example |
| 1107 | // a thread-private variable in OpenMP. |
Aaron Ballman | c656303a | 2014-03-14 18:08:33 +0000 | [diff] [blame] | 1108 | if (I.getCapturedVar() == Var) |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1109 | return true; |
| 1110 | } |
| 1111 | |
| 1112 | return false; |
| 1113 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1114 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1115 | StmtRange OMPClause::children() { |
| 1116 | switch(getClauseKind()) { |
| 1117 | default : break; |
| 1118 | #define OPENMP_CLAUSE(Name, Class) \ |
| 1119 | case OMPC_ ## Name : return static_cast<Class *>(this)->children(); |
| 1120 | #include "clang/Basic/OpenMPKinds.def" |
| 1121 | } |
| 1122 | llvm_unreachable("unknown OMPClause"); |
| 1123 | } |
| 1124 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1125 | OMPPrivateClause *OMPPrivateClause::Create(const ASTContext &C, |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1126 | SourceLocation StartLoc, |
| 1127 | SourceLocation LParenLoc, |
| 1128 | SourceLocation EndLoc, |
| 1129 | ArrayRef<Expr *> VL) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1130 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), |
| 1131 | llvm::alignOf<Expr *>()) + |
| 1132 | sizeof(Expr *) * VL.size()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1133 | OMPPrivateClause *Clause = new (Mem) OMPPrivateClause(StartLoc, LParenLoc, |
| 1134 | EndLoc, VL.size()); |
| 1135 | Clause->setVarRefs(VL); |
| 1136 | return Clause; |
| 1137 | } |
| 1138 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1139 | OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1140 | unsigned N) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1141 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), |
| 1142 | llvm::alignOf<Expr *>()) + |
| 1143 | sizeof(Expr *) * N); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1144 | return new (Mem) OMPPrivateClause(N); |
| 1145 | } |
| 1146 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1147 | OMPFirstprivateClause *OMPFirstprivateClause::Create(const ASTContext &C, |
| 1148 | SourceLocation StartLoc, |
| 1149 | SourceLocation LParenLoc, |
| 1150 | SourceLocation EndLoc, |
| 1151 | ArrayRef<Expr *> VL) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1152 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), |
| 1153 | llvm::alignOf<Expr *>()) + |
| 1154 | sizeof(Expr *) * VL.size()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1155 | OMPFirstprivateClause *Clause = new (Mem) OMPFirstprivateClause(StartLoc, |
| 1156 | LParenLoc, |
| 1157 | EndLoc, |
| 1158 | VL.size()); |
| 1159 | Clause->setVarRefs(VL); |
| 1160 | return Clause; |
| 1161 | } |
| 1162 | |
| 1163 | OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, |
| 1164 | unsigned N) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1165 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), |
| 1166 | llvm::alignOf<Expr *>()) + |
| 1167 | sizeof(Expr *) * N); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1168 | return new (Mem) OMPFirstprivateClause(N); |
| 1169 | } |
| 1170 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1171 | OMPLastprivateClause *OMPLastprivateClause::Create(const ASTContext &C, |
| 1172 | SourceLocation StartLoc, |
| 1173 | SourceLocation LParenLoc, |
| 1174 | SourceLocation EndLoc, |
| 1175 | ArrayRef<Expr *> VL) { |
| 1176 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), |
| 1177 | llvm::alignOf<Expr *>()) + |
| 1178 | sizeof(Expr *) * VL.size()); |
| 1179 | OMPLastprivateClause *Clause = |
| 1180 | new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1181 | Clause->setVarRefs(VL); |
| 1182 | return Clause; |
| 1183 | } |
| 1184 | |
| 1185 | OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, |
| 1186 | unsigned N) { |
| 1187 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), |
| 1188 | llvm::alignOf<Expr *>()) + |
| 1189 | sizeof(Expr *) * N); |
| 1190 | return new (Mem) OMPLastprivateClause(N); |
| 1191 | } |
| 1192 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1193 | OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, |
| 1194 | SourceLocation StartLoc, |
| 1195 | SourceLocation LParenLoc, |
| 1196 | SourceLocation EndLoc, |
| 1197 | ArrayRef<Expr *> VL) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1198 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), |
| 1199 | llvm::alignOf<Expr *>()) + |
| 1200 | sizeof(Expr *) * VL.size()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1201 | OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc, |
| 1202 | EndLoc, VL.size()); |
| 1203 | Clause->setVarRefs(VL); |
| 1204 | return Clause; |
| 1205 | } |
| 1206 | |
| 1207 | OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, |
| 1208 | unsigned N) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1209 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), |
| 1210 | llvm::alignOf<Expr *>()) + |
| 1211 | sizeof(Expr *) * N); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1212 | return new (Mem) OMPSharedClause(N); |
| 1213 | } |
| 1214 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1215 | OMPLinearClause *OMPLinearClause::Create(const ASTContext &C, |
| 1216 | SourceLocation StartLoc, |
| 1217 | SourceLocation LParenLoc, |
| 1218 | SourceLocation ColonLoc, |
| 1219 | SourceLocation EndLoc, |
| 1220 | ArrayRef<Expr *> VL, Expr *Step) { |
| 1221 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), |
| 1222 | llvm::alignOf<Expr *>()) + |
| 1223 | sizeof(Expr *) * (VL.size() + 1)); |
| 1224 | OMPLinearClause *Clause = new (Mem) |
| 1225 | OMPLinearClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 1226 | Clause->setVarRefs(VL); |
| 1227 | Clause->setStep(Step); |
| 1228 | return Clause; |
| 1229 | } |
| 1230 | |
| 1231 | OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, |
| 1232 | unsigned NumVars) { |
| 1233 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), |
| 1234 | llvm::alignOf<Expr *>()) + |
| 1235 | sizeof(Expr *) * (NumVars + 1)); |
| 1236 | return new (Mem) OMPLinearClause(NumVars); |
| 1237 | } |
| 1238 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1239 | OMPAlignedClause * |
| 1240 | OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1241 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 1242 | SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { |
| 1243 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), |
| 1244 | llvm::alignOf<Expr *>()) + |
| 1245 | sizeof(Expr *) * (VL.size() + 1)); |
| 1246 | OMPAlignedClause *Clause = new (Mem) |
| 1247 | OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 1248 | Clause->setVarRefs(VL); |
| 1249 | Clause->setAlignment(A); |
| 1250 | return Clause; |
| 1251 | } |
| 1252 | |
| 1253 | OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, |
| 1254 | unsigned NumVars) { |
| 1255 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), |
| 1256 | llvm::alignOf<Expr *>()) + |
| 1257 | sizeof(Expr *) * (NumVars + 1)); |
| 1258 | return new (Mem) OMPAlignedClause(NumVars); |
| 1259 | } |
| 1260 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1261 | OMPCopyinClause *OMPCopyinClause::Create(const ASTContext &C, |
| 1262 | SourceLocation StartLoc, |
| 1263 | SourceLocation LParenLoc, |
| 1264 | SourceLocation EndLoc, |
| 1265 | ArrayRef<Expr *> VL) { |
| 1266 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), |
| 1267 | llvm::alignOf<Expr *>()) + |
| 1268 | sizeof(Expr *) * VL.size()); |
| 1269 | OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc, |
| 1270 | EndLoc, VL.size()); |
| 1271 | Clause->setVarRefs(VL); |
| 1272 | return Clause; |
| 1273 | } |
| 1274 | |
| 1275 | OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, |
| 1276 | unsigned N) { |
| 1277 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), |
| 1278 | llvm::alignOf<Expr *>()) + |
| 1279 | sizeof(Expr *) * N); |
| 1280 | return new (Mem) OMPCopyinClause(N); |
| 1281 | } |
| 1282 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1283 | void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) { |
Alexander Musman | fd2b759 | 2014-03-27 15:14:18 +0000 | [diff] [blame] | 1284 | assert(Clauses.size() == getNumClauses() && |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1285 | "Number of clauses is not the same as the preallocated buffer"); |
Alexander Musman | fd2b759 | 2014-03-27 15:14:18 +0000 | [diff] [blame] | 1286 | std::copy(Clauses.begin(), Clauses.end(), getClauses().begin()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1289 | OMPReductionClause *OMPReductionClause::Create( |
| 1290 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1291 | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
| 1292 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo) { |
| 1293 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), |
| 1294 | llvm::alignOf<Expr *>()) + |
| 1295 | sizeof(Expr *) * VL.size()); |
| 1296 | OMPReductionClause *Clause = new (Mem) OMPReductionClause( |
| 1297 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
| 1298 | Clause->setVarRefs(VL); |
| 1299 | return Clause; |
| 1300 | } |
| 1301 | |
| 1302 | OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, |
| 1303 | unsigned N) { |
| 1304 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), |
| 1305 | llvm::alignOf<Expr *>()) + |
| 1306 | sizeof(Expr *) * N); |
| 1307 | return new (Mem) OMPReductionClause(N); |
| 1308 | } |
| 1309 | |
Craig Topper | cee6133 | 2013-08-21 04:01:01 +0000 | [diff] [blame] | 1310 | OMPParallelDirective *OMPParallelDirective::Create( |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1311 | const ASTContext &C, |
Craig Topper | cee6133 | 2013-08-21 04:01:01 +0000 | [diff] [blame] | 1312 | SourceLocation StartLoc, |
| 1313 | SourceLocation EndLoc, |
| 1314 | ArrayRef<OMPClause *> Clauses, |
| 1315 | Stmt *AssociatedStmt) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1316 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), |
| 1317 | llvm::alignOf<OMPClause *>()); |
| 1318 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1319 | sizeof(Stmt *)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1320 | OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc, |
| 1321 | Clauses.size()); |
| 1322 | Dir->setClauses(Clauses); |
| 1323 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1324 | return Dir; |
| 1325 | } |
| 1326 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1327 | OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1328 | unsigned NumClauses, |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1329 | EmptyShell) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1330 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), |
| 1331 | llvm::alignOf<OMPClause *>()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1332 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1333 | sizeof(Stmt *)); |
| 1334 | return new (Mem) OMPParallelDirective(NumClauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1335 | } |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1336 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1337 | OMPSimdDirective * |
| 1338 | OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1339 | SourceLocation EndLoc, unsigned CollapsedNum, |
| 1340 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1341 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), |
| 1342 | llvm::alignOf<OMPClause *>()); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1343 | void *Mem = |
| 1344 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1345 | OMPSimdDirective *Dir = new (Mem) |
| 1346 | OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1347 | Dir->setClauses(Clauses); |
| 1348 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1349 | return Dir; |
| 1350 | } |
| 1351 | |
| 1352 | OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C, |
| 1353 | unsigned NumClauses, |
| 1354 | unsigned CollapsedNum, |
| 1355 | EmptyShell) { |
| 1356 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), |
| 1357 | llvm::alignOf<OMPClause *>()); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1358 | void *Mem = |
| 1359 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1360 | return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses); |
| 1361 | } |
| 1362 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1363 | OMPForDirective * |
| 1364 | OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1365 | SourceLocation EndLoc, unsigned CollapsedNum, |
| 1366 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1367 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), |
| 1368 | llvm::alignOf<OMPClause *>()); |
| 1369 | void *Mem = |
| 1370 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1371 | OMPForDirective *Dir = |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1372 | new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1373 | Dir->setClauses(Clauses); |
| 1374 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1375 | return Dir; |
| 1376 | } |
| 1377 | |
| 1378 | OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C, |
| 1379 | unsigned NumClauses, |
| 1380 | unsigned CollapsedNum, |
| 1381 | EmptyShell) { |
| 1382 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), |
| 1383 | llvm::alignOf<OMPClause *>()); |
| 1384 | void *Mem = |
| 1385 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1386 | return new (Mem) OMPForDirective(CollapsedNum, NumClauses); |
| 1387 | } |
| 1388 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1389 | OMPSectionsDirective *OMPSectionsDirective::Create( |
| 1390 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1391 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
| 1392 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1393 | llvm::alignOf<OMPClause *>()); |
| 1394 | void *Mem = |
| 1395 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1396 | OMPSectionsDirective *Dir = |
| 1397 | new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size()); |
| 1398 | Dir->setClauses(Clauses); |
| 1399 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1400 | return Dir; |
| 1401 | } |
| 1402 | |
| 1403 | OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C, |
| 1404 | unsigned NumClauses, |
| 1405 | EmptyShell) { |
| 1406 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1407 | llvm::alignOf<OMPClause *>()); |
| 1408 | void *Mem = |
| 1409 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1410 | return new (Mem) OMPSectionsDirective(NumClauses); |
| 1411 | } |
| 1412 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame^] | 1413 | OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C, |
| 1414 | SourceLocation StartLoc, |
| 1415 | SourceLocation EndLoc, |
| 1416 | Stmt *AssociatedStmt) { |
| 1417 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1418 | llvm::alignOf<Stmt *>()); |
| 1419 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1420 | OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); |
| 1421 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1422 | return Dir; |
| 1423 | } |
| 1424 | |
| 1425 | OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C, |
| 1426 | EmptyShell) { |
| 1427 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective), |
| 1428 | llvm::alignOf<Stmt *>()); |
| 1429 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1430 | return new (Mem) OMPSectionDirective(); |
| 1431 | } |
| 1432 | |