• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// \brief This file defines OpenMP AST classes for clauses.
11 /// There are clauses for executable directives, clauses for declarative
12 /// directives and clauses which can be used in both kinds of directives.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
17 #define LLVM_CLANG_AST_OPENMPCLAUSE_H
18 
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/Stmt.h"
21 #include "clang/Basic/OpenMPKinds.h"
22 #include "clang/Basic/SourceLocation.h"
23 
24 namespace clang {
25 
26 //===----------------------------------------------------------------------===//
27 // AST classes for clauses.
28 //===----------------------------------------------------------------------===//
29 
30 /// \brief This is a basic class for representing single OpenMP clause.
31 ///
32 class OMPClause {
33   /// \brief Starting location of the clause (the clause keyword).
34   SourceLocation StartLoc;
35   /// \brief Ending location of the clause.
36   SourceLocation EndLoc;
37   /// \brief Kind of the clause.
38   OpenMPClauseKind Kind;
39 
40 protected:
OMPClause(OpenMPClauseKind K,SourceLocation StartLoc,SourceLocation EndLoc)41   OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
42       : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
43 
44 public:
45   /// \brief Returns the starting location of the clause.
getLocStart()46   SourceLocation getLocStart() const { return StartLoc; }
47   /// \brief Returns the ending location of the clause.
getLocEnd()48   SourceLocation getLocEnd() const { return EndLoc; }
49 
50   /// \brief Sets the starting location of the clause.
setLocStart(SourceLocation Loc)51   void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
52   /// \brief Sets the ending location of the clause.
setLocEnd(SourceLocation Loc)53   void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
54 
55   /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.).
getClauseKind()56   OpenMPClauseKind getClauseKind() const { return Kind; }
57 
isImplicit()58   bool isImplicit() const { return StartLoc.isInvalid(); }
59 
60   StmtRange children();
children()61   ConstStmtRange children() const {
62     return const_cast<OMPClause *>(this)->children();
63   }
classof(const OMPClause * T)64   static bool classof(const OMPClause *T) { return true; }
65 };
66 
67 /// \brief This represents clauses with the list of variables like 'private',
68 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
69 /// '#pragma omp ...' directives.
70 template <class T> class OMPVarListClause : public OMPClause {
71   friend class OMPClauseReader;
72   /// \brief Location of '('.
73   SourceLocation LParenLoc;
74   /// \brief Number of variables in the list.
75   unsigned NumVars;
76 
77 protected:
78   /// \brief Fetches list of variables associated with this clause.
getVarRefs()79   MutableArrayRef<Expr *> getVarRefs() {
80     return MutableArrayRef<Expr *>(
81         reinterpret_cast<Expr **>(
82             reinterpret_cast<char *>(this) +
83             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())),
84         NumVars);
85   }
86 
87   /// \brief Sets the list of variables for this clause.
setVarRefs(ArrayRef<Expr * > VL)88   void setVarRefs(ArrayRef<Expr *> VL) {
89     assert(VL.size() == NumVars &&
90            "Number of variables is not the same as the preallocated buffer");
91     std::copy(
92         VL.begin(), VL.end(),
93         reinterpret_cast<Expr **>(
94             reinterpret_cast<char *>(this) +
95             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())));
96   }
97 
98   /// \brief Build a clause with \a N variables
99   ///
100   /// \param K Kind of the clause.
101   /// \param StartLoc Starting location of the clause (the clause keyword).
102   /// \param LParenLoc Location of '('.
103   /// \param EndLoc Ending location of the clause.
104   /// \param N Number of the variables in the clause.
105   ///
OMPVarListClause(OpenMPClauseKind K,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)106   OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
107                    SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
108       : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
109 
110 public:
111   typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
112   typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
113   typedef llvm::iterator_range<varlist_iterator> varlist_range;
114   typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
115 
varlist_size()116   unsigned varlist_size() const { return NumVars; }
varlist_empty()117   bool varlist_empty() const { return NumVars == 0; }
118 
varlists()119   varlist_range varlists() {
120     return varlist_range(varlist_begin(), varlist_end());
121   }
varlists()122   varlist_const_range varlists() const {
123     return varlist_const_range(varlist_begin(), varlist_end());
124   }
125 
varlist_begin()126   varlist_iterator varlist_begin() { return getVarRefs().begin(); }
varlist_end()127   varlist_iterator varlist_end() { return getVarRefs().end(); }
varlist_begin()128   varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
varlist_end()129   varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
130 
131   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)132   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
133   /// \brief Returns the location of '('.
getLParenLoc()134   SourceLocation getLParenLoc() const { return LParenLoc; }
135 
136   /// \brief Fetches list of all variables in the clause.
getVarRefs()137   ArrayRef<const Expr *> getVarRefs() const {
138     return ArrayRef<const Expr *>(
139         reinterpret_cast<const Expr *const *>(
140             reinterpret_cast<const char *>(this) +
141             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())),
142         NumVars);
143   }
144 };
145 
146 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
147 ///
148 /// \code
149 /// #pragma omp parallel if(a > 5)
150 /// \endcode
151 /// In this example directive '#pragma omp parallel' has simple 'if'
152 /// clause with condition 'a > 5'.
153 ///
154 class OMPIfClause : public OMPClause {
155   friend class OMPClauseReader;
156   /// \brief Location of '('.
157   SourceLocation LParenLoc;
158   /// \brief Condition of the 'if' clause.
159   Stmt *Condition;
160 
161   /// \brief Set condition.
162   ///
setCondition(Expr * Cond)163   void setCondition(Expr *Cond) { Condition = Cond; }
164 
165 public:
166   /// \brief Build 'if' clause with condition \a Cond.
167   ///
168   /// \param StartLoc Starting location of the clause.
169   /// \param LParenLoc Location of '('.
170   /// \param Cond Condition of the clause.
171   /// \param EndLoc Ending location of the clause.
172   ///
OMPIfClause(Expr * Cond,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)173   OMPIfClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
174               SourceLocation EndLoc)
175       : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
176         Condition(Cond) {}
177 
178   /// \brief Build an empty clause.
179   ///
OMPIfClause()180   OMPIfClause()
181       : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
182         LParenLoc(SourceLocation()), Condition(nullptr) {}
183 
184   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)185   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
186   /// \brief Returns the location of '('.
getLParenLoc()187   SourceLocation getLParenLoc() const { return LParenLoc; }
188 
189   /// \brief Returns condition.
getCondition()190   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
191 
classof(const OMPClause * T)192   static bool classof(const OMPClause *T) {
193     return T->getClauseKind() == OMPC_if;
194   }
195 
children()196   StmtRange children() { return StmtRange(&Condition, &Condition + 1); }
197 };
198 
199 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
200 /// directive.
201 ///
202 /// \code
203 /// #pragma omp parallel num_threads(6)
204 /// \endcode
205 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
206 /// clause with number of threads '6'.
207 ///
208 class OMPNumThreadsClause : public OMPClause {
209   friend class OMPClauseReader;
210   /// \brief Location of '('.
211   SourceLocation LParenLoc;
212   /// \brief Condition of the 'num_threads' clause.
213   Stmt *NumThreads;
214 
215   /// \brief Set condition.
216   ///
setNumThreads(Expr * NThreads)217   void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
218 
219 public:
220   /// \brief Build 'num_threads' clause with condition \a NumThreads.
221   ///
222   /// \param NumThreads Number of threads for the construct.
223   /// \param StartLoc Starting location of the clause.
224   /// \param LParenLoc Location of '('.
225   /// \param EndLoc Ending location of the clause.
226   ///
OMPNumThreadsClause(Expr * NumThreads,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)227   OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
228                       SourceLocation LParenLoc, SourceLocation EndLoc)
229       : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
230         NumThreads(NumThreads) {}
231 
232   /// \brief Build an empty clause.
233   ///
OMPNumThreadsClause()234   OMPNumThreadsClause()
235       : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
236         LParenLoc(SourceLocation()), NumThreads(nullptr) {}
237 
238   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)239   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
240   /// \brief Returns the location of '('.
getLParenLoc()241   SourceLocation getLParenLoc() const { return LParenLoc; }
242 
243   /// \brief Returns number of threads.
getNumThreads()244   Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
245 
classof(const OMPClause * T)246   static bool classof(const OMPClause *T) {
247     return T->getClauseKind() == OMPC_num_threads;
248   }
249 
children()250   StmtRange children() { return StmtRange(&NumThreads, &NumThreads + 1); }
251 };
252 
253 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
254 /// directive.
255 ///
256 /// \code
257 /// #pragma omp simd safelen(4)
258 /// \endcode
259 /// In this example directive '#pragma omp simd' has clause 'safelen'
260 /// with single expression '4'.
261 /// If the safelen clause is used then no two iterations executed
262 /// concurrently with SIMD instructions can have a greater distance
263 /// in the logical iteration space than its value. The parameter of
264 /// the safelen clause must be a constant positive integer expression.
265 ///
266 class OMPSafelenClause : public OMPClause {
267   friend class OMPClauseReader;
268   /// \brief Location of '('.
269   SourceLocation LParenLoc;
270   /// \brief Safe iteration space distance.
271   Stmt *Safelen;
272 
273   /// \brief Set safelen.
setSafelen(Expr * Len)274   void setSafelen(Expr *Len) { Safelen = Len; }
275 
276 public:
277   /// \brief Build 'safelen' clause.
278   ///
279   /// \param Len Expression associated with this clause.
280   /// \param StartLoc Starting location of the clause.
281   /// \param EndLoc Ending location of the clause.
282   ///
OMPSafelenClause(Expr * Len,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)283   OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
284                    SourceLocation EndLoc)
285       : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
286         Safelen(Len) {}
287 
288   /// \brief Build an empty clause.
289   ///
OMPSafelenClause()290   explicit OMPSafelenClause()
291       : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
292         LParenLoc(SourceLocation()), Safelen(nullptr) {}
293 
294   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)295   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
296   /// \brief Returns the location of '('.
getLParenLoc()297   SourceLocation getLParenLoc() const { return LParenLoc; }
298 
299   /// \brief Return safe iteration space distance.
getSafelen()300   Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
301 
classof(const OMPClause * T)302   static bool classof(const OMPClause *T) {
303     return T->getClauseKind() == OMPC_safelen;
304   }
305 
children()306   StmtRange children() { return StmtRange(&Safelen, &Safelen + 1); }
307 };
308 
309 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
310 /// directive.
311 ///
312 /// \code
313 /// #pragma omp simd collapse(3)
314 /// \endcode
315 /// In this example directive '#pragma omp simd' has clause 'collapse'
316 /// with single expression '3'.
317 /// The parameter must be a constant positive integer expression, it specifies
318 /// the number of nested loops that should be collapsed into a single iteration
319 /// space.
320 ///
321 class OMPCollapseClause : public OMPClause {
322   friend class OMPClauseReader;
323   /// \brief Location of '('.
324   SourceLocation LParenLoc;
325   /// \brief Number of for-loops.
326   Stmt *NumForLoops;
327 
328   /// \brief Set the number of associated for-loops.
setNumForLoops(Expr * Num)329   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
330 
331 public:
332   /// \brief Build 'collapse' clause.
333   ///
334   /// \param Num Expression associated with this clause.
335   /// \param StartLoc Starting location of the clause.
336   /// \param LParenLoc Location of '('.
337   /// \param EndLoc Ending location of the clause.
338   ///
OMPCollapseClause(Expr * Num,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)339   OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
340                     SourceLocation LParenLoc, SourceLocation EndLoc)
341       : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
342         NumForLoops(Num) {}
343 
344   /// \brief Build an empty clause.
345   ///
OMPCollapseClause()346   explicit OMPCollapseClause()
347       : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
348         LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
349 
350   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)351   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
352   /// \brief Returns the location of '('.
getLParenLoc()353   SourceLocation getLParenLoc() const { return LParenLoc; }
354 
355   /// \brief Return the number of associated for-loops.
getNumForLoops()356   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
357 
classof(const OMPClause * T)358   static bool classof(const OMPClause *T) {
359     return T->getClauseKind() == OMPC_collapse;
360   }
361 
children()362   StmtRange children() { return StmtRange(&NumForLoops, &NumForLoops + 1); }
363 };
364 
365 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
366 ///
367 /// \code
368 /// #pragma omp parallel default(shared)
369 /// \endcode
370 /// In this example directive '#pragma omp parallel' has simple 'default'
371 /// clause with kind 'shared'.
372 ///
373 class OMPDefaultClause : public OMPClause {
374   friend class OMPClauseReader;
375   /// \brief Location of '('.
376   SourceLocation LParenLoc;
377   /// \brief A kind of the 'default' clause.
378   OpenMPDefaultClauseKind Kind;
379   /// \brief Start location of the kind in source code.
380   SourceLocation KindKwLoc;
381 
382   /// \brief Set kind of the clauses.
383   ///
384   /// \param K Argument of clause.
385   ///
setDefaultKind(OpenMPDefaultClauseKind K)386   void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
387 
388   /// \brief Set argument location.
389   ///
390   /// \param KLoc Argument location.
391   ///
setDefaultKindKwLoc(SourceLocation KLoc)392   void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
393 
394 public:
395   /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
396   ///
397   /// \param A Argument of the clause ('none' or 'shared').
398   /// \param ALoc Starting location of the argument.
399   /// \param StartLoc Starting location of the clause.
400   /// \param LParenLoc Location of '('.
401   /// \param EndLoc Ending location of the clause.
402   ///
OMPDefaultClause(OpenMPDefaultClauseKind A,SourceLocation ALoc,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)403   OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
404                    SourceLocation StartLoc, SourceLocation LParenLoc,
405                    SourceLocation EndLoc)
406       : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
407         Kind(A), KindKwLoc(ALoc) {}
408 
409   /// \brief Build an empty clause.
410   ///
OMPDefaultClause()411   OMPDefaultClause()
412       : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
413         LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
414         KindKwLoc(SourceLocation()) {}
415 
416   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)417   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
418   /// \brief Returns the location of '('.
getLParenLoc()419   SourceLocation getLParenLoc() const { return LParenLoc; }
420 
421   /// \brief Returns kind of the clause.
getDefaultKind()422   OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
423 
424   /// \brief Returns location of clause kind.
getDefaultKindKwLoc()425   SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
426 
classof(const OMPClause * T)427   static bool classof(const OMPClause *T) {
428     return T->getClauseKind() == OMPC_default;
429   }
430 
children()431   StmtRange children() { return StmtRange(); }
432 };
433 
434 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
435 /// directive.
436 ///
437 /// \code
438 /// #pragma omp parallel proc_bind(master)
439 /// \endcode
440 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
441 /// clause with kind 'master'.
442 ///
443 class OMPProcBindClause : public OMPClause {
444   friend class OMPClauseReader;
445   /// \brief Location of '('.
446   SourceLocation LParenLoc;
447   /// \brief A kind of the 'proc_bind' clause.
448   OpenMPProcBindClauseKind Kind;
449   /// \brief Start location of the kind in source code.
450   SourceLocation KindKwLoc;
451 
452   /// \brief Set kind of the clause.
453   ///
454   /// \param K Kind of clause.
455   ///
setProcBindKind(OpenMPProcBindClauseKind K)456   void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
457 
458   /// \brief Set clause kind location.
459   ///
460   /// \param KLoc Kind location.
461   ///
setProcBindKindKwLoc(SourceLocation KLoc)462   void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
463 
464 public:
465   /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
466   ///        'spread').
467   ///
468   /// \param A Argument of the clause ('master', 'close' or 'spread').
469   /// \param ALoc Starting location of the argument.
470   /// \param StartLoc Starting location of the clause.
471   /// \param LParenLoc Location of '('.
472   /// \param EndLoc Ending location of the clause.
473   ///
OMPProcBindClause(OpenMPProcBindClauseKind A,SourceLocation ALoc,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)474   OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
475                     SourceLocation StartLoc, SourceLocation LParenLoc,
476                     SourceLocation EndLoc)
477       : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
478         Kind(A), KindKwLoc(ALoc) {}
479 
480   /// \brief Build an empty clause.
481   ///
OMPProcBindClause()482   OMPProcBindClause()
483       : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
484         LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
485         KindKwLoc(SourceLocation()) {}
486 
487   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)488   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
489   /// \brief Returns the location of '('.
getLParenLoc()490   SourceLocation getLParenLoc() const { return LParenLoc; }
491 
492   /// \brief Returns kind of the clause.
getProcBindKind()493   OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
494 
495   /// \brief Returns location of clause kind.
getProcBindKindKwLoc()496   SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
497 
classof(const OMPClause * T)498   static bool classof(const OMPClause *T) {
499     return T->getClauseKind() == OMPC_proc_bind;
500   }
501 
children()502   StmtRange children() { return StmtRange(); }
503 };
504 
505 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
506 ///
507 /// \code
508 /// #pragma omp for schedule(static, 3)
509 /// \endcode
510 /// In this example directive '#pragma omp for' has 'schedule' clause with
511 /// arguments 'static' and '3'.
512 ///
513 class OMPScheduleClause : public OMPClause {
514   friend class OMPClauseReader;
515   /// \brief Location of '('.
516   SourceLocation LParenLoc;
517   /// \brief A kind of the 'schedule' clause.
518   OpenMPScheduleClauseKind Kind;
519   /// \brief Start location of the schedule ind in source code.
520   SourceLocation KindLoc;
521   /// \brief Location of ',' (if any).
522   SourceLocation CommaLoc;
523   /// \brief Chunk size.
524   Stmt *ChunkSize;
525 
526   /// \brief Set schedule kind.
527   ///
528   /// \param K Schedule kind.
529   ///
setScheduleKind(OpenMPScheduleClauseKind K)530   void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
531   /// \brief Sets the location of '('.
532   ///
533   /// \param Loc Location of '('.
534   ///
setLParenLoc(SourceLocation Loc)535   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
536   /// \brief Set schedule kind start location.
537   ///
538   /// \param KLoc Schedule kind location.
539   ///
setScheduleKindLoc(SourceLocation KLoc)540   void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
541   /// \brief Set location of ','.
542   ///
543   /// \param Loc Location of ','.
544   ///
setCommaLoc(SourceLocation Loc)545   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
546   /// \brief Set chunk size.
547   ///
548   /// \param E Chunk size.
549   ///
setChunkSize(Expr * E)550   void setChunkSize(Expr *E) { ChunkSize = E; }
551 
552 public:
553   /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
554   /// expression \a ChunkSize.
555   ///
556   /// \param StartLoc Starting location of the clause.
557   /// \param LParenLoc Location of '('.
558   /// \param KLoc Starting location of the argument.
559   /// \param CommaLoc Location of ','.
560   /// \param EndLoc Ending location of the clause.
561   /// \param Kind Schedule kind.
562   /// \param ChunkSize Chunk size.
563   ///
OMPScheduleClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation KLoc,SourceLocation CommaLoc,SourceLocation EndLoc,OpenMPScheduleClauseKind Kind,Expr * ChunkSize)564   OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
565                     SourceLocation KLoc, SourceLocation CommaLoc,
566                     SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
567                     Expr *ChunkSize)
568       : OMPClause(OMPC_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc),
569         Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {}
570 
571   /// \brief Build an empty clause.
572   ///
OMPScheduleClause()573   explicit OMPScheduleClause()
574       : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
575         Kind(OMPC_SCHEDULE_unknown), ChunkSize(nullptr) {}
576 
577   /// \brief Get kind of the clause.
578   ///
getScheduleKind()579   OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
580   /// \brief Get location of '('.
581   ///
getLParenLoc()582   SourceLocation getLParenLoc() { return LParenLoc; }
583   /// \brief Get kind location.
584   ///
getScheduleKindLoc()585   SourceLocation getScheduleKindLoc() { return KindLoc; }
586   /// \brief Get location of ','.
587   ///
getCommaLoc()588   SourceLocation getCommaLoc() { return CommaLoc; }
589   /// \brief Get chunk size.
590   ///
getChunkSize()591   Expr *getChunkSize() { return dyn_cast_or_null<Expr>(ChunkSize); }
592   /// \brief Get chunk size.
593   ///
getChunkSize()594   Expr *getChunkSize() const { return dyn_cast_or_null<Expr>(ChunkSize); }
595 
classof(const OMPClause * T)596   static bool classof(const OMPClause *T) {
597     return T->getClauseKind() == OMPC_schedule;
598   }
599 
children()600   StmtRange children() { return StmtRange(&ChunkSize, &ChunkSize + 1); }
601 };
602 
603 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
604 ///
605 /// \code
606 /// #pragma omp for ordered
607 /// \endcode
608 /// In this example directive '#pragma omp for' has 'ordered' clause.
609 ///
610 class OMPOrderedClause : public OMPClause {
611 public:
612   /// \brief Build 'ordered' clause.
613   ///
614   /// \param StartLoc Starting location of the clause.
615   /// \param EndLoc Ending location of the clause.
616   ///
OMPOrderedClause(SourceLocation StartLoc,SourceLocation EndLoc)617   OMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc)
618       : OMPClause(OMPC_ordered, StartLoc, EndLoc) {}
619 
620   /// \brief Build an empty clause.
621   ///
OMPOrderedClause()622   OMPOrderedClause()
623       : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
624 
classof(const OMPClause * T)625   static bool classof(const OMPClause *T) {
626     return T->getClauseKind() == OMPC_ordered;
627   }
628 
children()629   StmtRange children() { return StmtRange(); }
630 };
631 
632 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
633 ///
634 /// \code
635 /// #pragma omp for nowait
636 /// \endcode
637 /// In this example directive '#pragma omp for' has 'nowait' clause.
638 ///
639 class OMPNowaitClause : public OMPClause {
640 public:
641   /// \brief Build 'nowait' clause.
642   ///
643   /// \param StartLoc Starting location of the clause.
644   /// \param EndLoc Ending location of the clause.
645   ///
OMPNowaitClause(SourceLocation StartLoc,SourceLocation EndLoc)646   OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
647       : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
648 
649   /// \brief Build an empty clause.
650   ///
OMPNowaitClause()651   OMPNowaitClause()
652       : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
653 
classof(const OMPClause * T)654   static bool classof(const OMPClause *T) {
655     return T->getClauseKind() == OMPC_nowait;
656   }
657 
children()658   StmtRange children() { return StmtRange(); }
659 };
660 
661 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
662 ///
663 /// \code
664 /// #pragma omp parallel private(a,b)
665 /// \endcode
666 /// In this example directive '#pragma omp parallel' has clause 'private'
667 /// with the variables 'a' and 'b'.
668 ///
669 class OMPPrivateClause : public OMPVarListClause<OMPPrivateClause> {
670   /// \brief Build clause with number of variables \a N.
671   ///
672   /// \param StartLoc Starting location of the clause.
673   /// \param LParenLoc Location of '('.
674   /// \param EndLoc Ending location of the clause.
675   /// \param N Number of the variables in the clause.
676   ///
OMPPrivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)677   OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
678                    SourceLocation EndLoc, unsigned N)
679       : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
680                                            EndLoc, N) {}
681 
682   /// \brief Build an empty clause.
683   ///
684   /// \param N Number of variables.
685   ///
OMPPrivateClause(unsigned N)686   explicit OMPPrivateClause(unsigned N)
687       : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
688                                            SourceLocation(), SourceLocation(),
689                                            N) {}
690 
691 public:
692   /// \brief Creates clause with a list of variables \a VL.
693   ///
694   /// \param C AST context.
695   /// \param StartLoc Starting location of the clause.
696   /// \param LParenLoc Location of '('.
697   /// \param EndLoc Ending location of the clause.
698   /// \param VL List of references to the variables.
699   ///
700   static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
701                                   SourceLocation LParenLoc,
702                                   SourceLocation EndLoc, ArrayRef<Expr *> VL);
703   /// \brief Creates an empty clause with the place for \a N variables.
704   ///
705   /// \param C AST context.
706   /// \param N The number of variables.
707   ///
708   static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
709 
children()710   StmtRange children() {
711     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
712                      reinterpret_cast<Stmt **>(varlist_end()));
713   }
714 
classof(const OMPClause * T)715   static bool classof(const OMPClause *T) {
716     return T->getClauseKind() == OMPC_private;
717   }
718 };
719 
720 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
721 /// directives.
722 ///
723 /// \code
724 /// #pragma omp parallel firstprivate(a,b)
725 /// \endcode
726 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
727 /// with the variables 'a' and 'b'.
728 ///
729 class OMPFirstprivateClause : public OMPVarListClause<OMPFirstprivateClause> {
730   /// \brief Build clause with number of variables \a N.
731   ///
732   /// \param StartLoc Starting location of the clause.
733   /// \param LParenLoc Location of '('.
734   /// \param EndLoc Ending location of the clause.
735   /// \param N Number of the variables in the clause.
736   ///
OMPFirstprivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)737   OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
738                         SourceLocation EndLoc, unsigned N)
739       : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
740                                                 LParenLoc, EndLoc, N) {}
741 
742   /// \brief Build an empty clause.
743   ///
744   /// \param N Number of variables.
745   ///
OMPFirstprivateClause(unsigned N)746   explicit OMPFirstprivateClause(unsigned N)
747       : OMPVarListClause<OMPFirstprivateClause>(
748             OMPC_firstprivate, SourceLocation(), SourceLocation(),
749             SourceLocation(), N) {}
750 
751 public:
752   /// \brief Creates clause with a list of variables \a VL.
753   ///
754   /// \param C AST context.
755   /// \param StartLoc Starting location of the clause.
756   /// \param LParenLoc Location of '('.
757   /// \param EndLoc Ending location of the clause.
758   /// \param VL List of references to the variables.
759   ///
760   static OMPFirstprivateClause *
761   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
762          SourceLocation EndLoc, ArrayRef<Expr *> VL);
763   /// \brief Creates an empty clause with the place for \a N variables.
764   ///
765   /// \param C AST context.
766   /// \param N The number of variables.
767   ///
768   static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
769 
children()770   StmtRange children() {
771     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
772                      reinterpret_cast<Stmt **>(varlist_end()));
773   }
774 
classof(const OMPClause * T)775   static bool classof(const OMPClause *T) {
776     return T->getClauseKind() == OMPC_firstprivate;
777   }
778 };
779 
780 /// \brief This represents clause 'lastprivate' in the '#pragma omp ...'
781 /// directives.
782 ///
783 /// \code
784 /// #pragma omp simd lastprivate(a,b)
785 /// \endcode
786 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
787 /// with the variables 'a' and 'b'.
788 ///
789 class OMPLastprivateClause : public OMPVarListClause<OMPLastprivateClause> {
790   /// \brief Build clause with number of variables \a N.
791   ///
792   /// \param StartLoc Starting location of the clause.
793   /// \param LParenLoc Location of '('.
794   /// \param EndLoc Ending location of the clause.
795   /// \param N Number of the variables in the clause.
796   ///
OMPLastprivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)797   OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
798                        SourceLocation EndLoc, unsigned N)
799       : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
800                                                LParenLoc, EndLoc, N) {}
801 
802   /// \brief Build an empty clause.
803   ///
804   /// \param N Number of variables.
805   ///
OMPLastprivateClause(unsigned N)806   explicit OMPLastprivateClause(unsigned N)
807       : OMPVarListClause<OMPLastprivateClause>(
808             OMPC_lastprivate, SourceLocation(), SourceLocation(),
809             SourceLocation(), N) {}
810 
811 public:
812   /// \brief Creates clause with a list of variables \a VL.
813   ///
814   /// \param C AST context.
815   /// \param StartLoc Starting location of the clause.
816   /// \param LParenLoc Location of '('.
817   /// \param EndLoc Ending location of the clause.
818   /// \param VL List of references to the variables.
819   ///
820   static OMPLastprivateClause *
821   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
822          SourceLocation EndLoc, ArrayRef<Expr *> VL);
823   /// \brief Creates an empty clause with the place for \a N variables.
824   ///
825   /// \param C AST context.
826   /// \param N The number of variables.
827   ///
828   static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
829 
children()830   StmtRange children() {
831     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
832                      reinterpret_cast<Stmt **>(varlist_end()));
833   }
834 
classof(const OMPClause * T)835   static bool classof(const OMPClause *T) {
836     return T->getClauseKind() == OMPC_lastprivate;
837   }
838 };
839 
840 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
841 ///
842 /// \code
843 /// #pragma omp parallel shared(a,b)
844 /// \endcode
845 /// In this example directive '#pragma omp parallel' has clause 'shared'
846 /// with the variables 'a' and 'b'.
847 ///
848 class OMPSharedClause : public OMPVarListClause<OMPSharedClause> {
849   /// \brief Build clause with number of variables \a N.
850   ///
851   /// \param StartLoc Starting location of the clause.
852   /// \param LParenLoc Location of '('.
853   /// \param EndLoc Ending location of the clause.
854   /// \param N Number of the variables in the clause.
855   ///
OMPSharedClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)856   OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
857                   SourceLocation EndLoc, unsigned N)
858       : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
859                                           EndLoc, N) {}
860 
861   /// \brief Build an empty clause.
862   ///
863   /// \param N Number of variables.
864   ///
OMPSharedClause(unsigned N)865   explicit OMPSharedClause(unsigned N)
866       : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
867                                           SourceLocation(), SourceLocation(),
868                                           N) {}
869 
870 public:
871   /// \brief Creates clause with a list of variables \a VL.
872   ///
873   /// \param C AST context.
874   /// \param StartLoc Starting location of the clause.
875   /// \param LParenLoc Location of '('.
876   /// \param EndLoc Ending location of the clause.
877   /// \param VL List of references to the variables.
878   ///
879   static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
880                                  SourceLocation LParenLoc,
881                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
882   /// \brief Creates an empty clause with \a N variables.
883   ///
884   /// \param C AST context.
885   /// \param N The number of variables.
886   ///
887   static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
888 
children()889   StmtRange children() {
890     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
891                      reinterpret_cast<Stmt **>(varlist_end()));
892   }
893 
classof(const OMPClause * T)894   static bool classof(const OMPClause *T) {
895     return T->getClauseKind() == OMPC_shared;
896   }
897 };
898 
899 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
900 /// directives.
901 ///
902 /// \code
903 /// #pragma omp parallel reduction(+:a,b)
904 /// \endcode
905 /// In this example directive '#pragma omp parallel' has clause 'reduction'
906 /// with operator '+' and the variables 'a' and 'b'.
907 ///
908 class OMPReductionClause : public OMPVarListClause<OMPReductionClause> {
909   friend class OMPClauseReader;
910   /// \brief Location of ':'.
911   SourceLocation ColonLoc;
912   /// \brief Nested name specifier for C++.
913   NestedNameSpecifierLoc QualifierLoc;
914   /// \brief Name of custom operator.
915   DeclarationNameInfo NameInfo;
916 
917   /// \brief Build clause with number of variables \a N.
918   ///
919   /// \param StartLoc Starting location of the clause.
920   /// \param LParenLoc Location of '('.
921   /// \param EndLoc Ending location of the clause.
922   /// \param ColonLoc Location of ':'.
923   /// \param N Number of the variables in the clause.
924   /// \param QualifierLoc The nested-name qualifier with location information
925   /// \param NameInfo The full name info for reduction identifier.
926   ///
OMPReductionClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned N,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo)927   OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
928                      SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
929                      NestedNameSpecifierLoc QualifierLoc,
930                      const DeclarationNameInfo &NameInfo)
931       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
932                                              LParenLoc, EndLoc, N),
933         ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
934 
935   /// \brief Build an empty clause.
936   ///
937   /// \param N Number of variables.
938   ///
OMPReductionClause(unsigned N)939   explicit OMPReductionClause(unsigned N)
940       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
941                                              SourceLocation(), SourceLocation(),
942                                              N),
943         ColonLoc(), QualifierLoc(), NameInfo() {}
944 
945   /// \brief Sets location of ':' symbol in clause.
setColonLoc(SourceLocation CL)946   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
947   /// \brief Sets the name info for specified reduction identifier.
setNameInfo(DeclarationNameInfo DNI)948   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
949   /// \brief Sets the nested name specifier.
setQualifierLoc(NestedNameSpecifierLoc NSL)950   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
951 
952 public:
953   /// \brief Creates clause with a list of variables \a VL.
954   ///
955   /// \param StartLoc Starting location of the clause.
956   /// \param LParenLoc Location of '('.
957   /// \param ColonLoc Location of ':'.
958   /// \param EndLoc Ending location of the clause.
959   /// \param VL The variables in the clause.
960   /// \param QualifierLoc The nested-name qualifier with location information
961   /// \param NameInfo The full name info for reduction identifier.
962   ///
963   static OMPReductionClause *
964   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
965          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
966          NestedNameSpecifierLoc QualifierLoc,
967          const DeclarationNameInfo &NameInfo);
968   /// \brief Creates an empty clause with the place for \a N variables.
969   ///
970   /// \param C AST context.
971   /// \param N The number of variables.
972   ///
973   static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
974 
975   /// \brief Gets location of ':' symbol in clause.
getColonLoc()976   SourceLocation getColonLoc() const { return ColonLoc; }
977   /// \brief Gets the name info for specified reduction identifier.
getNameInfo()978   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
979   /// \brief Gets the nested name specifier.
getQualifierLoc()980   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
981 
children()982   StmtRange children() {
983     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
984                      reinterpret_cast<Stmt **>(varlist_end()));
985   }
986 
classof(const OMPClause * T)987   static bool classof(const OMPClause *T) {
988     return T->getClauseKind() == OMPC_reduction;
989   }
990 };
991 
992 /// \brief This represents clause 'linear' in the '#pragma omp ...'
993 /// directives.
994 ///
995 /// \code
996 /// #pragma omp simd linear(a,b : 2)
997 /// \endcode
998 /// In this example directive '#pragma omp simd' has clause 'linear'
999 /// with variables 'a', 'b' and linear step '2'.
1000 ///
1001 class OMPLinearClause : public OMPVarListClause<OMPLinearClause> {
1002   friend class OMPClauseReader;
1003   /// \brief Location of ':'.
1004   SourceLocation ColonLoc;
1005 
1006   /// \brief Sets the linear step for clause.
setStep(Expr * Step)1007   void setStep(Expr *Step) { *varlist_end() = Step; }
1008 
1009   /// \brief Build 'linear' clause with given number of variables \a NumVars.
1010   ///
1011   /// \param StartLoc Starting location of the clause.
1012   /// \param LParenLoc Location of '('.
1013   /// \param ColonLoc Location of ':'.
1014   /// \param EndLoc Ending location of the clause.
1015   /// \param NumVars Number of variables.
1016   ///
OMPLinearClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned NumVars)1017   OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1018                   SourceLocation ColonLoc, SourceLocation EndLoc,
1019                   unsigned NumVars)
1020       : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
1021                                           EndLoc, NumVars),
1022         ColonLoc(ColonLoc) {}
1023 
1024   /// \brief Build an empty clause.
1025   ///
1026   /// \param NumVars Number of variables.
1027   ///
OMPLinearClause(unsigned NumVars)1028   explicit OMPLinearClause(unsigned NumVars)
1029       : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
1030                                           SourceLocation(), SourceLocation(),
1031                                           NumVars),
1032         ColonLoc(SourceLocation()) {}
1033 
1034 public:
1035   /// \brief Creates clause with a list of variables \a VL and a linear step
1036   /// \a Step.
1037   ///
1038   /// \param C AST Context.
1039   /// \param StartLoc Starting location of the clause.
1040   /// \param LParenLoc Location of '('.
1041   /// \param ColonLoc Location of ':'.
1042   /// \param EndLoc Ending location of the clause.
1043   /// \param VL List of references to the variables.
1044   /// \param Step Linear step.
1045   static OMPLinearClause *Create(const ASTContext &C, SourceLocation StartLoc,
1046                                  SourceLocation LParenLoc,
1047                                  SourceLocation ColonLoc, SourceLocation EndLoc,
1048                                  ArrayRef<Expr *> VL, Expr *Step);
1049 
1050   /// \brief Creates an empty clause with the place for \a NumVars variables.
1051   ///
1052   /// \param C AST context.
1053   /// \param NumVars Number of variables.
1054   ///
1055   static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1056 
1057   /// \brief Sets the location of ':'.
setColonLoc(SourceLocation Loc)1058   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1059   /// \brief Returns the location of '('.
getColonLoc()1060   SourceLocation getColonLoc() const { return ColonLoc; }
1061 
1062   /// \brief Returns linear step.
getStep()1063   Expr *getStep() { return *varlist_end(); }
1064   /// \brief Returns linear step.
getStep()1065   const Expr *getStep() const { return *varlist_end(); }
1066 
children()1067   StmtRange children() {
1068     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1069                      reinterpret_cast<Stmt **>(varlist_end() + 1));
1070   }
1071 
classof(const OMPClause * T)1072   static bool classof(const OMPClause *T) {
1073     return T->getClauseKind() == OMPC_linear;
1074   }
1075 };
1076 
1077 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
1078 /// directives.
1079 ///
1080 /// \code
1081 /// #pragma omp simd aligned(a,b : 8)
1082 /// \endcode
1083 /// In this example directive '#pragma omp simd' has clause 'aligned'
1084 /// with variables 'a', 'b' and alignment '8'.
1085 ///
1086 class OMPAlignedClause : public OMPVarListClause<OMPAlignedClause> {
1087   friend class OMPClauseReader;
1088   /// \brief Location of ':'.
1089   SourceLocation ColonLoc;
1090 
1091   /// \brief Sets the alignment for clause.
setAlignment(Expr * A)1092   void setAlignment(Expr *A) { *varlist_end() = A; }
1093 
1094   /// \brief Build 'aligned' clause with given number of variables \a NumVars.
1095   ///
1096   /// \param StartLoc Starting location of the clause.
1097   /// \param LParenLoc Location of '('.
1098   /// \param ColonLoc Location of ':'.
1099   /// \param EndLoc Ending location of the clause.
1100   /// \param NumVars Number of variables.
1101   ///
OMPAlignedClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned NumVars)1102   OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1103                    SourceLocation ColonLoc, SourceLocation EndLoc,
1104                    unsigned NumVars)
1105       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
1106                                            EndLoc, NumVars),
1107         ColonLoc(ColonLoc) {}
1108 
1109   /// \brief Build an empty clause.
1110   ///
1111   /// \param NumVars Number of variables.
1112   ///
OMPAlignedClause(unsigned NumVars)1113   explicit OMPAlignedClause(unsigned NumVars)
1114       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
1115                                            SourceLocation(), SourceLocation(),
1116                                            NumVars),
1117         ColonLoc(SourceLocation()) {}
1118 
1119 public:
1120   /// \brief Creates clause with a list of variables \a VL and alignment \a A.
1121   ///
1122   /// \param C AST Context.
1123   /// \param StartLoc Starting location of the clause.
1124   /// \param LParenLoc Location of '('.
1125   /// \param ColonLoc Location of ':'.
1126   /// \param EndLoc Ending location of the clause.
1127   /// \param VL List of references to the variables.
1128   /// \param A Alignment.
1129   static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1130                                   SourceLocation LParenLoc,
1131                                   SourceLocation ColonLoc,
1132                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
1133                                   Expr *A);
1134 
1135   /// \brief Creates an empty clause with the place for \a NumVars variables.
1136   ///
1137   /// \param C AST context.
1138   /// \param NumVars Number of variables.
1139   ///
1140   static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1141 
1142   /// \brief Sets the location of ':'.
setColonLoc(SourceLocation Loc)1143   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1144   /// \brief Returns the location of ':'.
getColonLoc()1145   SourceLocation getColonLoc() const { return ColonLoc; }
1146 
1147   /// \brief Returns alignment.
getAlignment()1148   Expr *getAlignment() { return *varlist_end(); }
1149   /// \brief Returns alignment.
getAlignment()1150   const Expr *getAlignment() const { return *varlist_end(); }
1151 
children()1152   StmtRange children() {
1153     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1154                      reinterpret_cast<Stmt **>(varlist_end() + 1));
1155   }
1156 
classof(const OMPClause * T)1157   static bool classof(const OMPClause *T) {
1158     return T->getClauseKind() == OMPC_aligned;
1159   }
1160 };
1161 
1162 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
1163 ///
1164 /// \code
1165 /// #pragma omp parallel copyin(a,b)
1166 /// \endcode
1167 /// In this example directive '#pragma omp parallel' has clause 'copyin'
1168 /// with the variables 'a' and 'b'.
1169 ///
1170 class OMPCopyinClause : public OMPVarListClause<OMPCopyinClause> {
1171   /// \brief Build clause with number of variables \a N.
1172   ///
1173   /// \param StartLoc Starting location of the clause.
1174   /// \param LParenLoc Location of '('.
1175   /// \param EndLoc Ending location of the clause.
1176   /// \param N Number of the variables in the clause.
1177   ///
OMPCopyinClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)1178   OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1179                   SourceLocation EndLoc, unsigned N)
1180       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
1181                                           EndLoc, N) {}
1182 
1183   /// \brief Build an empty clause.
1184   ///
1185   /// \param N Number of variables.
1186   ///
OMPCopyinClause(unsigned N)1187   explicit OMPCopyinClause(unsigned N)
1188       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
1189                                           SourceLocation(), SourceLocation(),
1190                                           N) {}
1191 
1192 public:
1193   /// \brief Creates clause with a list of variables \a VL.
1194   ///
1195   /// \param C AST context.
1196   /// \param StartLoc Starting location of the clause.
1197   /// \param LParenLoc Location of '('.
1198   /// \param EndLoc Ending location of the clause.
1199   /// \param VL List of references to the variables.
1200   ///
1201   static OMPCopyinClause *Create(const ASTContext &C, SourceLocation StartLoc,
1202                                  SourceLocation LParenLoc,
1203                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
1204   /// \brief Creates an empty clause with \a N variables.
1205   ///
1206   /// \param C AST context.
1207   /// \param N The number of variables.
1208   ///
1209   static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
1210 
children()1211   StmtRange children() {
1212     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1213                      reinterpret_cast<Stmt **>(varlist_end()));
1214   }
1215 
classof(const OMPClause * T)1216   static bool classof(const OMPClause *T) {
1217     return T->getClauseKind() == OMPC_copyin;
1218   }
1219 };
1220 
1221 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
1222 /// directives.
1223 ///
1224 /// \code
1225 /// #pragma omp single copyprivate(a,b)
1226 /// \endcode
1227 /// In this example directive '#pragma omp single' has clause 'copyprivate'
1228 /// with the variables 'a' and 'b'.
1229 ///
1230 class OMPCopyprivateClause : public OMPVarListClause<OMPCopyprivateClause> {
1231   /// \brief Build clause with number of variables \a N.
1232   ///
1233   /// \param StartLoc Starting location of the clause.
1234   /// \param LParenLoc Location of '('.
1235   /// \param EndLoc Ending location of the clause.
1236   /// \param N Number of the variables in the clause.
1237   ///
OMPCopyprivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)1238   OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1239                        SourceLocation EndLoc, unsigned N)
1240       : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
1241                                                LParenLoc, EndLoc, N) {}
1242 
1243   /// \brief Build an empty clause.
1244   ///
1245   /// \param N Number of variables.
1246   ///
OMPCopyprivateClause(unsigned N)1247   explicit OMPCopyprivateClause(unsigned N)
1248       : OMPVarListClause<OMPCopyprivateClause>(
1249             OMPC_copyprivate, SourceLocation(), SourceLocation(),
1250             SourceLocation(), N) {}
1251 
1252 public:
1253   /// \brief Creates clause with a list of variables \a VL.
1254   ///
1255   /// \param C AST context.
1256   /// \param StartLoc Starting location of the clause.
1257   /// \param LParenLoc Location of '('.
1258   /// \param EndLoc Ending location of the clause.
1259   /// \param VL List of references to the variables.
1260   ///
1261   static OMPCopyprivateClause *
1262   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1263          SourceLocation EndLoc, ArrayRef<Expr *> VL);
1264   /// \brief Creates an empty clause with \a N variables.
1265   ///
1266   /// \param C AST context.
1267   /// \param N The number of variables.
1268   ///
1269   static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1270 
children()1271   StmtRange children() {
1272     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1273                      reinterpret_cast<Stmt **>(varlist_end()));
1274   }
1275 
classof(const OMPClause * T)1276   static bool classof(const OMPClause *T) {
1277     return T->getClauseKind() == OMPC_copyprivate;
1278   }
1279 };
1280 
1281 } // end namespace clang
1282 
1283 #endif
1284