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