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