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 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 107 | /// \brief Skip no-op (attributed, compound) container stmts and skip captured |
| 108 | /// stmt at the top, if \a IgnoreCaptured is true. |
| 109 | Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) { |
| 110 | Stmt *S = this; |
| 111 | if (IgnoreCaptured) |
| 112 | if (auto CapS = dyn_cast_or_null<CapturedStmt>(S)) |
| 113 | S = CapS->getCapturedStmt(); |
| 114 | while (true) { |
| 115 | if (auto AS = dyn_cast_or_null<AttributedStmt>(S)) |
| 116 | S = AS->getSubStmt(); |
| 117 | else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) { |
| 118 | if (CS->size() != 1) |
| 119 | break; |
| 120 | S = CS->body_back(); |
| 121 | } else |
| 122 | break; |
| 123 | } |
| 124 | return S; |
| 125 | } |
| 126 | |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 127 | /// \brief Strip off all label-like statements. |
| 128 | /// |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 129 | /// This will strip off label statements, case statements, attributed |
| 130 | /// statements and default statements recursively. |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 131 | const Stmt *Stmt::stripLabelLikeStatements() const { |
| 132 | const Stmt *S = this; |
| 133 | while (true) { |
| 134 | if (const LabelStmt *LS = dyn_cast<LabelStmt>(S)) |
| 135 | S = LS->getSubStmt(); |
| 136 | else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S)) |
| 137 | S = SC->getSubStmt(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 138 | else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S)) |
| 139 | S = AS->getSubStmt(); |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 140 | else |
| 141 | return S; |
| 142 | } |
| 143 | } |
| 144 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 145 | namespace { |
| 146 | struct good {}; |
| 147 | struct bad {}; |
John McCall | f75152f | 2011-02-09 08:31:17 +0000 | [diff] [blame] | 148 | |
| 149 | // These silly little functions have to be static inline to suppress |
| 150 | // unused warnings, and they have to be defined to suppress other |
| 151 | // warnings. |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 152 | static inline good is_good(good) { return good(); } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 153 | |
| 154 | typedef Stmt::child_range children_t(); |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 155 | template <class T> good implements_children(children_t T::*) { |
| 156 | return good(); |
| 157 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 158 | LLVM_ATTRIBUTE_UNUSED |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 159 | static inline bad implements_children(children_t Stmt::*) { |
| 160 | return bad(); |
| 161 | } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 162 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 163 | typedef SourceLocation getLocStart_t() const; |
| 164 | template <class T> good implements_getLocStart(getLocStart_t T::*) { |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 165 | return good(); |
| 166 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 167 | LLVM_ATTRIBUTE_UNUSED |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 168 | static inline bad implements_getLocStart(getLocStart_t Stmt::*) { |
| 169 | return bad(); |
| 170 | } |
| 171 | |
| 172 | typedef SourceLocation getLocEnd_t() const; |
| 173 | template <class T> good implements_getLocEnd(getLocEnd_t T::*) { |
| 174 | return good(); |
| 175 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 176 | LLVM_ATTRIBUTE_UNUSED |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 177 | static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) { |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 178 | return bad(); |
| 179 | } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 180 | |
| 181 | #define ASSERT_IMPLEMENTS_children(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 182 | (void) is_good(implements_children(&type::children)) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 183 | #define ASSERT_IMPLEMENTS_getLocStart(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 184 | (void) is_good(implements_getLocStart(&type::getLocStart)) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 185 | #define ASSERT_IMPLEMENTS_getLocEnd(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 186 | (void) is_good(implements_getLocEnd(&type::getLocEnd)) |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /// Check whether the various Stmt classes implement their member |
| 190 | /// functions. |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 191 | LLVM_ATTRIBUTE_UNUSED |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 192 | static inline void check_implementations() { |
| 193 | #define ABSTRACT_STMT(type) |
| 194 | #define STMT(type, base) \ |
| 195 | ASSERT_IMPLEMENTS_children(type); \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 196 | ASSERT_IMPLEMENTS_getLocStart(type); \ |
| 197 | ASSERT_IMPLEMENTS_getLocEnd(type); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 198 | #include "clang/AST/StmtNodes.inc" |
| 199 | } |
| 200 | |
| 201 | Stmt::child_range Stmt::children() { |
| 202 | switch (getStmtClass()) { |
| 203 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 204 | #define ABSTRACT_STMT(type) |
| 205 | #define STMT(type, base) \ |
| 206 | case Stmt::type##Class: \ |
| 207 | return static_cast<type*>(this)->children(); |
| 208 | #include "clang/AST/StmtNodes.inc" |
| 209 | } |
| 210 | llvm_unreachable("unknown statement kind!"); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 213 | // Amusing macro metaprogramming hack: check whether a class provides |
| 214 | // a more specific implementation of getSourceRange. |
| 215 | // |
| 216 | // See also Expr.cpp:getExprLoc(). |
| 217 | namespace { |
| 218 | /// This implementation is used when a class provides a custom |
| 219 | /// implementation of getSourceRange. |
| 220 | template <class S, class T> |
| 221 | SourceRange getSourceRangeImpl(const Stmt *stmt, |
| 222 | SourceRange (T::*v)() const) { |
| 223 | return static_cast<const S*>(stmt)->getSourceRange(); |
| 224 | } |
| 225 | |
| 226 | /// This implementation is used when a class doesn't provide a custom |
| 227 | /// implementation of getSourceRange. Overload resolution should pick it over |
| 228 | /// the implementation above because it's more specialized according to |
| 229 | /// function template partial ordering. |
| 230 | template <class S> |
| 231 | SourceRange getSourceRangeImpl(const Stmt *stmt, |
| 232 | SourceRange (Stmt::*v)() const) { |
| 233 | return SourceRange(static_cast<const S*>(stmt)->getLocStart(), |
| 234 | static_cast<const S*>(stmt)->getLocEnd()); |
| 235 | } |
| 236 | } |
| 237 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 238 | SourceRange Stmt::getSourceRange() const { |
| 239 | switch (getStmtClass()) { |
| 240 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 241 | #define ABSTRACT_STMT(type) |
| 242 | #define STMT(type, base) \ |
| 243 | case Stmt::type##Class: \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 244 | return getSourceRangeImpl<type>(this, &type::getSourceRange); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 245 | #include "clang/AST/StmtNodes.inc" |
| 246 | } |
| 247 | llvm_unreachable("unknown statement kind!"); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 250 | SourceLocation Stmt::getLocStart() const { |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 251 | // llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n"; |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 252 | switch (getStmtClass()) { |
| 253 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 254 | #define ABSTRACT_STMT(type) |
| 255 | #define STMT(type, base) \ |
| 256 | case Stmt::type##Class: \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 257 | return static_cast<const type*>(this)->getLocStart(); |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 258 | #include "clang/AST/StmtNodes.inc" |
| 259 | } |
| 260 | llvm_unreachable("unknown statement kind"); |
| 261 | } |
| 262 | |
| 263 | SourceLocation Stmt::getLocEnd() const { |
| 264 | switch (getStmtClass()) { |
| 265 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 266 | #define ABSTRACT_STMT(type) |
| 267 | #define STMT(type, base) \ |
| 268 | case Stmt::type##Class: \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 269 | return static_cast<const type*>(this)->getLocEnd(); |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 270 | #include "clang/AST/StmtNodes.inc" |
| 271 | } |
| 272 | llvm_unreachable("unknown statement kind"); |
| 273 | } |
| 274 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 275 | CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 276 | SourceLocation LB, SourceLocation RB) |
| 277 | : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { |
Nico Weber | a2a0eb9 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 278 | CompoundStmtBits.NumStmts = Stmts.size(); |
| 279 | assert(CompoundStmtBits.NumStmts == Stmts.size() && |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 280 | "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); |
| 281 | |
Nico Weber | a2a0eb9 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 282 | if (Stmts.size() == 0) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 283 | Body = nullptr; |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 284 | return; |
| 285 | } |
| 286 | |
Nico Weber | a2a0eb9 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 287 | Body = new (C) Stmt*[Stmts.size()]; |
| 288 | std::copy(Stmts.begin(), Stmts.end(), Body); |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 291 | void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts, |
| 292 | unsigned NumStmts) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 293 | if (this->Body) |
| 294 | C.Deallocate(Body); |
John McCall | 925b1662 | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 295 | this->CompoundStmtBits.NumStmts = NumStmts; |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 296 | |
| 297 | Body = new (C) Stmt*[NumStmts]; |
| 298 | memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts); |
| 299 | } |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 300 | |
Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 301 | const char *LabelStmt::getName() const { |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 302 | return getDecl()->getIdentifier()->getNameStart(); |
Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 305 | AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 306 | ArrayRef<const Attr*> Attrs, |
| 307 | Stmt *SubStmt) { |
Aaron Ballman | f3d9b09 | 2014-05-13 14:55:01 +0000 | [diff] [blame] | 308 | assert(!Attrs.empty() && "Attrs should not be empty"); |
| 309 | void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(), |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 310 | llvm::alignOf<AttributedStmt>()); |
| 311 | return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); |
| 312 | } |
| 313 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 314 | AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, |
| 315 | unsigned NumAttrs) { |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 316 | assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); |
Aaron Ballman | f3d9b09 | 2014-05-13 14:55:01 +0000 | [diff] [blame] | 317 | void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs, |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 318 | llvm::alignOf<AttributedStmt>()); |
| 319 | return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); |
| 320 | } |
| 321 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 322 | std::string AsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 323 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 324 | return gccAsmStmt->generateAsmString(C); |
| 325 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 326 | return msAsmStmt->generateAsmString(C); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 327 | llvm_unreachable("unknown asm statement kind!"); |
| 328 | } |
| 329 | |
| 330 | StringRef AsmStmt::getOutputConstraint(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 331 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 332 | return gccAsmStmt->getOutputConstraint(i); |
| 333 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 334 | return msAsmStmt->getOutputConstraint(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 335 | llvm_unreachable("unknown asm statement kind!"); |
| 336 | } |
| 337 | |
| 338 | const Expr *AsmStmt::getOutputExpr(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 339 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 340 | return gccAsmStmt->getOutputExpr(i); |
| 341 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 342 | return msAsmStmt->getOutputExpr(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 343 | llvm_unreachable("unknown asm statement kind!"); |
| 344 | } |
| 345 | |
| 346 | StringRef AsmStmt::getInputConstraint(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 347 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 348 | return gccAsmStmt->getInputConstraint(i); |
| 349 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 350 | return msAsmStmt->getInputConstraint(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 351 | llvm_unreachable("unknown asm statement kind!"); |
| 352 | } |
| 353 | |
| 354 | const Expr *AsmStmt::getInputExpr(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 355 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 356 | return gccAsmStmt->getInputExpr(i); |
| 357 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 358 | return msAsmStmt->getInputExpr(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 359 | llvm_unreachable("unknown asm statement kind!"); |
| 360 | } |
| 361 | |
| 362 | StringRef AsmStmt::getClobber(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 363 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 364 | return gccAsmStmt->getClobber(i); |
| 365 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 366 | return msAsmStmt->getClobber(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 367 | llvm_unreachable("unknown asm statement kind!"); |
| 368 | } |
| 369 | |
Chad Rosier | a1b5c8c | 2012-08-28 00:24:05 +0000 | [diff] [blame] | 370 | /// getNumPlusOperands - Return the number of output operands that have a "+" |
| 371 | /// constraint. |
| 372 | unsigned AsmStmt::getNumPlusOperands() const { |
| 373 | unsigned Res = 0; |
| 374 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) |
| 375 | if (isOutputPlusConstraint(i)) |
| 376 | ++Res; |
| 377 | return Res; |
| 378 | } |
| 379 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 380 | char GCCAsmStmt::AsmStringPiece::getModifier() const { |
| 381 | assert(isOperand() && "Only Operands can have modifiers."); |
| 382 | return isLetter(Str[0]) ? Str[0] : '\0'; |
| 383 | } |
| 384 | |
Chad Rosier | 6100ae1 | 2012-08-27 23:47:56 +0000 | [diff] [blame] | 385 | StringRef GCCAsmStmt::getClobber(unsigned i) const { |
| 386 | return getClobberStringLiteral(i)->getString(); |
| 387 | } |
| 388 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 389 | Expr *GCCAsmStmt::getOutputExpr(unsigned i) { |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 390 | return cast<Expr>(Exprs[i]); |
| 391 | } |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 392 | |
| 393 | /// getOutputConstraint - Return the constraint string for the specified |
| 394 | /// output operand. All output constraints are known to be non-empty (either |
| 395 | /// '=' or '+'). |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 396 | StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const { |
Anders Carlsson | 66de081 | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 397 | return getOutputConstraintLiteral(i)->getString(); |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 398 | } |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 399 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 400 | Expr *GCCAsmStmt::getInputExpr(unsigned i) { |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 401 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 402 | } |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 403 | void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) { |
Chris Lattner | 93ede02 | 2011-02-21 22:09:29 +0000 | [diff] [blame] | 404 | Exprs[i + NumOutputs] = E; |
| 405 | } |
| 406 | |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 407 | /// getInputConstraint - Return the specified input constraint. Unlike output |
| 408 | /// constraints, these can be empty. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 409 | StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { |
Anders Carlsson | 66de081 | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 410 | return getInputConstraintLiteral(i)->getString(); |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 413 | void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C, |
| 414 | IdentifierInfo **Names, |
| 415 | StringLiteral **Constraints, |
| 416 | Stmt **Exprs, |
| 417 | unsigned NumOutputs, |
| 418 | unsigned NumInputs, |
| 419 | StringLiteral **Clobbers, |
| 420 | unsigned NumClobbers) { |
Douglas Gregor | f994f06 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 421 | this->NumOutputs = NumOutputs; |
| 422 | this->NumInputs = NumInputs; |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 423 | this->NumClobbers = NumClobbers; |
| 424 | |
| 425 | unsigned NumExprs = NumOutputs + NumInputs; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 426 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 427 | C.Deallocate(this->Names); |
| 428 | this->Names = new (C) IdentifierInfo*[NumExprs]; |
| 429 | std::copy(Names, Names + NumExprs, this->Names); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 430 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 431 | C.Deallocate(this->Exprs); |
| 432 | this->Exprs = new (C) Stmt*[NumExprs]; |
| 433 | std::copy(Exprs, Exprs + NumExprs, this->Exprs); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 434 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 435 | C.Deallocate(this->Constraints); |
| 436 | this->Constraints = new (C) StringLiteral*[NumExprs]; |
| 437 | std::copy(Constraints, Constraints + NumExprs, this->Constraints); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 438 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 439 | C.Deallocate(this->Clobbers); |
| 440 | this->Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 441 | std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers); |
Douglas Gregor | f994f06 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 444 | /// getNamedOperand - Given a symbolic operand reference like %[foo], |
| 445 | /// translate this into a numeric value needed to reference the same operand. |
| 446 | /// This returns -1 if the operand name is invalid. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 447 | int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 448 | unsigned NumPlusOperands = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 450 | // Check if this is an output operand. |
| 451 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { |
| 452 | if (getOutputName(i) == SymbolicName) |
| 453 | return i; |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 454 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 456 | for (unsigned i = 0, e = getNumInputs(); i != e; ++i) |
| 457 | if (getInputName(i) == SymbolicName) |
| 458 | return getNumOutputs() + NumPlusOperands + i; |
| 459 | |
| 460 | // Not found. |
| 461 | return -1; |
| 462 | } |
| 463 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 464 | /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing |
| 465 | /// it into pieces. If the asm string is erroneous, emit errors and return |
| 466 | /// true, otherwise return false. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 467 | unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 468 | const ASTContext &C, unsigned &DiagOffs) const { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 469 | StringRef Str = getAsmString()->getString(); |
Benjamin Kramer | 35b077e | 2010-08-17 12:54:38 +0000 | [diff] [blame] | 470 | const char *StrStart = Str.begin(); |
| 471 | const char *StrEnd = Str.end(); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 472 | const char *CurPtr = StrStart; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 473 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 474 | // "Simple" inline asms have no constraints or operands, just convert the asm |
| 475 | // string to escape $'s. |
| 476 | if (isSimple()) { |
| 477 | std::string Result; |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 478 | for (; CurPtr != StrEnd; ++CurPtr) { |
| 479 | switch (*CurPtr) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 480 | case '$': |
| 481 | Result += "$$"; |
| 482 | break; |
| 483 | default: |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 484 | Result += *CurPtr; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 485 | break; |
| 486 | } |
| 487 | } |
| 488 | Pieces.push_back(AsmStringPiece(Result)); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 489 | return 0; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | // CurStringPiece - The current string that we are building up as we scan the |
| 493 | // asm string. |
| 494 | std::string CurStringPiece; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | |
Douglas Gregor | e8bbc12 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 496 | bool HasVariants = !C.getTargetInfo().hasNoAsmVariants(); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 497 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 498 | while (1) { |
| 499 | // Done with the string? |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 500 | if (CurPtr == StrEnd) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 501 | if (!CurStringPiece.empty()) |
| 502 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 503 | return 0; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 504 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 505 | |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 506 | char CurChar = *CurPtr++; |
Chris Lattner | da081a8 | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 507 | switch (CurChar) { |
| 508 | case '$': CurStringPiece += "$$"; continue; |
Chris Lattner | 1a8f394 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 509 | case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue; |
| 510 | case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue; |
| 511 | case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue; |
Chris Lattner | da081a8 | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 512 | case '%': |
| 513 | break; |
| 514 | default: |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 515 | CurStringPiece += CurChar; |
| 516 | continue; |
| 517 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 518 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 519 | // Escaped "%" character in asm string. |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 520 | if (CurPtr == StrEnd) { |
| 521 | // % at end of string is invalid (no escape). |
| 522 | DiagOffs = CurPtr-StrStart-1; |
| 523 | return diag::err_asm_invalid_escape; |
| 524 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 526 | char EscapedChar = *CurPtr++; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 527 | if (EscapedChar == '%') { // %% -> % |
| 528 | // Escaped percentage sign. |
| 529 | CurStringPiece += '%'; |
| 530 | continue; |
| 531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 532 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 533 | if (EscapedChar == '=') { // %= -> Generate an unique ID. |
| 534 | CurStringPiece += "${:uid}"; |
| 535 | continue; |
| 536 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 538 | // Otherwise, we have an operand. If we have accumulated a string so far, |
| 539 | // add it to the Pieces list. |
| 540 | if (!CurStringPiece.empty()) { |
| 541 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
| 542 | CurStringPiece.clear(); |
| 543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 545 | // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that |
| 546 | // don't (e.g., %x4). 'x' following the '%' is the constraint modifier. |
| 547 | |
| 548 | const char *Begin = CurPtr - 1; // Points to the character following '%'. |
| 549 | const char *Percent = Begin - 1; // Points to '%'. |
| 550 | |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 551 | if (isLetter(EscapedChar)) { |
Benjamin Kramer | e87c38b | 2011-07-05 11:13:37 +0000 | [diff] [blame] | 552 | if (CurPtr == StrEnd) { // Premature end. |
| 553 | DiagOffs = CurPtr-StrStart-1; |
| 554 | return diag::err_asm_invalid_escape; |
| 555 | } |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 556 | EscapedChar = *CurPtr++; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 557 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 558 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 559 | const TargetInfo &TI = C.getTargetInfo(); |
| 560 | const SourceManager &SM = C.getSourceManager(); |
| 561 | const LangOptions &LO = C.getLangOpts(); |
| 562 | |
| 563 | // Handle operands that don't have asmSymbolicName (e.g., %x4). |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 564 | if (isDigit(EscapedChar)) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 565 | // %n - Assembler operand n |
Chris Lattner | 99d892b | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 566 | unsigned N = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 567 | |
Chris Lattner | 99d892b | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 568 | --CurPtr; |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 569 | while (CurPtr != StrEnd && isDigit(*CurPtr)) |
Chris Lattner | 84f3afa | 2009-03-11 23:09:16 +0000 | [diff] [blame] | 570 | N = N*10 + ((*CurPtr++)-'0'); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 571 | |
Chris Lattner | 1431192 | 2009-03-11 00:23:13 +0000 | [diff] [blame] | 572 | unsigned NumOperands = |
| 573 | getNumOutputs() + getNumPlusOperands() + getNumInputs(); |
| 574 | if (N >= NumOperands) { |
| 575 | DiagOffs = CurPtr-StrStart-1; |
| 576 | return diag::err_asm_invalid_operand_number; |
| 577 | } |
| 578 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 579 | // Str contains "x4" (Operand without the leading %). |
| 580 | std::string Str(Begin, CurPtr - Begin); |
| 581 | |
| 582 | // (BeginLoc, EndLoc) represents the range of the operand we are currently |
| 583 | // processing. Unlike Str, the range includes the leading '%'. |
| 584 | SourceLocation BeginLoc = |
| 585 | getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI); |
| 586 | SourceLocation EndLoc = |
| 587 | getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI); |
| 588 | |
| 589 | Pieces.push_back(AsmStringPiece(N, Str, BeginLoc, EndLoc)); |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 590 | continue; |
| 591 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 592 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 593 | // Handle operands that have asmSymbolicName (e.g., %x[foo]). |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 594 | if (EscapedChar == '[') { |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 595 | DiagOffs = CurPtr-StrStart-1; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 596 | |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 597 | // Find the ']'. |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 598 | const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 599 | if (NameEnd == nullptr) |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 600 | return diag::err_asm_unterminated_symbolic_operand_name; |
| 601 | if (NameEnd == CurPtr) |
| 602 | return diag::err_asm_empty_symbolic_operand_name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 604 | StringRef SymbolicName(CurPtr, NameEnd - CurPtr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 606 | int N = getNamedOperand(SymbolicName); |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 607 | if (N == -1) { |
| 608 | // Verify that an operand with that name exists. |
| 609 | DiagOffs = CurPtr-StrStart; |
| 610 | return diag::err_asm_unknown_symbolic_operand_name; |
| 611 | } |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 612 | |
| 613 | // Str contains "x[foo]" (Operand without the leading %). |
| 614 | std::string Str(Begin, NameEnd + 1 - Begin); |
| 615 | |
| 616 | // (BeginLoc, EndLoc) represents the range of the operand we are currently |
| 617 | // processing. Unlike Str, the range includes the leading '%'. |
| 618 | SourceLocation BeginLoc = |
| 619 | getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI); |
| 620 | SourceLocation EndLoc = |
| 621 | getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI); |
| 622 | |
| 623 | Pieces.push_back(AsmStringPiece(N, Str, BeginLoc, EndLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 624 | |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 625 | CurPtr = NameEnd+1; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 626 | continue; |
| 627 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 628 | |
Chris Lattner | 0cdaa2e | 2009-03-10 23:57:07 +0000 | [diff] [blame] | 629 | DiagOffs = CurPtr-StrStart-1; |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 630 | return diag::err_asm_invalid_escape; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 631 | } |
| 632 | } |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 633 | |
| 634 | /// Assemble final IR asm string (GCC-style). |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 635 | std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 636 | // Analyze the asm string to decompose it into its pieces. We know that Sema |
| 637 | // has already done this, so it is guaranteed to be successful. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 638 | SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces; |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 639 | unsigned DiagOffs; |
| 640 | AnalyzeAsmString(Pieces, C, DiagOffs); |
| 641 | |
| 642 | std::string AsmString; |
| 643 | for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { |
| 644 | if (Pieces[i].isString()) |
| 645 | AsmString += Pieces[i].getString(); |
| 646 | else if (Pieces[i].getModifier() == '\0') |
| 647 | AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); |
| 648 | else |
| 649 | AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + |
| 650 | Pieces[i].getModifier() + '}'; |
| 651 | } |
| 652 | return AsmString; |
| 653 | } |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 654 | |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 655 | /// Assemble final IR asm string (MS-style). |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 656 | std::string MSAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 657 | // FIXME: This needs to be translated into the IR string representation. |
Chad Rosier | 0bca469 | 2012-08-28 20:33:49 +0000 | [diff] [blame] | 658 | return AsmStr; |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 661 | Expr *MSAsmStmt::getOutputExpr(unsigned i) { |
| 662 | return cast<Expr>(Exprs[i]); |
| 663 | } |
| 664 | |
| 665 | Expr *MSAsmStmt::getInputExpr(unsigned i) { |
| 666 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 667 | } |
| 668 | void MSAsmStmt::setInputExpr(unsigned i, Expr *E) { |
| 669 | Exprs[i + NumOutputs] = E; |
| 670 | } |
| 671 | |
Sam Weinig | ebcea98 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 672 | QualType CXXCatchStmt::getCaughtType() const { |
| 673 | if (ExceptionDecl) |
| 674 | return ExceptionDecl->getType(); |
| 675 | return QualType(); |
| 676 | } |
| 677 | |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 678 | //===----------------------------------------------------------------------===// |
| 679 | // Constructors |
| 680 | //===----------------------------------------------------------------------===// |
| 681 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 682 | GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, |
| 683 | bool issimple, bool isvolatile, unsigned numoutputs, |
| 684 | unsigned numinputs, IdentifierInfo **names, |
| 685 | StringLiteral **constraints, Expr **exprs, |
| 686 | StringLiteral *asmstr, unsigned numclobbers, |
| 687 | StringLiteral **clobbers, SourceLocation rparenloc) |
Chad Rosier | fe3352e | 2012-08-27 19:38:01 +0000 | [diff] [blame] | 688 | : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
| 689 | numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) { |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 690 | |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 691 | unsigned NumExprs = NumOutputs + NumInputs; |
| 692 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 693 | Names = new (C) IdentifierInfo*[NumExprs]; |
| 694 | std::copy(names, names + NumExprs, Names); |
| 695 | |
| 696 | Exprs = new (C) Stmt*[NumExprs]; |
| 697 | std::copy(exprs, exprs + NumExprs, Exprs); |
| 698 | |
| 699 | Constraints = new (C) StringLiteral*[NumExprs]; |
| 700 | std::copy(constraints, constraints + NumExprs, Constraints); |
| 701 | |
| 702 | Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 703 | std::copy(clobbers, clobbers + NumClobbers, Clobbers); |
Anders Carlsson | 94ea8aa | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 706 | MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc, |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 707 | SourceLocation lbraceloc, bool issimple, bool isvolatile, |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 708 | ArrayRef<Token> asmtoks, unsigned numoutputs, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 709 | unsigned numinputs, |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 710 | ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs, |
| 711 | StringRef asmstr, ArrayRef<StringRef> clobbers, |
| 712 | SourceLocation endloc) |
| 713 | : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
| 714 | numinputs, clobbers.size()), LBraceLoc(lbraceloc), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 715 | EndLoc(endloc), NumAsmToks(asmtoks.size()) { |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 716 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 717 | initialize(C, asmstr, asmtoks, constraints, exprs, clobbers); |
| 718 | } |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 719 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 720 | static StringRef copyIntoContext(const ASTContext &C, StringRef str) { |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 721 | size_t size = str.size(); |
| 722 | char *buffer = new (C) char[size]; |
| 723 | memcpy(buffer, str.data(), size); |
| 724 | return StringRef(buffer, size); |
| 725 | } |
| 726 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 727 | void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 728 | ArrayRef<Token> asmtoks, |
| 729 | ArrayRef<StringRef> constraints, |
| 730 | ArrayRef<Expr*> exprs, |
| 731 | ArrayRef<StringRef> clobbers) { |
| 732 | assert(NumAsmToks == asmtoks.size()); |
| 733 | assert(NumClobbers == clobbers.size()); |
| 734 | |
| 735 | unsigned NumExprs = exprs.size(); |
| 736 | assert(NumExprs == NumOutputs + NumInputs); |
| 737 | assert(NumExprs == constraints.size()); |
| 738 | |
| 739 | AsmStr = copyIntoContext(C, asmstr); |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 740 | |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 741 | Exprs = new (C) Stmt*[NumExprs]; |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 742 | for (unsigned i = 0, e = NumExprs; i != e; ++i) |
| 743 | Exprs[i] = exprs[i]; |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 744 | |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 745 | AsmToks = new (C) Token[NumAsmToks]; |
| 746 | for (unsigned i = 0, e = NumAsmToks; i != e; ++i) |
| 747 | AsmToks[i] = asmtoks[i]; |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 748 | |
Chad Rosier | 3dd7bf2 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 749 | Constraints = new (C) StringRef[NumExprs]; |
| 750 | for (unsigned i = 0, e = NumExprs; i != e; ++i) { |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 751 | Constraints[i] = copyIntoContext(C, constraints[i]); |
Chad Rosier | 3dd7bf2 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Chad Rosier | baf53f9 | 2012-08-10 21:36:25 +0000 | [diff] [blame] | 754 | Clobbers = new (C) StringRef[NumClobbers]; |
Chad Rosier | d6ef704 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 755 | for (unsigned i = 0, e = NumClobbers; i != e; ++i) { |
| 756 | // FIXME: Avoid the allocation/copy if at all possible. |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 757 | Clobbers[i] = copyIntoContext(C, clobbers[i]); |
Chad Rosier | d6ef704 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 758 | } |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 761 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 762 | Stmt *Body, SourceLocation FCL, |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 763 | SourceLocation RPL) |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 764 | : Stmt(ObjCForCollectionStmtClass) { |
| 765 | SubExprs[ELEM] = Elem; |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 766 | SubExprs[COLLECTION] = Collect; |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 767 | SubExprs[BODY] = Body; |
| 768 | ForLoc = FCL; |
| 769 | RParenLoc = RPL; |
| 770 | } |
| 771 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 772 | ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, |
| 773 | Stmt **CatchStmts, unsigned NumCatchStmts, |
| 774 | Stmt *atFinallyStmt) |
| 775 | : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 776 | NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 777 | Stmt **Stmts = getStmts(); |
| 778 | Stmts[0] = atTryStmt; |
| 779 | for (unsigned I = 0; I != NumCatchStmts; ++I) |
| 780 | Stmts[I + 1] = CatchStmts[I]; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 781 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 782 | if (HasFinally) |
| 783 | Stmts[NumCatchStmts + 1] = atFinallyStmt; |
| 784 | } |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 785 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 786 | ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 787 | SourceLocation atTryLoc, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 788 | Stmt *atTryStmt, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 789 | Stmt **CatchStmts, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 790 | unsigned NumCatchStmts, |
| 791 | Stmt *atFinallyStmt) { |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 792 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 793 | (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *); |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 794 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 795 | return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts, |
| 796 | atFinallyStmt); |
| 797 | } |
Ted Kremenek | a496584 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 798 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 799 | ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context, |
| 800 | unsigned NumCatchStmts, |
| 801 | bool HasFinally) { |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 802 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 803 | (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *); |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 804 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 805 | return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 806 | } |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 807 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 808 | SourceLocation ObjCAtTryStmt::getLocEnd() const { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 809 | if (HasFinally) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 810 | return getFinallyStmt()->getLocEnd(); |
| 811 | if (NumCatchStmts) |
| 812 | return getCatchStmt(NumCatchStmts - 1)->getLocEnd(); |
| 813 | return getTryBody()->getLocEnd(); |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 816 | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc, |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 817 | Stmt *tryBlock, ArrayRef<Stmt*> handlers) { |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 818 | std::size_t Size = sizeof(CXXTryStmt); |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 819 | Size += ((handlers.size() + 1) * sizeof(Stmt)); |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 820 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 821 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 822 | return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 825 | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, |
Argyrios Kyrtzidis | 47cd7a9 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 826 | unsigned numHandlers) { |
| 827 | std::size_t Size = sizeof(CXXTryStmt); |
| 828 | Size += ((numHandlers + 1) * sizeof(Stmt)); |
| 829 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 830 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Argyrios Kyrtzidis | 47cd7a9 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 831 | return new (Mem) CXXTryStmt(Empty, numHandlers); |
| 832 | } |
| 833 | |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 834 | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 835 | ArrayRef<Stmt*> handlers) |
| 836 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 837 | Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); |
Sam Weinig | ebcea98 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 838 | Stmts[0] = tryBlock; |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 839 | std::copy(handlers.begin(), handlers.end(), Stmts + 1); |
Sam Weinig | ebcea98 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 842 | CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt, |
| 843 | Expr *Cond, Expr *Inc, DeclStmt *LoopVar, |
| 844 | Stmt *Body, SourceLocation FL, |
| 845 | SourceLocation CL, SourceLocation RPL) |
| 846 | : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) { |
| 847 | SubExprs[RANGE] = Range; |
| 848 | SubExprs[BEGINEND] = BeginEndStmt; |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 849 | SubExprs[COND] = Cond; |
| 850 | SubExprs[INC] = Inc; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 851 | SubExprs[LOOPVAR] = LoopVar; |
| 852 | SubExprs[BODY] = Body; |
| 853 | } |
| 854 | |
| 855 | Expr *CXXForRangeStmt::getRangeInit() { |
| 856 | DeclStmt *RangeStmt = getRangeStmt(); |
| 857 | VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl()); |
Richard Trieu | 8673869 | 2014-02-27 23:59:14 +0000 | [diff] [blame] | 858 | assert(RangeDecl && "for-range should have a single var decl"); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 859 | return RangeDecl->getInit(); |
| 860 | } |
| 861 | |
| 862 | const Expr *CXXForRangeStmt::getRangeInit() const { |
| 863 | return const_cast<CXXForRangeStmt*>(this)->getRangeInit(); |
| 864 | } |
| 865 | |
| 866 | VarDecl *CXXForRangeStmt::getLoopVariable() { |
| 867 | Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl(); |
| 868 | assert(LV && "No loop variable in CXXForRangeStmt"); |
| 869 | return cast<VarDecl>(LV); |
| 870 | } |
| 871 | |
| 872 | const VarDecl *CXXForRangeStmt::getLoopVariable() const { |
| 873 | return const_cast<CXXForRangeStmt*>(this)->getLoopVariable(); |
| 874 | } |
| 875 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 876 | IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 877 | Stmt *then, SourceLocation EL, Stmt *elsev) |
| 878 | : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL) |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 879 | { |
| 880 | setConditionVariable(C, var); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 881 | SubExprs[COND] = cond; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 882 | SubExprs[THEN] = then; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 883 | SubExprs[ELSE] = elsev; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | VarDecl *IfStmt::getConditionVariable() const { |
| 887 | if (!SubExprs[VAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 888 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 889 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 890 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 891 | return cast<VarDecl>(DS->getSingleDecl()); |
| 892 | } |
| 893 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 894 | void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 895 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 896 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 897 | return; |
| 898 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 899 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 900 | SourceRange VarRange = V->getSourceRange(); |
| 901 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 902 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 905 | ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 906 | Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 907 | SourceLocation RP) |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 908 | : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP) |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 909 | { |
| 910 | SubExprs[INIT] = Init; |
| 911 | setConditionVariable(C, condVar); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 912 | SubExprs[COND] = Cond; |
| 913 | SubExprs[INC] = Inc; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 914 | SubExprs[BODY] = Body; |
| 915 | } |
| 916 | |
| 917 | VarDecl *ForStmt::getConditionVariable() const { |
| 918 | if (!SubExprs[CONDVAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 919 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 920 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 921 | DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]); |
| 922 | return cast<VarDecl>(DS->getSingleDecl()); |
| 923 | } |
| 924 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 925 | void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 926 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 927 | SubExprs[CONDVAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 928 | return; |
| 929 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 930 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 931 | SourceRange VarRange = V->getSourceRange(); |
| 932 | SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 933 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 936 | SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 937 | : Stmt(SwitchStmtClass), FirstCase(nullptr), AllEnumCasesCovered(0) |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 938 | { |
| 939 | setConditionVariable(C, Var); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 940 | SubExprs[COND] = cond; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 941 | SubExprs[BODY] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | VarDecl *SwitchStmt::getConditionVariable() const { |
| 945 | if (!SubExprs[VAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 946 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 947 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 948 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 949 | return cast<VarDecl>(DS->getSingleDecl()); |
| 950 | } |
| 951 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 952 | void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 953 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 954 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 955 | return; |
| 956 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 957 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 958 | SourceRange VarRange = V->getSourceRange(); |
| 959 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 960 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 961 | } |
| 962 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 963 | Stmt *SwitchCase::getSubStmt() { |
Chris Lattner | 80d51eb | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 964 | if (isa<CaseStmt>(this)) |
| 965 | return cast<CaseStmt>(this)->getSubStmt(); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 966 | return cast<DefaultStmt>(this)->getSubStmt(); |
| 967 | } |
| 968 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 969 | WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 970 | SourceLocation WL) |
Chris Lattner | 80d51eb | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 971 | : Stmt(WhileStmtClass) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 972 | setConditionVariable(C, Var); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 973 | SubExprs[COND] = cond; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 974 | SubExprs[BODY] = body; |
| 975 | WhileLoc = WL; |
| 976 | } |
| 977 | |
| 978 | VarDecl *WhileStmt::getConditionVariable() const { |
| 979 | if (!SubExprs[VAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 980 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 981 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 982 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 983 | return cast<VarDecl>(DS->getSingleDecl()); |
| 984 | } |
| 985 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 986 | void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 987 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 988 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 989 | return; |
| 990 | } |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 991 | |
| 992 | SourceRange VarRange = V->getSourceRange(); |
| 993 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 994 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 995 | } |
| 996 | |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 997 | // IndirectGotoStmt |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 998 | LabelDecl *IndirectGotoStmt::getConstantTarget() { |
John McCall | 9de9160 | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 999 | if (AddrLabelExpr *E = |
| 1000 | dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts())) |
| 1001 | return E->getLabel(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1002 | return nullptr; |
John McCall | 9de9160 | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 1003 | } |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1004 | |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1005 | // ReturnStmt |
Ted Kremenek | c6501db | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 1006 | const Expr* ReturnStmt::getRetValue() const { |
| 1007 | return cast_or_null<Expr>(RetExpr); |
| 1008 | } |
| 1009 | Expr* ReturnStmt::getRetValue() { |
| 1010 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1011 | } |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1012 | |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1013 | SEHTryStmt::SEHTryStmt(bool IsCXXTry, |
| 1014 | SourceLocation TryLoc, |
| 1015 | Stmt *TryBlock, |
| 1016 | Stmt *Handler) |
| 1017 | : Stmt(SEHTryStmtClass), |
| 1018 | IsCXXTry(IsCXXTry), |
| 1019 | TryLoc(TryLoc) |
| 1020 | { |
| 1021 | Children[TRY] = TryBlock; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1022 | Children[HANDLER] = Handler; |
| 1023 | } |
| 1024 | |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1025 | SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry, |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1026 | SourceLocation TryLoc, Stmt *TryBlock, |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1027 | Stmt *Handler) { |
| 1028 | return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | SEHExceptStmt* SEHTryStmt::getExceptHandler() const { |
| 1032 | return dyn_cast<SEHExceptStmt>(getHandler()); |
| 1033 | } |
| 1034 | |
| 1035 | SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const { |
| 1036 | return dyn_cast<SEHFinallyStmt>(getHandler()); |
| 1037 | } |
| 1038 | |
| 1039 | SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, |
| 1040 | Expr *FilterExpr, |
| 1041 | Stmt *Block) |
| 1042 | : Stmt(SEHExceptStmtClass), |
| 1043 | Loc(Loc) |
| 1044 | { |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 1045 | Children[FILTER_EXPR] = FilterExpr; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1046 | Children[BLOCK] = Block; |
| 1047 | } |
| 1048 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1049 | SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc, |
| 1050 | Expr *FilterExpr, Stmt *Block) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1051 | return new(C) SEHExceptStmt(Loc,FilterExpr,Block); |
| 1052 | } |
| 1053 | |
| 1054 | SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, |
| 1055 | Stmt *Block) |
| 1056 | : Stmt(SEHFinallyStmtClass), |
| 1057 | Loc(Loc), |
| 1058 | Block(Block) |
| 1059 | {} |
| 1060 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1061 | SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1062 | Stmt *Block) { |
| 1063 | return new(C)SEHFinallyStmt(Loc,Block); |
| 1064 | } |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1065 | |
| 1066 | CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const { |
| 1067 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1068 | |
| 1069 | // Offset of the first Capture object. |
| 1070 | unsigned FirstCaptureOffset = |
| 1071 | llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1072 | |
| 1073 | return reinterpret_cast<Capture *>( |
| 1074 | reinterpret_cast<char *>(const_cast<CapturedStmt *>(this)) |
| 1075 | + FirstCaptureOffset); |
| 1076 | } |
| 1077 | |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1078 | CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind, |
| 1079 | ArrayRef<Capture> Captures, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1080 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1081 | CapturedDecl *CD, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1082 | RecordDecl *RD) |
| 1083 | : Stmt(CapturedStmtClass), NumCaptures(Captures.size()), |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1084 | CapDeclAndKind(CD, Kind), TheRecordDecl(RD) { |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1085 | assert( S && "null captured statement"); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1086 | assert(CD && "null captured declaration for captured statement"); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1087 | assert(RD && "null record declaration for captured statement"); |
| 1088 | |
| 1089 | // Copy initialization expressions. |
| 1090 | Stmt **Stored = getStoredStmts(); |
| 1091 | for (unsigned I = 0, N = NumCaptures; I != N; ++I) |
| 1092 | *Stored++ = CaptureInits[I]; |
| 1093 | |
| 1094 | // Copy the statement being captured. |
| 1095 | *Stored = S; |
| 1096 | |
| 1097 | // Copy all Capture objects. |
| 1098 | Capture *Buffer = getStoredCaptures(); |
| 1099 | std::copy(Captures.begin(), Captures.end(), Buffer); |
| 1100 | } |
| 1101 | |
| 1102 | CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures) |
| 1103 | : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1104 | CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) { |
| 1105 | getStoredStmts()[NumCaptures] = nullptr; |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1108 | CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S, |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1109 | CapturedRegionKind Kind, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1110 | ArrayRef<Capture> Captures, |
| 1111 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1112 | CapturedDecl *CD, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1113 | RecordDecl *RD) { |
| 1114 | // The layout is |
| 1115 | // |
| 1116 | // ----------------------------------------------------------- |
| 1117 | // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture | |
| 1118 | // ----------------^-------------------^---------------------- |
| 1119 | // getStoredStmts() getStoredCaptures() |
| 1120 | // |
| 1121 | // where S is the statement being captured. |
| 1122 | // |
| 1123 | assert(CaptureInits.size() == Captures.size() && "wrong number of arguments"); |
| 1124 | |
| 1125 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1); |
| 1126 | if (!Captures.empty()) { |
| 1127 | // Realign for the following Capture array. |
| 1128 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1129 | Size += sizeof(Capture) * Captures.size(); |
| 1130 | } |
| 1131 | |
| 1132 | void *Mem = Context.Allocate(Size); |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1133 | return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1136 | CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1137 | unsigned NumCaptures) { |
| 1138 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1139 | if (NumCaptures > 0) { |
| 1140 | // Realign for the following Capture array. |
| 1141 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1142 | Size += sizeof(Capture) * NumCaptures; |
| 1143 | } |
| 1144 | |
| 1145 | void *Mem = Context.Allocate(Size); |
| 1146 | return new (Mem) CapturedStmt(EmptyShell(), NumCaptures); |
| 1147 | } |
| 1148 | |
| 1149 | Stmt::child_range CapturedStmt::children() { |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1150 | // Children are captured field initilizers. |
| 1151 | return child_range(getStoredStmts(), getStoredStmts() + NumCaptures); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | bool CapturedStmt::capturesVariable(const VarDecl *Var) const { |
Aaron Ballman | c656303a | 2014-03-14 18:08:33 +0000 | [diff] [blame] | 1155 | for (const auto &I : captures()) { |
| 1156 | if (!I.capturesVariable()) |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1157 | continue; |
| 1158 | |
| 1159 | // This does not handle variable redeclarations. This should be |
| 1160 | // extended to capture variables with redeclarations, for example |
| 1161 | // a thread-private variable in OpenMP. |
Aaron Ballman | c656303a | 2014-03-14 18:08:33 +0000 | [diff] [blame] | 1162 | if (I.getCapturedVar() == Var) |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1163 | return true; |
| 1164 | } |
| 1165 | |
| 1166 | return false; |
| 1167 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1168 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1169 | StmtRange OMPClause::children() { |
| 1170 | switch(getClauseKind()) { |
| 1171 | default : break; |
| 1172 | #define OPENMP_CLAUSE(Name, Class) \ |
| 1173 | case OMPC_ ## Name : return static_cast<Class *>(this)->children(); |
| 1174 | #include "clang/Basic/OpenMPKinds.def" |
| 1175 | } |
| 1176 | llvm_unreachable("unknown OMPClause"); |
| 1177 | } |
| 1178 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 1179 | void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 1180 | assert(VL.size() == varlist_size() && |
| 1181 | "Number of private copies is not the same as the preallocated buffer"); |
| 1182 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 1183 | } |
| 1184 | |
| 1185 | OMPPrivateClause * |
| 1186 | OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1187 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 1188 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { |
| 1189 | // Allocate space for private variables and initializer expressions. |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1190 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), |
| 1191 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 1192 | 2 * sizeof(Expr *) * VL.size()); |
| 1193 | OMPPrivateClause *Clause = |
| 1194 | new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1195 | Clause->setVarRefs(VL); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 1196 | Clause->setPrivateCopies(PrivateVL); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1197 | return Clause; |
| 1198 | } |
| 1199 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1200 | OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1201 | unsigned N) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1202 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), |
| 1203 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 1204 | 2 * sizeof(Expr *) * N); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1205 | return new (Mem) OMPPrivateClause(N); |
| 1206 | } |
| 1207 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 1208 | void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 1209 | assert(VL.size() == varlist_size() && |
| 1210 | "Number of private copies is not the same as the preallocated buffer"); |
| 1211 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 1212 | } |
| 1213 | |
| 1214 | void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { |
| 1215 | assert(VL.size() == varlist_size() && |
| 1216 | "Number of inits is not the same as the preallocated buffer"); |
| 1217 | std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); |
| 1218 | } |
| 1219 | |
| 1220 | OMPFirstprivateClause * |
| 1221 | OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1222 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 1223 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, |
| 1224 | ArrayRef<Expr *> InitVL) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1225 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), |
| 1226 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 1227 | 3 * sizeof(Expr *) * VL.size()); |
| 1228 | OMPFirstprivateClause *Clause = |
| 1229 | new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1230 | Clause->setVarRefs(VL); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 1231 | Clause->setPrivateCopies(PrivateVL); |
| 1232 | Clause->setInits(InitVL); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1233 | return Clause; |
| 1234 | } |
| 1235 | |
| 1236 | OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, |
| 1237 | unsigned N) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1238 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), |
| 1239 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 1240 | 3 * sizeof(Expr *) * N); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1241 | return new (Mem) OMPFirstprivateClause(N); |
| 1242 | } |
| 1243 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1244 | OMPLastprivateClause *OMPLastprivateClause::Create(const ASTContext &C, |
| 1245 | SourceLocation StartLoc, |
| 1246 | SourceLocation LParenLoc, |
| 1247 | SourceLocation EndLoc, |
| 1248 | ArrayRef<Expr *> VL) { |
| 1249 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), |
| 1250 | llvm::alignOf<Expr *>()) + |
| 1251 | sizeof(Expr *) * VL.size()); |
| 1252 | OMPLastprivateClause *Clause = |
| 1253 | new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1254 | Clause->setVarRefs(VL); |
| 1255 | return Clause; |
| 1256 | } |
| 1257 | |
| 1258 | OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, |
| 1259 | unsigned N) { |
| 1260 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), |
| 1261 | llvm::alignOf<Expr *>()) + |
| 1262 | sizeof(Expr *) * N); |
| 1263 | return new (Mem) OMPLastprivateClause(N); |
| 1264 | } |
| 1265 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1266 | OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, |
| 1267 | SourceLocation StartLoc, |
| 1268 | SourceLocation LParenLoc, |
| 1269 | SourceLocation EndLoc, |
| 1270 | ArrayRef<Expr *> VL) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1271 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), |
| 1272 | llvm::alignOf<Expr *>()) + |
| 1273 | sizeof(Expr *) * VL.size()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1274 | OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc, |
| 1275 | EndLoc, VL.size()); |
| 1276 | Clause->setVarRefs(VL); |
| 1277 | return Clause; |
| 1278 | } |
| 1279 | |
| 1280 | OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, |
| 1281 | unsigned N) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1282 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), |
| 1283 | llvm::alignOf<Expr *>()) + |
| 1284 | sizeof(Expr *) * N); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1285 | return new (Mem) OMPSharedClause(N); |
| 1286 | } |
| 1287 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1288 | OMPLinearClause *OMPLinearClause::Create(const ASTContext &C, |
| 1289 | SourceLocation StartLoc, |
| 1290 | SourceLocation LParenLoc, |
| 1291 | SourceLocation ColonLoc, |
| 1292 | SourceLocation EndLoc, |
| 1293 | ArrayRef<Expr *> VL, Expr *Step) { |
| 1294 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), |
| 1295 | llvm::alignOf<Expr *>()) + |
| 1296 | sizeof(Expr *) * (VL.size() + 1)); |
| 1297 | OMPLinearClause *Clause = new (Mem) |
| 1298 | OMPLinearClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 1299 | Clause->setVarRefs(VL); |
| 1300 | Clause->setStep(Step); |
| 1301 | return Clause; |
| 1302 | } |
| 1303 | |
| 1304 | OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, |
| 1305 | unsigned NumVars) { |
| 1306 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), |
| 1307 | llvm::alignOf<Expr *>()) + |
| 1308 | sizeof(Expr *) * (NumVars + 1)); |
| 1309 | return new (Mem) OMPLinearClause(NumVars); |
| 1310 | } |
| 1311 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1312 | OMPAlignedClause * |
| 1313 | OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1314 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 1315 | SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { |
| 1316 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), |
| 1317 | llvm::alignOf<Expr *>()) + |
| 1318 | sizeof(Expr *) * (VL.size() + 1)); |
| 1319 | OMPAlignedClause *Clause = new (Mem) |
| 1320 | OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 1321 | Clause->setVarRefs(VL); |
| 1322 | Clause->setAlignment(A); |
| 1323 | return Clause; |
| 1324 | } |
| 1325 | |
| 1326 | OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, |
| 1327 | unsigned NumVars) { |
| 1328 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), |
| 1329 | llvm::alignOf<Expr *>()) + |
| 1330 | sizeof(Expr *) * (NumVars + 1)); |
| 1331 | return new (Mem) OMPAlignedClause(NumVars); |
| 1332 | } |
| 1333 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1334 | OMPCopyinClause *OMPCopyinClause::Create(const ASTContext &C, |
| 1335 | SourceLocation StartLoc, |
| 1336 | SourceLocation LParenLoc, |
| 1337 | SourceLocation EndLoc, |
| 1338 | ArrayRef<Expr *> VL) { |
| 1339 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), |
| 1340 | llvm::alignOf<Expr *>()) + |
| 1341 | sizeof(Expr *) * VL.size()); |
| 1342 | OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc, |
| 1343 | EndLoc, VL.size()); |
| 1344 | Clause->setVarRefs(VL); |
| 1345 | return Clause; |
| 1346 | } |
| 1347 | |
| 1348 | OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, |
| 1349 | unsigned N) { |
| 1350 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), |
| 1351 | llvm::alignOf<Expr *>()) + |
| 1352 | sizeof(Expr *) * N); |
| 1353 | return new (Mem) OMPCopyinClause(N); |
| 1354 | } |
| 1355 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1356 | OMPCopyprivateClause *OMPCopyprivateClause::Create(const ASTContext &C, |
| 1357 | SourceLocation StartLoc, |
| 1358 | SourceLocation LParenLoc, |
| 1359 | SourceLocation EndLoc, |
| 1360 | ArrayRef<Expr *> VL) { |
| 1361 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), |
| 1362 | llvm::alignOf<Expr *>()) + |
| 1363 | sizeof(Expr *) * VL.size()); |
| 1364 | OMPCopyprivateClause *Clause = |
| 1365 | new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1366 | Clause->setVarRefs(VL); |
| 1367 | return Clause; |
| 1368 | } |
| 1369 | |
| 1370 | OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, |
| 1371 | unsigned N) { |
| 1372 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), |
| 1373 | llvm::alignOf<Expr *>()) + |
| 1374 | sizeof(Expr *) * N); |
| 1375 | return new (Mem) OMPCopyprivateClause(N); |
| 1376 | } |
| 1377 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1378 | void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) { |
Alexander Musman | fd2b759 | 2014-03-27 15:14:18 +0000 | [diff] [blame] | 1379 | assert(Clauses.size() == getNumClauses() && |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1380 | "Number of clauses is not the same as the preallocated buffer"); |
Alexander Musman | fd2b759 | 2014-03-27 15:14:18 +0000 | [diff] [blame] | 1381 | std::copy(Clauses.begin(), Clauses.end(), getClauses().begin()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1384 | void OMPLoopDirective::setCounters(ArrayRef<Expr *> A) { |
| 1385 | assert(A.size() == getCollapsedNumber() && |
| 1386 | "Number of loop counters is not the same as the collapsed number"); |
| 1387 | std::copy(A.begin(), A.end(), getCounters().begin()); |
| 1388 | } |
| 1389 | |
| 1390 | void OMPLoopDirective::setUpdates(ArrayRef<Expr *> A) { |
| 1391 | assert(A.size() == getCollapsedNumber() && |
| 1392 | "Number of counter updates is not the same as the collapsed number"); |
| 1393 | std::copy(A.begin(), A.end(), getUpdates().begin()); |
| 1394 | } |
| 1395 | |
| 1396 | void OMPLoopDirective::setFinals(ArrayRef<Expr *> A) { |
| 1397 | assert(A.size() == getCollapsedNumber() && |
| 1398 | "Number of counter finals is not the same as the collapsed number"); |
| 1399 | std::copy(A.begin(), A.end(), getFinals().begin()); |
| 1400 | } |
| 1401 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1402 | OMPReductionClause *OMPReductionClause::Create( |
| 1403 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1404 | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
| 1405 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo) { |
| 1406 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), |
| 1407 | llvm::alignOf<Expr *>()) + |
| 1408 | sizeof(Expr *) * VL.size()); |
| 1409 | OMPReductionClause *Clause = new (Mem) OMPReductionClause( |
| 1410 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
| 1411 | Clause->setVarRefs(VL); |
| 1412 | return Clause; |
| 1413 | } |
| 1414 | |
| 1415 | OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, |
| 1416 | unsigned N) { |
| 1417 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), |
| 1418 | llvm::alignOf<Expr *>()) + |
| 1419 | sizeof(Expr *) * N); |
| 1420 | return new (Mem) OMPReductionClause(N); |
| 1421 | } |
| 1422 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1423 | OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, |
| 1424 | SourceLocation StartLoc, |
| 1425 | SourceLocation LParenLoc, |
| 1426 | SourceLocation EndLoc, |
| 1427 | ArrayRef<Expr *> VL) { |
| 1428 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), |
| 1429 | llvm::alignOf<Expr *>()) + |
| 1430 | sizeof(Expr *) * VL.size()); |
| 1431 | OMPFlushClause *Clause = |
| 1432 | new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1433 | Clause->setVarRefs(VL); |
| 1434 | return Clause; |
| 1435 | } |
| 1436 | |
| 1437 | OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { |
| 1438 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), |
| 1439 | llvm::alignOf<Expr *>()) + |
| 1440 | sizeof(Expr *) * N); |
| 1441 | return new (Mem) OMPFlushClause(N); |
| 1442 | } |
| 1443 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 1444 | const OMPClause * |
| 1445 | OMPExecutableDirective::getSingleClause(OpenMPClauseKind K) const { |
| 1446 | auto ClauseFilter = |
| 1447 | [=](const OMPClause *C) -> bool { return C->getClauseKind() == K; }; |
| 1448 | OMPExecutableDirective::filtered_clause_iterator<decltype(ClauseFilter)> I( |
| 1449 | clauses(), ClauseFilter); |
| 1450 | |
| 1451 | if (I) { |
| 1452 | auto *Clause = *I; |
| 1453 | assert(!++I && "There are at least 2 clauses of the specified kind"); |
| 1454 | return Clause; |
| 1455 | } |
| 1456 | return nullptr; |
| 1457 | } |
| 1458 | |
Craig Topper | cee6133 | 2013-08-21 04:01:01 +0000 | [diff] [blame] | 1459 | OMPParallelDirective *OMPParallelDirective::Create( |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1460 | const ASTContext &C, |
Craig Topper | cee6133 | 2013-08-21 04:01:01 +0000 | [diff] [blame] | 1461 | SourceLocation StartLoc, |
| 1462 | SourceLocation EndLoc, |
| 1463 | ArrayRef<OMPClause *> Clauses, |
| 1464 | Stmt *AssociatedStmt) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1465 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), |
| 1466 | llvm::alignOf<OMPClause *>()); |
| 1467 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1468 | sizeof(Stmt *)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1469 | OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc, |
| 1470 | Clauses.size()); |
| 1471 | Dir->setClauses(Clauses); |
| 1472 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1473 | return Dir; |
| 1474 | } |
| 1475 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1476 | OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1477 | unsigned NumClauses, |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1478 | EmptyShell) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1479 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), |
| 1480 | llvm::alignOf<OMPClause *>()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1481 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1482 | sizeof(Stmt *)); |
| 1483 | return new (Mem) OMPParallelDirective(NumClauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1484 | } |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1485 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1486 | OMPSimdDirective * |
| 1487 | OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1488 | SourceLocation EndLoc, unsigned CollapsedNum, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1489 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
| 1490 | Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, |
| 1491 | Expr *PreCond, Expr *Cond, Expr *SeparatedCond, |
| 1492 | Expr *Init, Expr *Inc, ArrayRef<Expr *> Counters, |
| 1493 | ArrayRef<Expr *> Updates, ArrayRef<Expr *> Finals) { |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1494 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), |
| 1495 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1496 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1497 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1498 | OMPSimdDirective *Dir = new (Mem) |
| 1499 | OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1500 | Dir->setClauses(Clauses); |
| 1501 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1502 | Dir->setIterationVariable(IV); |
| 1503 | Dir->setLastIteration(LastIteration); |
| 1504 | Dir->setCalcLastIteration(CalcLastIteration); |
| 1505 | Dir->setPreCond(PreCond); |
| 1506 | Dir->setCond(Cond, SeparatedCond); |
| 1507 | Dir->setInit(Init); |
| 1508 | Dir->setInc(Inc); |
| 1509 | Dir->setCounters(Counters); |
| 1510 | Dir->setUpdates(Updates); |
| 1511 | Dir->setFinals(Finals); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1512 | return Dir; |
| 1513 | } |
| 1514 | |
| 1515 | OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C, |
| 1516 | unsigned NumClauses, |
| 1517 | unsigned CollapsedNum, |
| 1518 | EmptyShell) { |
| 1519 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), |
| 1520 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1521 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1522 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1523 | return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses); |
| 1524 | } |
| 1525 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1526 | OMPForDirective * |
| 1527 | OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1528 | SourceLocation EndLoc, unsigned CollapsedNum, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1529 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
| 1530 | Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, |
| 1531 | Expr *PreCond, Expr *Cond, Expr *SeparatedCond, |
| 1532 | Expr *Init, Expr *Inc, ArrayRef<Expr *> Counters, |
| 1533 | ArrayRef<Expr *> Updates, ArrayRef<Expr *> Finals) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1534 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), |
| 1535 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1536 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1537 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1538 | OMPForDirective *Dir = |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1539 | new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1540 | Dir->setClauses(Clauses); |
| 1541 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1542 | Dir->setIterationVariable(IV); |
| 1543 | Dir->setLastIteration(LastIteration); |
| 1544 | Dir->setCalcLastIteration(CalcLastIteration); |
| 1545 | Dir->setPreCond(PreCond); |
| 1546 | Dir->setCond(Cond, SeparatedCond); |
| 1547 | Dir->setInit(Init); |
| 1548 | Dir->setInc(Inc); |
| 1549 | Dir->setCounters(Counters); |
| 1550 | Dir->setUpdates(Updates); |
| 1551 | Dir->setFinals(Finals); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1552 | return Dir; |
| 1553 | } |
| 1554 | |
| 1555 | OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C, |
| 1556 | unsigned NumClauses, |
| 1557 | unsigned CollapsedNum, |
| 1558 | EmptyShell) { |
| 1559 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), |
| 1560 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1561 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1562 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1563 | return new (Mem) OMPForDirective(CollapsedNum, NumClauses); |
| 1564 | } |
| 1565 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1566 | OMPForSimdDirective *OMPForSimdDirective::Create( |
| 1567 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1568 | unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
| 1569 | Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, Expr *PreCond, |
| 1570 | Expr *Cond, Expr *SeparatedCond, Expr *Init, Expr *Inc, |
| 1571 | ArrayRef<Expr *> Counters, ArrayRef<Expr *> Updates, |
| 1572 | ArrayRef<Expr *> Finals) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1573 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective), |
| 1574 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1575 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1576 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1577 | OMPForSimdDirective *Dir = new (Mem) |
| 1578 | OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1579 | Dir->setClauses(Clauses); |
| 1580 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1581 | Dir->setIterationVariable(IV); |
| 1582 | Dir->setLastIteration(LastIteration); |
| 1583 | Dir->setCalcLastIteration(CalcLastIteration); |
| 1584 | Dir->setPreCond(PreCond); |
| 1585 | Dir->setCond(Cond, SeparatedCond); |
| 1586 | Dir->setInit(Init); |
| 1587 | Dir->setInc(Inc); |
| 1588 | Dir->setCounters(Counters); |
| 1589 | Dir->setUpdates(Updates); |
| 1590 | Dir->setFinals(Finals); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1591 | return Dir; |
| 1592 | } |
| 1593 | |
| 1594 | OMPForSimdDirective *OMPForSimdDirective::CreateEmpty(const ASTContext &C, |
| 1595 | unsigned NumClauses, |
| 1596 | unsigned CollapsedNum, |
| 1597 | EmptyShell) { |
| 1598 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective), |
| 1599 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1600 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1601 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1602 | return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses); |
| 1603 | } |
| 1604 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1605 | OMPSectionsDirective *OMPSectionsDirective::Create( |
| 1606 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1607 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
| 1608 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1609 | llvm::alignOf<OMPClause *>()); |
| 1610 | void *Mem = |
| 1611 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1612 | OMPSectionsDirective *Dir = |
| 1613 | new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size()); |
| 1614 | Dir->setClauses(Clauses); |
| 1615 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1616 | return Dir; |
| 1617 | } |
| 1618 | |
| 1619 | OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C, |
| 1620 | unsigned NumClauses, |
| 1621 | EmptyShell) { |
| 1622 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1623 | llvm::alignOf<OMPClause *>()); |
| 1624 | void *Mem = |
| 1625 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1626 | return new (Mem) OMPSectionsDirective(NumClauses); |
| 1627 | } |
| 1628 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1629 | OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C, |
| 1630 | SourceLocation StartLoc, |
| 1631 | SourceLocation EndLoc, |
| 1632 | Stmt *AssociatedStmt) { |
| 1633 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1634 | llvm::alignOf<Stmt *>()); |
| 1635 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1636 | OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); |
| 1637 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1638 | return Dir; |
| 1639 | } |
| 1640 | |
| 1641 | OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C, |
| 1642 | EmptyShell) { |
| 1643 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective), |
| 1644 | llvm::alignOf<Stmt *>()); |
| 1645 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1646 | return new (Mem) OMPSectionDirective(); |
| 1647 | } |
| 1648 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1649 | OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C, |
| 1650 | SourceLocation StartLoc, |
| 1651 | SourceLocation EndLoc, |
| 1652 | ArrayRef<OMPClause *> Clauses, |
| 1653 | Stmt *AssociatedStmt) { |
| 1654 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), |
| 1655 | llvm::alignOf<OMPClause *>()); |
| 1656 | void *Mem = |
| 1657 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1658 | OMPSingleDirective *Dir = |
| 1659 | new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size()); |
| 1660 | Dir->setClauses(Clauses); |
| 1661 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1662 | return Dir; |
| 1663 | } |
| 1664 | |
| 1665 | OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C, |
| 1666 | unsigned NumClauses, |
| 1667 | EmptyShell) { |
| 1668 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), |
| 1669 | llvm::alignOf<OMPClause *>()); |
| 1670 | void *Mem = |
| 1671 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1672 | return new (Mem) OMPSingleDirective(NumClauses); |
| 1673 | } |
| 1674 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1675 | OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C, |
| 1676 | SourceLocation StartLoc, |
| 1677 | SourceLocation EndLoc, |
| 1678 | Stmt *AssociatedStmt) { |
| 1679 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), |
| 1680 | llvm::alignOf<Stmt *>()); |
| 1681 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1682 | OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc); |
| 1683 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1684 | return Dir; |
| 1685 | } |
| 1686 | |
| 1687 | OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C, |
| 1688 | EmptyShell) { |
| 1689 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), |
| 1690 | llvm::alignOf<Stmt *>()); |
| 1691 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1692 | return new (Mem) OMPMasterDirective(); |
| 1693 | } |
| 1694 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1695 | OMPCriticalDirective *OMPCriticalDirective::Create( |
| 1696 | const ASTContext &C, const DeclarationNameInfo &Name, |
| 1697 | SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) { |
| 1698 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), |
| 1699 | llvm::alignOf<Stmt *>()); |
| 1700 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1701 | OMPCriticalDirective *Dir = |
| 1702 | new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc); |
| 1703 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1704 | return Dir; |
| 1705 | } |
| 1706 | |
| 1707 | OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C, |
| 1708 | EmptyShell) { |
| 1709 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), |
| 1710 | llvm::alignOf<Stmt *>()); |
| 1711 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1712 | return new (Mem) OMPCriticalDirective(); |
| 1713 | } |
| 1714 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1715 | OMPParallelForDirective *OMPParallelForDirective::Create( |
| 1716 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1717 | unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
| 1718 | Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, Expr *PreCond, |
| 1719 | Expr *Cond, Expr *SeparatedCond, Expr *Init, Expr *Inc, |
| 1720 | ArrayRef<Expr *> Counters, ArrayRef<Expr *> Updates, |
| 1721 | ArrayRef<Expr *> Finals) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1722 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), |
| 1723 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1724 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1725 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1726 | OMPParallelForDirective *Dir = new (Mem) |
| 1727 | OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1728 | Dir->setClauses(Clauses); |
| 1729 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1730 | Dir->setIterationVariable(IV); |
| 1731 | Dir->setLastIteration(LastIteration); |
| 1732 | Dir->setCalcLastIteration(CalcLastIteration); |
| 1733 | Dir->setPreCond(PreCond); |
| 1734 | Dir->setCond(Cond, SeparatedCond); |
| 1735 | Dir->setInit(Init); |
| 1736 | Dir->setInc(Inc); |
| 1737 | Dir->setCounters(Counters); |
| 1738 | Dir->setUpdates(Updates); |
| 1739 | Dir->setFinals(Finals); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1740 | return Dir; |
| 1741 | } |
| 1742 | |
| 1743 | OMPParallelForDirective * |
| 1744 | OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, |
| 1745 | unsigned CollapsedNum, EmptyShell) { |
| 1746 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), |
| 1747 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1748 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1749 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1750 | return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses); |
| 1751 | } |
| 1752 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1753 | OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create( |
| 1754 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1755 | unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
| 1756 | Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, Expr *PreCond, |
| 1757 | Expr *Cond, Expr *SeparatedCond, Expr *Init, Expr *Inc, |
| 1758 | ArrayRef<Expr *> Counters, ArrayRef<Expr *> Updates, |
| 1759 | ArrayRef<Expr *> Finals) { |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1760 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective), |
| 1761 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1762 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1763 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1764 | OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective( |
| 1765 | StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1766 | Dir->setClauses(Clauses); |
| 1767 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1768 | Dir->setIterationVariable(IV); |
| 1769 | Dir->setLastIteration(LastIteration); |
| 1770 | Dir->setCalcLastIteration(CalcLastIteration); |
| 1771 | Dir->setPreCond(PreCond); |
| 1772 | Dir->setCond(Cond, SeparatedCond); |
| 1773 | Dir->setInit(Init); |
| 1774 | Dir->setInc(Inc); |
| 1775 | Dir->setCounters(Counters); |
| 1776 | Dir->setUpdates(Updates); |
| 1777 | Dir->setFinals(Finals); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1778 | return Dir; |
| 1779 | } |
| 1780 | |
| 1781 | OMPParallelForSimdDirective * |
| 1782 | OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C, |
| 1783 | unsigned NumClauses, |
| 1784 | unsigned CollapsedNum, EmptyShell) { |
| 1785 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective), |
| 1786 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1787 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1788 | sizeof(Stmt *) * numLoopChildren(CollapsedNum)); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1789 | return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses); |
| 1790 | } |
| 1791 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1792 | OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create( |
| 1793 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1794 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
| 1795 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), |
| 1796 | llvm::alignOf<OMPClause *>()); |
| 1797 | void *Mem = |
| 1798 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1799 | OMPParallelSectionsDirective *Dir = |
| 1800 | new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size()); |
| 1801 | Dir->setClauses(Clauses); |
| 1802 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1803 | return Dir; |
| 1804 | } |
| 1805 | |
| 1806 | OMPParallelSectionsDirective * |
| 1807 | OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C, |
| 1808 | unsigned NumClauses, EmptyShell) { |
| 1809 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), |
| 1810 | llvm::alignOf<OMPClause *>()); |
| 1811 | void *Mem = |
| 1812 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1813 | return new (Mem) OMPParallelSectionsDirective(NumClauses); |
| 1814 | } |
| 1815 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1816 | OMPTaskDirective *OMPTaskDirective::Create(const ASTContext &C, |
| 1817 | SourceLocation StartLoc, |
| 1818 | SourceLocation EndLoc, |
| 1819 | ArrayRef<OMPClause *> Clauses, |
| 1820 | Stmt *AssociatedStmt) { |
| 1821 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), |
| 1822 | llvm::alignOf<OMPClause *>()); |
| 1823 | void *Mem = |
| 1824 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1825 | OMPTaskDirective *Dir = |
| 1826 | new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size()); |
| 1827 | Dir->setClauses(Clauses); |
| 1828 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1829 | return Dir; |
| 1830 | } |
| 1831 | |
| 1832 | OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C, |
| 1833 | unsigned NumClauses, |
| 1834 | EmptyShell) { |
| 1835 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), |
| 1836 | llvm::alignOf<OMPClause *>()); |
| 1837 | void *Mem = |
| 1838 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1839 | return new (Mem) OMPTaskDirective(NumClauses); |
| 1840 | } |
| 1841 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1842 | OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C, |
| 1843 | SourceLocation StartLoc, |
| 1844 | SourceLocation EndLoc) { |
| 1845 | void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); |
| 1846 | OMPTaskyieldDirective *Dir = |
| 1847 | new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc); |
| 1848 | return Dir; |
| 1849 | } |
| 1850 | |
| 1851 | OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C, |
| 1852 | EmptyShell) { |
| 1853 | void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); |
| 1854 | return new (Mem) OMPTaskyieldDirective(); |
| 1855 | } |
| 1856 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1857 | OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C, |
| 1858 | SourceLocation StartLoc, |
| 1859 | SourceLocation EndLoc) { |
| 1860 | void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); |
| 1861 | OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc); |
| 1862 | return Dir; |
| 1863 | } |
| 1864 | |
| 1865 | OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C, |
| 1866 | EmptyShell) { |
| 1867 | void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); |
| 1868 | return new (Mem) OMPBarrierDirective(); |
| 1869 | } |
| 1870 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1871 | OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C, |
| 1872 | SourceLocation StartLoc, |
| 1873 | SourceLocation EndLoc) { |
| 1874 | void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); |
| 1875 | OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc); |
| 1876 | return Dir; |
| 1877 | } |
| 1878 | |
| 1879 | OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C, |
| 1880 | EmptyShell) { |
| 1881 | void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); |
| 1882 | return new (Mem) OMPTaskwaitDirective(); |
| 1883 | } |
| 1884 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1885 | OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C, |
| 1886 | SourceLocation StartLoc, |
| 1887 | SourceLocation EndLoc, |
| 1888 | ArrayRef<OMPClause *> Clauses) { |
| 1889 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), |
| 1890 | llvm::alignOf<OMPClause *>()); |
| 1891 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size()); |
| 1892 | OMPFlushDirective *Dir = |
| 1893 | new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size()); |
| 1894 | Dir->setClauses(Clauses); |
| 1895 | return Dir; |
| 1896 | } |
| 1897 | |
| 1898 | OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C, |
| 1899 | unsigned NumClauses, |
| 1900 | EmptyShell) { |
| 1901 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), |
| 1902 | llvm::alignOf<OMPClause *>()); |
| 1903 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses); |
| 1904 | return new (Mem) OMPFlushDirective(NumClauses); |
| 1905 | } |
| 1906 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1907 | OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C, |
| 1908 | SourceLocation StartLoc, |
| 1909 | SourceLocation EndLoc, |
| 1910 | Stmt *AssociatedStmt) { |
| 1911 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective), |
| 1912 | llvm::alignOf<Stmt *>()); |
| 1913 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1914 | OMPOrderedDirective *Dir = new (Mem) OMPOrderedDirective(StartLoc, EndLoc); |
| 1915 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1916 | return Dir; |
| 1917 | } |
| 1918 | |
| 1919 | OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C, |
| 1920 | EmptyShell) { |
| 1921 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective), |
| 1922 | llvm::alignOf<Stmt *>()); |
| 1923 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1924 | return new (Mem) OMPOrderedDirective(); |
| 1925 | } |
| 1926 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1927 | OMPAtomicDirective *OMPAtomicDirective::Create(const ASTContext &C, |
| 1928 | SourceLocation StartLoc, |
| 1929 | SourceLocation EndLoc, |
| 1930 | ArrayRef<OMPClause *> Clauses, |
| 1931 | Stmt *AssociatedStmt) { |
| 1932 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective), |
| 1933 | llvm::alignOf<OMPClause *>()); |
| 1934 | void *Mem = |
| 1935 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1936 | OMPAtomicDirective *Dir = |
| 1937 | new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size()); |
| 1938 | Dir->setClauses(Clauses); |
| 1939 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1940 | return Dir; |
| 1941 | } |
| 1942 | |
| 1943 | OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C, |
| 1944 | unsigned NumClauses, |
| 1945 | EmptyShell) { |
| 1946 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective), |
| 1947 | llvm::alignOf<OMPClause *>()); |
| 1948 | void *Mem = |
| 1949 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1950 | return new (Mem) OMPAtomicDirective(NumClauses); |
| 1951 | } |
| 1952 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1953 | OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C, |
| 1954 | SourceLocation StartLoc, |
| 1955 | SourceLocation EndLoc, |
| 1956 | ArrayRef<OMPClause *> Clauses, |
| 1957 | Stmt *AssociatedStmt) { |
| 1958 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective), |
| 1959 | llvm::alignOf<OMPClause *>()); |
| 1960 | void *Mem = |
| 1961 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1962 | OMPTargetDirective *Dir = |
| 1963 | new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size()); |
| 1964 | Dir->setClauses(Clauses); |
| 1965 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1966 | return Dir; |
| 1967 | } |
| 1968 | |
| 1969 | OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C, |
| 1970 | unsigned NumClauses, |
| 1971 | EmptyShell) { |
| 1972 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective), |
| 1973 | llvm::alignOf<OMPClause *>()); |
| 1974 | void *Mem = |
| 1975 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1976 | return new (Mem) OMPTargetDirective(NumClauses); |
| 1977 | } |
| 1978 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1979 | OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C, |
| 1980 | SourceLocation StartLoc, |
| 1981 | SourceLocation EndLoc, |
| 1982 | ArrayRef<OMPClause *> Clauses, |
| 1983 | Stmt *AssociatedStmt) { |
| 1984 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), |
| 1985 | llvm::alignOf<OMPClause *>()); |
| 1986 | void *Mem = |
| 1987 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1988 | OMPTeamsDirective *Dir = |
| 1989 | new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size()); |
| 1990 | Dir->setClauses(Clauses); |
| 1991 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1992 | return Dir; |
| 1993 | } |
| 1994 | |
| 1995 | OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C, |
| 1996 | unsigned NumClauses, |
| 1997 | EmptyShell) { |
| 1998 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), |
| 1999 | llvm::alignOf<OMPClause *>()); |
| 2000 | void *Mem = |
| 2001 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 2002 | return new (Mem) OMPTeamsDirective(NumClauses); |
| 2003 | } |
| 2004 | |