]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/StmtOpenMP.h
Merge ^/head r274961 through r276342.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / StmtOpenMP.h
1 //===- StmtOpenMP.h - Classes for OpenMP directives  ------------*- 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 executable directives and
11 /// clauses.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_AST_STMTOPENMP_H
16 #define LLVM_CLANG_AST_STMTOPENMP_H
17
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/OpenMPClause.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 directives.
28 //===----------------------------------------------------------------------===//
29
30 /// \brief This is a basic class for representing single OpenMP executable
31 /// directive.
32 ///
33 class OMPExecutableDirective : public Stmt {
34   friend class ASTStmtReader;
35   /// \brief Kind of the directive.
36   OpenMPDirectiveKind Kind;
37   /// \brief Starting location of the directive (directive keyword).
38   SourceLocation StartLoc;
39   /// \brief Ending location of the directive.
40   SourceLocation EndLoc;
41   /// \brief Numbers of clauses.
42   const unsigned NumClauses;
43   /// \brief Number of child expressions/stmts.
44   const unsigned NumChildren;
45   /// \brief Offset from this to the start of clauses.
46   /// There are NumClauses pointers to clauses, they are followed by
47   /// NumChildren pointers to child stmts/exprs (if the directive type
48   /// requires an associated stmt, then it has to be the first of them).
49   const unsigned ClausesOffset;
50
51   /// \brief Get the clauses storage.
52   MutableArrayRef<OMPClause *> getClauses() {
53     OMPClause **ClauseStorage = reinterpret_cast<OMPClause **>(
54         reinterpret_cast<char *>(this) + ClausesOffset);
55     return MutableArrayRef<OMPClause *>(ClauseStorage, NumClauses);
56   }
57
58 protected:
59   /// \brief Build instance of directive of class \a K.
60   ///
61   /// \param SC Statement class.
62   /// \param K Kind of OpenMP directive.
63   /// \param StartLoc Starting location of the directive (directive keyword).
64   /// \param EndLoc Ending location of the directive.
65   ///
66   template <typename T>
67   OMPExecutableDirective(const T *, StmtClass SC, OpenMPDirectiveKind K,
68                          SourceLocation StartLoc, SourceLocation EndLoc,
69                          unsigned NumClauses, unsigned NumChildren)
70       : Stmt(SC), Kind(K), StartLoc(std::move(StartLoc)),
71         EndLoc(std::move(EndLoc)), NumClauses(NumClauses),
72         NumChildren(NumChildren),
73         ClausesOffset(llvm::RoundUpToAlignment(sizeof(T),
74                                                llvm::alignOf<OMPClause *>())) {}
75
76   /// \brief Sets the list of variables for this clause.
77   ///
78   /// \param Clauses The list of clauses for the directive.
79   ///
80   void setClauses(ArrayRef<OMPClause *> Clauses);
81
82   /// \brief Set the associated statement for the directive.
83   ///
84   /// /param S Associated statement.
85   ///
86   void setAssociatedStmt(Stmt *S) {
87     assert(hasAssociatedStmt() && "no associated statement.");
88     *child_begin() = S;
89   }
90
91 public:
92   /// \brief Iterates over a filtered subrange of clauses applied to a
93   /// directive.
94   ///
95   /// This iterator visits only those declarations that meet some run-time
96   /// criteria.
97   template <class FilterPredicate> class filtered_clause_iterator {
98     ArrayRef<OMPClause *>::const_iterator Current;
99     ArrayRef<OMPClause *>::const_iterator End;
100     FilterPredicate Pred;
101     void SkipToNextClause() {
102       while (Current != End && !Pred(*Current))
103         ++Current;
104     }
105
106   public:
107     typedef const OMPClause *value_type;
108     filtered_clause_iterator() : Current(), End() {}
109     filtered_clause_iterator(ArrayRef<OMPClause *> Arr, FilterPredicate Pred)
110         : Current(Arr.begin()), End(Arr.end()), Pred(Pred) {
111       SkipToNextClause();
112     }
113     value_type operator*() const { return *Current; }
114     value_type operator->() const { return *Current; }
115     filtered_clause_iterator &operator++() {
116       ++Current;
117       SkipToNextClause();
118       return *this;
119     }
120
121     filtered_clause_iterator operator++(int) {
122       filtered_clause_iterator tmp(*this);
123       ++(*this);
124       return tmp;
125     }
126
127     bool operator!() { return Current == End; }
128     operator bool() { return Current != End; }
129   };
130
131   /// \brief Returns starting location of directive kind.
132   SourceLocation getLocStart() const { return StartLoc; }
133   /// \brief Returns ending location of directive.
134   SourceLocation getLocEnd() const { return EndLoc; }
135
136   /// \brief Set starting location of directive kind.
137   ///
138   /// \param Loc New starting location of directive.
139   ///
140   void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
141   /// \brief Set ending location of directive.
142   ///
143   /// \param Loc New ending location of directive.
144   ///
145   void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
146
147   /// \brief Get number of clauses.
148   unsigned getNumClauses() const { return NumClauses; }
149
150   /// \brief Returns specified clause.
151   ///
152   /// \param i Number of clause.
153   ///
154   OMPClause *getClause(unsigned i) const { return clauses()[i]; }
155
156   /// \brief Returns true if directive has associated statement.
157   bool hasAssociatedStmt() const { return NumChildren > 0; }
158
159   /// \brief Returns statement associated with the directive.
160   Stmt *getAssociatedStmt() const {
161     assert(hasAssociatedStmt() && "no associated statement.");
162     return const_cast<Stmt *>(*child_begin());
163   }
164
165   OpenMPDirectiveKind getDirectiveKind() const { return Kind; }
166
167   static bool classof(const Stmt *S) {
168     return S->getStmtClass() >= firstOMPExecutableDirectiveConstant &&
169            S->getStmtClass() <= lastOMPExecutableDirectiveConstant;
170   }
171
172   child_range children() {
173     if (!hasAssociatedStmt())
174       return child_range();
175     Stmt **ChildStorage = reinterpret_cast<Stmt **>(getClauses().end());
176     return child_range(ChildStorage, ChildStorage + NumChildren);
177   }
178
179   ArrayRef<OMPClause *> clauses() { return getClauses(); }
180
181   ArrayRef<OMPClause *> clauses() const {
182     return const_cast<OMPExecutableDirective *>(this)->getClauses();
183   }
184 };
185
186 /// \brief This represents '#pragma omp parallel' directive.
187 ///
188 /// \code
189 /// #pragma omp parallel private(a,b) reduction(+: c,d)
190 /// \endcode
191 /// In this example directive '#pragma omp parallel' has clauses 'private'
192 /// with the variables 'a' and 'b' and 'reduction' with operator '+' and
193 /// variables 'c' and 'd'.
194 ///
195 class OMPParallelDirective : public OMPExecutableDirective {
196   /// \brief Build directive with the given start and end location.
197   ///
198   /// \param StartLoc Starting location of the directive (directive keyword).
199   /// \param EndLoc Ending Location of the directive.
200   ///
201   OMPParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc,
202                        unsigned NumClauses)
203       : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
204                                StartLoc, EndLoc, NumClauses, 1) {}
205
206   /// \brief Build an empty directive.
207   ///
208   /// \param NumClauses Number of clauses.
209   ///
210   explicit OMPParallelDirective(unsigned NumClauses)
211       : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
212                                SourceLocation(), SourceLocation(), NumClauses,
213                                1) {}
214
215 public:
216   /// \brief Creates directive with a list of \a Clauses.
217   ///
218   /// \param C AST context.
219   /// \param StartLoc Starting location of the directive kind.
220   /// \param EndLoc Ending Location of the directive.
221   /// \param Clauses List of clauses.
222   /// \param AssociatedStmt Statement associated with the directive.
223   ///
224   static OMPParallelDirective *
225   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
226          ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
227
228   /// \brief Creates an empty directive with the place for \a N clauses.
229   ///
230   /// \param C AST context.
231   /// \param NumClauses Number of clauses.
232   ///
233   static OMPParallelDirective *CreateEmpty(const ASTContext &C,
234                                            unsigned NumClauses, EmptyShell);
235
236   static bool classof(const Stmt *T) {
237     return T->getStmtClass() == OMPParallelDirectiveClass;
238   }
239 };
240
241 /// \brief This represents '#pragma omp simd' directive.
242 ///
243 /// \code
244 /// #pragma omp simd private(a,b) linear(i,j:s) reduction(+:c,d)
245 /// \endcode
246 /// In this example directive '#pragma omp simd' has clauses 'private'
247 /// with the variables 'a' and 'b', 'linear' with variables 'i', 'j' and
248 /// linear step 's', 'reduction' with operator '+' and variables 'c' and 'd'.
249 ///
250 class OMPSimdDirective : public OMPExecutableDirective {
251   friend class ASTStmtReader;
252   /// \brief Number of collapsed loops as specified by 'collapse' clause.
253   unsigned CollapsedNum;
254   /// \brief Build directive with the given start and end location.
255   ///
256   /// \param StartLoc Starting location of the directive kind.
257   /// \param EndLoc Ending location of the directive.
258   /// \param CollapsedNum Number of collapsed nested loops.
259   /// \param NumClauses Number of clauses.
260   ///
261   OMPSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
262                    unsigned CollapsedNum, unsigned NumClauses)
263       : OMPExecutableDirective(this, OMPSimdDirectiveClass, OMPD_simd, StartLoc,
264                                EndLoc, NumClauses, 1),
265         CollapsedNum(CollapsedNum) {}
266
267   /// \brief Build an empty directive.
268   ///
269   /// \param CollapsedNum Number of collapsed nested loops.
270   /// \param NumClauses Number of clauses.
271   ///
272   explicit OMPSimdDirective(unsigned CollapsedNum, unsigned NumClauses)
273       : OMPExecutableDirective(this, OMPSimdDirectiveClass, OMPD_simd,
274                                SourceLocation(), SourceLocation(), NumClauses,
275                                1),
276         CollapsedNum(CollapsedNum) {}
277
278 public:
279   /// \brief Creates directive with a list of \a Clauses.
280   ///
281   /// \param C AST context.
282   /// \param StartLoc Starting location of the directive kind.
283   /// \param EndLoc Ending Location of the directive.
284   /// \param CollapsedNum Number of collapsed loops.
285   /// \param Clauses List of clauses.
286   /// \param AssociatedStmt Statement, associated with the directive.
287   ///
288   static OMPSimdDirective *Create(const ASTContext &C, SourceLocation StartLoc,
289                                   SourceLocation EndLoc, unsigned CollapsedNum,
290                                   ArrayRef<OMPClause *> Clauses,
291                                   Stmt *AssociatedStmt);
292
293   /// \brief Creates an empty directive with the place
294   /// for \a NumClauses clauses.
295   ///
296   /// \param C AST context.
297   /// \param CollapsedNum Number of collapsed nested loops.
298   /// \param NumClauses Number of clauses.
299   ///
300   static OMPSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
301                                        unsigned CollapsedNum, EmptyShell);
302
303   unsigned getCollapsedNumber() const { return CollapsedNum; }
304
305   static bool classof(const Stmt *T) {
306     return T->getStmtClass() == OMPSimdDirectiveClass;
307   }
308 };
309
310 /// \brief This represents '#pragma omp for' directive.
311 ///
312 /// \code
313 /// #pragma omp for private(a,b) reduction(+:c,d)
314 /// \endcode
315 /// In this example directive '#pragma omp for' has clauses 'private' with the
316 /// variables 'a' and 'b' and 'reduction' with operator '+' and variables 'c'
317 /// and 'd'.
318 ///
319 class OMPForDirective : public OMPExecutableDirective {
320   friend class ASTStmtReader;
321   /// \brief Number of collapsed loops as specified by 'collapse' clause.
322   unsigned CollapsedNum;
323   /// \brief Build directive with the given start and end location.
324   ///
325   /// \param StartLoc Starting location of the directive kind.
326   /// \param EndLoc Ending location of the directive.
327   /// \param CollapsedNum Number of collapsed nested loops.
328   /// \param NumClauses Number of clauses.
329   ///
330   OMPForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
331                   unsigned CollapsedNum, unsigned NumClauses)
332       : OMPExecutableDirective(this, OMPForDirectiveClass, OMPD_for, StartLoc,
333                                EndLoc, NumClauses, 1),
334         CollapsedNum(CollapsedNum) {}
335
336   /// \brief Build an empty directive.
337   ///
338   /// \param CollapsedNum Number of collapsed nested loops.
339   /// \param NumClauses Number of clauses.
340   ///
341   explicit OMPForDirective(unsigned CollapsedNum, unsigned NumClauses)
342       : OMPExecutableDirective(this, OMPForDirectiveClass, OMPD_for,
343                                SourceLocation(), SourceLocation(), NumClauses,
344                                1),
345         CollapsedNum(CollapsedNum) {}
346
347 public:
348   /// \brief Creates directive with a list of \a Clauses.
349   ///
350   /// \param C AST context.
351   /// \param StartLoc Starting location of the directive kind.
352   /// \param EndLoc Ending Location of the directive.
353   /// \param CollapsedNum Number of collapsed loops.
354   /// \param Clauses List of clauses.
355   /// \param AssociatedStmt Statement, associated with the directive.
356   ///
357   static OMPForDirective *Create(const ASTContext &C, SourceLocation StartLoc,
358                                  SourceLocation EndLoc, unsigned CollapsedNum,
359                                  ArrayRef<OMPClause *> Clauses,
360                                  Stmt *AssociatedStmt);
361
362   /// \brief Creates an empty directive with the place
363   /// for \a NumClauses clauses.
364   ///
365   /// \param C AST context.
366   /// \param CollapsedNum Number of collapsed nested loops.
367   /// \param NumClauses Number of clauses.
368   ///
369   static OMPForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
370                                       unsigned CollapsedNum, EmptyShell);
371
372   unsigned getCollapsedNumber() const { return CollapsedNum; }
373
374   static bool classof(const Stmt *T) {
375     return T->getStmtClass() == OMPForDirectiveClass;
376   }
377 };
378
379 /// \brief This represents '#pragma omp sections' directive.
380 ///
381 /// \code
382 /// #pragma omp sections private(a,b) reduction(+:c,d)
383 /// \endcode
384 /// In this example directive '#pragma omp sections' has clauses 'private' with
385 /// the variables 'a' and 'b' and 'reduction' with operator '+' and variables
386 /// 'c' and 'd'.
387 ///
388 class OMPSectionsDirective : public OMPExecutableDirective {
389   friend class ASTStmtReader;
390   /// \brief Build directive with the given start and end location.
391   ///
392   /// \param StartLoc Starting location of the directive kind.
393   /// \param EndLoc Ending location of the directive.
394   /// \param NumClauses Number of clauses.
395   ///
396   OMPSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc,
397                        unsigned NumClauses)
398       : OMPExecutableDirective(this, OMPSectionsDirectiveClass, OMPD_sections,
399                                StartLoc, EndLoc, NumClauses, 1) {}
400
401   /// \brief Build an empty directive.
402   ///
403   /// \param NumClauses Number of clauses.
404   ///
405   explicit OMPSectionsDirective(unsigned NumClauses)
406       : OMPExecutableDirective(this, OMPSectionsDirectiveClass, OMPD_sections,
407                                SourceLocation(), SourceLocation(), NumClauses,
408                                1) {}
409
410 public:
411   /// \brief Creates directive with a list of \a Clauses.
412   ///
413   /// \param C AST context.
414   /// \param StartLoc Starting location of the directive kind.
415   /// \param EndLoc Ending Location of the directive.
416   /// \param Clauses List of clauses.
417   /// \param AssociatedStmt Statement, associated with the directive.
418   ///
419   static OMPSectionsDirective *
420   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
421          ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
422
423   /// \brief Creates an empty directive with the place for \a NumClauses
424   /// clauses.
425   ///
426   /// \param C AST context.
427   /// \param NumClauses Number of clauses.
428   ///
429   static OMPSectionsDirective *CreateEmpty(const ASTContext &C,
430                                            unsigned NumClauses, EmptyShell);
431
432   static bool classof(const Stmt *T) {
433     return T->getStmtClass() == OMPSectionsDirectiveClass;
434   }
435 };
436
437 /// \brief This represents '#pragma omp section' directive.
438 ///
439 /// \code
440 /// #pragma omp section
441 /// \endcode
442 ///
443 class OMPSectionDirective : public OMPExecutableDirective {
444   friend class ASTStmtReader;
445   /// \brief Build directive with the given start and end location.
446   ///
447   /// \param StartLoc Starting location of the directive kind.
448   /// \param EndLoc Ending location of the directive.
449   ///
450   OMPSectionDirective(SourceLocation StartLoc, SourceLocation EndLoc)
451       : OMPExecutableDirective(this, OMPSectionDirectiveClass, OMPD_section,
452                                StartLoc, EndLoc, 0, 1) {}
453
454   /// \brief Build an empty directive.
455   ///
456   explicit OMPSectionDirective()
457       : OMPExecutableDirective(this, OMPSectionDirectiveClass, OMPD_section,
458                                SourceLocation(), SourceLocation(), 0, 1) {}
459
460 public:
461   /// \brief Creates directive.
462   ///
463   /// \param C AST context.
464   /// \param StartLoc Starting location of the directive kind.
465   /// \param EndLoc Ending Location of the directive.
466   /// \param AssociatedStmt Statement, associated with the directive.
467   ///
468   static OMPSectionDirective *Create(const ASTContext &C,
469                                      SourceLocation StartLoc,
470                                      SourceLocation EndLoc,
471                                      Stmt *AssociatedStmt);
472
473   /// \brief Creates an empty directive.
474   ///
475   /// \param C AST context.
476   ///
477   static OMPSectionDirective *CreateEmpty(const ASTContext &C, EmptyShell);
478
479   static bool classof(const Stmt *T) {
480     return T->getStmtClass() == OMPSectionDirectiveClass;
481   }
482 };
483
484 /// \brief This represents '#pragma omp single' directive.
485 ///
486 /// \code
487 /// #pragma omp single private(a,b) copyprivate(c,d)
488 /// \endcode
489 /// In this example directive '#pragma omp single' has clauses 'private' with
490 /// the variables 'a' and 'b' and 'copyprivate' with variables 'c' and 'd'.
491 ///
492 class OMPSingleDirective : public OMPExecutableDirective {
493   friend class ASTStmtReader;
494   /// \brief Build directive with the given start and end location.
495   ///
496   /// \param StartLoc Starting location of the directive kind.
497   /// \param EndLoc Ending location of the directive.
498   /// \param NumClauses Number of clauses.
499   ///
500   OMPSingleDirective(SourceLocation StartLoc, SourceLocation EndLoc,
501                      unsigned NumClauses)
502       : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single,
503                                StartLoc, EndLoc, NumClauses, 1) {}
504
505   /// \brief Build an empty directive.
506   ///
507   /// \param NumClauses Number of clauses.
508   ///
509   explicit OMPSingleDirective(unsigned NumClauses)
510       : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single,
511                                SourceLocation(), SourceLocation(), NumClauses,
512                                1) {}
513
514 public:
515   /// \brief Creates directive with a list of \a Clauses.
516   ///
517   /// \param C AST context.
518   /// \param StartLoc Starting location of the directive kind.
519   /// \param EndLoc Ending Location of the directive.
520   /// \param Clauses List of clauses.
521   /// \param AssociatedStmt Statement, associated with the directive.
522   ///
523   static OMPSingleDirective *
524   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
525          ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
526
527   /// \brief Creates an empty directive with the place for \a NumClauses
528   /// clauses.
529   ///
530   /// \param C AST context.
531   /// \param NumClauses Number of clauses.
532   ///
533   static OMPSingleDirective *CreateEmpty(const ASTContext &C,
534                                          unsigned NumClauses, EmptyShell);
535
536   static bool classof(const Stmt *T) {
537     return T->getStmtClass() == OMPSingleDirectiveClass;
538   }
539 };
540
541 /// \brief This represents '#pragma omp master' directive.
542 ///
543 /// \code
544 /// #pragma omp master
545 /// \endcode
546 ///
547 class OMPMasterDirective : public OMPExecutableDirective {
548   friend class ASTStmtReader;
549   /// \brief Build directive with the given start and end location.
550   ///
551   /// \param StartLoc Starting location of the directive kind.
552   /// \param EndLoc Ending location of the directive.
553   ///
554   OMPMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc)
555       : OMPExecutableDirective(this, OMPMasterDirectiveClass, OMPD_master,
556                                StartLoc, EndLoc, 0, 1) {}
557
558   /// \brief Build an empty directive.
559   ///
560   explicit OMPMasterDirective()
561       : OMPExecutableDirective(this, OMPMasterDirectiveClass, OMPD_master,
562                                SourceLocation(), SourceLocation(), 0, 1) {}
563
564 public:
565   /// \brief Creates directive.
566   ///
567   /// \param C AST context.
568   /// \param StartLoc Starting location of the directive kind.
569   /// \param EndLoc Ending Location of the directive.
570   /// \param AssociatedStmt Statement, associated with the directive.
571   ///
572   static OMPMasterDirective *Create(const ASTContext &C,
573                                     SourceLocation StartLoc,
574                                     SourceLocation EndLoc,
575                                     Stmt *AssociatedStmt);
576
577   /// \brief Creates an empty directive.
578   ///
579   /// \param C AST context.
580   ///
581   static OMPMasterDirective *CreateEmpty(const ASTContext &C, EmptyShell);
582
583   static bool classof(const Stmt *T) {
584     return T->getStmtClass() == OMPMasterDirectiveClass;
585   }
586 };
587
588 /// \brief This represents '#pragma omp critical' directive.
589 ///
590 /// \code
591 /// #pragma omp critical
592 /// \endcode
593 ///
594 class OMPCriticalDirective : public OMPExecutableDirective {
595   friend class ASTStmtReader;
596   /// \brief Name of the directive.
597   DeclarationNameInfo DirName;
598   /// \brief Build directive with the given start and end location.
599   ///
600   /// \param Name Name of the directive.
601   /// \param StartLoc Starting location of the directive kind.
602   /// \param EndLoc Ending location of the directive.
603   ///
604   OMPCriticalDirective(const DeclarationNameInfo &Name, SourceLocation StartLoc,
605                        SourceLocation EndLoc)
606       : OMPExecutableDirective(this, OMPCriticalDirectiveClass, OMPD_critical,
607                                StartLoc, EndLoc, 0, 1),
608         DirName(Name) {}
609
610   /// \brief Build an empty directive.
611   ///
612   explicit OMPCriticalDirective()
613       : OMPExecutableDirective(this, OMPCriticalDirectiveClass, OMPD_critical,
614                                SourceLocation(), SourceLocation(), 0, 1),
615         DirName() {}
616
617   /// \brief Set name of the directive.
618   ///
619   /// \param Name Name of the directive.
620   ///
621   void setDirectiveName(const DeclarationNameInfo &Name) { DirName = Name; }
622
623 public:
624   /// \brief Creates directive.
625   ///
626   /// \param C AST context.
627   /// \param Name Name of the directive.
628   /// \param StartLoc Starting location of the directive kind.
629   /// \param EndLoc Ending Location of the directive.
630   /// \param AssociatedStmt Statement, associated with the directive.
631   ///
632   static OMPCriticalDirective *
633   Create(const ASTContext &C, const DeclarationNameInfo &Name,
634          SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt);
635
636   /// \brief Creates an empty directive.
637   ///
638   /// \param C AST context.
639   ///
640   static OMPCriticalDirective *CreateEmpty(const ASTContext &C, EmptyShell);
641
642   /// \brief Return name of the directive.
643   ///
644   DeclarationNameInfo getDirectiveName() const { return DirName; }
645
646   static bool classof(const Stmt *T) {
647     return T->getStmtClass() == OMPCriticalDirectiveClass;
648   }
649 };
650
651 /// \brief This represents '#pragma omp parallel for' directive.
652 ///
653 /// \code
654 /// #pragma omp parallel for private(a,b) reduction(+:c,d)
655 /// \endcode
656 /// In this example directive '#pragma omp parallel for' has clauses 'private'
657 /// with the variables 'a' and 'b' and 'reduction' with operator '+' and
658 /// variables 'c' and 'd'.
659 ///
660 class OMPParallelForDirective : public OMPExecutableDirective {
661   friend class ASTStmtReader;
662   /// \brief Number of collapsed loops as specified by 'collapse' clause.
663   unsigned CollapsedNum;
664   /// \brief Build directive with the given start and end location.
665   ///
666   /// \param StartLoc Starting location of the directive kind.
667   /// \param EndLoc Ending location of the directive.
668   /// \param CollapsedNum Number of collapsed nested loops.
669   /// \param NumClauses Number of clauses.
670   ///
671   OMPParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
672                           unsigned CollapsedNum, unsigned NumClauses)
673       : OMPExecutableDirective(this, OMPParallelForDirectiveClass,
674                                OMPD_parallel_for, StartLoc, EndLoc, NumClauses,
675                                1),
676         CollapsedNum(CollapsedNum) {}
677
678   /// \brief Build an empty directive.
679   ///
680   /// \param CollapsedNum Number of collapsed nested loops.
681   /// \param NumClauses Number of clauses.
682   ///
683   explicit OMPParallelForDirective(unsigned CollapsedNum, unsigned NumClauses)
684       : OMPExecutableDirective(this, OMPParallelForDirectiveClass,
685                                OMPD_parallel_for, SourceLocation(),
686                                SourceLocation(), NumClauses, 1),
687         CollapsedNum(CollapsedNum) {}
688
689 public:
690   /// \brief Creates directive with a list of \a Clauses.
691   ///
692   /// \param C AST context.
693   /// \param StartLoc Starting location of the directive kind.
694   /// \param EndLoc Ending Location of the directive.
695   /// \param CollapsedNum Number of collapsed loops.
696   /// \param Clauses List of clauses.
697   /// \param AssociatedStmt Statement, associated with the directive.
698   ///
699   static OMPParallelForDirective *
700   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
701          unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
702          Stmt *AssociatedStmt);
703
704   /// \brief Creates an empty directive with the place
705   /// for \a NumClauses clauses.
706   ///
707   /// \param C AST context.
708   /// \param CollapsedNum Number of collapsed nested loops.
709   /// \param NumClauses Number of clauses.
710   ///
711   static OMPParallelForDirective *CreateEmpty(const ASTContext &C,
712                                               unsigned NumClauses,
713                                               unsigned CollapsedNum,
714                                               EmptyShell);
715
716   unsigned getCollapsedNumber() const { return CollapsedNum; }
717
718   static bool classof(const Stmt *T) {
719     return T->getStmtClass() == OMPParallelForDirectiveClass;
720   }
721 };
722
723 /// \brief This represents '#pragma omp parallel sections' directive.
724 ///
725 /// \code
726 /// #pragma omp parallel sections private(a,b) reduction(+:c,d)
727 /// \endcode
728 /// In this example directive '#pragma omp parallel sections' has clauses
729 /// 'private' with the variables 'a' and 'b' and 'reduction' with operator '+'
730 /// and variables 'c' and 'd'.
731 ///
732 class OMPParallelSectionsDirective : public OMPExecutableDirective {
733   friend class ASTStmtReader;
734   /// \brief Build directive with the given start and end location.
735   ///
736   /// \param StartLoc Starting location of the directive kind.
737   /// \param EndLoc Ending location of the directive.
738   /// \param NumClauses Number of clauses.
739   ///
740   OMPParallelSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc,
741                                unsigned NumClauses)
742       : OMPExecutableDirective(this, OMPParallelSectionsDirectiveClass,
743                                OMPD_parallel_sections, StartLoc, EndLoc,
744                                NumClauses, 1) {}
745
746   /// \brief Build an empty directive.
747   ///
748   /// \param NumClauses Number of clauses.
749   ///
750   explicit OMPParallelSectionsDirective(unsigned NumClauses)
751       : OMPExecutableDirective(this, OMPParallelSectionsDirectiveClass,
752                                OMPD_parallel_sections, SourceLocation(),
753                                SourceLocation(), NumClauses, 1) {}
754
755 public:
756   /// \brief Creates directive with a list of \a Clauses.
757   ///
758   /// \param C AST context.
759   /// \param StartLoc Starting location of the directive kind.
760   /// \param EndLoc Ending Location of the directive.
761   /// \param Clauses List of clauses.
762   /// \param AssociatedStmt Statement, associated with the directive.
763   ///
764   static OMPParallelSectionsDirective *
765   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
766          ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
767
768   /// \brief Creates an empty directive with the place for \a NumClauses
769   /// clauses.
770   ///
771   /// \param C AST context.
772   /// \param NumClauses Number of clauses.
773   ///
774   static OMPParallelSectionsDirective *
775   CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell);
776
777   static bool classof(const Stmt *T) {
778     return T->getStmtClass() == OMPParallelSectionsDirectiveClass;
779   }
780 };
781
782 /// \brief This represents '#pragma omp task' directive.
783 ///
784 /// \code
785 /// #pragma omp task private(a,b) final(d)
786 /// \endcode
787 /// In this example directive '#pragma omp task' has clauses 'private' with the
788 /// variables 'a' and 'b' and 'final' with condition 'd'.
789 ///
790 class OMPTaskDirective : public OMPExecutableDirective {
791   friend class ASTStmtReader;
792   /// \brief Build directive with the given start and end location.
793   ///
794   /// \param StartLoc Starting location of the directive kind.
795   /// \param EndLoc Ending location of the directive.
796   /// \param NumClauses Number of clauses.
797   ///
798   OMPTaskDirective(SourceLocation StartLoc, SourceLocation EndLoc,
799                    unsigned NumClauses)
800       : OMPExecutableDirective(this, OMPTaskDirectiveClass, OMPD_task, StartLoc,
801                                EndLoc, NumClauses, 1) {}
802
803   /// \brief Build an empty directive.
804   ///
805   /// \param NumClauses Number of clauses.
806   ///
807   explicit OMPTaskDirective(unsigned NumClauses)
808       : OMPExecutableDirective(this, OMPTaskDirectiveClass, OMPD_task,
809                                SourceLocation(), SourceLocation(), NumClauses,
810                                1) {}
811
812 public:
813   /// \brief Creates directive with a list of \a Clauses.
814   ///
815   /// \param C AST context.
816   /// \param StartLoc Starting location of the directive kind.
817   /// \param EndLoc Ending Location of the directive.
818   /// \param Clauses List of clauses.
819   /// \param AssociatedStmt Statement, associated with the directive.
820   ///
821   static OMPTaskDirective *Create(const ASTContext &C, SourceLocation StartLoc,
822                                   SourceLocation EndLoc,
823                                   ArrayRef<OMPClause *> Clauses,
824                                   Stmt *AssociatedStmt);
825
826   /// \brief Creates an empty directive with the place for \a NumClauses
827   /// clauses.
828   ///
829   /// \param C AST context.
830   /// \param NumClauses Number of clauses.
831   ///
832   static OMPTaskDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
833                                        EmptyShell);
834
835   static bool classof(const Stmt *T) {
836     return T->getStmtClass() == OMPTaskDirectiveClass;
837   }
838 };
839
840 /// \brief This represents '#pragma omp taskyield' directive.
841 ///
842 /// \code
843 /// #pragma omp taskyield
844 /// \endcode
845 ///
846 class OMPTaskyieldDirective : public OMPExecutableDirective {
847   friend class ASTStmtReader;
848   /// \brief Build directive with the given start and end location.
849   ///
850   /// \param StartLoc Starting location of the directive kind.
851   /// \param EndLoc Ending location of the directive.
852   ///
853   OMPTaskyieldDirective(SourceLocation StartLoc, SourceLocation EndLoc)
854       : OMPExecutableDirective(this, OMPTaskyieldDirectiveClass, OMPD_taskyield,
855                                StartLoc, EndLoc, 0, 0) {}
856
857   /// \brief Build an empty directive.
858   ///
859   explicit OMPTaskyieldDirective()
860       : OMPExecutableDirective(this, OMPTaskyieldDirectiveClass, OMPD_taskyield,
861                                SourceLocation(), SourceLocation(), 0, 0) {}
862
863 public:
864   /// \brief Creates directive.
865   ///
866   /// \param C AST context.
867   /// \param StartLoc Starting location of the directive kind.
868   /// \param EndLoc Ending Location of the directive.
869   ///
870   static OMPTaskyieldDirective *
871   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
872
873   /// \brief Creates an empty directive.
874   ///
875   /// \param C AST context.
876   ///
877   static OMPTaskyieldDirective *CreateEmpty(const ASTContext &C, EmptyShell);
878
879   static bool classof(const Stmt *T) {
880     return T->getStmtClass() == OMPTaskyieldDirectiveClass;
881   }
882 };
883
884 /// \brief This represents '#pragma omp barrier' directive.
885 ///
886 /// \code
887 /// #pragma omp barrier
888 /// \endcode
889 ///
890 class OMPBarrierDirective : public OMPExecutableDirective {
891   friend class ASTStmtReader;
892   /// \brief Build directive with the given start and end location.
893   ///
894   /// \param StartLoc Starting location of the directive kind.
895   /// \param EndLoc Ending location of the directive.
896   ///
897   OMPBarrierDirective(SourceLocation StartLoc, SourceLocation EndLoc)
898       : OMPExecutableDirective(this, OMPBarrierDirectiveClass, OMPD_barrier,
899                                StartLoc, EndLoc, 0, 0) {}
900
901   /// \brief Build an empty directive.
902   ///
903   explicit OMPBarrierDirective()
904       : OMPExecutableDirective(this, OMPBarrierDirectiveClass, OMPD_barrier,
905                                SourceLocation(), SourceLocation(), 0, 0) {}
906
907 public:
908   /// \brief Creates directive.
909   ///
910   /// \param C AST context.
911   /// \param StartLoc Starting location of the directive kind.
912   /// \param EndLoc Ending Location of the directive.
913   ///
914   static OMPBarrierDirective *
915   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
916
917   /// \brief Creates an empty directive.
918   ///
919   /// \param C AST context.
920   ///
921   static OMPBarrierDirective *CreateEmpty(const ASTContext &C, EmptyShell);
922
923   static bool classof(const Stmt *T) {
924     return T->getStmtClass() == OMPBarrierDirectiveClass;
925   }
926 };
927
928 /// \brief This represents '#pragma omp taskwait' directive.
929 ///
930 /// \code
931 /// #pragma omp taskwait
932 /// \endcode
933 ///
934 class OMPTaskwaitDirective : public OMPExecutableDirective {
935   friend class ASTStmtReader;
936   /// \brief Build directive with the given start and end location.
937   ///
938   /// \param StartLoc Starting location of the directive kind.
939   /// \param EndLoc Ending location of the directive.
940   ///
941   OMPTaskwaitDirective(SourceLocation StartLoc, SourceLocation EndLoc)
942       : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, OMPD_taskwait,
943                                StartLoc, EndLoc, 0, 0) {}
944
945   /// \brief Build an empty directive.
946   ///
947   explicit OMPTaskwaitDirective()
948       : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, OMPD_taskwait,
949                                SourceLocation(), SourceLocation(), 0, 0) {}
950
951 public:
952   /// \brief Creates directive.
953   ///
954   /// \param C AST context.
955   /// \param StartLoc Starting location of the directive kind.
956   /// \param EndLoc Ending Location of the directive.
957   ///
958   static OMPTaskwaitDirective *
959   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
960
961   /// \brief Creates an empty directive.
962   ///
963   /// \param C AST context.
964   ///
965   static OMPTaskwaitDirective *CreateEmpty(const ASTContext &C, EmptyShell);
966
967   static bool classof(const Stmt *T) {
968     return T->getStmtClass() == OMPTaskwaitDirectiveClass;
969   }
970 };
971
972 /// \brief This represents '#pragma omp flush' directive.
973 ///
974 /// \code
975 /// #pragma omp flush(a,b)
976 /// \endcode
977 /// In this example directive '#pragma omp flush' has 2 arguments- variables 'a'
978 /// and 'b'.
979 /// 'omp flush' directive does not have clauses but have an optional list of
980 /// variables to flush. This list of variables is stored within some fake clause
981 /// FlushClause.
982 class OMPFlushDirective : public OMPExecutableDirective {
983   friend class ASTStmtReader;
984   /// \brief Build directive with the given start and end location.
985   ///
986   /// \param StartLoc Starting location of the directive kind.
987   /// \param EndLoc Ending location of the directive.
988   /// \param NumClauses Number of clauses.
989   ///
990   OMPFlushDirective(SourceLocation StartLoc, SourceLocation EndLoc,
991                     unsigned NumClauses)
992       : OMPExecutableDirective(this, OMPFlushDirectiveClass, OMPD_flush,
993                                StartLoc, EndLoc, NumClauses, 0) {}
994
995   /// \brief Build an empty directive.
996   ///
997   /// \param NumClauses Number of clauses.
998   ///
999   explicit OMPFlushDirective(unsigned NumClauses)
1000       : OMPExecutableDirective(this, OMPFlushDirectiveClass, OMPD_flush,
1001                                SourceLocation(), SourceLocation(), NumClauses,
1002                                0) {}
1003
1004 public:
1005   /// \brief Creates directive with a list of \a Clauses.
1006   ///
1007   /// \param C AST context.
1008   /// \param StartLoc Starting location of the directive kind.
1009   /// \param EndLoc Ending Location of the directive.
1010   /// \param Clauses List of clauses (only single OMPFlushClause clause is
1011   /// allowed).
1012   ///
1013   static OMPFlushDirective *Create(const ASTContext &C, SourceLocation StartLoc,
1014                                    SourceLocation EndLoc,
1015                                    ArrayRef<OMPClause *> Clauses);
1016
1017   /// \brief Creates an empty directive with the place for \a NumClauses
1018   /// clauses.
1019   ///
1020   /// \param C AST context.
1021   /// \param NumClauses Number of clauses.
1022   ///
1023   static OMPFlushDirective *CreateEmpty(const ASTContext &C,
1024                                         unsigned NumClauses, EmptyShell);
1025
1026   static bool classof(const Stmt *T) {
1027     return T->getStmtClass() == OMPFlushDirectiveClass;
1028   }
1029 };
1030
1031 } // end namespace clang
1032
1033 #endif