blob: d3047faebbe45bf5db087c2364e8e587cc1eeea0 [file] [log] [blame]
Chris Lattnerf42cce72006-10-25 04:09:21 +00001//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerf42cce72006-10-25 04:09:21 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt class and statement subclasses.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer444a1302012-12-01 17:12:56 +000014#include "clang/AST/ASTContext.h"
15#include "clang/AST/ASTDiagnostic.h"
Chris Lattner29375652006-12-04 18:06:35 +000016#include "clang/AST/ExprCXX.h"
Steve Naroff021ca182008-05-29 21:12:08 +000017#include "clang/AST/ExprObjC.h"
Benjamin Kramer444a1302012-12-01 17:12:56 +000018#include "clang/AST/Stmt.h"
Chris Lattnerf0b64d72009-04-26 01:32:48 +000019#include "clang/AST/StmtCXX.h"
20#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000021#include "clang/AST/StmtOpenMP.h"
Sebastian Redl54c04d42008-12-22 19:15:10 +000022#include "clang/AST/Type.h"
Jordan Rosea7d03842013-02-08 22:30:41 +000023#include "clang/Basic/CharInfo.h"
Chris Lattner1a8f3942010-04-23 16:29:58 +000024#include "clang/Basic/TargetInfo.h"
Benjamin Kramer444a1302012-12-01 17:12:56 +000025#include "clang/Lex/Token.h"
Chad Rosier14836ba2012-08-24 17:05:45 +000026#include "llvm/ADT/StringExtras.h"
Chandler Carruthbfb154a2011-07-04 06:13:27 +000027#include "llvm/Support/raw_ostream.h"
Chris Lattnerf42cce72006-10-25 04:09:21 +000028using namespace clang;
29
Steve Narofff84d11f2007-05-23 21:48:04 +000030static struct StmtClassNameTable {
Chris Lattner4d15a0d2007-08-25 01:42:24 +000031 const char *Name;
32 unsigned Counter;
33 unsigned Size;
Alexis Hunt656bb312010-05-05 15:24:00 +000034} StmtClassInfo[Stmt::lastStmtConstant+1];
Chris Lattner4d15a0d2007-08-25 01:42:24 +000035
36static 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 Huntabb2ac82010-05-18 06:22:21 +000043#define ABSTRACT_STMT(STMT)
Douglas Gregorbe35ce92008-11-14 12:46:07 +000044#define STMT(CLASS, PARENT) \
45 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
46 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
Alexis Hunt656bb312010-05-05 15:24:00 +000047#include "clang/AST/StmtNodes.inc"
Nico Weberde565e32008-08-05 23:15:29 +000048
Chris Lattner4d15a0d2007-08-25 01:42:24 +000049 return StmtClassInfo[E];
50}
51
Craig Topper37932912013-08-18 10:09:15 +000052void *Stmt::operator new(size_t bytes, const ASTContext& C,
Craig Topper5a050012013-08-18 17:45:38 +000053 unsigned alignment) {
Benjamin Kramerea70eb32012-12-01 15:09:41 +000054 return ::operator new(bytes, C, alignment);
55}
56
Steve Narofff1e53692007-03-23 22:27:02 +000057const char *Stmt::getStmtClassName() const {
John McCall925b16622010-10-26 08:39:16 +000058 return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
Steve Narofff1e53692007-03-23 22:27:02 +000059}
Steve Narofff84d11f2007-05-23 21:48:04 +000060
61void Stmt::PrintStats() {
Chris Lattner4d15a0d2007-08-25 01:42:24 +000062 // Ensure the table is primed.
63 getStmtInfoTableEntry(Stmt::NullStmtClass);
Nico Weberde565e32008-08-05 23:15:29 +000064
Steve Narofff84d11f2007-05-23 21:48:04 +000065 unsigned sum = 0;
Chandler Carruthbfb154a2011-07-04 06:13:27 +000066 llvm::errs() << "\n*** Stmt/Expr Stats:\n";
Alexis Hunt656bb312010-05-05 15:24:00 +000067 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Craig Topper36250ad2014-05-12 05:36:57 +000068 if (StmtClassInfo[i].Name == nullptr) continue;
Chris Lattner4d15a0d2007-08-25 01:42:24 +000069 sum += StmtClassInfo[i].Counter;
Steve Narofff84d11f2007-05-23 21:48:04 +000070 }
Chandler Carruthbfb154a2011-07-04 06:13:27 +000071 llvm::errs() << " " << sum << " stmts/exprs total.\n";
Steve Narofff84d11f2007-05-23 21:48:04 +000072 sum = 0;
Alexis Hunt656bb312010-05-05 15:24:00 +000073 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Craig Topper36250ad2014-05-12 05:36:57 +000074 if (StmtClassInfo[i].Name == nullptr) continue;
Douglas Gregora30d0462009-05-26 14:40:08 +000075 if (StmtClassInfo[i].Counter == 0) continue;
Chandler Carruthbfb154a2011-07-04 06:13:27 +000076 llvm::errs() << " " << StmtClassInfo[i].Counter << " "
77 << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size
78 << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size
79 << " bytes)\n";
Chris Lattner4d15a0d2007-08-25 01:42:24 +000080 sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
Steve Narofff84d11f2007-05-23 21:48:04 +000081 }
Chandler Carruthbfb154a2011-07-04 06:13:27 +000082
83 llvm::errs() << "Total bytes = " << sum << "\n";
Steve Narofff84d11f2007-05-23 21:48:04 +000084}
85
86void Stmt::addStmtClass(StmtClass s) {
Chris Lattner4d15a0d2007-08-25 01:42:24 +000087 ++getStmtInfoTableEntry(s).Counter;
Steve Narofff84d11f2007-05-23 21:48:04 +000088}
89
Daniel Dunbar62905572012-03-05 21:42:49 +000090bool Stmt::StatisticsEnabled = false;
91void Stmt::EnableStatistics() {
92 StatisticsEnabled = true;
Steve Narofff84d11f2007-05-23 21:48:04 +000093}
94
John McCall4db5c3c2011-07-07 06:58:02 +000095Stmt *Stmt::IgnoreImplicit() {
96 Stmt *s = this;
97
98 if (ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(s))
99 s = ewc->getSubExpr();
100
101 while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(s))
102 s = ice->getSubExpr();
103
104 return s;
105}
106
Alexander Musmana5f070a2014-10-01 06:03:56 +0000107/// \brief Skip no-op (attributed, compound) container stmts and skip captured
108/// stmt at the top, if \a IgnoreCaptured is true.
109Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) {
110 Stmt *S = this;
111 if (IgnoreCaptured)
112 if (auto CapS = dyn_cast_or_null<CapturedStmt>(S))
113 S = CapS->getCapturedStmt();
114 while (true) {
115 if (auto AS = dyn_cast_or_null<AttributedStmt>(S))
116 S = AS->getSubStmt();
117 else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) {
118 if (CS->size() != 1)
119 break;
120 S = CS->body_back();
121 } else
122 break;
123 }
124 return S;
125}
126
Chandler Carrutha626d642011-09-10 00:02:34 +0000127/// \brief Strip off all label-like statements.
128///
Richard Smithc202b282012-04-14 00:33:13 +0000129/// This will strip off label statements, case statements, attributed
130/// statements and default statements recursively.
Chandler Carrutha626d642011-09-10 00:02:34 +0000131const Stmt *Stmt::stripLabelLikeStatements() const {
132 const Stmt *S = this;
133 while (true) {
134 if (const LabelStmt *LS = dyn_cast<LabelStmt>(S))
135 S = LS->getSubStmt();
136 else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S))
137 S = SC->getSubStmt();
Richard Smithc202b282012-04-14 00:33:13 +0000138 else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S))
139 S = AS->getSubStmt();
Chandler Carrutha626d642011-09-10 00:02:34 +0000140 else
141 return S;
142 }
143}
144
John McCallbd066782011-02-09 08:16:59 +0000145namespace {
146 struct good {};
147 struct bad {};
John McCallf75152f2011-02-09 08:31:17 +0000148
149 // These silly little functions have to be static inline to suppress
150 // unused warnings, and they have to be defined to suppress other
151 // warnings.
Nick Lewyckybae992f2011-02-09 08:42:57 +0000152 static inline good is_good(good) { return good(); }
John McCallbd066782011-02-09 08:16:59 +0000153
154 typedef Stmt::child_range children_t();
Nick Lewyckybae992f2011-02-09 08:42:57 +0000155 template <class T> good implements_children(children_t T::*) {
156 return good();
157 }
Eli Friedmandc41d792013-09-10 22:57:15 +0000158 LLVM_ATTRIBUTE_UNUSED
Nick Lewyckybae992f2011-02-09 08:42:57 +0000159 static inline bad implements_children(children_t Stmt::*) {
160 return bad();
161 }
John McCallbd066782011-02-09 08:16:59 +0000162
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000163 typedef SourceLocation getLocStart_t() const;
164 template <class T> good implements_getLocStart(getLocStart_t T::*) {
Nick Lewyckybae992f2011-02-09 08:42:57 +0000165 return good();
166 }
Eli Friedmandc41d792013-09-10 22:57:15 +0000167 LLVM_ATTRIBUTE_UNUSED
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000168 static inline bad implements_getLocStart(getLocStart_t Stmt::*) {
169 return bad();
170 }
171
172 typedef SourceLocation getLocEnd_t() const;
173 template <class T> good implements_getLocEnd(getLocEnd_t T::*) {
174 return good();
175 }
Eli Friedmandc41d792013-09-10 22:57:15 +0000176 LLVM_ATTRIBUTE_UNUSED
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000177 static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) {
Nick Lewyckybae992f2011-02-09 08:42:57 +0000178 return bad();
179 }
John McCallbd066782011-02-09 08:16:59 +0000180
181#define ASSERT_IMPLEMENTS_children(type) \
Eli Friedmandc41d792013-09-10 22:57:15 +0000182 (void) is_good(implements_children(&type::children))
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000183#define ASSERT_IMPLEMENTS_getLocStart(type) \
Eli Friedmandc41d792013-09-10 22:57:15 +0000184 (void) is_good(implements_getLocStart(&type::getLocStart))
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000185#define ASSERT_IMPLEMENTS_getLocEnd(type) \
Eli Friedmandc41d792013-09-10 22:57:15 +0000186 (void) is_good(implements_getLocEnd(&type::getLocEnd))
John McCallbd066782011-02-09 08:16:59 +0000187}
188
189/// Check whether the various Stmt classes implement their member
190/// functions.
Eli Friedmandc41d792013-09-10 22:57:15 +0000191LLVM_ATTRIBUTE_UNUSED
John McCallbd066782011-02-09 08:16:59 +0000192static inline void check_implementations() {
193#define ABSTRACT_STMT(type)
194#define STMT(type, base) \
195 ASSERT_IMPLEMENTS_children(type); \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000196 ASSERT_IMPLEMENTS_getLocStart(type); \
197 ASSERT_IMPLEMENTS_getLocEnd(type);
John McCallbd066782011-02-09 08:16:59 +0000198#include "clang/AST/StmtNodes.inc"
199}
200
201Stmt::child_range Stmt::children() {
202 switch (getStmtClass()) {
203 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
204#define ABSTRACT_STMT(type)
205#define STMT(type, base) \
206 case Stmt::type##Class: \
207 return static_cast<type*>(this)->children();
208#include "clang/AST/StmtNodes.inc"
209 }
210 llvm_unreachable("unknown statement kind!");
John McCallbd066782011-02-09 08:16:59 +0000211}
212
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000213// Amusing macro metaprogramming hack: check whether a class provides
214// a more specific implementation of getSourceRange.
215//
216// See also Expr.cpp:getExprLoc().
217namespace {
218 /// This implementation is used when a class provides a custom
219 /// implementation of getSourceRange.
220 template <class S, class T>
221 SourceRange getSourceRangeImpl(const Stmt *stmt,
222 SourceRange (T::*v)() const) {
223 return static_cast<const S*>(stmt)->getSourceRange();
224 }
225
226 /// This implementation is used when a class doesn't provide a custom
227 /// implementation of getSourceRange. Overload resolution should pick it over
228 /// the implementation above because it's more specialized according to
229 /// function template partial ordering.
230 template <class S>
231 SourceRange getSourceRangeImpl(const Stmt *stmt,
232 SourceRange (Stmt::*v)() const) {
233 return SourceRange(static_cast<const S*>(stmt)->getLocStart(),
234 static_cast<const S*>(stmt)->getLocEnd());
235 }
236}
237
John McCallbd066782011-02-09 08:16:59 +0000238SourceRange Stmt::getSourceRange() const {
239 switch (getStmtClass()) {
240 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
241#define ABSTRACT_STMT(type)
242#define STMT(type, base) \
243 case Stmt::type##Class: \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000244 return getSourceRangeImpl<type>(this, &type::getSourceRange);
John McCallbd066782011-02-09 08:16:59 +0000245#include "clang/AST/StmtNodes.inc"
246 }
247 llvm_unreachable("unknown statement kind!");
John McCallbd066782011-02-09 08:16:59 +0000248}
249
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000250SourceLocation Stmt::getLocStart() const {
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000251// llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n";
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000252 switch (getStmtClass()) {
253 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
254#define ABSTRACT_STMT(type)
255#define STMT(type, base) \
256 case Stmt::type##Class: \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000257 return static_cast<const type*>(this)->getLocStart();
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000258#include "clang/AST/StmtNodes.inc"
259 }
260 llvm_unreachable("unknown statement kind");
261}
262
263SourceLocation Stmt::getLocEnd() const {
264 switch (getStmtClass()) {
265 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
266#define ABSTRACT_STMT(type)
267#define STMT(type, base) \
268 case Stmt::type##Class: \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000269 return static_cast<const type*>(this)->getLocEnd();
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000270#include "clang/AST/StmtNodes.inc"
271 }
272 llvm_unreachable("unknown statement kind");
273}
274
Craig Toppere6960e22013-08-22 05:28:54 +0000275CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000276 SourceLocation LB, SourceLocation RB)
277 : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) {
Nico Webera2a0eb92012-12-29 20:03:39 +0000278 CompoundStmtBits.NumStmts = Stmts.size();
279 assert(CompoundStmtBits.NumStmts == Stmts.size() &&
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000280 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
281
Nico Webera2a0eb92012-12-29 20:03:39 +0000282 if (Stmts.size() == 0) {
Craig Topper36250ad2014-05-12 05:36:57 +0000283 Body = nullptr;
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000284 return;
285 }
286
Nico Webera2a0eb92012-12-29 20:03:39 +0000287 Body = new (C) Stmt*[Stmts.size()];
288 std::copy(Stmts.begin(), Stmts.end(), Body);
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000289}
290
Craig Topperc571c812013-08-22 06:02:26 +0000291void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts,
292 unsigned NumStmts) {
Douglas Gregora9af1d12009-04-17 00:04:06 +0000293 if (this->Body)
294 C.Deallocate(Body);
John McCall925b16622010-10-26 08:39:16 +0000295 this->CompoundStmtBits.NumStmts = NumStmts;
Douglas Gregora9af1d12009-04-17 00:04:06 +0000296
297 Body = new (C) Stmt*[NumStmts];
298 memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts);
299}
Steve Narofff84d11f2007-05-23 21:48:04 +0000300
Chris Lattnereefa10e2007-05-28 06:56:27 +0000301const char *LabelStmt::getName() const {
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000302 return getDecl()->getIdentifier()->getNameStart();
Chris Lattnereefa10e2007-05-28 06:56:27 +0000303}
304
Craig Toppere6960e22013-08-22 05:28:54 +0000305AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc,
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000306 ArrayRef<const Attr*> Attrs,
307 Stmt *SubStmt) {
Aaron Ballmanf3d9b092014-05-13 14:55:01 +0000308 assert(!Attrs.empty() && "Attrs should not be empty");
309 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(),
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000310 llvm::alignOf<AttributedStmt>());
311 return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
312}
313
Craig Toppere6960e22013-08-22 05:28:54 +0000314AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C,
315 unsigned NumAttrs) {
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000316 assert(NumAttrs > 0 && "NumAttrs should be greater than zero");
Aaron Ballmanf3d9b092014-05-13 14:55:01 +0000317 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs,
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000318 llvm::alignOf<AttributedStmt>());
319 return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
320}
321
Craig Topperc571c812013-08-22 06:02:26 +0000322std::string AsmStmt::generateAsmString(const ASTContext &C) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000323 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
324 return gccAsmStmt->generateAsmString(C);
325 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
326 return msAsmStmt->generateAsmString(C);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000327 llvm_unreachable("unknown asm statement kind!");
328}
329
330StringRef AsmStmt::getOutputConstraint(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000331 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
332 return gccAsmStmt->getOutputConstraint(i);
333 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
334 return msAsmStmt->getOutputConstraint(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000335 llvm_unreachable("unknown asm statement kind!");
336}
337
338const Expr *AsmStmt::getOutputExpr(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000339 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
340 return gccAsmStmt->getOutputExpr(i);
341 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
342 return msAsmStmt->getOutputExpr(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000343 llvm_unreachable("unknown asm statement kind!");
344}
345
346StringRef AsmStmt::getInputConstraint(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000347 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
348 return gccAsmStmt->getInputConstraint(i);
349 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
350 return msAsmStmt->getInputConstraint(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000351 llvm_unreachable("unknown asm statement kind!");
352}
353
354const Expr *AsmStmt::getInputExpr(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000355 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
356 return gccAsmStmt->getInputExpr(i);
357 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
358 return msAsmStmt->getInputExpr(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000359 llvm_unreachable("unknown asm statement kind!");
360}
361
362StringRef AsmStmt::getClobber(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000363 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
364 return gccAsmStmt->getClobber(i);
365 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
366 return msAsmStmt->getClobber(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000367 llvm_unreachable("unknown asm statement kind!");
368}
369
Chad Rosiera1b5c8c2012-08-28 00:24:05 +0000370/// getNumPlusOperands - Return the number of output operands that have a "+"
371/// constraint.
372unsigned AsmStmt::getNumPlusOperands() const {
373 unsigned Res = 0;
374 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
375 if (isOutputPlusConstraint(i))
376 ++Res;
377 return Res;
378}
379
Akira Hatanaka987f1862014-08-22 06:05:21 +0000380char GCCAsmStmt::AsmStringPiece::getModifier() const {
381 assert(isOperand() && "Only Operands can have modifiers.");
382 return isLetter(Str[0]) ? Str[0] : '\0';
383}
384
Chad Rosier6100ae12012-08-27 23:47:56 +0000385StringRef GCCAsmStmt::getClobber(unsigned i) const {
386 return getClobberStringLiteral(i)->getString();
387}
388
Chad Rosierde70e0e2012-08-25 00:11:56 +0000389Expr *GCCAsmStmt::getOutputExpr(unsigned i) {
Ted Kremenek5778acf2008-10-27 18:40:21 +0000390 return cast<Expr>(Exprs[i]);
391}
Chris Lattner72bbf172009-03-10 04:59:06 +0000392
393/// getOutputConstraint - Return the constraint string for the specified
394/// output operand. All output constraints are known to be non-empty (either
395/// '=' or '+').
Chad Rosierde70e0e2012-08-25 00:11:56 +0000396StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const {
Anders Carlsson66de0812010-01-30 20:38:10 +0000397 return getOutputConstraintLiteral(i)->getString();
Ted Kremenek5778acf2008-10-27 18:40:21 +0000398}
Chris Lattner72bbf172009-03-10 04:59:06 +0000399
Chad Rosierde70e0e2012-08-25 00:11:56 +0000400Expr *GCCAsmStmt::getInputExpr(unsigned i) {
Ted Kremenek5778acf2008-10-27 18:40:21 +0000401 return cast<Expr>(Exprs[i + NumOutputs]);
402}
Chad Rosierde70e0e2012-08-25 00:11:56 +0000403void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) {
Chris Lattner93ede022011-02-21 22:09:29 +0000404 Exprs[i + NumOutputs] = E;
405}
406
Chris Lattner72bbf172009-03-10 04:59:06 +0000407/// getInputConstraint - Return the specified input constraint. Unlike output
408/// constraints, these can be empty.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000409StringRef GCCAsmStmt::getInputConstraint(unsigned i) const {
Anders Carlsson66de0812010-01-30 20:38:10 +0000410 return getInputConstraintLiteral(i)->getString();
Ted Kremenek5778acf2008-10-27 18:40:21 +0000411}
412
Craig Topperc571c812013-08-22 06:02:26 +0000413void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
414 IdentifierInfo **Names,
415 StringLiteral **Constraints,
416 Stmt **Exprs,
417 unsigned NumOutputs,
418 unsigned NumInputs,
419 StringLiteral **Clobbers,
420 unsigned NumClobbers) {
Douglas Gregorf994f062009-04-17 20:57:14 +0000421 this->NumOutputs = NumOutputs;
422 this->NumInputs = NumInputs;
Anders Carlsson98323d22010-01-30 23:19:41 +0000423 this->NumClobbers = NumClobbers;
424
425 unsigned NumExprs = NumOutputs + NumInputs;
Chad Rosier42032fa2012-08-07 23:12:23 +0000426
Anders Carlsson98323d22010-01-30 23:19:41 +0000427 C.Deallocate(this->Names);
428 this->Names = new (C) IdentifierInfo*[NumExprs];
429 std::copy(Names, Names + NumExprs, this->Names);
Chad Rosier42032fa2012-08-07 23:12:23 +0000430
Anders Carlsson98323d22010-01-30 23:19:41 +0000431 C.Deallocate(this->Exprs);
432 this->Exprs = new (C) Stmt*[NumExprs];
433 std::copy(Exprs, Exprs + NumExprs, this->Exprs);
Chad Rosier42032fa2012-08-07 23:12:23 +0000434
Anders Carlsson98323d22010-01-30 23:19:41 +0000435 C.Deallocate(this->Constraints);
436 this->Constraints = new (C) StringLiteral*[NumExprs];
437 std::copy(Constraints, Constraints + NumExprs, this->Constraints);
Chad Rosier42032fa2012-08-07 23:12:23 +0000438
Anders Carlsson98323d22010-01-30 23:19:41 +0000439 C.Deallocate(this->Clobbers);
440 this->Clobbers = new (C) StringLiteral*[NumClobbers];
441 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
Douglas Gregorf994f062009-04-17 20:57:14 +0000442}
443
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000444/// getNamedOperand - Given a symbolic operand reference like %[foo],
445/// translate this into a numeric value needed to reference the same operand.
446/// This returns -1 if the operand name is invalid.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000447int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const {
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000448 unsigned NumPlusOperands = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000449
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000450 // Check if this is an output operand.
451 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
452 if (getOutputName(i) == SymbolicName)
453 return i;
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000454 }
Mike Stump11289f42009-09-09 15:08:12 +0000455
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000456 for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
457 if (getInputName(i) == SymbolicName)
458 return getNumOutputs() + NumPlusOperands + i;
459
460 // Not found.
461 return -1;
462}
463
Chris Lattner35b58362009-03-10 23:21:44 +0000464/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
465/// it into pieces. If the asm string is erroneous, emit errors and return
466/// true, otherwise return false.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000467unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
Craig Topperc571c812013-08-22 06:02:26 +0000468 const ASTContext &C, unsigned &DiagOffs) const {
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000469 StringRef Str = getAsmString()->getString();
Benjamin Kramer35b077e2010-08-17 12:54:38 +0000470 const char *StrStart = Str.begin();
471 const char *StrEnd = Str.end();
Chris Lattnera41b8472009-03-10 23:51:40 +0000472 const char *CurPtr = StrStart;
Mike Stump11289f42009-09-09 15:08:12 +0000473
Chris Lattner35b58362009-03-10 23:21:44 +0000474 // "Simple" inline asms have no constraints or operands, just convert the asm
475 // string to escape $'s.
476 if (isSimple()) {
477 std::string Result;
Chris Lattnera41b8472009-03-10 23:51:40 +0000478 for (; CurPtr != StrEnd; ++CurPtr) {
479 switch (*CurPtr) {
Chris Lattner35b58362009-03-10 23:21:44 +0000480 case '$':
481 Result += "$$";
482 break;
483 default:
Chris Lattnera41b8472009-03-10 23:51:40 +0000484 Result += *CurPtr;
Chris Lattner35b58362009-03-10 23:21:44 +0000485 break;
486 }
487 }
488 Pieces.push_back(AsmStringPiece(Result));
Chris Lattnera41b8472009-03-10 23:51:40 +0000489 return 0;
Chris Lattner35b58362009-03-10 23:21:44 +0000490 }
491
492 // CurStringPiece - The current string that we are building up as we scan the
493 // asm string.
494 std::string CurStringPiece;
Mike Stump11289f42009-09-09 15:08:12 +0000495
Douglas Gregore8bbc122011-09-02 00:18:52 +0000496 bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
Chad Rosier42032fa2012-08-07 23:12:23 +0000497
Chris Lattner35b58362009-03-10 23:21:44 +0000498 while (1) {
499 // Done with the string?
Chris Lattnera41b8472009-03-10 23:51:40 +0000500 if (CurPtr == StrEnd) {
Chris Lattner35b58362009-03-10 23:21:44 +0000501 if (!CurStringPiece.empty())
502 Pieces.push_back(AsmStringPiece(CurStringPiece));
Chris Lattnera41b8472009-03-10 23:51:40 +0000503 return 0;
Chris Lattner35b58362009-03-10 23:21:44 +0000504 }
Mike Stump11289f42009-09-09 15:08:12 +0000505
Chris Lattnera41b8472009-03-10 23:51:40 +0000506 char CurChar = *CurPtr++;
Chris Lattnerda081a82010-04-05 18:44:00 +0000507 switch (CurChar) {
508 case '$': CurStringPiece += "$$"; continue;
Chris Lattner1a8f3942010-04-23 16:29:58 +0000509 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
510 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
511 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
Chris Lattnerda081a82010-04-05 18:44:00 +0000512 case '%':
513 break;
514 default:
Chris Lattner35b58362009-03-10 23:21:44 +0000515 CurStringPiece += CurChar;
516 continue;
517 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000518
Chris Lattner35b58362009-03-10 23:21:44 +0000519 // Escaped "%" character in asm string.
Chris Lattner3fa25c62009-03-11 00:06:36 +0000520 if (CurPtr == StrEnd) {
521 // % at end of string is invalid (no escape).
522 DiagOffs = CurPtr-StrStart-1;
523 return diag::err_asm_invalid_escape;
524 }
Mike Stump11289f42009-09-09 15:08:12 +0000525
Chris Lattnera41b8472009-03-10 23:51:40 +0000526 char EscapedChar = *CurPtr++;
Chris Lattner35b58362009-03-10 23:21:44 +0000527 if (EscapedChar == '%') { // %% -> %
528 // Escaped percentage sign.
529 CurStringPiece += '%';
530 continue;
531 }
Mike Stump11289f42009-09-09 15:08:12 +0000532
Chris Lattner35b58362009-03-10 23:21:44 +0000533 if (EscapedChar == '=') { // %= -> Generate an unique ID.
534 CurStringPiece += "${:uid}";
535 continue;
536 }
Mike Stump11289f42009-09-09 15:08:12 +0000537
Chris Lattner35b58362009-03-10 23:21:44 +0000538 // Otherwise, we have an operand. If we have accumulated a string so far,
539 // add it to the Pieces list.
540 if (!CurStringPiece.empty()) {
541 Pieces.push_back(AsmStringPiece(CurStringPiece));
542 CurStringPiece.clear();
543 }
Mike Stump11289f42009-09-09 15:08:12 +0000544
Akira Hatanaka987f1862014-08-22 06:05:21 +0000545 // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that
546 // don't (e.g., %x4). 'x' following the '%' is the constraint modifier.
547
548 const char *Begin = CurPtr - 1; // Points to the character following '%'.
549 const char *Percent = Begin - 1; // Points to '%'.
550
Jordan Rosea7d03842013-02-08 22:30:41 +0000551 if (isLetter(EscapedChar)) {
Benjamin Kramere87c38b2011-07-05 11:13:37 +0000552 if (CurPtr == StrEnd) { // Premature end.
553 DiagOffs = CurPtr-StrStart-1;
554 return diag::err_asm_invalid_escape;
555 }
Chris Lattnera41b8472009-03-10 23:51:40 +0000556 EscapedChar = *CurPtr++;
Chris Lattner35b58362009-03-10 23:21:44 +0000557 }
Mike Stump11289f42009-09-09 15:08:12 +0000558
Akira Hatanaka987f1862014-08-22 06:05:21 +0000559 const TargetInfo &TI = C.getTargetInfo();
560 const SourceManager &SM = C.getSourceManager();
561 const LangOptions &LO = C.getLangOpts();
562
563 // Handle operands that don't have asmSymbolicName (e.g., %x4).
Jordan Rosea7d03842013-02-08 22:30:41 +0000564 if (isDigit(EscapedChar)) {
Chris Lattner35b58362009-03-10 23:21:44 +0000565 // %n - Assembler operand n
Chris Lattner99d892b2009-03-11 22:52:17 +0000566 unsigned N = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000567
Chris Lattner99d892b2009-03-11 22:52:17 +0000568 --CurPtr;
Jordan Rosea7d03842013-02-08 22:30:41 +0000569 while (CurPtr != StrEnd && isDigit(*CurPtr))
Chris Lattner84f3afa2009-03-11 23:09:16 +0000570 N = N*10 + ((*CurPtr++)-'0');
Mike Stump11289f42009-09-09 15:08:12 +0000571
Chris Lattner14311922009-03-11 00:23:13 +0000572 unsigned NumOperands =
573 getNumOutputs() + getNumPlusOperands() + getNumInputs();
574 if (N >= NumOperands) {
575 DiagOffs = CurPtr-StrStart-1;
576 return diag::err_asm_invalid_operand_number;
577 }
578
Akira Hatanaka987f1862014-08-22 06:05:21 +0000579 // Str contains "x4" (Operand without the leading %).
580 std::string Str(Begin, CurPtr - Begin);
581
582 // (BeginLoc, EndLoc) represents the range of the operand we are currently
583 // processing. Unlike Str, the range includes the leading '%'.
584 SourceLocation BeginLoc =
585 getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
586 SourceLocation EndLoc =
587 getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI);
588
589 Pieces.push_back(AsmStringPiece(N, Str, BeginLoc, EndLoc));
Chris Lattner35b58362009-03-10 23:21:44 +0000590 continue;
591 }
Mike Stump11289f42009-09-09 15:08:12 +0000592
Akira Hatanaka987f1862014-08-22 06:05:21 +0000593 // Handle operands that have asmSymbolicName (e.g., %x[foo]).
Chris Lattner35b58362009-03-10 23:21:44 +0000594 if (EscapedChar == '[') {
Chris Lattner3fa25c62009-03-11 00:06:36 +0000595 DiagOffs = CurPtr-StrStart-1;
Mike Stump11289f42009-09-09 15:08:12 +0000596
Chris Lattner3fa25c62009-03-11 00:06:36 +0000597 // Find the ']'.
Chris Lattnera41b8472009-03-10 23:51:40 +0000598 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
Craig Topper36250ad2014-05-12 05:36:57 +0000599 if (NameEnd == nullptr)
Chris Lattner3fa25c62009-03-11 00:06:36 +0000600 return diag::err_asm_unterminated_symbolic_operand_name;
601 if (NameEnd == CurPtr)
602 return diag::err_asm_empty_symbolic_operand_name;
Mike Stump11289f42009-09-09 15:08:12 +0000603
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000604 StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
Mike Stump11289f42009-09-09 15:08:12 +0000605
Chris Lattner35b58362009-03-10 23:21:44 +0000606 int N = getNamedOperand(SymbolicName);
Chris Lattner3fa25c62009-03-11 00:06:36 +0000607 if (N == -1) {
608 // Verify that an operand with that name exists.
609 DiagOffs = CurPtr-StrStart;
610 return diag::err_asm_unknown_symbolic_operand_name;
611 }
Akira Hatanaka987f1862014-08-22 06:05:21 +0000612
613 // Str contains "x[foo]" (Operand without the leading %).
614 std::string Str(Begin, NameEnd + 1 - Begin);
615
616 // (BeginLoc, EndLoc) represents the range of the operand we are currently
617 // processing. Unlike Str, the range includes the leading '%'.
618 SourceLocation BeginLoc =
619 getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
620 SourceLocation EndLoc =
621 getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI);
622
623 Pieces.push_back(AsmStringPiece(N, Str, BeginLoc, EndLoc));
Mike Stump11289f42009-09-09 15:08:12 +0000624
Chris Lattner3fa25c62009-03-11 00:06:36 +0000625 CurPtr = NameEnd+1;
Chris Lattner35b58362009-03-10 23:21:44 +0000626 continue;
627 }
Mike Stump11289f42009-09-09 15:08:12 +0000628
Chris Lattner0cdaa2e2009-03-10 23:57:07 +0000629 DiagOffs = CurPtr-StrStart-1;
Chris Lattnera41b8472009-03-10 23:51:40 +0000630 return diag::err_asm_invalid_escape;
Chris Lattner35b58362009-03-10 23:21:44 +0000631 }
632}
Chad Rosier3b0c2602012-08-27 20:23:31 +0000633
634/// Assemble final IR asm string (GCC-style).
Craig Topperc571c812013-08-22 06:02:26 +0000635std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const {
Chad Rosier14836ba2012-08-24 17:05:45 +0000636 // Analyze the asm string to decompose it into its pieces. We know that Sema
637 // has already done this, so it is guaranteed to be successful.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000638 SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces;
Chad Rosier14836ba2012-08-24 17:05:45 +0000639 unsigned DiagOffs;
640 AnalyzeAsmString(Pieces, C, DiagOffs);
641
642 std::string AsmString;
643 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
644 if (Pieces[i].isString())
645 AsmString += Pieces[i].getString();
646 else if (Pieces[i].getModifier() == '\0')
647 AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo());
648 else
649 AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' +
650 Pieces[i].getModifier() + '}';
651 }
652 return AsmString;
653}
Chris Lattner35b58362009-03-10 23:21:44 +0000654
Chad Rosier3b0c2602012-08-27 20:23:31 +0000655/// Assemble final IR asm string (MS-style).
Craig Topperc571c812013-08-22 06:02:26 +0000656std::string MSAsmStmt::generateAsmString(const ASTContext &C) const {
Chad Rosier3b0c2602012-08-27 20:23:31 +0000657 // FIXME: This needs to be translated into the IR string representation.
Chad Rosier0bca4692012-08-28 20:33:49 +0000658 return AsmStr;
Chad Rosier3b0c2602012-08-27 20:23:31 +0000659}
660
Chad Rosierfe31e622012-08-24 00:07:09 +0000661Expr *MSAsmStmt::getOutputExpr(unsigned i) {
662 return cast<Expr>(Exprs[i]);
663}
664
665Expr *MSAsmStmt::getInputExpr(unsigned i) {
666 return cast<Expr>(Exprs[i + NumOutputs]);
667}
668void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
669 Exprs[i + NumOutputs] = E;
670}
671
Sam Weinigebcea982010-02-03 02:09:59 +0000672QualType CXXCatchStmt::getCaughtType() const {
673 if (ExceptionDecl)
674 return ExceptionDecl->getType();
675 return QualType();
676}
677
Chris Lattner86f5e132008-01-30 05:01:46 +0000678//===----------------------------------------------------------------------===//
679// Constructors
680//===----------------------------------------------------------------------===//
681
Craig Toppere6960e22013-08-22 05:28:54 +0000682GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc,
683 bool issimple, bool isvolatile, unsigned numoutputs,
684 unsigned numinputs, IdentifierInfo **names,
685 StringLiteral **constraints, Expr **exprs,
686 StringLiteral *asmstr, unsigned numclobbers,
687 StringLiteral **clobbers, SourceLocation rparenloc)
Chad Rosierfe3352e2012-08-27 19:38:01 +0000688 : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
689 numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) {
Nico Weberde565e32008-08-05 23:15:29 +0000690
Chad Rosier42032fa2012-08-07 23:12:23 +0000691 unsigned NumExprs = NumOutputs + NumInputs;
692
Anders Carlsson98323d22010-01-30 23:19:41 +0000693 Names = new (C) IdentifierInfo*[NumExprs];
694 std::copy(names, names + NumExprs, Names);
695
696 Exprs = new (C) Stmt*[NumExprs];
697 std::copy(exprs, exprs + NumExprs, Exprs);
698
699 Constraints = new (C) StringLiteral*[NumExprs];
700 std::copy(constraints, constraints + NumExprs, Constraints);
701
702 Clobbers = new (C) StringLiteral*[NumClobbers];
703 std::copy(clobbers, clobbers + NumClobbers, Clobbers);
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000704}
705
Craig Toppere6960e22013-08-22 05:28:54 +0000706MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
Chad Rosier7dbef3e2012-08-16 00:06:53 +0000707 SourceLocation lbraceloc, bool issimple, bool isvolatile,
Chad Rosierf8037a12012-10-16 21:55:39 +0000708 ArrayRef<Token> asmtoks, unsigned numoutputs,
John McCallf413f5e2013-05-03 00:10:13 +0000709 unsigned numinputs,
Chad Rosierf8037a12012-10-16 21:55:39 +0000710 ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs,
711 StringRef asmstr, ArrayRef<StringRef> clobbers,
712 SourceLocation endloc)
713 : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
714 numinputs, clobbers.size()), LBraceLoc(lbraceloc),
John McCallf413f5e2013-05-03 00:10:13 +0000715 EndLoc(endloc), NumAsmToks(asmtoks.size()) {
Chad Rosier7dbef3e2012-08-16 00:06:53 +0000716
John McCallf413f5e2013-05-03 00:10:13 +0000717 initialize(C, asmstr, asmtoks, constraints, exprs, clobbers);
718}
Chad Rosier7dbef3e2012-08-16 00:06:53 +0000719
Craig Toppere6960e22013-08-22 05:28:54 +0000720static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
John McCallf413f5e2013-05-03 00:10:13 +0000721 size_t size = str.size();
722 char *buffer = new (C) char[size];
723 memcpy(buffer, str.data(), size);
724 return StringRef(buffer, size);
725}
726
Craig Toppere6960e22013-08-22 05:28:54 +0000727void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,
John McCallf413f5e2013-05-03 00:10:13 +0000728 ArrayRef<Token> asmtoks,
729 ArrayRef<StringRef> constraints,
730 ArrayRef<Expr*> exprs,
731 ArrayRef<StringRef> clobbers) {
732 assert(NumAsmToks == asmtoks.size());
733 assert(NumClobbers == clobbers.size());
734
735 unsigned NumExprs = exprs.size();
736 assert(NumExprs == NumOutputs + NumInputs);
737 assert(NumExprs == constraints.size());
738
739 AsmStr = copyIntoContext(C, asmstr);
Chad Rosier99fc3812012-08-07 00:29:06 +0000740
Chad Rosierfe31e622012-08-24 00:07:09 +0000741 Exprs = new (C) Stmt*[NumExprs];
Chad Rosierf8037a12012-10-16 21:55:39 +0000742 for (unsigned i = 0, e = NumExprs; i != e; ++i)
743 Exprs[i] = exprs[i];
Chad Rosierfe31e622012-08-24 00:07:09 +0000744
Chad Rosier99fc3812012-08-07 00:29:06 +0000745 AsmToks = new (C) Token[NumAsmToks];
746 for (unsigned i = 0, e = NumAsmToks; i != e; ++i)
747 AsmToks[i] = asmtoks[i];
Chad Rosier3ed0bd92012-08-08 19:48:07 +0000748
Chad Rosier3dd7bf22012-08-28 20:28:20 +0000749 Constraints = new (C) StringRef[NumExprs];
750 for (unsigned i = 0, e = NumExprs; i != e; ++i) {
John McCallf413f5e2013-05-03 00:10:13 +0000751 Constraints[i] = copyIntoContext(C, constraints[i]);
Chad Rosier3dd7bf22012-08-28 20:28:20 +0000752 }
753
Chad Rosierbaf53f92012-08-10 21:36:25 +0000754 Clobbers = new (C) StringRef[NumClobbers];
Chad Rosierd6ef7042012-08-10 21:06:19 +0000755 for (unsigned i = 0, e = NumClobbers; i != e; ++i) {
756 // FIXME: Avoid the allocation/copy if at all possible.
John McCallf413f5e2013-05-03 00:10:13 +0000757 Clobbers[i] = copyIntoContext(C, clobbers[i]);
Chad Rosierd6ef7042012-08-10 21:06:19 +0000758 }
Chad Rosier32503022012-06-11 20:47:18 +0000759}
760
Chris Lattner86f5e132008-01-30 05:01:46 +0000761ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
762 Stmt *Body, SourceLocation FCL,
Nico Weberde565e32008-08-05 23:15:29 +0000763 SourceLocation RPL)
Chris Lattner86f5e132008-01-30 05:01:46 +0000764: Stmt(ObjCForCollectionStmtClass) {
765 SubExprs[ELEM] = Elem;
Pavel Labath515f4db2013-09-03 14:41:16 +0000766 SubExprs[COLLECTION] = Collect;
Chris Lattner86f5e132008-01-30 05:01:46 +0000767 SubExprs[BODY] = Body;
768 ForLoc = FCL;
769 RParenLoc = RPL;
770}
771
Douglas Gregor96c79492010-04-23 22:50:49 +0000772ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
773 Stmt **CatchStmts, unsigned NumCatchStmts,
774 Stmt *atFinallyStmt)
775 : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
Craig Topper36250ad2014-05-12 05:36:57 +0000776 NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000777 Stmt **Stmts = getStmts();
778 Stmts[0] = atTryStmt;
779 for (unsigned I = 0; I != NumCatchStmts; ++I)
780 Stmts[I + 1] = CatchStmts[I];
Chad Rosier42032fa2012-08-07 23:12:23 +0000781
Douglas Gregor96c79492010-04-23 22:50:49 +0000782 if (HasFinally)
783 Stmts[NumCatchStmts + 1] = atFinallyStmt;
784}
Chris Lattner86f5e132008-01-30 05:01:46 +0000785
Craig Toppere6960e22013-08-22 05:28:54 +0000786ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context,
Chad Rosier42032fa2012-08-07 23:12:23 +0000787 SourceLocation atTryLoc,
Douglas Gregor96c79492010-04-23 22:50:49 +0000788 Stmt *atTryStmt,
Chad Rosier42032fa2012-08-07 23:12:23 +0000789 Stmt **CatchStmts,
Douglas Gregor96c79492010-04-23 22:50:49 +0000790 unsigned NumCatchStmts,
791 Stmt *atFinallyStmt) {
Chad Rosier42032fa2012-08-07 23:12:23 +0000792 unsigned Size = sizeof(ObjCAtTryStmt) +
Craig Topper36250ad2014-05-12 05:36:57 +0000793 (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
Chris Lattner5c0b4052010-10-30 05:14:06 +0000794 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Douglas Gregor96c79492010-04-23 22:50:49 +0000795 return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
796 atFinallyStmt);
797}
Ted Kremeneka4965842008-02-01 21:28:59 +0000798
Craig Toppere6960e22013-08-22 05:28:54 +0000799ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
800 unsigned NumCatchStmts,
801 bool HasFinally) {
Chad Rosier42032fa2012-08-07 23:12:23 +0000802 unsigned Size = sizeof(ObjCAtTryStmt) +
Douglas Gregor96c79492010-04-23 22:50:49 +0000803 (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
Chris Lattner5c0b4052010-10-30 05:14:06 +0000804 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Chad Rosier42032fa2012-08-07 23:12:23 +0000805 return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
Douglas Gregor96c79492010-04-23 22:50:49 +0000806}
Nico Weberde565e32008-08-05 23:15:29 +0000807
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000808SourceLocation ObjCAtTryStmt::getLocEnd() const {
Douglas Gregor96c79492010-04-23 22:50:49 +0000809 if (HasFinally)
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000810 return getFinallyStmt()->getLocEnd();
811 if (NumCatchStmts)
812 return getCatchStmt(NumCatchStmts - 1)->getLocEnd();
813 return getTryBody()->getLocEnd();
Chris Lattner86f5e132008-01-30 05:01:46 +0000814}
815
Craig Toppere6960e22013-08-22 05:28:54 +0000816CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc,
Nico Weber9dff3782012-12-29 20:13:03 +0000817 Stmt *tryBlock, ArrayRef<Stmt*> handlers) {
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000818 std::size_t Size = sizeof(CXXTryStmt);
Nico Weber9dff3782012-12-29 20:13:03 +0000819 Size += ((handlers.size() + 1) * sizeof(Stmt));
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000820
Chris Lattner5c0b4052010-10-30 05:14:06 +0000821 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Nico Weber9dff3782012-12-29 20:13:03 +0000822 return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000823}
824
Craig Toppere6960e22013-08-22 05:28:54 +0000825CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +0000826 unsigned numHandlers) {
827 std::size_t Size = sizeof(CXXTryStmt);
828 Size += ((numHandlers + 1) * sizeof(Stmt));
829
Chris Lattner5c0b4052010-10-30 05:14:06 +0000830 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +0000831 return new (Mem) CXXTryStmt(Empty, numHandlers);
832}
833
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000834CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
Nico Weber9dff3782012-12-29 20:13:03 +0000835 ArrayRef<Stmt*> handlers)
836 : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000837 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
Sam Weinigebcea982010-02-03 02:09:59 +0000838 Stmts[0] = tryBlock;
Nico Weber9dff3782012-12-29 20:13:03 +0000839 std::copy(handlers.begin(), handlers.end(), Stmts + 1);
Sam Weinigebcea982010-02-03 02:09:59 +0000840}
841
Richard Smith02e85f32011-04-14 22:09:26 +0000842CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt,
843 Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
844 Stmt *Body, SourceLocation FL,
845 SourceLocation CL, SourceLocation RPL)
846 : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) {
847 SubExprs[RANGE] = Range;
848 SubExprs[BEGINEND] = BeginEndStmt;
Pavel Labath515f4db2013-09-03 14:41:16 +0000849 SubExprs[COND] = Cond;
850 SubExprs[INC] = Inc;
Richard Smith02e85f32011-04-14 22:09:26 +0000851 SubExprs[LOOPVAR] = LoopVar;
852 SubExprs[BODY] = Body;
853}
854
855Expr *CXXForRangeStmt::getRangeInit() {
856 DeclStmt *RangeStmt = getRangeStmt();
857 VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
Richard Trieu86738692014-02-27 23:59:14 +0000858 assert(RangeDecl && "for-range should have a single var decl");
Richard Smith02e85f32011-04-14 22:09:26 +0000859 return RangeDecl->getInit();
860}
861
862const Expr *CXXForRangeStmt::getRangeInit() const {
863 return const_cast<CXXForRangeStmt*>(this)->getRangeInit();
864}
865
866VarDecl *CXXForRangeStmt::getLoopVariable() {
867 Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
868 assert(LV && "No loop variable in CXXForRangeStmt");
869 return cast<VarDecl>(LV);
870}
871
872const VarDecl *CXXForRangeStmt::getLoopVariable() const {
873 return const_cast<CXXForRangeStmt*>(this)->getLoopVariable();
874}
875
Craig Toppere6960e22013-08-22 05:28:54 +0000876IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000877 Stmt *then, SourceLocation EL, Stmt *elsev)
878 : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000879{
880 setConditionVariable(C, var);
Pavel Labath515f4db2013-09-03 14:41:16 +0000881 SubExprs[COND] = cond;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000882 SubExprs[THEN] = then;
Chad Rosier42032fa2012-08-07 23:12:23 +0000883 SubExprs[ELSE] = elsev;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000884}
885
886VarDecl *IfStmt::getConditionVariable() const {
887 if (!SubExprs[VAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000888 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000889
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000890 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
891 return cast<VarDecl>(DS->getSingleDecl());
892}
893
Craig Toppere6960e22013-08-22 05:28:54 +0000894void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000895 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000896 SubExprs[VAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000897 return;
898 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000899
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000900 SourceRange VarRange = V->getSourceRange();
901 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
902 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000903}
904
Craig Toppere6960e22013-08-22 05:28:54 +0000905ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
Chad Rosier42032fa2012-08-07 23:12:23 +0000906 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000907 SourceLocation RP)
Chad Rosier42032fa2012-08-07 23:12:23 +0000908 : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000909{
910 SubExprs[INIT] = Init;
911 setConditionVariable(C, condVar);
Pavel Labath515f4db2013-09-03 14:41:16 +0000912 SubExprs[COND] = Cond;
913 SubExprs[INC] = Inc;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000914 SubExprs[BODY] = Body;
915}
916
917VarDecl *ForStmt::getConditionVariable() const {
918 if (!SubExprs[CONDVAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000919 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000920
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000921 DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
922 return cast<VarDecl>(DS->getSingleDecl());
923}
924
Craig Toppere6960e22013-08-22 05:28:54 +0000925void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000926 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000927 SubExprs[CONDVAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000928 return;
929 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000930
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000931 SourceRange VarRange = V->getSourceRange();
932 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
933 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000934}
935
Craig Toppere6960e22013-08-22 05:28:54 +0000936SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond)
Craig Topper36250ad2014-05-12 05:36:57 +0000937 : Stmt(SwitchStmtClass), FirstCase(nullptr), AllEnumCasesCovered(0)
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000938{
939 setConditionVariable(C, Var);
Pavel Labath515f4db2013-09-03 14:41:16 +0000940 SubExprs[COND] = cond;
Craig Topper36250ad2014-05-12 05:36:57 +0000941 SubExprs[BODY] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000942}
943
944VarDecl *SwitchStmt::getConditionVariable() const {
945 if (!SubExprs[VAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000946 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000947
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000948 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
949 return cast<VarDecl>(DS->getSingleDecl());
950}
951
Craig Toppere6960e22013-08-22 05:28:54 +0000952void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000953 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000954 SubExprs[VAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000955 return;
956 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000957
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000958 SourceRange VarRange = V->getSourceRange();
959 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
960 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000961}
962
John McCallbd066782011-02-09 08:16:59 +0000963Stmt *SwitchCase::getSubStmt() {
Chris Lattner80d51eb2011-02-28 00:18:06 +0000964 if (isa<CaseStmt>(this))
965 return cast<CaseStmt>(this)->getSubStmt();
John McCallbd066782011-02-09 08:16:59 +0000966 return cast<DefaultStmt>(this)->getSubStmt();
967}
968
Craig Toppere6960e22013-08-22 05:28:54 +0000969WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000970 SourceLocation WL)
Chris Lattner80d51eb2011-02-28 00:18:06 +0000971 : Stmt(WhileStmtClass) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000972 setConditionVariable(C, Var);
Pavel Labath515f4db2013-09-03 14:41:16 +0000973 SubExprs[COND] = cond;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000974 SubExprs[BODY] = body;
975 WhileLoc = WL;
976}
977
978VarDecl *WhileStmt::getConditionVariable() const {
979 if (!SubExprs[VAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000980 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000981
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000982 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
983 return cast<VarDecl>(DS->getSingleDecl());
984}
985
Craig Toppere6960e22013-08-22 05:28:54 +0000986void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000987 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000988 SubExprs[VAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000989 return;
990 }
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000991
992 SourceRange VarRange = V->getSourceRange();
993 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
994 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000995}
996
Ted Kremenek066dd932007-08-24 21:09:09 +0000997// IndirectGotoStmt
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000998LabelDecl *IndirectGotoStmt::getConstantTarget() {
John McCall9de91602010-10-28 08:53:48 +0000999 if (AddrLabelExpr *E =
1000 dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
1001 return E->getLabel();
Craig Topper36250ad2014-05-12 05:36:57 +00001002 return nullptr;
John McCall9de91602010-10-28 08:53:48 +00001003}
Ted Kremenek066dd932007-08-24 21:09:09 +00001004
Ted Kremenek066dd932007-08-24 21:09:09 +00001005// ReturnStmt
Ted Kremenekc6501db2008-06-17 03:11:08 +00001006const Expr* ReturnStmt::getRetValue() const {
1007 return cast_or_null<Expr>(RetExpr);
1008}
1009Expr* ReturnStmt::getRetValue() {
1010 return cast_or_null<Expr>(RetExpr);
Ted Kremenek066dd932007-08-24 21:09:09 +00001011}
John Wiegley1c0675e2011-04-28 01:08:34 +00001012
Warren Huntf6be4cb2014-07-25 20:52:51 +00001013SEHTryStmt::SEHTryStmt(bool IsCXXTry,
1014 SourceLocation TryLoc,
1015 Stmt *TryBlock,
1016 Stmt *Handler)
1017 : Stmt(SEHTryStmtClass),
1018 IsCXXTry(IsCXXTry),
1019 TryLoc(TryLoc)
1020{
1021 Children[TRY] = TryBlock;
John Wiegley1c0675e2011-04-28 01:08:34 +00001022 Children[HANDLER] = Handler;
1023}
1024
Warren Huntf6be4cb2014-07-25 20:52:51 +00001025SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
Craig Toppere6960e22013-08-22 05:28:54 +00001026 SourceLocation TryLoc, Stmt *TryBlock,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001027 Stmt *Handler) {
1028 return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001029}
1030
1031SEHExceptStmt* SEHTryStmt::getExceptHandler() const {
1032 return dyn_cast<SEHExceptStmt>(getHandler());
1033}
1034
1035SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const {
1036 return dyn_cast<SEHFinallyStmt>(getHandler());
1037}
1038
1039SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
1040 Expr *FilterExpr,
1041 Stmt *Block)
1042 : Stmt(SEHExceptStmtClass),
1043 Loc(Loc)
1044{
Pavel Labath515f4db2013-09-03 14:41:16 +00001045 Children[FILTER_EXPR] = FilterExpr;
John Wiegley1c0675e2011-04-28 01:08:34 +00001046 Children[BLOCK] = Block;
1047}
1048
Craig Toppere6960e22013-08-22 05:28:54 +00001049SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc,
1050 Expr *FilterExpr, Stmt *Block) {
John Wiegley1c0675e2011-04-28 01:08:34 +00001051 return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
1052}
1053
1054SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc,
1055 Stmt *Block)
1056 : Stmt(SEHFinallyStmtClass),
1057 Loc(Loc),
1058 Block(Block)
1059{}
1060
Craig Toppere6960e22013-08-22 05:28:54 +00001061SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc,
John Wiegley1c0675e2011-04-28 01:08:34 +00001062 Stmt *Block) {
1063 return new(C)SEHFinallyStmt(Loc,Block);
1064}
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001065
1066CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const {
1067 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1068
1069 // Offset of the first Capture object.
1070 unsigned FirstCaptureOffset =
1071 llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1072
1073 return reinterpret_cast<Capture *>(
1074 reinterpret_cast<char *>(const_cast<CapturedStmt *>(this))
1075 + FirstCaptureOffset);
1076}
1077
Wei Pan17fbf6e2013-05-04 03:59:06 +00001078CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind,
1079 ArrayRef<Capture> Captures,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001080 ArrayRef<Expr *> CaptureInits,
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001081 CapturedDecl *CD,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001082 RecordDecl *RD)
1083 : Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
Wei Pan17fbf6e2013-05-04 03:59:06 +00001084 CapDeclAndKind(CD, Kind), TheRecordDecl(RD) {
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001085 assert( S && "null captured statement");
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001086 assert(CD && "null captured declaration for captured statement");
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001087 assert(RD && "null record declaration for captured statement");
1088
1089 // Copy initialization expressions.
1090 Stmt **Stored = getStoredStmts();
1091 for (unsigned I = 0, N = NumCaptures; I != N; ++I)
1092 *Stored++ = CaptureInits[I];
1093
1094 // Copy the statement being captured.
1095 *Stored = S;
1096
1097 // Copy all Capture objects.
1098 Capture *Buffer = getStoredCaptures();
1099 std::copy(Captures.begin(), Captures.end(), Buffer);
1100}
1101
1102CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
1103 : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
Craig Topper36250ad2014-05-12 05:36:57 +00001104 CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) {
1105 getStoredStmts()[NumCaptures] = nullptr;
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001106}
1107
Craig Toppere6960e22013-08-22 05:28:54 +00001108CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S,
Wei Pan17fbf6e2013-05-04 03:59:06 +00001109 CapturedRegionKind Kind,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001110 ArrayRef<Capture> Captures,
1111 ArrayRef<Expr *> CaptureInits,
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001112 CapturedDecl *CD,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001113 RecordDecl *RD) {
1114 // The layout is
1115 //
1116 // -----------------------------------------------------------
1117 // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture |
1118 // ----------------^-------------------^----------------------
1119 // getStoredStmts() getStoredCaptures()
1120 //
1121 // where S is the statement being captured.
1122 //
1123 assert(CaptureInits.size() == Captures.size() && "wrong number of arguments");
1124
1125 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1);
1126 if (!Captures.empty()) {
1127 // Realign for the following Capture array.
1128 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1129 Size += sizeof(Capture) * Captures.size();
1130 }
1131
1132 void *Mem = Context.Allocate(Size);
Wei Pan17fbf6e2013-05-04 03:59:06 +00001133 return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001134}
1135
Craig Toppere6960e22013-08-22 05:28:54 +00001136CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001137 unsigned NumCaptures) {
1138 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1139 if (NumCaptures > 0) {
1140 // Realign for the following Capture array.
1141 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1142 Size += sizeof(Capture) * NumCaptures;
1143 }
1144
1145 void *Mem = Context.Allocate(Size);
1146 return new (Mem) CapturedStmt(EmptyShell(), NumCaptures);
1147}
1148
1149Stmt::child_range CapturedStmt::children() {
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001150 // Children are captured field initilizers.
1151 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001152}
1153
1154bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
Aaron Ballmanc656303a2014-03-14 18:08:33 +00001155 for (const auto &I : captures()) {
1156 if (!I.capturesVariable())
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001157 continue;
1158
1159 // This does not handle variable redeclarations. This should be
1160 // extended to capture variables with redeclarations, for example
1161 // a thread-private variable in OpenMP.
Aaron Ballmanc656303a2014-03-14 18:08:33 +00001162 if (I.getCapturedVar() == Var)
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001163 return true;
1164 }
1165
1166 return false;
1167}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001168
Alexey Bataev758e55e2013-09-06 18:03:48 +00001169StmtRange OMPClause::children() {
1170 switch(getClauseKind()) {
1171 default : break;
1172#define OPENMP_CLAUSE(Name, Class) \
1173 case OMPC_ ## Name : return static_cast<Class *>(this)->children();
1174#include "clang/Basic/OpenMPKinds.def"
1175 }
1176 llvm_unreachable("unknown OMPClause");
1177}
1178
Craig Toppere6960e22013-08-22 05:28:54 +00001179OMPPrivateClause *OMPPrivateClause::Create(const ASTContext &C,
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001180 SourceLocation StartLoc,
1181 SourceLocation LParenLoc,
1182 SourceLocation EndLoc,
1183 ArrayRef<Expr *> VL) {
Alexey Bataev13193812014-02-25 11:25:38 +00001184 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
1185 llvm::alignOf<Expr *>()) +
1186 sizeof(Expr *) * VL.size());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001187 OMPPrivateClause *Clause = new (Mem) OMPPrivateClause(StartLoc, LParenLoc,
1188 EndLoc, VL.size());
1189 Clause->setVarRefs(VL);
1190 return Clause;
1191}
1192
Craig Toppere6960e22013-08-22 05:28:54 +00001193OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001194 unsigned N) {
Alexey Bataev13193812014-02-25 11:25:38 +00001195 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
1196 llvm::alignOf<Expr *>()) +
1197 sizeof(Expr *) * N);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001198 return new (Mem) OMPPrivateClause(N);
1199}
1200
Alexey Bataev4a5bb772014-10-08 14:01:46 +00001201void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1202 assert(VL.size() == varlist_size() &&
1203 "Number of private copies is not the same as the preallocated buffer");
1204 std::copy(VL.begin(), VL.end(), varlist_end());
1205}
1206
1207void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
1208 assert(VL.size() == varlist_size() &&
1209 "Number of inits is not the same as the preallocated buffer");
1210 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1211}
1212
1213OMPFirstprivateClause *
1214OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
1215 SourceLocation LParenLoc, SourceLocation EndLoc,
1216 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1217 ArrayRef<Expr *> InitVL) {
Alexey Bataev13193812014-02-25 11:25:38 +00001218 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
1219 llvm::alignOf<Expr *>()) +
Alexey Bataev4a5bb772014-10-08 14:01:46 +00001220 3 * sizeof(Expr *) * VL.size());
1221 OMPFirstprivateClause *Clause =
1222 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001223 Clause->setVarRefs(VL);
Alexey Bataev4a5bb772014-10-08 14:01:46 +00001224 Clause->setPrivateCopies(PrivateVL);
1225 Clause->setInits(InitVL);
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001226 return Clause;
1227}
1228
1229OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
1230 unsigned N) {
Alexey Bataev13193812014-02-25 11:25:38 +00001231 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
1232 llvm::alignOf<Expr *>()) +
Alexey Bataev4a5bb772014-10-08 14:01:46 +00001233 3 * sizeof(Expr *) * N);
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001234 return new (Mem) OMPFirstprivateClause(N);
1235}
1236
Alexander Musman1bb328c2014-06-04 13:06:39 +00001237OMPLastprivateClause *OMPLastprivateClause::Create(const ASTContext &C,
1238 SourceLocation StartLoc,
1239 SourceLocation LParenLoc,
1240 SourceLocation EndLoc,
1241 ArrayRef<Expr *> VL) {
1242 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause),
1243 llvm::alignOf<Expr *>()) +
1244 sizeof(Expr *) * VL.size());
1245 OMPLastprivateClause *Clause =
1246 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
1247 Clause->setVarRefs(VL);
1248 return Clause;
1249}
1250
1251OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
1252 unsigned N) {
1253 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause),
1254 llvm::alignOf<Expr *>()) +
1255 sizeof(Expr *) * N);
1256 return new (Mem) OMPLastprivateClause(N);
1257}
1258
Alexey Bataev758e55e2013-09-06 18:03:48 +00001259OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
1260 SourceLocation StartLoc,
1261 SourceLocation LParenLoc,
1262 SourceLocation EndLoc,
1263 ArrayRef<Expr *> VL) {
Alexey Bataev13193812014-02-25 11:25:38 +00001264 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
1265 llvm::alignOf<Expr *>()) +
1266 sizeof(Expr *) * VL.size());
Alexey Bataev758e55e2013-09-06 18:03:48 +00001267 OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc,
1268 EndLoc, VL.size());
1269 Clause->setVarRefs(VL);
1270 return Clause;
1271}
1272
1273OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C,
1274 unsigned N) {
Alexey Bataev13193812014-02-25 11:25:38 +00001275 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
1276 llvm::alignOf<Expr *>()) +
1277 sizeof(Expr *) * N);
Alexey Bataev758e55e2013-09-06 18:03:48 +00001278 return new (Mem) OMPSharedClause(N);
1279}
1280
Alexander Musman8dba6642014-04-22 13:09:42 +00001281OMPLinearClause *OMPLinearClause::Create(const ASTContext &C,
1282 SourceLocation StartLoc,
1283 SourceLocation LParenLoc,
1284 SourceLocation ColonLoc,
1285 SourceLocation EndLoc,
1286 ArrayRef<Expr *> VL, Expr *Step) {
1287 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
1288 llvm::alignOf<Expr *>()) +
1289 sizeof(Expr *) * (VL.size() + 1));
1290 OMPLinearClause *Clause = new (Mem)
1291 OMPLinearClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
1292 Clause->setVarRefs(VL);
1293 Clause->setStep(Step);
1294 return Clause;
1295}
1296
1297OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
1298 unsigned NumVars) {
1299 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
1300 llvm::alignOf<Expr *>()) +
1301 sizeof(Expr *) * (NumVars + 1));
1302 return new (Mem) OMPLinearClause(NumVars);
1303}
1304
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001305OMPAlignedClause *
1306OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
1307 SourceLocation LParenLoc, SourceLocation ColonLoc,
1308 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
1309 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause),
1310 llvm::alignOf<Expr *>()) +
1311 sizeof(Expr *) * (VL.size() + 1));
1312 OMPAlignedClause *Clause = new (Mem)
1313 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
1314 Clause->setVarRefs(VL);
1315 Clause->setAlignment(A);
1316 return Clause;
1317}
1318
1319OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
1320 unsigned NumVars) {
1321 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause),
1322 llvm::alignOf<Expr *>()) +
1323 sizeof(Expr *) * (NumVars + 1));
1324 return new (Mem) OMPAlignedClause(NumVars);
1325}
1326
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001327OMPCopyinClause *OMPCopyinClause::Create(const ASTContext &C,
1328 SourceLocation StartLoc,
1329 SourceLocation LParenLoc,
1330 SourceLocation EndLoc,
1331 ArrayRef<Expr *> VL) {
1332 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause),
1333 llvm::alignOf<Expr *>()) +
1334 sizeof(Expr *) * VL.size());
1335 OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc,
1336 EndLoc, VL.size());
1337 Clause->setVarRefs(VL);
1338 return Clause;
1339}
1340
1341OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C,
1342 unsigned N) {
1343 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause),
1344 llvm::alignOf<Expr *>()) +
1345 sizeof(Expr *) * N);
1346 return new (Mem) OMPCopyinClause(N);
1347}
1348
Alexey Bataevbae9a792014-06-27 10:37:06 +00001349OMPCopyprivateClause *OMPCopyprivateClause::Create(const ASTContext &C,
1350 SourceLocation StartLoc,
1351 SourceLocation LParenLoc,
1352 SourceLocation EndLoc,
1353 ArrayRef<Expr *> VL) {
1354 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause),
1355 llvm::alignOf<Expr *>()) +
1356 sizeof(Expr *) * VL.size());
1357 OMPCopyprivateClause *Clause =
1358 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
1359 Clause->setVarRefs(VL);
1360 return Clause;
1361}
1362
1363OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
1364 unsigned N) {
1365 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause),
1366 llvm::alignOf<Expr *>()) +
1367 sizeof(Expr *) * N);
1368 return new (Mem) OMPCopyprivateClause(N);
1369}
1370
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001371void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) {
Alexander Musmanfd2b7592014-03-27 15:14:18 +00001372 assert(Clauses.size() == getNumClauses() &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001373 "Number of clauses is not the same as the preallocated buffer");
Alexander Musmanfd2b7592014-03-27 15:14:18 +00001374 std::copy(Clauses.begin(), Clauses.end(), getClauses().begin());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001375}
1376
Alexander Musmana5f070a2014-10-01 06:03:56 +00001377void OMPLoopDirective::setCounters(ArrayRef<Expr *> A) {
1378 assert(A.size() == getCollapsedNumber() &&
1379 "Number of loop counters is not the same as the collapsed number");
1380 std::copy(A.begin(), A.end(), getCounters().begin());
1381}
1382
1383void OMPLoopDirective::setUpdates(ArrayRef<Expr *> A) {
1384 assert(A.size() == getCollapsedNumber() &&
1385 "Number of counter updates is not the same as the collapsed number");
1386 std::copy(A.begin(), A.end(), getUpdates().begin());
1387}
1388
1389void OMPLoopDirective::setFinals(ArrayRef<Expr *> A) {
1390 assert(A.size() == getCollapsedNumber() &&
1391 "Number of counter finals is not the same as the collapsed number");
1392 std::copy(A.begin(), A.end(), getFinals().begin());
1393}
1394
Alexey Bataevc5e02582014-06-16 07:08:35 +00001395OMPReductionClause *OMPReductionClause::Create(
1396 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1397 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
1398 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo) {
1399 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause),
1400 llvm::alignOf<Expr *>()) +
1401 sizeof(Expr *) * VL.size());
1402 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
1403 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
1404 Clause->setVarRefs(VL);
1405 return Clause;
1406}
1407
1408OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
1409 unsigned N) {
1410 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause),
1411 llvm::alignOf<Expr *>()) +
1412 sizeof(Expr *) * N);
1413 return new (Mem) OMPReductionClause(N);
1414}
1415
Alexey Bataev6125da92014-07-21 11:26:11 +00001416OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
1417 SourceLocation StartLoc,
1418 SourceLocation LParenLoc,
1419 SourceLocation EndLoc,
1420 ArrayRef<Expr *> VL) {
1421 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause),
1422 llvm::alignOf<Expr *>()) +
1423 sizeof(Expr *) * VL.size());
1424 OMPFlushClause *Clause =
1425 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
1426 Clause->setVarRefs(VL);
1427 return Clause;
1428}
1429
1430OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
1431 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause),
1432 llvm::alignOf<Expr *>()) +
1433 sizeof(Expr *) * N);
1434 return new (Mem) OMPFlushClause(N);
1435}
1436
Craig Toppercee61332013-08-21 04:01:01 +00001437OMPParallelDirective *OMPParallelDirective::Create(
Craig Toppere6960e22013-08-22 05:28:54 +00001438 const ASTContext &C,
Craig Toppercee61332013-08-21 04:01:01 +00001439 SourceLocation StartLoc,
1440 SourceLocation EndLoc,
1441 ArrayRef<OMPClause *> Clauses,
1442 Stmt *AssociatedStmt) {
Alexey Bataev13193812014-02-25 11:25:38 +00001443 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
1444 llvm::alignOf<OMPClause *>());
1445 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1446 sizeof(Stmt *));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001447 OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc,
1448 Clauses.size());
1449 Dir->setClauses(Clauses);
1450 Dir->setAssociatedStmt(AssociatedStmt);
1451 return Dir;
1452}
1453
Craig Toppere6960e22013-08-22 05:28:54 +00001454OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001455 unsigned NumClauses,
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001456 EmptyShell) {
Alexey Bataev13193812014-02-25 11:25:38 +00001457 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
1458 llvm::alignOf<OMPClause *>());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001459 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1460 sizeof(Stmt *));
1461 return new (Mem) OMPParallelDirective(NumClauses);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001462}
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001463
Alexey Bataevabfc0692014-06-25 06:52:00 +00001464OMPSimdDirective *
1465OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
1466 SourceLocation EndLoc, unsigned CollapsedNum,
Alexander Musmana5f070a2014-10-01 06:03:56 +00001467 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1468 Expr *IV, Expr *LastIteration, Expr *CalcLastIteration,
1469 Expr *PreCond, Expr *Cond, Expr *SeparatedCond,
1470 Expr *Init, Expr *Inc, ArrayRef<Expr *> Counters,
1471 ArrayRef<Expr *> Updates, ArrayRef<Expr *> Finals) {
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001472 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective),
1473 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001474 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1475 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexey Bataevabfc0692014-06-25 06:52:00 +00001476 OMPSimdDirective *Dir = new (Mem)
1477 OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001478 Dir->setClauses(Clauses);
1479 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001480 Dir->setIterationVariable(IV);
1481 Dir->setLastIteration(LastIteration);
1482 Dir->setCalcLastIteration(CalcLastIteration);
1483 Dir->setPreCond(PreCond);
1484 Dir->setCond(Cond, SeparatedCond);
1485 Dir->setInit(Init);
1486 Dir->setInc(Inc);
1487 Dir->setCounters(Counters);
1488 Dir->setUpdates(Updates);
1489 Dir->setFinals(Finals);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001490 return Dir;
1491}
1492
1493OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C,
1494 unsigned NumClauses,
1495 unsigned CollapsedNum,
1496 EmptyShell) {
1497 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective),
1498 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001499 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1500 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001501 return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses);
1502}
1503
Alexey Bataevabfc0692014-06-25 06:52:00 +00001504OMPForDirective *
1505OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc,
1506 SourceLocation EndLoc, unsigned CollapsedNum,
Alexander Musmana5f070a2014-10-01 06:03:56 +00001507 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1508 Expr *IV, Expr *LastIteration, Expr *CalcLastIteration,
1509 Expr *PreCond, Expr *Cond, Expr *SeparatedCond,
1510 Expr *Init, Expr *Inc, ArrayRef<Expr *> Counters,
1511 ArrayRef<Expr *> Updates, ArrayRef<Expr *> Finals) {
Alexey Bataevf29276e2014-06-18 04:14:57 +00001512 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective),
1513 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001514 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1515 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexey Bataevf29276e2014-06-18 04:14:57 +00001516 OMPForDirective *Dir =
Alexey Bataevabfc0692014-06-25 06:52:00 +00001517 new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
Alexey Bataevf29276e2014-06-18 04:14:57 +00001518 Dir->setClauses(Clauses);
1519 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001520 Dir->setIterationVariable(IV);
1521 Dir->setLastIteration(LastIteration);
1522 Dir->setCalcLastIteration(CalcLastIteration);
1523 Dir->setPreCond(PreCond);
1524 Dir->setCond(Cond, SeparatedCond);
1525 Dir->setInit(Init);
1526 Dir->setInc(Inc);
1527 Dir->setCounters(Counters);
1528 Dir->setUpdates(Updates);
1529 Dir->setFinals(Finals);
Alexey Bataevf29276e2014-06-18 04:14:57 +00001530 return Dir;
1531}
1532
1533OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C,
1534 unsigned NumClauses,
1535 unsigned CollapsedNum,
1536 EmptyShell) {
1537 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective),
1538 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001539 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1540 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexey Bataevf29276e2014-06-18 04:14:57 +00001541 return new (Mem) OMPForDirective(CollapsedNum, NumClauses);
1542}
1543
Alexander Musmana5f070a2014-10-01 06:03:56 +00001544OMPForSimdDirective *OMPForSimdDirective::Create(
1545 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1546 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1547 Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, Expr *PreCond,
1548 Expr *Cond, Expr *SeparatedCond, Expr *Init, Expr *Inc,
1549 ArrayRef<Expr *> Counters, ArrayRef<Expr *> Updates,
1550 ArrayRef<Expr *> Finals) {
Alexander Musmanf82886e2014-09-18 05:12:34 +00001551 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective),
1552 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001553 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1554 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexander Musmanf82886e2014-09-18 05:12:34 +00001555 OMPForSimdDirective *Dir = new (Mem)
1556 OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
1557 Dir->setClauses(Clauses);
1558 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001559 Dir->setIterationVariable(IV);
1560 Dir->setLastIteration(LastIteration);
1561 Dir->setCalcLastIteration(CalcLastIteration);
1562 Dir->setPreCond(PreCond);
1563 Dir->setCond(Cond, SeparatedCond);
1564 Dir->setInit(Init);
1565 Dir->setInc(Inc);
1566 Dir->setCounters(Counters);
1567 Dir->setUpdates(Updates);
1568 Dir->setFinals(Finals);
Alexander Musmanf82886e2014-09-18 05:12:34 +00001569 return Dir;
1570}
1571
1572OMPForSimdDirective *OMPForSimdDirective::CreateEmpty(const ASTContext &C,
1573 unsigned NumClauses,
1574 unsigned CollapsedNum,
1575 EmptyShell) {
1576 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective),
1577 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001578 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1579 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexander Musmanf82886e2014-09-18 05:12:34 +00001580 return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses);
1581}
1582
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001583OMPSectionsDirective *OMPSectionsDirective::Create(
1584 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1585 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
1586 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
1587 llvm::alignOf<OMPClause *>());
1588 void *Mem =
1589 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1590 OMPSectionsDirective *Dir =
1591 new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size());
1592 Dir->setClauses(Clauses);
1593 Dir->setAssociatedStmt(AssociatedStmt);
1594 return Dir;
1595}
1596
1597OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C,
1598 unsigned NumClauses,
1599 EmptyShell) {
1600 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
1601 llvm::alignOf<OMPClause *>());
1602 void *Mem =
1603 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1604 return new (Mem) OMPSectionsDirective(NumClauses);
1605}
1606
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001607OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C,
1608 SourceLocation StartLoc,
1609 SourceLocation EndLoc,
1610 Stmt *AssociatedStmt) {
1611 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
1612 llvm::alignOf<Stmt *>());
1613 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1614 OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc);
1615 Dir->setAssociatedStmt(AssociatedStmt);
1616 return Dir;
1617}
1618
1619OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C,
1620 EmptyShell) {
1621 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective),
1622 llvm::alignOf<Stmt *>());
1623 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1624 return new (Mem) OMPSectionDirective();
1625}
1626
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00001627OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C,
1628 SourceLocation StartLoc,
1629 SourceLocation EndLoc,
1630 ArrayRef<OMPClause *> Clauses,
1631 Stmt *AssociatedStmt) {
1632 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective),
1633 llvm::alignOf<OMPClause *>());
1634 void *Mem =
1635 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1636 OMPSingleDirective *Dir =
1637 new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size());
1638 Dir->setClauses(Clauses);
1639 Dir->setAssociatedStmt(AssociatedStmt);
1640 return Dir;
1641}
1642
1643OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C,
1644 unsigned NumClauses,
1645 EmptyShell) {
1646 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective),
1647 llvm::alignOf<OMPClause *>());
1648 void *Mem =
1649 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1650 return new (Mem) OMPSingleDirective(NumClauses);
1651}
1652
Alexander Musman80c22892014-07-17 08:54:58 +00001653OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C,
1654 SourceLocation StartLoc,
1655 SourceLocation EndLoc,
1656 Stmt *AssociatedStmt) {
1657 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective),
1658 llvm::alignOf<Stmt *>());
1659 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1660 OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc);
1661 Dir->setAssociatedStmt(AssociatedStmt);
1662 return Dir;
1663}
1664
1665OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C,
1666 EmptyShell) {
1667 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective),
1668 llvm::alignOf<Stmt *>());
1669 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1670 return new (Mem) OMPMasterDirective();
1671}
1672
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001673OMPCriticalDirective *OMPCriticalDirective::Create(
1674 const ASTContext &C, const DeclarationNameInfo &Name,
1675 SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) {
1676 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective),
1677 llvm::alignOf<Stmt *>());
1678 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1679 OMPCriticalDirective *Dir =
1680 new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc);
1681 Dir->setAssociatedStmt(AssociatedStmt);
1682 return Dir;
1683}
1684
1685OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C,
1686 EmptyShell) {
1687 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective),
1688 llvm::alignOf<Stmt *>());
1689 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1690 return new (Mem) OMPCriticalDirective();
1691}
1692
Alexander Musmana5f070a2014-10-01 06:03:56 +00001693OMPParallelForDirective *OMPParallelForDirective::Create(
1694 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1695 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1696 Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, Expr *PreCond,
1697 Expr *Cond, Expr *SeparatedCond, Expr *Init, Expr *Inc,
1698 ArrayRef<Expr *> Counters, ArrayRef<Expr *> Updates,
1699 ArrayRef<Expr *> Finals) {
Alexey Bataev4acb8592014-07-07 13:01:15 +00001700 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective),
1701 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001702 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1703 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexey Bataev4acb8592014-07-07 13:01:15 +00001704 OMPParallelForDirective *Dir = new (Mem)
1705 OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
1706 Dir->setClauses(Clauses);
1707 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001708 Dir->setIterationVariable(IV);
1709 Dir->setLastIteration(LastIteration);
1710 Dir->setCalcLastIteration(CalcLastIteration);
1711 Dir->setPreCond(PreCond);
1712 Dir->setCond(Cond, SeparatedCond);
1713 Dir->setInit(Init);
1714 Dir->setInc(Inc);
1715 Dir->setCounters(Counters);
1716 Dir->setUpdates(Updates);
1717 Dir->setFinals(Finals);
Alexey Bataev4acb8592014-07-07 13:01:15 +00001718 return Dir;
1719}
1720
1721OMPParallelForDirective *
1722OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses,
1723 unsigned CollapsedNum, EmptyShell) {
1724 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective),
1725 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001726 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1727 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexey Bataev4acb8592014-07-07 13:01:15 +00001728 return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses);
1729}
1730
Alexander Musmane4e893b2014-09-23 09:33:00 +00001731OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create(
1732 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
Alexander Musmana5f070a2014-10-01 06:03:56 +00001733 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1734 Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, Expr *PreCond,
1735 Expr *Cond, Expr *SeparatedCond, Expr *Init, Expr *Inc,
1736 ArrayRef<Expr *> Counters, ArrayRef<Expr *> Updates,
1737 ArrayRef<Expr *> Finals) {
Alexander Musmane4e893b2014-09-23 09:33:00 +00001738 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective),
1739 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001740 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1741 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexander Musmane4e893b2014-09-23 09:33:00 +00001742 OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective(
1743 StartLoc, EndLoc, CollapsedNum, Clauses.size());
1744 Dir->setClauses(Clauses);
1745 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmana5f070a2014-10-01 06:03:56 +00001746 Dir->setIterationVariable(IV);
1747 Dir->setLastIteration(LastIteration);
1748 Dir->setCalcLastIteration(CalcLastIteration);
1749 Dir->setPreCond(PreCond);
1750 Dir->setCond(Cond, SeparatedCond);
1751 Dir->setInit(Init);
1752 Dir->setInc(Inc);
1753 Dir->setCounters(Counters);
1754 Dir->setUpdates(Updates);
1755 Dir->setFinals(Finals);
Alexander Musmane4e893b2014-09-23 09:33:00 +00001756 return Dir;
1757}
1758
1759OMPParallelForSimdDirective *
1760OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C,
1761 unsigned NumClauses,
1762 unsigned CollapsedNum, EmptyShell) {
1763 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective),
1764 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001765 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1766 sizeof(Stmt *) * numLoopChildren(CollapsedNum));
Alexander Musmane4e893b2014-09-23 09:33:00 +00001767 return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses);
1768}
1769
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00001770OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create(
1771 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1772 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
1773 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective),
1774 llvm::alignOf<OMPClause *>());
1775 void *Mem =
1776 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1777 OMPParallelSectionsDirective *Dir =
1778 new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size());
1779 Dir->setClauses(Clauses);
1780 Dir->setAssociatedStmt(AssociatedStmt);
1781 return Dir;
1782}
1783
1784OMPParallelSectionsDirective *
1785OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C,
1786 unsigned NumClauses, EmptyShell) {
1787 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective),
1788 llvm::alignOf<OMPClause *>());
1789 void *Mem =
1790 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1791 return new (Mem) OMPParallelSectionsDirective(NumClauses);
1792}
1793
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00001794OMPTaskDirective *OMPTaskDirective::Create(const ASTContext &C,
1795 SourceLocation StartLoc,
1796 SourceLocation EndLoc,
1797 ArrayRef<OMPClause *> Clauses,
1798 Stmt *AssociatedStmt) {
1799 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective),
1800 llvm::alignOf<OMPClause *>());
1801 void *Mem =
1802 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1803 OMPTaskDirective *Dir =
1804 new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size());
1805 Dir->setClauses(Clauses);
1806 Dir->setAssociatedStmt(AssociatedStmt);
1807 return Dir;
1808}
1809
1810OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C,
1811 unsigned NumClauses,
1812 EmptyShell) {
1813 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective),
1814 llvm::alignOf<OMPClause *>());
1815 void *Mem =
1816 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1817 return new (Mem) OMPTaskDirective(NumClauses);
1818}
1819
Alexey Bataev68446b72014-07-18 07:47:19 +00001820OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C,
1821 SourceLocation StartLoc,
1822 SourceLocation EndLoc) {
1823 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
1824 OMPTaskyieldDirective *Dir =
1825 new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc);
1826 return Dir;
1827}
1828
1829OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C,
1830 EmptyShell) {
1831 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
1832 return new (Mem) OMPTaskyieldDirective();
1833}
1834
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00001835OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C,
1836 SourceLocation StartLoc,
1837 SourceLocation EndLoc) {
1838 void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
1839 OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc);
1840 return Dir;
1841}
1842
1843OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C,
1844 EmptyShell) {
1845 void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
1846 return new (Mem) OMPBarrierDirective();
1847}
1848
Alexey Bataev2df347a2014-07-18 10:17:07 +00001849OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C,
1850 SourceLocation StartLoc,
1851 SourceLocation EndLoc) {
1852 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
1853 OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc);
1854 return Dir;
1855}
1856
1857OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C,
1858 EmptyShell) {
1859 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
1860 return new (Mem) OMPTaskwaitDirective();
1861}
1862
Alexey Bataev6125da92014-07-21 11:26:11 +00001863OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C,
1864 SourceLocation StartLoc,
1865 SourceLocation EndLoc,
1866 ArrayRef<OMPClause *> Clauses) {
1867 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective),
1868 llvm::alignOf<OMPClause *>());
1869 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size());
1870 OMPFlushDirective *Dir =
1871 new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size());
1872 Dir->setClauses(Clauses);
1873 return Dir;
1874}
1875
1876OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C,
1877 unsigned NumClauses,
1878 EmptyShell) {
1879 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective),
1880 llvm::alignOf<OMPClause *>());
1881 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses);
1882 return new (Mem) OMPFlushDirective(NumClauses);
1883}
1884
Alexey Bataev9fb6e642014-07-22 06:45:04 +00001885OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C,
1886 SourceLocation StartLoc,
1887 SourceLocation EndLoc,
1888 Stmt *AssociatedStmt) {
1889 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective),
1890 llvm::alignOf<Stmt *>());
1891 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1892 OMPOrderedDirective *Dir = new (Mem) OMPOrderedDirective(StartLoc, EndLoc);
1893 Dir->setAssociatedStmt(AssociatedStmt);
1894 return Dir;
1895}
1896
1897OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C,
1898 EmptyShell) {
1899 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective),
1900 llvm::alignOf<Stmt *>());
1901 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1902 return new (Mem) OMPOrderedDirective();
1903}
1904
Alexey Bataev0162e452014-07-22 10:10:35 +00001905OMPAtomicDirective *OMPAtomicDirective::Create(const ASTContext &C,
1906 SourceLocation StartLoc,
1907 SourceLocation EndLoc,
1908 ArrayRef<OMPClause *> Clauses,
1909 Stmt *AssociatedStmt) {
1910 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective),
1911 llvm::alignOf<OMPClause *>());
1912 void *Mem =
1913 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1914 OMPAtomicDirective *Dir =
1915 new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size());
1916 Dir->setClauses(Clauses);
1917 Dir->setAssociatedStmt(AssociatedStmt);
1918 return Dir;
1919}
1920
1921OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C,
1922 unsigned NumClauses,
1923 EmptyShell) {
1924 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective),
1925 llvm::alignOf<OMPClause *>());
1926 void *Mem =
1927 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1928 return new (Mem) OMPAtomicDirective(NumClauses);
1929}
1930
Alexey Bataev0bd520b2014-09-19 08:19:49 +00001931OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C,
1932 SourceLocation StartLoc,
1933 SourceLocation EndLoc,
1934 ArrayRef<OMPClause *> Clauses,
1935 Stmt *AssociatedStmt) {
1936 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective),
1937 llvm::alignOf<OMPClause *>());
1938 void *Mem =
1939 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1940 OMPTargetDirective *Dir =
1941 new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size());
1942 Dir->setClauses(Clauses);
1943 Dir->setAssociatedStmt(AssociatedStmt);
1944 return Dir;
1945}
1946
1947OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C,
1948 unsigned NumClauses,
1949 EmptyShell) {
1950 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective),
1951 llvm::alignOf<OMPClause *>());
1952 void *Mem =
1953 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1954 return new (Mem) OMPTargetDirective(NumClauses);
1955}
1956
Alexey Bataev13314bf2014-10-09 04:18:56 +00001957OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C,
1958 SourceLocation StartLoc,
1959 SourceLocation EndLoc,
1960 ArrayRef<OMPClause *> Clauses,
1961 Stmt *AssociatedStmt) {
1962 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective),
1963 llvm::alignOf<OMPClause *>());
1964 void *Mem =
1965 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1966 OMPTeamsDirective *Dir =
1967 new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size());
1968 Dir->setClauses(Clauses);
1969 Dir->setAssociatedStmt(AssociatedStmt);
1970 return Dir;
1971}
1972
1973OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C,
1974 unsigned NumClauses,
1975 EmptyShell) {
1976 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective),
1977 llvm::alignOf<OMPClause *>());
1978 void *Mem =
1979 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1980 return new (Mem) OMPTeamsDirective(NumClauses);
1981}
1982