]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/OpenMPClause.h
Merge ^/head r278351 through r278498.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / OpenMPClause.h
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:
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.
46   SourceLocation getLocStart() const { return StartLoc; }
47   /// \brief Returns the ending location of the clause.
48   SourceLocation getLocEnd() const { return EndLoc; }
49
50   /// \brief Sets the starting location of the clause.
51   void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
52   /// \brief Sets the ending location of the clause.
53   void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
54
55   /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.).
56   OpenMPClauseKind getClauseKind() const { return Kind; }
57
58   bool isImplicit() const { return StartLoc.isInvalid(); }
59
60   StmtRange children();
61   ConstStmtRange children() const {
62     return const_cast<OMPClause *>(this)->children();
63   }
64   static bool classof(const OMPClause *) { 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.
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.
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   ///
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
116   unsigned varlist_size() const { return NumVars; }
117   bool varlist_empty() const { return NumVars == 0; }
118
119   varlist_range varlists() {
120     return varlist_range(varlist_begin(), varlist_end());
121   }
122   varlist_const_range varlists() const {
123     return varlist_const_range(varlist_begin(), varlist_end());
124   }
125
126   varlist_iterator varlist_begin() { return getVarRefs().begin(); }
127   varlist_iterator varlist_end() { return getVarRefs().end(); }
128   varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
129   varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
130
131   /// \brief Sets the location of '('.
132   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
133   /// \brief Returns the location of '('.
134   SourceLocation getLParenLoc() const { return LParenLoc; }
135
136   /// \brief Fetches list of all variables in the clause.
137   ArrayRef<const Expr *> getVarRefs() const {
138     return llvm::makeArrayRef(
139         reinterpret_cast<const Expr *const *>(
140             reinterpret_cast<const char *>(this) +
141             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<const 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   ///
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   ///
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   ///
180   OMPIfClause()
181       : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
182         LParenLoc(SourceLocation()), Condition(nullptr) {}
183
184   /// \brief Sets the location of '('.
185   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
186   /// \brief Returns the location of '('.
187   SourceLocation getLParenLoc() const { return LParenLoc; }
188
189   /// \brief Returns condition.
190   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
191
192   static bool classof(const OMPClause *T) {
193     return T->getClauseKind() == OMPC_if;
194   }
195
196   StmtRange children() { return StmtRange(&Condition, &Condition + 1); }
197 };
198
199 /// \brief This represents 'final' clause in the '#pragma omp ...' directive.
200 ///
201 /// \code
202 /// #pragma omp task final(a > 5)
203 /// \endcode
204 /// In this example directive '#pragma omp task' has simple 'final'
205 /// clause with condition 'a > 5'.
206 ///
207 class OMPFinalClause : public OMPClause {
208   friend class OMPClauseReader;
209   /// \brief Location of '('.
210   SourceLocation LParenLoc;
211   /// \brief Condition of the 'if' clause.
212   Stmt *Condition;
213
214   /// \brief Set condition.
215   ///
216   void setCondition(Expr *Cond) { Condition = Cond; }
217
218 public:
219   /// \brief Build 'final' clause with condition \a Cond.
220   ///
221   /// \param StartLoc Starting location of the clause.
222   /// \param LParenLoc Location of '('.
223   /// \param Cond Condition of the clause.
224   /// \param EndLoc Ending location of the clause.
225   ///
226   OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
227                  SourceLocation EndLoc)
228       : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
229         Condition(Cond) {}
230
231   /// \brief Build an empty clause.
232   ///
233   OMPFinalClause()
234       : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
235         LParenLoc(SourceLocation()), Condition(nullptr) {}
236
237   /// \brief Sets the location of '('.
238   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
239   /// \brief Returns the location of '('.
240   SourceLocation getLParenLoc() const { return LParenLoc; }
241
242   /// \brief Returns condition.
243   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
244
245   static bool classof(const OMPClause *T) {
246     return T->getClauseKind() == OMPC_final;
247   }
248
249   StmtRange children() { return StmtRange(&Condition, &Condition + 1); }
250 };
251
252 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
253 /// directive.
254 ///
255 /// \code
256 /// #pragma omp parallel num_threads(6)
257 /// \endcode
258 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
259 /// clause with number of threads '6'.
260 ///
261 class OMPNumThreadsClause : public OMPClause {
262   friend class OMPClauseReader;
263   /// \brief Location of '('.
264   SourceLocation LParenLoc;
265   /// \brief Condition of the 'num_threads' clause.
266   Stmt *NumThreads;
267
268   /// \brief Set condition.
269   ///
270   void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
271
272 public:
273   /// \brief Build 'num_threads' clause with condition \a NumThreads.
274   ///
275   /// \param NumThreads Number of threads for the construct.
276   /// \param StartLoc Starting location of the clause.
277   /// \param LParenLoc Location of '('.
278   /// \param EndLoc Ending location of the clause.
279   ///
280   OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
281                       SourceLocation LParenLoc, SourceLocation EndLoc)
282       : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
283         NumThreads(NumThreads) {}
284
285   /// \brief Build an empty clause.
286   ///
287   OMPNumThreadsClause()
288       : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
289         LParenLoc(SourceLocation()), NumThreads(nullptr) {}
290
291   /// \brief Sets the location of '('.
292   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
293   /// \brief Returns the location of '('.
294   SourceLocation getLParenLoc() const { return LParenLoc; }
295
296   /// \brief Returns number of threads.
297   Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
298
299   static bool classof(const OMPClause *T) {
300     return T->getClauseKind() == OMPC_num_threads;
301   }
302
303   StmtRange children() { return StmtRange(&NumThreads, &NumThreads + 1); }
304 };
305
306 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
307 /// directive.
308 ///
309 /// \code
310 /// #pragma omp simd safelen(4)
311 /// \endcode
312 /// In this example directive '#pragma omp simd' has clause 'safelen'
313 /// with single expression '4'.
314 /// If the safelen clause is used then no two iterations executed
315 /// concurrently with SIMD instructions can have a greater distance
316 /// in the logical iteration space than its value. The parameter of
317 /// the safelen clause must be a constant positive integer expression.
318 ///
319 class OMPSafelenClause : public OMPClause {
320   friend class OMPClauseReader;
321   /// \brief Location of '('.
322   SourceLocation LParenLoc;
323   /// \brief Safe iteration space distance.
324   Stmt *Safelen;
325
326   /// \brief Set safelen.
327   void setSafelen(Expr *Len) { Safelen = Len; }
328
329 public:
330   /// \brief Build 'safelen' clause.
331   ///
332   /// \param Len Expression associated with this clause.
333   /// \param StartLoc Starting location of the clause.
334   /// \param EndLoc Ending location of the clause.
335   ///
336   OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
337                    SourceLocation EndLoc)
338       : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
339         Safelen(Len) {}
340
341   /// \brief Build an empty clause.
342   ///
343   explicit OMPSafelenClause()
344       : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
345         LParenLoc(SourceLocation()), Safelen(nullptr) {}
346
347   /// \brief Sets the location of '('.
348   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
349   /// \brief Returns the location of '('.
350   SourceLocation getLParenLoc() const { return LParenLoc; }
351
352   /// \brief Return safe iteration space distance.
353   Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
354
355   static bool classof(const OMPClause *T) {
356     return T->getClauseKind() == OMPC_safelen;
357   }
358
359   StmtRange children() { return StmtRange(&Safelen, &Safelen + 1); }
360 };
361
362 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
363 /// directive.
364 ///
365 /// \code
366 /// #pragma omp simd collapse(3)
367 /// \endcode
368 /// In this example directive '#pragma omp simd' has clause 'collapse'
369 /// with single expression '3'.
370 /// The parameter must be a constant positive integer expression, it specifies
371 /// the number of nested loops that should be collapsed into a single iteration
372 /// space.
373 ///
374 class OMPCollapseClause : public OMPClause {
375   friend class OMPClauseReader;
376   /// \brief Location of '('.
377   SourceLocation LParenLoc;
378   /// \brief Number of for-loops.
379   Stmt *NumForLoops;
380
381   /// \brief Set the number of associated for-loops.
382   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
383
384 public:
385   /// \brief Build 'collapse' clause.
386   ///
387   /// \param Num Expression associated with this clause.
388   /// \param StartLoc Starting location of the clause.
389   /// \param LParenLoc Location of '('.
390   /// \param EndLoc Ending location of the clause.
391   ///
392   OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
393                     SourceLocation LParenLoc, SourceLocation EndLoc)
394       : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
395         NumForLoops(Num) {}
396
397   /// \brief Build an empty clause.
398   ///
399   explicit OMPCollapseClause()
400       : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
401         LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
402
403   /// \brief Sets the location of '('.
404   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
405   /// \brief Returns the location of '('.
406   SourceLocation getLParenLoc() const { return LParenLoc; }
407
408   /// \brief Return the number of associated for-loops.
409   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
410
411   static bool classof(const OMPClause *T) {
412     return T->getClauseKind() == OMPC_collapse;
413   }
414
415   StmtRange children() { return StmtRange(&NumForLoops, &NumForLoops + 1); }
416 };
417
418 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
419 ///
420 /// \code
421 /// #pragma omp parallel default(shared)
422 /// \endcode
423 /// In this example directive '#pragma omp parallel' has simple 'default'
424 /// clause with kind 'shared'.
425 ///
426 class OMPDefaultClause : public OMPClause {
427   friend class OMPClauseReader;
428   /// \brief Location of '('.
429   SourceLocation LParenLoc;
430   /// \brief A kind of the 'default' clause.
431   OpenMPDefaultClauseKind Kind;
432   /// \brief Start location of the kind in source code.
433   SourceLocation KindKwLoc;
434
435   /// \brief Set kind of the clauses.
436   ///
437   /// \param K Argument of clause.
438   ///
439   void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
440
441   /// \brief Set argument location.
442   ///
443   /// \param KLoc Argument location.
444   ///
445   void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
446
447 public:
448   /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
449   ///
450   /// \param A Argument of the clause ('none' or 'shared').
451   /// \param ALoc Starting location of the argument.
452   /// \param StartLoc Starting location of the clause.
453   /// \param LParenLoc Location of '('.
454   /// \param EndLoc Ending location of the clause.
455   ///
456   OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
457                    SourceLocation StartLoc, SourceLocation LParenLoc,
458                    SourceLocation EndLoc)
459       : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
460         Kind(A), KindKwLoc(ALoc) {}
461
462   /// \brief Build an empty clause.
463   ///
464   OMPDefaultClause()
465       : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
466         LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
467         KindKwLoc(SourceLocation()) {}
468
469   /// \brief Sets the location of '('.
470   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
471   /// \brief Returns the location of '('.
472   SourceLocation getLParenLoc() const { return LParenLoc; }
473
474   /// \brief Returns kind of the clause.
475   OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
476
477   /// \brief Returns location of clause kind.
478   SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
479
480   static bool classof(const OMPClause *T) {
481     return T->getClauseKind() == OMPC_default;
482   }
483
484   StmtRange children() { return StmtRange(); }
485 };
486
487 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
488 /// directive.
489 ///
490 /// \code
491 /// #pragma omp parallel proc_bind(master)
492 /// \endcode
493 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
494 /// clause with kind 'master'.
495 ///
496 class OMPProcBindClause : public OMPClause {
497   friend class OMPClauseReader;
498   /// \brief Location of '('.
499   SourceLocation LParenLoc;
500   /// \brief A kind of the 'proc_bind' clause.
501   OpenMPProcBindClauseKind Kind;
502   /// \brief Start location of the kind in source code.
503   SourceLocation KindKwLoc;
504
505   /// \brief Set kind of the clause.
506   ///
507   /// \param K Kind of clause.
508   ///
509   void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
510
511   /// \brief Set clause kind location.
512   ///
513   /// \param KLoc Kind location.
514   ///
515   void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
516
517 public:
518   /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
519   ///        'spread').
520   ///
521   /// \param A Argument of the clause ('master', 'close' or 'spread').
522   /// \param ALoc Starting location of the argument.
523   /// \param StartLoc Starting location of the clause.
524   /// \param LParenLoc Location of '('.
525   /// \param EndLoc Ending location of the clause.
526   ///
527   OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
528                     SourceLocation StartLoc, SourceLocation LParenLoc,
529                     SourceLocation EndLoc)
530       : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
531         Kind(A), KindKwLoc(ALoc) {}
532
533   /// \brief Build an empty clause.
534   ///
535   OMPProcBindClause()
536       : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
537         LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
538         KindKwLoc(SourceLocation()) {}
539
540   /// \brief Sets the location of '('.
541   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
542   /// \brief Returns the location of '('.
543   SourceLocation getLParenLoc() const { return LParenLoc; }
544
545   /// \brief Returns kind of the clause.
546   OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
547
548   /// \brief Returns location of clause kind.
549   SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
550
551   static bool classof(const OMPClause *T) {
552     return T->getClauseKind() == OMPC_proc_bind;
553   }
554
555   StmtRange children() { return StmtRange(); }
556 };
557
558 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
559 ///
560 /// \code
561 /// #pragma omp for schedule(static, 3)
562 /// \endcode
563 /// In this example directive '#pragma omp for' has 'schedule' clause with
564 /// arguments 'static' and '3'.
565 ///
566 class OMPScheduleClause : public OMPClause {
567   friend class OMPClauseReader;
568   /// \brief Location of '('.
569   SourceLocation LParenLoc;
570   /// \brief A kind of the 'schedule' clause.
571   OpenMPScheduleClauseKind Kind;
572   /// \brief Start location of the schedule ind in source code.
573   SourceLocation KindLoc;
574   /// \brief Location of ',' (if any).
575   SourceLocation CommaLoc;
576   /// \brief Chunk size.
577   Stmt *ChunkSize;
578
579   /// \brief Set schedule kind.
580   ///
581   /// \param K Schedule kind.
582   ///
583   void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
584   /// \brief Sets the location of '('.
585   ///
586   /// \param Loc Location of '('.
587   ///
588   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
589   /// \brief Set schedule kind start location.
590   ///
591   /// \param KLoc Schedule kind location.
592   ///
593   void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
594   /// \brief Set location of ','.
595   ///
596   /// \param Loc Location of ','.
597   ///
598   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
599   /// \brief Set chunk size.
600   ///
601   /// \param E Chunk size.
602   ///
603   void setChunkSize(Expr *E) { ChunkSize = E; }
604
605 public:
606   /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
607   /// expression \a ChunkSize.
608   ///
609   /// \param StartLoc Starting location of the clause.
610   /// \param LParenLoc Location of '('.
611   /// \param KLoc Starting location of the argument.
612   /// \param CommaLoc Location of ','.
613   /// \param EndLoc Ending location of the clause.
614   /// \param Kind Schedule kind.
615   /// \param ChunkSize Chunk size.
616   ///
617   OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
618                     SourceLocation KLoc, SourceLocation CommaLoc,
619                     SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
620                     Expr *ChunkSize)
621       : OMPClause(OMPC_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc),
622         Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {}
623
624   /// \brief Build an empty clause.
625   ///
626   explicit OMPScheduleClause()
627       : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
628         Kind(OMPC_SCHEDULE_unknown), ChunkSize(nullptr) {}
629
630   /// \brief Get kind of the clause.
631   ///
632   OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
633   /// \brief Get location of '('.
634   ///
635   SourceLocation getLParenLoc() { return LParenLoc; }
636   /// \brief Get kind location.
637   ///
638   SourceLocation getScheduleKindLoc() { return KindLoc; }
639   /// \brief Get location of ','.
640   ///
641   SourceLocation getCommaLoc() { return CommaLoc; }
642   /// \brief Get chunk size.
643   ///
644   Expr *getChunkSize() { return dyn_cast_or_null<Expr>(ChunkSize); }
645   /// \brief Get chunk size.
646   ///
647   Expr *getChunkSize() const { return dyn_cast_or_null<Expr>(ChunkSize); }
648
649   static bool classof(const OMPClause *T) {
650     return T->getClauseKind() == OMPC_schedule;
651   }
652
653   StmtRange children() { return StmtRange(&ChunkSize, &ChunkSize + 1); }
654 };
655
656 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
657 ///
658 /// \code
659 /// #pragma omp for ordered
660 /// \endcode
661 /// In this example directive '#pragma omp for' has 'ordered' clause.
662 ///
663 class OMPOrderedClause : public OMPClause {
664 public:
665   /// \brief Build 'ordered' clause.
666   ///
667   /// \param StartLoc Starting location of the clause.
668   /// \param EndLoc Ending location of the clause.
669   ///
670   OMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc)
671       : OMPClause(OMPC_ordered, StartLoc, EndLoc) {}
672
673   /// \brief Build an empty clause.
674   ///
675   OMPOrderedClause()
676       : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
677
678   static bool classof(const OMPClause *T) {
679     return T->getClauseKind() == OMPC_ordered;
680   }
681
682   StmtRange children() { return StmtRange(); }
683 };
684
685 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
686 ///
687 /// \code
688 /// #pragma omp for nowait
689 /// \endcode
690 /// In this example directive '#pragma omp for' has 'nowait' clause.
691 ///
692 class OMPNowaitClause : public OMPClause {
693 public:
694   /// \brief Build 'nowait' clause.
695   ///
696   /// \param StartLoc Starting location of the clause.
697   /// \param EndLoc Ending location of the clause.
698   ///
699   OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
700       : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
701
702   /// \brief Build an empty clause.
703   ///
704   OMPNowaitClause()
705       : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
706
707   static bool classof(const OMPClause *T) {
708     return T->getClauseKind() == OMPC_nowait;
709   }
710
711   StmtRange children() { return StmtRange(); }
712 };
713
714 /// \brief This represents 'untied' clause in the '#pragma omp ...' directive.
715 ///
716 /// \code
717 /// #pragma omp task untied
718 /// \endcode
719 /// In this example directive '#pragma omp task' has 'untied' clause.
720 ///
721 class OMPUntiedClause : public OMPClause {
722 public:
723   /// \brief Build 'untied' clause.
724   ///
725   /// \param StartLoc Starting location of the clause.
726   /// \param EndLoc Ending location of the clause.
727   ///
728   OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
729       : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
730
731   /// \brief Build an empty clause.
732   ///
733   OMPUntiedClause()
734       : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
735
736   static bool classof(const OMPClause *T) {
737     return T->getClauseKind() == OMPC_untied;
738   }
739
740   StmtRange children() { return StmtRange(); }
741 };
742
743 /// \brief This represents 'mergeable' clause in the '#pragma omp ...'
744 /// directive.
745 ///
746 /// \code
747 /// #pragma omp task mergeable
748 /// \endcode
749 /// In this example directive '#pragma omp task' has 'mergeable' clause.
750 ///
751 class OMPMergeableClause : public OMPClause {
752 public:
753   /// \brief Build 'mergeable' clause.
754   ///
755   /// \param StartLoc Starting location of the clause.
756   /// \param EndLoc Ending location of the clause.
757   ///
758   OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
759       : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
760
761   /// \brief Build an empty clause.
762   ///
763   OMPMergeableClause()
764       : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
765
766   static bool classof(const OMPClause *T) {
767     return T->getClauseKind() == OMPC_mergeable;
768   }
769
770   StmtRange children() { return StmtRange(); }
771 };
772
773 /// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
774 ///
775 /// \code
776 /// #pragma omp atomic read
777 /// \endcode
778 /// In this example directive '#pragma omp atomic' has 'read' clause.
779 ///
780 class OMPReadClause : public OMPClause {
781 public:
782   /// \brief Build 'read' clause.
783   ///
784   /// \param StartLoc Starting location of the clause.
785   /// \param EndLoc Ending location of the clause.
786   ///
787   OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
788       : OMPClause(OMPC_read, StartLoc, EndLoc) {}
789
790   /// \brief Build an empty clause.
791   ///
792   OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
793
794   static bool classof(const OMPClause *T) {
795     return T->getClauseKind() == OMPC_read;
796   }
797
798   StmtRange children() { return StmtRange(); }
799 };
800
801 /// \brief This represents 'write' clause in the '#pragma omp atomic' directive.
802 ///
803 /// \code
804 /// #pragma omp atomic write
805 /// \endcode
806 /// In this example directive '#pragma omp atomic' has 'write' clause.
807 ///
808 class OMPWriteClause : public OMPClause {
809 public:
810   /// \brief Build 'write' clause.
811   ///
812   /// \param StartLoc Starting location of the clause.
813   /// \param EndLoc Ending location of the clause.
814   ///
815   OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
816       : OMPClause(OMPC_write, StartLoc, EndLoc) {}
817
818   /// \brief Build an empty clause.
819   ///
820   OMPWriteClause()
821       : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
822
823   static bool classof(const OMPClause *T) {
824     return T->getClauseKind() == OMPC_write;
825   }
826
827   StmtRange children() { return StmtRange(); }
828 };
829
830 /// \brief This represents 'update' clause in the '#pragma omp atomic'
831 /// directive.
832 ///
833 /// \code
834 /// #pragma omp atomic update
835 /// \endcode
836 /// In this example directive '#pragma omp atomic' has 'update' clause.
837 ///
838 class OMPUpdateClause : public OMPClause {
839 public:
840   /// \brief Build 'update' clause.
841   ///
842   /// \param StartLoc Starting location of the clause.
843   /// \param EndLoc Ending location of the clause.
844   ///
845   OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
846       : OMPClause(OMPC_update, StartLoc, EndLoc) {}
847
848   /// \brief Build an empty clause.
849   ///
850   OMPUpdateClause()
851       : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
852
853   static bool classof(const OMPClause *T) {
854     return T->getClauseKind() == OMPC_update;
855   }
856
857   StmtRange children() { return StmtRange(); }
858 };
859
860 /// \brief This represents 'capture' clause in the '#pragma omp atomic'
861 /// directive.
862 ///
863 /// \code
864 /// #pragma omp atomic capture
865 /// \endcode
866 /// In this example directive '#pragma omp atomic' has 'capture' clause.
867 ///
868 class OMPCaptureClause : public OMPClause {
869 public:
870   /// \brief Build 'capture' clause.
871   ///
872   /// \param StartLoc Starting location of the clause.
873   /// \param EndLoc Ending location of the clause.
874   ///
875   OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
876       : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
877
878   /// \brief Build an empty clause.
879   ///
880   OMPCaptureClause()
881       : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
882
883   static bool classof(const OMPClause *T) {
884     return T->getClauseKind() == OMPC_capture;
885   }
886
887   StmtRange children() { return StmtRange(); }
888 };
889
890 /// \brief This represents 'seq_cst' clause in the '#pragma omp atomic'
891 /// directive.
892 ///
893 /// \code
894 /// #pragma omp atomic seq_cst
895 /// \endcode
896 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
897 ///
898 class OMPSeqCstClause : public OMPClause {
899 public:
900   /// \brief Build 'seq_cst' clause.
901   ///
902   /// \param StartLoc Starting location of the clause.
903   /// \param EndLoc Ending location of the clause.
904   ///
905   OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
906       : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
907
908   /// \brief Build an empty clause.
909   ///
910   OMPSeqCstClause()
911       : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
912
913   static bool classof(const OMPClause *T) {
914     return T->getClauseKind() == OMPC_seq_cst;
915   }
916
917   StmtRange children() { return StmtRange(); }
918 };
919
920 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
921 ///
922 /// \code
923 /// #pragma omp parallel private(a,b)
924 /// \endcode
925 /// In this example directive '#pragma omp parallel' has clause 'private'
926 /// with the variables 'a' and 'b'.
927 ///
928 class OMPPrivateClause : public OMPVarListClause<OMPPrivateClause> {
929   friend class OMPClauseReader;
930   /// \brief Build clause with number of variables \a N.
931   ///
932   /// \param StartLoc Starting location of the clause.
933   /// \param LParenLoc Location of '('.
934   /// \param EndLoc Ending location of the clause.
935   /// \param N Number of the variables in the clause.
936   ///
937   OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
938                    SourceLocation EndLoc, unsigned N)
939       : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
940                                            EndLoc, N) {}
941
942   /// \brief Build an empty clause.
943   ///
944   /// \param N Number of variables.
945   ///
946   explicit OMPPrivateClause(unsigned N)
947       : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
948                                            SourceLocation(), SourceLocation(),
949                                            N) {}
950
951   /// \brief Sets the list of references to private copies with initializers for
952   /// new private variables.
953   /// \param VL List of references.
954   void setPrivateCopies(ArrayRef<Expr *> VL);
955
956   /// \brief Gets the list of references to private copies with initializers for
957   /// new private variables.
958   MutableArrayRef<Expr *> getPrivateCopies() {
959     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
960   }
961   ArrayRef<const Expr *> getPrivateCopies() const {
962     return llvm::makeArrayRef(varlist_end(), varlist_size());
963   }
964
965 public:
966   /// \brief Creates clause with a list of variables \a VL.
967   ///
968   /// \param C AST context.
969   /// \param StartLoc Starting location of the clause.
970   /// \param LParenLoc Location of '('.
971   /// \param EndLoc Ending location of the clause.
972   /// \param VL List of references to the variables.
973   /// \param PrivateVL List of references to private copies with initializers.
974   ///
975   static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
976                                   SourceLocation LParenLoc,
977                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
978                                   ArrayRef<Expr *> PrivateVL);
979   /// \brief Creates an empty clause with the place for \a N variables.
980   ///
981   /// \param C AST context.
982   /// \param N The number of variables.
983   ///
984   static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
985
986   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
987   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
988   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
989   typedef llvm::iterator_range<private_copies_const_iterator>
990       private_copies_const_range;
991
992   private_copies_range private_copies() {
993     return private_copies_range(getPrivateCopies().begin(),
994                                 getPrivateCopies().end());
995   }
996   private_copies_const_range private_copies() const {
997     return private_copies_const_range(getPrivateCopies().begin(),
998                                       getPrivateCopies().end());
999   }
1000
1001   StmtRange children() {
1002     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1003                      reinterpret_cast<Stmt **>(varlist_end()));
1004   }
1005
1006   static bool classof(const OMPClause *T) {
1007     return T->getClauseKind() == OMPC_private;
1008   }
1009 };
1010
1011 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
1012 /// directives.
1013 ///
1014 /// \code
1015 /// #pragma omp parallel firstprivate(a,b)
1016 /// \endcode
1017 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1018 /// with the variables 'a' and 'b'.
1019 ///
1020 class OMPFirstprivateClause : public OMPVarListClause<OMPFirstprivateClause> {
1021   friend class OMPClauseReader;
1022
1023   /// \brief Build clause with number of variables \a N.
1024   ///
1025   /// \param StartLoc Starting location of the clause.
1026   /// \param LParenLoc Location of '('.
1027   /// \param EndLoc Ending location of the clause.
1028   /// \param N Number of the variables in the clause.
1029   ///
1030   OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1031                         SourceLocation EndLoc, unsigned N)
1032       : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1033                                                 LParenLoc, EndLoc, N) {}
1034
1035   /// \brief Build an empty clause.
1036   ///
1037   /// \param N Number of variables.
1038   ///
1039   explicit OMPFirstprivateClause(unsigned N)
1040       : OMPVarListClause<OMPFirstprivateClause>(
1041             OMPC_firstprivate, SourceLocation(), SourceLocation(),
1042             SourceLocation(), N) {}
1043   /// \brief Sets the list of references to private copies with initializers for
1044   /// new private variables.
1045   /// \param VL List of references.
1046   void setPrivateCopies(ArrayRef<Expr *> VL);
1047
1048   /// \brief Gets the list of references to private copies with initializers for
1049   /// new private variables.
1050   MutableArrayRef<Expr *> getPrivateCopies() {
1051     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1052   }
1053   ArrayRef<const Expr *> getPrivateCopies() const {
1054     return llvm::makeArrayRef(varlist_end(), varlist_size());
1055   }
1056
1057   /// \brief Sets the list of references to initializer variables for new
1058   /// private variables.
1059   /// \param VL List of references.
1060   void setInits(ArrayRef<Expr *> VL);
1061
1062   /// \brief Gets the list of references to initializer variables for new
1063   /// private variables.
1064   MutableArrayRef<Expr *> getInits() {
1065     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1066   }
1067   ArrayRef<const Expr *> getInits() const {
1068     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1069   }
1070
1071 public:
1072   /// \brief Creates clause with a list of variables \a VL.
1073   ///
1074   /// \param C AST context.
1075   /// \param StartLoc Starting location of the clause.
1076   /// \param LParenLoc Location of '('.
1077   /// \param EndLoc Ending location of the clause.
1078   /// \param VL List of references to the original variables.
1079   /// \param PrivateVL List of references to private copies with initializers.
1080   /// \param InitVL List of references to auto generated variables used for
1081   /// initialization of a single array element. Used if firstprivate variable is
1082   /// of array type.
1083   ///
1084   static OMPFirstprivateClause *
1085   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1086          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1087          ArrayRef<Expr *> InitVL);
1088   /// \brief Creates an empty clause with the place for \a N variables.
1089   ///
1090   /// \param C AST context.
1091   /// \param N The number of variables.
1092   ///
1093   static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1094
1095   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1096   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1097   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1098   typedef llvm::iterator_range<private_copies_const_iterator>
1099       private_copies_const_range;
1100
1101   private_copies_range private_copies() {
1102     return private_copies_range(getPrivateCopies().begin(),
1103                                 getPrivateCopies().end());
1104   }
1105   private_copies_const_range private_copies() const {
1106     return private_copies_const_range(getPrivateCopies().begin(),
1107                                       getPrivateCopies().end());
1108   }
1109
1110   typedef MutableArrayRef<Expr *>::iterator inits_iterator;
1111   typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
1112   typedef llvm::iterator_range<inits_iterator> inits_range;
1113   typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
1114
1115   inits_range inits() {
1116     return inits_range(getInits().begin(), getInits().end());
1117   }
1118   inits_const_range inits() const {
1119     return inits_const_range(getInits().begin(), getInits().end());
1120   }
1121
1122   StmtRange children() {
1123     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1124                      reinterpret_cast<Stmt **>(varlist_end()));
1125   }
1126
1127   static bool classof(const OMPClause *T) {
1128     return T->getClauseKind() == OMPC_firstprivate;
1129   }
1130 };
1131
1132 /// \brief This represents clause 'lastprivate' in the '#pragma omp ...'
1133 /// directives.
1134 ///
1135 /// \code
1136 /// #pragma omp simd lastprivate(a,b)
1137 /// \endcode
1138 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1139 /// with the variables 'a' and 'b'.
1140 ///
1141 class OMPLastprivateClause : public OMPVarListClause<OMPLastprivateClause> {
1142   /// \brief Build clause with number of variables \a N.
1143   ///
1144   /// \param StartLoc Starting location of the clause.
1145   /// \param LParenLoc Location of '('.
1146   /// \param EndLoc Ending location of the clause.
1147   /// \param N Number of the variables in the clause.
1148   ///
1149   OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1150                        SourceLocation EndLoc, unsigned N)
1151       : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1152                                                LParenLoc, EndLoc, N) {}
1153
1154   /// \brief Build an empty clause.
1155   ///
1156   /// \param N Number of variables.
1157   ///
1158   explicit OMPLastprivateClause(unsigned N)
1159       : OMPVarListClause<OMPLastprivateClause>(
1160             OMPC_lastprivate, SourceLocation(), SourceLocation(),
1161             SourceLocation(), N) {}
1162
1163 public:
1164   /// \brief Creates clause with a list of variables \a VL.
1165   ///
1166   /// \param C AST context.
1167   /// \param StartLoc Starting location of the clause.
1168   /// \param LParenLoc Location of '('.
1169   /// \param EndLoc Ending location of the clause.
1170   /// \param VL List of references to the variables.
1171   ///
1172   static OMPLastprivateClause *
1173   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1174          SourceLocation EndLoc, ArrayRef<Expr *> VL);
1175   /// \brief Creates an empty clause with the place for \a N variables.
1176   ///
1177   /// \param C AST context.
1178   /// \param N The number of variables.
1179   ///
1180   static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1181
1182   StmtRange children() {
1183     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1184                      reinterpret_cast<Stmt **>(varlist_end()));
1185   }
1186
1187   static bool classof(const OMPClause *T) {
1188     return T->getClauseKind() == OMPC_lastprivate;
1189   }
1190 };
1191
1192 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
1193 ///
1194 /// \code
1195 /// #pragma omp parallel shared(a,b)
1196 /// \endcode
1197 /// In this example directive '#pragma omp parallel' has clause 'shared'
1198 /// with the variables 'a' and 'b'.
1199 ///
1200 class OMPSharedClause : public OMPVarListClause<OMPSharedClause> {
1201   /// \brief Build clause with number of variables \a N.
1202   ///
1203   /// \param StartLoc Starting location of the clause.
1204   /// \param LParenLoc Location of '('.
1205   /// \param EndLoc Ending location of the clause.
1206   /// \param N Number of the variables in the clause.
1207   ///
1208   OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1209                   SourceLocation EndLoc, unsigned N)
1210       : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1211                                           EndLoc, N) {}
1212
1213   /// \brief Build an empty clause.
1214   ///
1215   /// \param N Number of variables.
1216   ///
1217   explicit OMPSharedClause(unsigned N)
1218       : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
1219                                           SourceLocation(), SourceLocation(),
1220                                           N) {}
1221
1222 public:
1223   /// \brief Creates clause with a list of variables \a VL.
1224   ///
1225   /// \param C AST context.
1226   /// \param StartLoc Starting location of the clause.
1227   /// \param LParenLoc Location of '('.
1228   /// \param EndLoc Ending location of the clause.
1229   /// \param VL List of references to the variables.
1230   ///
1231   static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1232                                  SourceLocation LParenLoc,
1233                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
1234   /// \brief Creates an empty clause with \a N variables.
1235   ///
1236   /// \param C AST context.
1237   /// \param N The number of variables.
1238   ///
1239   static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1240
1241   StmtRange children() {
1242     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1243                      reinterpret_cast<Stmt **>(varlist_end()));
1244   }
1245
1246   static bool classof(const OMPClause *T) {
1247     return T->getClauseKind() == OMPC_shared;
1248   }
1249 };
1250
1251 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
1252 /// directives.
1253 ///
1254 /// \code
1255 /// #pragma omp parallel reduction(+:a,b)
1256 /// \endcode
1257 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1258 /// with operator '+' and the variables 'a' and 'b'.
1259 ///
1260 class OMPReductionClause : public OMPVarListClause<OMPReductionClause> {
1261   friend class OMPClauseReader;
1262   /// \brief Location of ':'.
1263   SourceLocation ColonLoc;
1264   /// \brief Nested name specifier for C++.
1265   NestedNameSpecifierLoc QualifierLoc;
1266   /// \brief Name of custom operator.
1267   DeclarationNameInfo NameInfo;
1268
1269   /// \brief Build clause with number of variables \a N.
1270   ///
1271   /// \param StartLoc Starting location of the clause.
1272   /// \param LParenLoc Location of '('.
1273   /// \param EndLoc Ending location of the clause.
1274   /// \param ColonLoc Location of ':'.
1275   /// \param N Number of the variables in the clause.
1276   /// \param QualifierLoc The nested-name qualifier with location information
1277   /// \param NameInfo The full name info for reduction identifier.
1278   ///
1279   OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1280                      SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1281                      NestedNameSpecifierLoc QualifierLoc,
1282                      const DeclarationNameInfo &NameInfo)
1283       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1284                                              LParenLoc, EndLoc, N),
1285         ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1286
1287   /// \brief Build an empty clause.
1288   ///
1289   /// \param N Number of variables.
1290   ///
1291   explicit OMPReductionClause(unsigned N)
1292       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1293                                              SourceLocation(), SourceLocation(),
1294                                              N),
1295         ColonLoc(), QualifierLoc(), NameInfo() {}
1296
1297   /// \brief Sets location of ':' symbol in clause.
1298   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1299   /// \brief Sets the name info for specified reduction identifier.
1300   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1301   /// \brief Sets the nested name specifier.
1302   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1303
1304 public:
1305   /// \brief Creates clause with a list of variables \a VL.
1306   ///
1307   /// \param StartLoc Starting location of the clause.
1308   /// \param LParenLoc Location of '('.
1309   /// \param ColonLoc Location of ':'.
1310   /// \param EndLoc Ending location of the clause.
1311   /// \param VL The variables in the clause.
1312   /// \param QualifierLoc The nested-name qualifier with location information
1313   /// \param NameInfo The full name info for reduction identifier.
1314   ///
1315   static OMPReductionClause *
1316   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1317          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1318          NestedNameSpecifierLoc QualifierLoc,
1319          const DeclarationNameInfo &NameInfo);
1320   /// \brief Creates an empty clause with the place for \a N variables.
1321   ///
1322   /// \param C AST context.
1323   /// \param N The number of variables.
1324   ///
1325   static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1326
1327   /// \brief Gets location of ':' symbol in clause.
1328   SourceLocation getColonLoc() const { return ColonLoc; }
1329   /// \brief Gets the name info for specified reduction identifier.
1330   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1331   /// \brief Gets the nested name specifier.
1332   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1333
1334   StmtRange children() {
1335     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1336                      reinterpret_cast<Stmt **>(varlist_end()));
1337   }
1338
1339   static bool classof(const OMPClause *T) {
1340     return T->getClauseKind() == OMPC_reduction;
1341   }
1342 };
1343
1344 /// \brief This represents clause 'linear' in the '#pragma omp ...'
1345 /// directives.
1346 ///
1347 /// \code
1348 /// #pragma omp simd linear(a,b : 2)
1349 /// \endcode
1350 /// In this example directive '#pragma omp simd' has clause 'linear'
1351 /// with variables 'a', 'b' and linear step '2'.
1352 ///
1353 class OMPLinearClause : public OMPVarListClause<OMPLinearClause> {
1354   friend class OMPClauseReader;
1355   /// \brief Location of ':'.
1356   SourceLocation ColonLoc;
1357
1358   /// \brief Sets the linear step for clause.
1359   void setStep(Expr *Step) { *varlist_end() = Step; }
1360
1361   /// \brief Build 'linear' clause with given number of variables \a NumVars.
1362   ///
1363   /// \param StartLoc Starting location of the clause.
1364   /// \param LParenLoc Location of '('.
1365   /// \param ColonLoc Location of ':'.
1366   /// \param EndLoc Ending location of the clause.
1367   /// \param NumVars Number of variables.
1368   ///
1369   OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1370                   SourceLocation ColonLoc, SourceLocation EndLoc,
1371                   unsigned NumVars)
1372       : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
1373                                           EndLoc, NumVars),
1374         ColonLoc(ColonLoc) {}
1375
1376   /// \brief Build an empty clause.
1377   ///
1378   /// \param NumVars Number of variables.
1379   ///
1380   explicit OMPLinearClause(unsigned NumVars)
1381       : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
1382                                           SourceLocation(), SourceLocation(),
1383                                           NumVars),
1384         ColonLoc(SourceLocation()) {}
1385
1386 public:
1387   /// \brief Creates clause with a list of variables \a VL and a linear step
1388   /// \a Step.
1389   ///
1390   /// \param C AST Context.
1391   /// \param StartLoc Starting location of the clause.
1392   /// \param LParenLoc Location of '('.
1393   /// \param ColonLoc Location of ':'.
1394   /// \param EndLoc Ending location of the clause.
1395   /// \param VL List of references to the variables.
1396   /// \param Step Linear step.
1397   static OMPLinearClause *Create(const ASTContext &C, SourceLocation StartLoc,
1398                                  SourceLocation LParenLoc,
1399                                  SourceLocation ColonLoc, SourceLocation EndLoc,
1400                                  ArrayRef<Expr *> VL, Expr *Step);
1401
1402   /// \brief Creates an empty clause with the place for \a NumVars variables.
1403   ///
1404   /// \param C AST context.
1405   /// \param NumVars Number of variables.
1406   ///
1407   static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1408
1409   /// \brief Sets the location of ':'.
1410   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1411   /// \brief Returns the location of '('.
1412   SourceLocation getColonLoc() const { return ColonLoc; }
1413
1414   /// \brief Returns linear step.
1415   Expr *getStep() { return *varlist_end(); }
1416   /// \brief Returns linear step.
1417   const Expr *getStep() const { return *varlist_end(); }
1418
1419   StmtRange children() {
1420     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1421                      reinterpret_cast<Stmt **>(varlist_end() + 1));
1422   }
1423
1424   static bool classof(const OMPClause *T) {
1425     return T->getClauseKind() == OMPC_linear;
1426   }
1427 };
1428
1429 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
1430 /// directives.
1431 ///
1432 /// \code
1433 /// #pragma omp simd aligned(a,b : 8)
1434 /// \endcode
1435 /// In this example directive '#pragma omp simd' has clause 'aligned'
1436 /// with variables 'a', 'b' and alignment '8'.
1437 ///
1438 class OMPAlignedClause : public OMPVarListClause<OMPAlignedClause> {
1439   friend class OMPClauseReader;
1440   /// \brief Location of ':'.
1441   SourceLocation ColonLoc;
1442
1443   /// \brief Sets the alignment for clause.
1444   void setAlignment(Expr *A) { *varlist_end() = A; }
1445
1446   /// \brief Build 'aligned' clause with given number of variables \a NumVars.
1447   ///
1448   /// \param StartLoc Starting location of the clause.
1449   /// \param LParenLoc Location of '('.
1450   /// \param ColonLoc Location of ':'.
1451   /// \param EndLoc Ending location of the clause.
1452   /// \param NumVars Number of variables.
1453   ///
1454   OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1455                    SourceLocation ColonLoc, SourceLocation EndLoc,
1456                    unsigned NumVars)
1457       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
1458                                            EndLoc, NumVars),
1459         ColonLoc(ColonLoc) {}
1460
1461   /// \brief Build an empty clause.
1462   ///
1463   /// \param NumVars Number of variables.
1464   ///
1465   explicit OMPAlignedClause(unsigned NumVars)
1466       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
1467                                            SourceLocation(), SourceLocation(),
1468                                            NumVars),
1469         ColonLoc(SourceLocation()) {}
1470
1471 public:
1472   /// \brief Creates clause with a list of variables \a VL and alignment \a A.
1473   ///
1474   /// \param C AST Context.
1475   /// \param StartLoc Starting location of the clause.
1476   /// \param LParenLoc Location of '('.
1477   /// \param ColonLoc Location of ':'.
1478   /// \param EndLoc Ending location of the clause.
1479   /// \param VL List of references to the variables.
1480   /// \param A Alignment.
1481   static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1482                                   SourceLocation LParenLoc,
1483                                   SourceLocation ColonLoc,
1484                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
1485                                   Expr *A);
1486
1487   /// \brief Creates an empty clause with the place for \a NumVars variables.
1488   ///
1489   /// \param C AST context.
1490   /// \param NumVars Number of variables.
1491   ///
1492   static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1493
1494   /// \brief Sets the location of ':'.
1495   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1496   /// \brief Returns the location of ':'.
1497   SourceLocation getColonLoc() const { return ColonLoc; }
1498
1499   /// \brief Returns alignment.
1500   Expr *getAlignment() { return *varlist_end(); }
1501   /// \brief Returns alignment.
1502   const Expr *getAlignment() const { return *varlist_end(); }
1503
1504   StmtRange children() {
1505     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1506                      reinterpret_cast<Stmt **>(varlist_end() + 1));
1507   }
1508
1509   static bool classof(const OMPClause *T) {
1510     return T->getClauseKind() == OMPC_aligned;
1511   }
1512 };
1513
1514 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
1515 ///
1516 /// \code
1517 /// #pragma omp parallel copyin(a,b)
1518 /// \endcode
1519 /// In this example directive '#pragma omp parallel' has clause 'copyin'
1520 /// with the variables 'a' and 'b'.
1521 ///
1522 class OMPCopyinClause : public OMPVarListClause<OMPCopyinClause> {
1523   /// \brief Build clause with number of variables \a N.
1524   ///
1525   /// \param StartLoc Starting location of the clause.
1526   /// \param LParenLoc Location of '('.
1527   /// \param EndLoc Ending location of the clause.
1528   /// \param N Number of the variables in the clause.
1529   ///
1530   OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1531                   SourceLocation EndLoc, unsigned N)
1532       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
1533                                           EndLoc, N) {}
1534
1535   /// \brief Build an empty clause.
1536   ///
1537   /// \param N Number of variables.
1538   ///
1539   explicit OMPCopyinClause(unsigned N)
1540       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
1541                                           SourceLocation(), SourceLocation(),
1542                                           N) {}
1543
1544 public:
1545   /// \brief Creates clause with a list of variables \a VL.
1546   ///
1547   /// \param C AST context.
1548   /// \param StartLoc Starting location of the clause.
1549   /// \param LParenLoc Location of '('.
1550   /// \param EndLoc Ending location of the clause.
1551   /// \param VL List of references to the variables.
1552   ///
1553   static OMPCopyinClause *Create(const ASTContext &C, SourceLocation StartLoc,
1554                                  SourceLocation LParenLoc,
1555                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
1556   /// \brief Creates an empty clause with \a N variables.
1557   ///
1558   /// \param C AST context.
1559   /// \param N The number of variables.
1560   ///
1561   static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
1562
1563   StmtRange children() {
1564     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1565                      reinterpret_cast<Stmt **>(varlist_end()));
1566   }
1567
1568   static bool classof(const OMPClause *T) {
1569     return T->getClauseKind() == OMPC_copyin;
1570   }
1571 };
1572
1573 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
1574 /// directives.
1575 ///
1576 /// \code
1577 /// #pragma omp single copyprivate(a,b)
1578 /// \endcode
1579 /// In this example directive '#pragma omp single' has clause 'copyprivate'
1580 /// with the variables 'a' and 'b'.
1581 ///
1582 class OMPCopyprivateClause : public OMPVarListClause<OMPCopyprivateClause> {
1583   /// \brief Build clause with number of variables \a N.
1584   ///
1585   /// \param StartLoc Starting location of the clause.
1586   /// \param LParenLoc Location of '('.
1587   /// \param EndLoc Ending location of the clause.
1588   /// \param N Number of the variables in the clause.
1589   ///
1590   OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1591                        SourceLocation EndLoc, unsigned N)
1592       : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
1593                                                LParenLoc, EndLoc, N) {}
1594
1595   /// \brief Build an empty clause.
1596   ///
1597   /// \param N Number of variables.
1598   ///
1599   explicit OMPCopyprivateClause(unsigned N)
1600       : OMPVarListClause<OMPCopyprivateClause>(
1601             OMPC_copyprivate, SourceLocation(), SourceLocation(),
1602             SourceLocation(), N) {}
1603
1604 public:
1605   /// \brief Creates clause with a list of variables \a VL.
1606   ///
1607   /// \param C AST context.
1608   /// \param StartLoc Starting location of the clause.
1609   /// \param LParenLoc Location of '('.
1610   /// \param EndLoc Ending location of the clause.
1611   /// \param VL List of references to the variables.
1612   ///
1613   static OMPCopyprivateClause *
1614   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1615          SourceLocation EndLoc, ArrayRef<Expr *> VL);
1616   /// \brief Creates an empty clause with \a N variables.
1617   ///
1618   /// \param C AST context.
1619   /// \param N The number of variables.
1620   ///
1621   static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1622
1623   StmtRange children() {
1624     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1625                      reinterpret_cast<Stmt **>(varlist_end()));
1626   }
1627
1628   static bool classof(const OMPClause *T) {
1629     return T->getClauseKind() == OMPC_copyprivate;
1630   }
1631 };
1632
1633 /// \brief This represents implicit clause 'flush' for the '#pragma omp flush'
1634 /// directive.
1635 /// This clause does not exist by itself, it can be only as a part of 'omp
1636 /// flush' directive. This clause is introduced to keep the original structure
1637 /// of \a OMPExecutableDirective class and its derivatives and to use the
1638 /// existing infrastructure of clauses with the list of variables.
1639 ///
1640 /// \code
1641 /// #pragma omp flush(a,b)
1642 /// \endcode
1643 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
1644 /// with the variables 'a' and 'b'.
1645 ///
1646 class OMPFlushClause : public OMPVarListClause<OMPFlushClause> {
1647   /// \brief Build clause with number of variables \a N.
1648   ///
1649   /// \param StartLoc Starting location of the clause.
1650   /// \param LParenLoc Location of '('.
1651   /// \param EndLoc Ending location of the clause.
1652   /// \param N Number of the variables in the clause.
1653   ///
1654   OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1655                  SourceLocation EndLoc, unsigned N)
1656       : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
1657                                          EndLoc, N) {}
1658
1659   /// \brief Build an empty clause.
1660   ///
1661   /// \param N Number of variables.
1662   ///
1663   explicit OMPFlushClause(unsigned N)
1664       : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
1665                                          SourceLocation(), SourceLocation(),
1666                                          N) {}
1667
1668 public:
1669   /// \brief Creates clause with a list of variables \a VL.
1670   ///
1671   /// \param C AST context.
1672   /// \param StartLoc Starting location of the clause.
1673   /// \param LParenLoc Location of '('.
1674   /// \param EndLoc Ending location of the clause.
1675   /// \param VL List of references to the variables.
1676   ///
1677   static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
1678                                 SourceLocation LParenLoc, SourceLocation EndLoc,
1679                                 ArrayRef<Expr *> VL);
1680   /// \brief Creates an empty clause with \a N variables.
1681   ///
1682   /// \param C AST context.
1683   /// \param N The number of variables.
1684   ///
1685   static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
1686
1687   StmtRange children() {
1688     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1689                      reinterpret_cast<Stmt **>(varlist_end()));
1690   }
1691
1692   static bool classof(const OMPClause *T) {
1693     return T->getClauseKind() == OMPC_flush;
1694   }
1695 };
1696
1697 } // end namespace clang
1698
1699 #endif
1700