clang API Documentation

OpenMPClause.h
Go to the documentation of this file.
00001 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 /// \file
00010 /// \brief This file defines OpenMP AST classes for clauses.
00011 /// There are clauses for executable directives, clauses for declarative
00012 /// directives and clauses which can be used in both kinds of directives.
00013 ///
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
00017 #define LLVM_CLANG_AST_OPENMPCLAUSE_H
00018 
00019 #include "clang/AST/Expr.h"
00020 #include "clang/AST/Stmt.h"
00021 #include "clang/Basic/OpenMPKinds.h"
00022 #include "clang/Basic/SourceLocation.h"
00023 
00024 namespace clang {
00025 
00026 //===----------------------------------------------------------------------===//
00027 // AST classes for clauses.
00028 //===----------------------------------------------------------------------===//
00029 
00030 /// \brief This is a basic class for representing single OpenMP clause.
00031 ///
00032 class OMPClause {
00033   /// \brief Starting location of the clause (the clause keyword).
00034   SourceLocation StartLoc;
00035   /// \brief Ending location of the clause.
00036   SourceLocation EndLoc;
00037   /// \brief Kind of the clause.
00038   OpenMPClauseKind Kind;
00039 
00040 protected:
00041   OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
00042       : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
00043 
00044 public:
00045   /// \brief Returns the starting location of the clause.
00046   SourceLocation getLocStart() const { return StartLoc; }
00047   /// \brief Returns the ending location of the clause.
00048   SourceLocation getLocEnd() const { return EndLoc; }
00049 
00050   /// \brief Sets the starting location of the clause.
00051   void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
00052   /// \brief Sets the ending location of the clause.
00053   void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
00054 
00055   /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.).
00056   OpenMPClauseKind getClauseKind() const { return Kind; }
00057 
00058   bool isImplicit() const { return StartLoc.isInvalid(); }
00059 
00060   StmtRange children();
00061   ConstStmtRange children() const {
00062     return const_cast<OMPClause *>(this)->children();
00063   }
00064   static bool classof(const OMPClause *) { return true; }
00065 };
00066 
00067 /// \brief This represents clauses with the list of variables like 'private',
00068 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
00069 /// '#pragma omp ...' directives.
00070 template <class T> class OMPVarListClause : public OMPClause {
00071   friend class OMPClauseReader;
00072   /// \brief Location of '('.
00073   SourceLocation LParenLoc;
00074   /// \brief Number of variables in the list.
00075   unsigned NumVars;
00076 
00077 protected:
00078   /// \brief Fetches list of variables associated with this clause.
00079   MutableArrayRef<Expr *> getVarRefs() {
00080     return MutableArrayRef<Expr *>(
00081         reinterpret_cast<Expr **>(
00082             reinterpret_cast<char *>(this) +
00083             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())),
00084         NumVars);
00085   }
00086 
00087   /// \brief Sets the list of variables for this clause.
00088   void setVarRefs(ArrayRef<Expr *> VL) {
00089     assert(VL.size() == NumVars &&
00090            "Number of variables is not the same as the preallocated buffer");
00091     std::copy(
00092         VL.begin(), VL.end(),
00093         reinterpret_cast<Expr **>(
00094             reinterpret_cast<char *>(this) +
00095             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())));
00096   }
00097 
00098   /// \brief Build a clause with \a N variables
00099   ///
00100   /// \param K Kind of the clause.
00101   /// \param StartLoc Starting location of the clause (the clause keyword).
00102   /// \param LParenLoc Location of '('.
00103   /// \param EndLoc Ending location of the clause.
00104   /// \param N Number of the variables in the clause.
00105   ///
00106   OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
00107                    SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
00108       : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
00109 
00110 public:
00111   typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
00112   typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
00113   typedef llvm::iterator_range<varlist_iterator> varlist_range;
00114   typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
00115 
00116   unsigned varlist_size() const { return NumVars; }
00117   bool varlist_empty() const { return NumVars == 0; }
00118 
00119   varlist_range varlists() {
00120     return varlist_range(varlist_begin(), varlist_end());
00121   }
00122   varlist_const_range varlists() const {
00123     return varlist_const_range(varlist_begin(), varlist_end());
00124   }
00125 
00126   varlist_iterator varlist_begin() { return getVarRefs().begin(); }
00127   varlist_iterator varlist_end() { return getVarRefs().end(); }
00128   varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
00129   varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
00130 
00131   /// \brief Sets the location of '('.
00132   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
00133   /// \brief Returns the location of '('.
00134   SourceLocation getLParenLoc() const { return LParenLoc; }
00135 
00136   /// \brief Fetches list of all variables in the clause.
00137   ArrayRef<const Expr *> getVarRefs() const {
00138     return llvm::makeArrayRef(
00139         reinterpret_cast<const Expr *const *>(
00140             reinterpret_cast<const char *>(this) +
00141             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<const Expr *>())),
00142         NumVars);
00143   }
00144 };
00145 
00146 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
00147 ///
00148 /// \code
00149 /// #pragma omp parallel if(a > 5)
00150 /// \endcode
00151 /// In this example directive '#pragma omp parallel' has simple 'if'
00152 /// clause with condition 'a > 5'.
00153 ///
00154 class OMPIfClause : public OMPClause {
00155   friend class OMPClauseReader;
00156   /// \brief Location of '('.
00157   SourceLocation LParenLoc;
00158   /// \brief Condition of the 'if' clause.
00159   Stmt *Condition;
00160 
00161   /// \brief Set condition.
00162   ///
00163   void setCondition(Expr *Cond) { Condition = Cond; }
00164 
00165 public:
00166   /// \brief Build 'if' clause with condition \a Cond.
00167   ///
00168   /// \param StartLoc Starting location of the clause.
00169   /// \param LParenLoc Location of '('.
00170   /// \param Cond Condition of the clause.
00171   /// \param EndLoc Ending location of the clause.
00172   ///
00173   OMPIfClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
00174               SourceLocation EndLoc)
00175       : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
00176         Condition(Cond) {}
00177 
00178   /// \brief Build an empty clause.
00179   ///
00180   OMPIfClause()
00181       : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
00182         LParenLoc(SourceLocation()), Condition(nullptr) {}
00183 
00184   /// \brief Sets the location of '('.
00185   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
00186   /// \brief Returns the location of '('.
00187   SourceLocation getLParenLoc() const { return LParenLoc; }
00188 
00189   /// \brief Returns condition.
00190   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
00191 
00192   static bool classof(const OMPClause *T) {
00193     return T->getClauseKind() == OMPC_if;
00194   }
00195 
00196   StmtRange children() { return StmtRange(&Condition, &Condition + 1); }
00197 };
00198 
00199 /// \brief This represents 'final' clause in the '#pragma omp ...' directive.
00200 ///
00201 /// \code
00202 /// #pragma omp task final(a > 5)
00203 /// \endcode
00204 /// In this example directive '#pragma omp task' has simple 'final'
00205 /// clause with condition 'a > 5'.
00206 ///
00207 class OMPFinalClause : public OMPClause {
00208   friend class OMPClauseReader;
00209   /// \brief Location of '('.
00210   SourceLocation LParenLoc;
00211   /// \brief Condition of the 'if' clause.
00212   Stmt *Condition;
00213 
00214   /// \brief Set condition.
00215   ///
00216   void setCondition(Expr *Cond) { Condition = Cond; }
00217 
00218 public:
00219   /// \brief Build 'final' clause with condition \a Cond.
00220   ///
00221   /// \param StartLoc Starting location of the clause.
00222   /// \param LParenLoc Location of '('.
00223   /// \param Cond Condition of the clause.
00224   /// \param EndLoc Ending location of the clause.
00225   ///
00226   OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
00227                  SourceLocation EndLoc)
00228       : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
00229         Condition(Cond) {}
00230 
00231   /// \brief Build an empty clause.
00232   ///
00233   OMPFinalClause()
00234       : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
00235         LParenLoc(SourceLocation()), Condition(nullptr) {}
00236 
00237   /// \brief Sets the location of '('.
00238   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
00239   /// \brief Returns the location of '('.
00240   SourceLocation getLParenLoc() const { return LParenLoc; }
00241 
00242   /// \brief Returns condition.
00243   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
00244 
00245   static bool classof(const OMPClause *T) {
00246     return T->getClauseKind() == OMPC_final;
00247   }
00248 
00249   StmtRange children() { return StmtRange(&Condition, &Condition + 1); }
00250 };
00251 
00252 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
00253 /// directive.
00254 ///
00255 /// \code
00256 /// #pragma omp parallel num_threads(6)
00257 /// \endcode
00258 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
00259 /// clause with number of threads '6'.
00260 ///
00261 class OMPNumThreadsClause : public OMPClause {
00262   friend class OMPClauseReader;
00263   /// \brief Location of '('.
00264   SourceLocation LParenLoc;
00265   /// \brief Condition of the 'num_threads' clause.
00266   Stmt *NumThreads;
00267 
00268   /// \brief Set condition.
00269   ///
00270   void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
00271 
00272 public:
00273   /// \brief Build 'num_threads' clause with condition \a NumThreads.
00274   ///
00275   /// \param NumThreads Number of threads for the construct.
00276   /// \param StartLoc Starting location of the clause.
00277   /// \param LParenLoc Location of '('.
00278   /// \param EndLoc Ending location of the clause.
00279   ///
00280   OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
00281                       SourceLocation LParenLoc, SourceLocation EndLoc)
00282       : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
00283         NumThreads(NumThreads) {}
00284 
00285   /// \brief Build an empty clause.
00286   ///
00287   OMPNumThreadsClause()
00288       : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
00289         LParenLoc(SourceLocation()), NumThreads(nullptr) {}
00290 
00291   /// \brief Sets the location of '('.
00292   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
00293   /// \brief Returns the location of '('.
00294   SourceLocation getLParenLoc() const { return LParenLoc; }
00295 
00296   /// \brief Returns number of threads.
00297   Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
00298 
00299   static bool classof(const OMPClause *T) {
00300     return T->getClauseKind() == OMPC_num_threads;
00301   }
00302 
00303   StmtRange children() { return StmtRange(&NumThreads, &NumThreads + 1); }
00304 };
00305 
00306 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
00307 /// directive.
00308 ///
00309 /// \code
00310 /// #pragma omp simd safelen(4)
00311 /// \endcode
00312 /// In this example directive '#pragma omp simd' has clause 'safelen'
00313 /// with single expression '4'.
00314 /// If the safelen clause is used then no two iterations executed
00315 /// concurrently with SIMD instructions can have a greater distance
00316 /// in the logical iteration space than its value. The parameter of
00317 /// the safelen clause must be a constant positive integer expression.
00318 ///
00319 class OMPSafelenClause : public OMPClause {
00320   friend class OMPClauseReader;
00321   /// \brief Location of '('.
00322   SourceLocation LParenLoc;
00323   /// \brief Safe iteration space distance.
00324   Stmt *Safelen;
00325 
00326   /// \brief Set safelen.
00327   void setSafelen(Expr *Len) { Safelen = Len; }
00328 
00329 public:
00330   /// \brief Build 'safelen' clause.
00331   ///
00332   /// \param Len Expression associated with this clause.
00333   /// \param StartLoc Starting location of the clause.
00334   /// \param EndLoc Ending location of the clause.
00335   ///
00336   OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
00337                    SourceLocation EndLoc)
00338       : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
00339         Safelen(Len) {}
00340 
00341   /// \brief Build an empty clause.
00342   ///
00343   explicit OMPSafelenClause()
00344       : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
00345         LParenLoc(SourceLocation()), Safelen(nullptr) {}
00346 
00347   /// \brief Sets the location of '('.
00348   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
00349   /// \brief Returns the location of '('.
00350   SourceLocation getLParenLoc() const { return LParenLoc; }
00351 
00352   /// \brief Return safe iteration space distance.
00353   Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
00354 
00355   static bool classof(const OMPClause *T) {
00356     return T->getClauseKind() == OMPC_safelen;
00357   }
00358 
00359   StmtRange children() { return StmtRange(&Safelen, &Safelen + 1); }
00360 };
00361 
00362 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
00363 /// directive.
00364 ///
00365 /// \code
00366 /// #pragma omp simd collapse(3)
00367 /// \endcode
00368 /// In this example directive '#pragma omp simd' has clause 'collapse'
00369 /// with single expression '3'.
00370 /// The parameter must be a constant positive integer expression, it specifies
00371 /// the number of nested loops that should be collapsed into a single iteration
00372 /// space.
00373 ///
00374 class OMPCollapseClause : public OMPClause {
00375   friend class OMPClauseReader;
00376   /// \brief Location of '('.
00377   SourceLocation LParenLoc;
00378   /// \brief Number of for-loops.
00379   Stmt *NumForLoops;
00380 
00381   /// \brief Set the number of associated for-loops.
00382   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
00383 
00384 public:
00385   /// \brief Build 'collapse' clause.
00386   ///
00387   /// \param Num Expression associated with this clause.
00388   /// \param StartLoc Starting location of the clause.
00389   /// \param LParenLoc Location of '('.
00390   /// \param EndLoc Ending location of the clause.
00391   ///
00392   OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
00393                     SourceLocation LParenLoc, SourceLocation EndLoc)
00394       : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
00395         NumForLoops(Num) {}
00396 
00397   /// \brief Build an empty clause.
00398   ///
00399   explicit OMPCollapseClause()
00400       : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
00401         LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
00402 
00403   /// \brief Sets the location of '('.
00404   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
00405   /// \brief Returns the location of '('.
00406   SourceLocation getLParenLoc() const { return LParenLoc; }
00407 
00408   /// \brief Return the number of associated for-loops.
00409   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
00410 
00411   static bool classof(const OMPClause *T) {
00412     return T->getClauseKind() == OMPC_collapse;
00413   }
00414 
00415   StmtRange children() { return StmtRange(&NumForLoops, &NumForLoops + 1); }
00416 };
00417 
00418 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
00419 ///
00420 /// \code
00421 /// #pragma omp parallel default(shared)
00422 /// \endcode
00423 /// In this example directive '#pragma omp parallel' has simple 'default'
00424 /// clause with kind 'shared'.
00425 ///
00426 class OMPDefaultClause : public OMPClause {
00427   friend class OMPClauseReader;
00428   /// \brief Location of '('.
00429   SourceLocation LParenLoc;
00430   /// \brief A kind of the 'default' clause.
00431   OpenMPDefaultClauseKind Kind;
00432   /// \brief Start location of the kind in source code.
00433   SourceLocation KindKwLoc;
00434 
00435   /// \brief Set kind of the clauses.
00436   ///
00437   /// \param K Argument of clause.
00438   ///
00439   void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
00440 
00441   /// \brief Set argument location.
00442   ///
00443   /// \param KLoc Argument location.
00444   ///
00445   void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
00446 
00447 public:
00448   /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
00449   ///
00450   /// \param A Argument of the clause ('none' or 'shared').
00451   /// \param ALoc Starting location of the argument.
00452   /// \param StartLoc Starting location of the clause.
00453   /// \param LParenLoc Location of '('.
00454   /// \param EndLoc Ending location of the clause.
00455   ///
00456   OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
00457                    SourceLocation StartLoc, SourceLocation LParenLoc,
00458                    SourceLocation EndLoc)
00459       : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
00460         Kind(A), KindKwLoc(ALoc) {}
00461 
00462   /// \brief Build an empty clause.
00463   ///
00464   OMPDefaultClause()
00465       : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
00466         LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
00467         KindKwLoc(SourceLocation()) {}
00468 
00469   /// \brief Sets the location of '('.
00470   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
00471   /// \brief Returns the location of '('.
00472   SourceLocation getLParenLoc() const { return LParenLoc; }
00473 
00474   /// \brief Returns kind of the clause.
00475   OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
00476 
00477   /// \brief Returns location of clause kind.
00478   SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
00479 
00480   static bool classof(const OMPClause *T) {
00481     return T->getClauseKind() == OMPC_default;
00482   }
00483 
00484   StmtRange children() { return StmtRange(); }
00485 };
00486 
00487 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
00488 /// directive.
00489 ///
00490 /// \code
00491 /// #pragma omp parallel proc_bind(master)
00492 /// \endcode
00493 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
00494 /// clause with kind 'master'.
00495 ///
00496 class OMPProcBindClause : public OMPClause {
00497   friend class OMPClauseReader;
00498   /// \brief Location of '('.
00499   SourceLocation LParenLoc;
00500   /// \brief A kind of the 'proc_bind' clause.
00501   OpenMPProcBindClauseKind Kind;
00502   /// \brief Start location of the kind in source code.
00503   SourceLocation KindKwLoc;
00504 
00505   /// \brief Set kind of the clause.
00506   ///
00507   /// \param K Kind of clause.
00508   ///
00509   void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
00510 
00511   /// \brief Set clause kind location.
00512   ///
00513   /// \param KLoc Kind location.
00514   ///
00515   void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
00516 
00517 public:
00518   /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
00519   ///        'spread').
00520   ///
00521   /// \param A Argument of the clause ('master', 'close' or 'spread').
00522   /// \param ALoc Starting location of the argument.
00523   /// \param StartLoc Starting location of the clause.
00524   /// \param LParenLoc Location of '('.
00525   /// \param EndLoc Ending location of the clause.
00526   ///
00527   OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
00528                     SourceLocation StartLoc, SourceLocation LParenLoc,
00529                     SourceLocation EndLoc)
00530       : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
00531         Kind(A), KindKwLoc(ALoc) {}
00532 
00533   /// \brief Build an empty clause.
00534   ///
00535   OMPProcBindClause()
00536       : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
00537         LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
00538         KindKwLoc(SourceLocation()) {}
00539 
00540   /// \brief Sets the location of '('.
00541   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
00542   /// \brief Returns the location of '('.
00543   SourceLocation getLParenLoc() const { return LParenLoc; }
00544 
00545   /// \brief Returns kind of the clause.
00546   OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
00547 
00548   /// \brief Returns location of clause kind.
00549   SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
00550 
00551   static bool classof(const OMPClause *T) {
00552     return T->getClauseKind() == OMPC_proc_bind;
00553   }
00554 
00555   StmtRange children() { return StmtRange(); }
00556 };
00557 
00558 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
00559 ///
00560 /// \code
00561 /// #pragma omp for schedule(static, 3)
00562 /// \endcode
00563 /// In this example directive '#pragma omp for' has 'schedule' clause with
00564 /// arguments 'static' and '3'.
00565 ///
00566 class OMPScheduleClause : public OMPClause {
00567   friend class OMPClauseReader;
00568   /// \brief Location of '('.
00569   SourceLocation LParenLoc;
00570   /// \brief A kind of the 'schedule' clause.
00571   OpenMPScheduleClauseKind Kind;
00572   /// \brief Start location of the schedule ind in source code.
00573   SourceLocation KindLoc;
00574   /// \brief Location of ',' (if any).
00575   SourceLocation CommaLoc;
00576   /// \brief Chunk size.
00577   Stmt *ChunkSize;
00578 
00579   /// \brief Set schedule kind.
00580   ///
00581   /// \param K Schedule kind.
00582   ///
00583   void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
00584   /// \brief Sets the location of '('.
00585   ///
00586   /// \param Loc Location of '('.
00587   ///
00588   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
00589   /// \brief Set schedule kind start location.
00590   ///
00591   /// \param KLoc Schedule kind location.
00592   ///
00593   void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
00594   /// \brief Set location of ','.
00595   ///
00596   /// \param Loc Location of ','.
00597   ///
00598   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
00599   /// \brief Set chunk size.
00600   ///
00601   /// \param E Chunk size.
00602   ///
00603   void setChunkSize(Expr *E) { ChunkSize = E; }
00604 
00605 public:
00606   /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
00607   /// expression \a ChunkSize.
00608   ///
00609   /// \param StartLoc Starting location of the clause.
00610   /// \param LParenLoc Location of '('.
00611   /// \param KLoc Starting location of the argument.
00612   /// \param CommaLoc Location of ','.
00613   /// \param EndLoc Ending location of the clause.
00614   /// \param Kind Schedule kind.
00615   /// \param ChunkSize Chunk size.
00616   ///
00617   OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
00618                     SourceLocation KLoc, SourceLocation CommaLoc,
00619                     SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
00620                     Expr *ChunkSize)
00621       : OMPClause(OMPC_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc),
00622         Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {}
00623 
00624   /// \brief Build an empty clause.
00625   ///
00626   explicit OMPScheduleClause()
00627       : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
00628         Kind(OMPC_SCHEDULE_unknown), ChunkSize(nullptr) {}
00629 
00630   /// \brief Get kind of the clause.
00631   ///
00632   OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
00633   /// \brief Get location of '('.
00634   ///
00635   SourceLocation getLParenLoc() { return LParenLoc; }
00636   /// \brief Get kind location.
00637   ///
00638   SourceLocation getScheduleKindLoc() { return KindLoc; }
00639   /// \brief Get location of ','.
00640   ///
00641   SourceLocation getCommaLoc() { return CommaLoc; }
00642   /// \brief Get chunk size.
00643   ///
00644   Expr *getChunkSize() { return dyn_cast_or_null<Expr>(ChunkSize); }
00645   /// \brief Get chunk size.
00646   ///
00647   Expr *getChunkSize() const { return dyn_cast_or_null<Expr>(ChunkSize); }
00648 
00649   static bool classof(const OMPClause *T) {
00650     return T->getClauseKind() == OMPC_schedule;
00651   }
00652 
00653   StmtRange children() { return StmtRange(&ChunkSize, &ChunkSize + 1); }
00654 };
00655 
00656 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
00657 ///
00658 /// \code
00659 /// #pragma omp for ordered
00660 /// \endcode
00661 /// In this example directive '#pragma omp for' has 'ordered' clause.
00662 ///
00663 class OMPOrderedClause : public OMPClause {
00664 public:
00665   /// \brief Build 'ordered' clause.
00666   ///
00667   /// \param StartLoc Starting location of the clause.
00668   /// \param EndLoc Ending location of the clause.
00669   ///
00670   OMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc)
00671       : OMPClause(OMPC_ordered, StartLoc, EndLoc) {}
00672 
00673   /// \brief Build an empty clause.
00674   ///
00675   OMPOrderedClause()
00676       : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
00677 
00678   static bool classof(const OMPClause *T) {
00679     return T->getClauseKind() == OMPC_ordered;
00680   }
00681 
00682   StmtRange children() { return StmtRange(); }
00683 };
00684 
00685 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
00686 ///
00687 /// \code
00688 /// #pragma omp for nowait
00689 /// \endcode
00690 /// In this example directive '#pragma omp for' has 'nowait' clause.
00691 ///
00692 class OMPNowaitClause : public OMPClause {
00693 public:
00694   /// \brief Build 'nowait' clause.
00695   ///
00696   /// \param StartLoc Starting location of the clause.
00697   /// \param EndLoc Ending location of the clause.
00698   ///
00699   OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
00700       : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
00701 
00702   /// \brief Build an empty clause.
00703   ///
00704   OMPNowaitClause()
00705       : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
00706 
00707   static bool classof(const OMPClause *T) {
00708     return T->getClauseKind() == OMPC_nowait;
00709   }
00710 
00711   StmtRange children() { return StmtRange(); }
00712 };
00713 
00714 /// \brief This represents 'untied' clause in the '#pragma omp ...' directive.
00715 ///
00716 /// \code
00717 /// #pragma omp task untied
00718 /// \endcode
00719 /// In this example directive '#pragma omp task' has 'untied' clause.
00720 ///
00721 class OMPUntiedClause : public OMPClause {
00722 public:
00723   /// \brief Build 'untied' clause.
00724   ///
00725   /// \param StartLoc Starting location of the clause.
00726   /// \param EndLoc Ending location of the clause.
00727   ///
00728   OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
00729       : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
00730 
00731   /// \brief Build an empty clause.
00732   ///
00733   OMPUntiedClause()
00734       : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
00735 
00736   static bool classof(const OMPClause *T) {
00737     return T->getClauseKind() == OMPC_untied;
00738   }
00739 
00740   StmtRange children() { return StmtRange(); }
00741 };
00742 
00743 /// \brief This represents 'mergeable' clause in the '#pragma omp ...'
00744 /// directive.
00745 ///
00746 /// \code
00747 /// #pragma omp task mergeable
00748 /// \endcode
00749 /// In this example directive '#pragma omp task' has 'mergeable' clause.
00750 ///
00751 class OMPMergeableClause : public OMPClause {
00752 public:
00753   /// \brief Build 'mergeable' clause.
00754   ///
00755   /// \param StartLoc Starting location of the clause.
00756   /// \param EndLoc Ending location of the clause.
00757   ///
00758   OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
00759       : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
00760 
00761   /// \brief Build an empty clause.
00762   ///
00763   OMPMergeableClause()
00764       : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
00765 
00766   static bool classof(const OMPClause *T) {
00767     return T->getClauseKind() == OMPC_mergeable;
00768   }
00769 
00770   StmtRange children() { return StmtRange(); }
00771 };
00772 
00773 /// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
00774 ///
00775 /// \code
00776 /// #pragma omp atomic read
00777 /// \endcode
00778 /// In this example directive '#pragma omp atomic' has 'read' clause.
00779 ///
00780 class OMPReadClause : public OMPClause {
00781 public:
00782   /// \brief Build 'read' clause.
00783   ///
00784   /// \param StartLoc Starting location of the clause.
00785   /// \param EndLoc Ending location of the clause.
00786   ///
00787   OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
00788       : OMPClause(OMPC_read, StartLoc, EndLoc) {}
00789 
00790   /// \brief Build an empty clause.
00791   ///
00792   OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
00793 
00794   static bool classof(const OMPClause *T) {
00795     return T->getClauseKind() == OMPC_read;
00796   }
00797 
00798   StmtRange children() { return StmtRange(); }
00799 };
00800 
00801 /// \brief This represents 'write' clause in the '#pragma omp atomic' directive.
00802 ///
00803 /// \code
00804 /// #pragma omp atomic write
00805 /// \endcode
00806 /// In this example directive '#pragma omp atomic' has 'write' clause.
00807 ///
00808 class OMPWriteClause : public OMPClause {
00809 public:
00810   /// \brief Build 'write' clause.
00811   ///
00812   /// \param StartLoc Starting location of the clause.
00813   /// \param EndLoc Ending location of the clause.
00814   ///
00815   OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
00816       : OMPClause(OMPC_write, StartLoc, EndLoc) {}
00817 
00818   /// \brief Build an empty clause.
00819   ///
00820   OMPWriteClause()
00821       : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
00822 
00823   static bool classof(const OMPClause *T) {
00824     return T->getClauseKind() == OMPC_write;
00825   }
00826 
00827   StmtRange children() { return StmtRange(); }
00828 };
00829 
00830 /// \brief This represents 'update' clause in the '#pragma omp atomic'
00831 /// directive.
00832 ///
00833 /// \code
00834 /// #pragma omp atomic update
00835 /// \endcode
00836 /// In this example directive '#pragma omp atomic' has 'update' clause.
00837 ///
00838 class OMPUpdateClause : public OMPClause {
00839 public:
00840   /// \brief Build 'update' clause.
00841   ///
00842   /// \param StartLoc Starting location of the clause.
00843   /// \param EndLoc Ending location of the clause.
00844   ///
00845   OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
00846       : OMPClause(OMPC_update, StartLoc, EndLoc) {}
00847 
00848   /// \brief Build an empty clause.
00849   ///
00850   OMPUpdateClause()
00851       : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
00852 
00853   static bool classof(const OMPClause *T) {
00854     return T->getClauseKind() == OMPC_update;
00855   }
00856 
00857   StmtRange children() { return StmtRange(); }
00858 };
00859 
00860 /// \brief This represents 'capture' clause in the '#pragma omp atomic'
00861 /// directive.
00862 ///
00863 /// \code
00864 /// #pragma omp atomic capture
00865 /// \endcode
00866 /// In this example directive '#pragma omp atomic' has 'capture' clause.
00867 ///
00868 class OMPCaptureClause : public OMPClause {
00869 public:
00870   /// \brief Build 'capture' clause.
00871   ///
00872   /// \param StartLoc Starting location of the clause.
00873   /// \param EndLoc Ending location of the clause.
00874   ///
00875   OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
00876       : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
00877 
00878   /// \brief Build an empty clause.
00879   ///
00880   OMPCaptureClause()
00881       : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
00882 
00883   static bool classof(const OMPClause *T) {
00884     return T->getClauseKind() == OMPC_capture;
00885   }
00886 
00887   StmtRange children() { return StmtRange(); }
00888 };
00889 
00890 /// \brief This represents 'seq_cst' clause in the '#pragma omp atomic'
00891 /// directive.
00892 ///
00893 /// \code
00894 /// #pragma omp atomic seq_cst
00895 /// \endcode
00896 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
00897 ///
00898 class OMPSeqCstClause : public OMPClause {
00899 public:
00900   /// \brief Build 'seq_cst' clause.
00901   ///
00902   /// \param StartLoc Starting location of the clause.
00903   /// \param EndLoc Ending location of the clause.
00904   ///
00905   OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
00906       : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
00907 
00908   /// \brief Build an empty clause.
00909   ///
00910   OMPSeqCstClause()
00911       : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
00912 
00913   static bool classof(const OMPClause *T) {
00914     return T->getClauseKind() == OMPC_seq_cst;
00915   }
00916 
00917   StmtRange children() { return StmtRange(); }
00918 };
00919 
00920 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
00921 ///
00922 /// \code
00923 /// #pragma omp parallel private(a,b)
00924 /// \endcode
00925 /// In this example directive '#pragma omp parallel' has clause 'private'
00926 /// with the variables 'a' and 'b'.
00927 ///
00928 class OMPPrivateClause : public OMPVarListClause<OMPPrivateClause> {
00929   friend class OMPClauseReader;
00930   /// \brief Build clause with number of variables \a N.
00931   ///
00932   /// \param StartLoc Starting location of the clause.
00933   /// \param LParenLoc Location of '('.
00934   /// \param EndLoc Ending location of the clause.
00935   /// \param N Number of the variables in the clause.
00936   ///
00937   OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
00938                    SourceLocation EndLoc, unsigned N)
00939       : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
00940                                            EndLoc, N) {}
00941 
00942   /// \brief Build an empty clause.
00943   ///
00944   /// \param N Number of variables.
00945   ///
00946   explicit OMPPrivateClause(unsigned N)
00947       : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
00948                                            SourceLocation(), SourceLocation(),
00949                                            N) {}
00950 
00951   /// \brief Sets the list of references to private copies with initializers for
00952   /// new private variables.
00953   /// \param VL List of references.
00954   void setPrivateCopies(ArrayRef<Expr *> VL);
00955 
00956   /// \brief Gets the list of references to private copies with initializers for
00957   /// new private variables.
00958   MutableArrayRef<Expr *> getPrivateCopies() {
00959     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
00960   }
00961   ArrayRef<const Expr *> getPrivateCopies() const {
00962     return llvm::makeArrayRef(varlist_end(), varlist_size());
00963   }
00964 
00965 public:
00966   /// \brief Creates clause with a list of variables \a VL.
00967   ///
00968   /// \param C AST context.
00969   /// \param StartLoc Starting location of the clause.
00970   /// \param LParenLoc Location of '('.
00971   /// \param EndLoc Ending location of the clause.
00972   /// \param VL List of references to the variables.
00973   /// \param PrivateVL List of references to private copies with initializers.
00974   ///
00975   static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
00976                                   SourceLocation LParenLoc,
00977                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
00978                                   ArrayRef<Expr *> PrivateVL);
00979   /// \brief Creates an empty clause with the place for \a N variables.
00980   ///
00981   /// \param C AST context.
00982   /// \param N The number of variables.
00983   ///
00984   static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
00985 
00986   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
00987   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
00988   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
00989   typedef llvm::iterator_range<private_copies_const_iterator>
00990       private_copies_const_range;
00991 
00992   private_copies_range private_copies() {
00993     return private_copies_range(getPrivateCopies().begin(),
00994                                 getPrivateCopies().end());
00995   }
00996   private_copies_const_range private_copies() const {
00997     return private_copies_const_range(getPrivateCopies().begin(),
00998                                       getPrivateCopies().end());
00999   }
01000 
01001   StmtRange children() {
01002     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01003                      reinterpret_cast<Stmt **>(varlist_end()));
01004   }
01005 
01006   static bool classof(const OMPClause *T) {
01007     return T->getClauseKind() == OMPC_private;
01008   }
01009 };
01010 
01011 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
01012 /// directives.
01013 ///
01014 /// \code
01015 /// #pragma omp parallel firstprivate(a,b)
01016 /// \endcode
01017 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
01018 /// with the variables 'a' and 'b'.
01019 ///
01020 class OMPFirstprivateClause : public OMPVarListClause<OMPFirstprivateClause> {
01021   friend class OMPClauseReader;
01022 
01023   /// \brief Build clause with number of variables \a N.
01024   ///
01025   /// \param StartLoc Starting location of the clause.
01026   /// \param LParenLoc Location of '('.
01027   /// \param EndLoc Ending location of the clause.
01028   /// \param N Number of the variables in the clause.
01029   ///
01030   OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
01031                         SourceLocation EndLoc, unsigned N)
01032       : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
01033                                                 LParenLoc, EndLoc, N) {}
01034 
01035   /// \brief Build an empty clause.
01036   ///
01037   /// \param N Number of variables.
01038   ///
01039   explicit OMPFirstprivateClause(unsigned N)
01040       : OMPVarListClause<OMPFirstprivateClause>(
01041             OMPC_firstprivate, SourceLocation(), SourceLocation(),
01042             SourceLocation(), N) {}
01043   /// \brief Sets the list of references to private copies with initializers for
01044   /// new private variables.
01045   /// \param VL List of references.
01046   void setPrivateCopies(ArrayRef<Expr *> VL);
01047 
01048   /// \brief Gets the list of references to private copies with initializers for
01049   /// new private variables.
01050   MutableArrayRef<Expr *> getPrivateCopies() {
01051     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
01052   }
01053   ArrayRef<const Expr *> getPrivateCopies() const {
01054     return llvm::makeArrayRef(varlist_end(), varlist_size());
01055   }
01056 
01057   /// \brief Sets the list of references to initializer variables for new
01058   /// private variables.
01059   /// \param VL List of references.
01060   void setInits(ArrayRef<Expr *> VL);
01061 
01062   /// \brief Gets the list of references to initializer variables for new
01063   /// private variables.
01064   MutableArrayRef<Expr *> getInits() {
01065     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
01066   }
01067   ArrayRef<const Expr *> getInits() const {
01068     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
01069   }
01070 
01071 public:
01072   /// \brief Creates clause with a list of variables \a VL.
01073   ///
01074   /// \param C AST context.
01075   /// \param StartLoc Starting location of the clause.
01076   /// \param LParenLoc Location of '('.
01077   /// \param EndLoc Ending location of the clause.
01078   /// \param VL List of references to the original variables.
01079   /// \param PrivateVL List of references to private copies with initializers.
01080   /// \param InitVL List of references to auto generated variables used for
01081   /// initialization of a single array element. Used if firstprivate variable is
01082   /// of array type.
01083   ///
01084   static OMPFirstprivateClause *
01085   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
01086          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
01087          ArrayRef<Expr *> InitVL);
01088   /// \brief Creates an empty clause with the place for \a N variables.
01089   ///
01090   /// \param C AST context.
01091   /// \param N The number of variables.
01092   ///
01093   static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
01094 
01095   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
01096   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
01097   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
01098   typedef llvm::iterator_range<private_copies_const_iterator>
01099       private_copies_const_range;
01100 
01101   private_copies_range private_copies() {
01102     return private_copies_range(getPrivateCopies().begin(),
01103                                 getPrivateCopies().end());
01104   }
01105   private_copies_const_range private_copies() const {
01106     return private_copies_const_range(getPrivateCopies().begin(),
01107                                       getPrivateCopies().end());
01108   }
01109 
01110   typedef MutableArrayRef<Expr *>::iterator inits_iterator;
01111   typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
01112   typedef llvm::iterator_range<inits_iterator> inits_range;
01113   typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
01114 
01115   inits_range inits() {
01116     return inits_range(getInits().begin(), getInits().end());
01117   }
01118   inits_const_range inits() const {
01119     return inits_const_range(getInits().begin(), getInits().end());
01120   }
01121 
01122   StmtRange children() {
01123     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01124                      reinterpret_cast<Stmt **>(varlist_end()));
01125   }
01126 
01127   static bool classof(const OMPClause *T) {
01128     return T->getClauseKind() == OMPC_firstprivate;
01129   }
01130 };
01131 
01132 /// \brief This represents clause 'lastprivate' in the '#pragma omp ...'
01133 /// directives.
01134 ///
01135 /// \code
01136 /// #pragma omp simd lastprivate(a,b)
01137 /// \endcode
01138 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
01139 /// with the variables 'a' and 'b'.
01140 ///
01141 class OMPLastprivateClause : public OMPVarListClause<OMPLastprivateClause> {
01142   /// \brief Build clause with number of variables \a N.
01143   ///
01144   /// \param StartLoc Starting location of the clause.
01145   /// \param LParenLoc Location of '('.
01146   /// \param EndLoc Ending location of the clause.
01147   /// \param N Number of the variables in the clause.
01148   ///
01149   OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
01150                        SourceLocation EndLoc, unsigned N)
01151       : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
01152                                                LParenLoc, EndLoc, N) {}
01153 
01154   /// \brief Build an empty clause.
01155   ///
01156   /// \param N Number of variables.
01157   ///
01158   explicit OMPLastprivateClause(unsigned N)
01159       : OMPVarListClause<OMPLastprivateClause>(
01160             OMPC_lastprivate, SourceLocation(), SourceLocation(),
01161             SourceLocation(), N) {}
01162 
01163 public:
01164   /// \brief Creates clause with a list of variables \a VL.
01165   ///
01166   /// \param C AST context.
01167   /// \param StartLoc Starting location of the clause.
01168   /// \param LParenLoc Location of '('.
01169   /// \param EndLoc Ending location of the clause.
01170   /// \param VL List of references to the variables.
01171   ///
01172   static OMPLastprivateClause *
01173   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
01174          SourceLocation EndLoc, ArrayRef<Expr *> VL);
01175   /// \brief Creates an empty clause with the place for \a N variables.
01176   ///
01177   /// \param C AST context.
01178   /// \param N The number of variables.
01179   ///
01180   static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
01181 
01182   StmtRange children() {
01183     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01184                      reinterpret_cast<Stmt **>(varlist_end()));
01185   }
01186 
01187   static bool classof(const OMPClause *T) {
01188     return T->getClauseKind() == OMPC_lastprivate;
01189   }
01190 };
01191 
01192 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
01193 ///
01194 /// \code
01195 /// #pragma omp parallel shared(a,b)
01196 /// \endcode
01197 /// In this example directive '#pragma omp parallel' has clause 'shared'
01198 /// with the variables 'a' and 'b'.
01199 ///
01200 class OMPSharedClause : public OMPVarListClause<OMPSharedClause> {
01201   /// \brief Build clause with number of variables \a N.
01202   ///
01203   /// \param StartLoc Starting location of the clause.
01204   /// \param LParenLoc Location of '('.
01205   /// \param EndLoc Ending location of the clause.
01206   /// \param N Number of the variables in the clause.
01207   ///
01208   OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
01209                   SourceLocation EndLoc, unsigned N)
01210       : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
01211                                           EndLoc, N) {}
01212 
01213   /// \brief Build an empty clause.
01214   ///
01215   /// \param N Number of variables.
01216   ///
01217   explicit OMPSharedClause(unsigned N)
01218       : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
01219                                           SourceLocation(), SourceLocation(),
01220                                           N) {}
01221 
01222 public:
01223   /// \brief Creates clause with a list of variables \a VL.
01224   ///
01225   /// \param C AST context.
01226   /// \param StartLoc Starting location of the clause.
01227   /// \param LParenLoc Location of '('.
01228   /// \param EndLoc Ending location of the clause.
01229   /// \param VL List of references to the variables.
01230   ///
01231   static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
01232                                  SourceLocation LParenLoc,
01233                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
01234   /// \brief Creates an empty clause with \a N variables.
01235   ///
01236   /// \param C AST context.
01237   /// \param N The number of variables.
01238   ///
01239   static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
01240 
01241   StmtRange children() {
01242     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01243                      reinterpret_cast<Stmt **>(varlist_end()));
01244   }
01245 
01246   static bool classof(const OMPClause *T) {
01247     return T->getClauseKind() == OMPC_shared;
01248   }
01249 };
01250 
01251 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
01252 /// directives.
01253 ///
01254 /// \code
01255 /// #pragma omp parallel reduction(+:a,b)
01256 /// \endcode
01257 /// In this example directive '#pragma omp parallel' has clause 'reduction'
01258 /// with operator '+' and the variables 'a' and 'b'.
01259 ///
01260 class OMPReductionClause : public OMPVarListClause<OMPReductionClause> {
01261   friend class OMPClauseReader;
01262   /// \brief Location of ':'.
01263   SourceLocation ColonLoc;
01264   /// \brief Nested name specifier for C++.
01265   NestedNameSpecifierLoc QualifierLoc;
01266   /// \brief Name of custom operator.
01267   DeclarationNameInfo NameInfo;
01268 
01269   /// \brief Build clause with number of variables \a N.
01270   ///
01271   /// \param StartLoc Starting location of the clause.
01272   /// \param LParenLoc Location of '('.
01273   /// \param EndLoc Ending location of the clause.
01274   /// \param ColonLoc Location of ':'.
01275   /// \param N Number of the variables in the clause.
01276   /// \param QualifierLoc The nested-name qualifier with location information
01277   /// \param NameInfo The full name info for reduction identifier.
01278   ///
01279   OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
01280                      SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
01281                      NestedNameSpecifierLoc QualifierLoc,
01282                      const DeclarationNameInfo &NameInfo)
01283       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
01284                                              LParenLoc, EndLoc, N),
01285         ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
01286 
01287   /// \brief Build an empty clause.
01288   ///
01289   /// \param N Number of variables.
01290   ///
01291   explicit OMPReductionClause(unsigned N)
01292       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
01293                                              SourceLocation(), SourceLocation(),
01294                                              N),
01295         ColonLoc(), QualifierLoc(), NameInfo() {}
01296 
01297   /// \brief Sets location of ':' symbol in clause.
01298   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
01299   /// \brief Sets the name info for specified reduction identifier.
01300   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
01301   /// \brief Sets the nested name specifier.
01302   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
01303 
01304 public:
01305   /// \brief Creates clause with a list of variables \a VL.
01306   ///
01307   /// \param StartLoc Starting location of the clause.
01308   /// \param LParenLoc Location of '('.
01309   /// \param ColonLoc Location of ':'.
01310   /// \param EndLoc Ending location of the clause.
01311   /// \param VL The variables in the clause.
01312   /// \param QualifierLoc The nested-name qualifier with location information
01313   /// \param NameInfo The full name info for reduction identifier.
01314   ///
01315   static OMPReductionClause *
01316   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
01317          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
01318          NestedNameSpecifierLoc QualifierLoc,
01319          const DeclarationNameInfo &NameInfo);
01320   /// \brief Creates an empty clause with the place for \a N variables.
01321   ///
01322   /// \param C AST context.
01323   /// \param N The number of variables.
01324   ///
01325   static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
01326 
01327   /// \brief Gets location of ':' symbol in clause.
01328   SourceLocation getColonLoc() const { return ColonLoc; }
01329   /// \brief Gets the name info for specified reduction identifier.
01330   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
01331   /// \brief Gets the nested name specifier.
01332   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
01333 
01334   StmtRange children() {
01335     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01336                      reinterpret_cast<Stmt **>(varlist_end()));
01337   }
01338 
01339   static bool classof(const OMPClause *T) {
01340     return T->getClauseKind() == OMPC_reduction;
01341   }
01342 };
01343 
01344 /// \brief This represents clause 'linear' in the '#pragma omp ...'
01345 /// directives.
01346 ///
01347 /// \code
01348 /// #pragma omp simd linear(a,b : 2)
01349 /// \endcode
01350 /// In this example directive '#pragma omp simd' has clause 'linear'
01351 /// with variables 'a', 'b' and linear step '2'.
01352 ///
01353 class OMPLinearClause : public OMPVarListClause<OMPLinearClause> {
01354   friend class OMPClauseReader;
01355   /// \brief Location of ':'.
01356   SourceLocation ColonLoc;
01357 
01358   /// \brief Sets the linear step for clause.
01359   void setStep(Expr *Step) { *varlist_end() = Step; }
01360 
01361   /// \brief Build 'linear' clause with given number of variables \a NumVars.
01362   ///
01363   /// \param StartLoc Starting location of the clause.
01364   /// \param LParenLoc Location of '('.
01365   /// \param ColonLoc Location of ':'.
01366   /// \param EndLoc Ending location of the clause.
01367   /// \param NumVars Number of variables.
01368   ///
01369   OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
01370                   SourceLocation ColonLoc, SourceLocation EndLoc,
01371                   unsigned NumVars)
01372       : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
01373                                           EndLoc, NumVars),
01374         ColonLoc(ColonLoc) {}
01375 
01376   /// \brief Build an empty clause.
01377   ///
01378   /// \param NumVars Number of variables.
01379   ///
01380   explicit OMPLinearClause(unsigned NumVars)
01381       : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
01382                                           SourceLocation(), SourceLocation(),
01383                                           NumVars),
01384         ColonLoc(SourceLocation()) {}
01385 
01386 public:
01387   /// \brief Creates clause with a list of variables \a VL and a linear step
01388   /// \a Step.
01389   ///
01390   /// \param C AST Context.
01391   /// \param StartLoc Starting location of the clause.
01392   /// \param LParenLoc Location of '('.
01393   /// \param ColonLoc Location of ':'.
01394   /// \param EndLoc Ending location of the clause.
01395   /// \param VL List of references to the variables.
01396   /// \param Step Linear step.
01397   static OMPLinearClause *Create(const ASTContext &C, SourceLocation StartLoc,
01398                                  SourceLocation LParenLoc,
01399                                  SourceLocation ColonLoc, SourceLocation EndLoc,
01400                                  ArrayRef<Expr *> VL, Expr *Step);
01401 
01402   /// \brief Creates an empty clause with the place for \a NumVars variables.
01403   ///
01404   /// \param C AST context.
01405   /// \param NumVars Number of variables.
01406   ///
01407   static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
01408 
01409   /// \brief Sets the location of ':'.
01410   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
01411   /// \brief Returns the location of '('.
01412   SourceLocation getColonLoc() const { return ColonLoc; }
01413 
01414   /// \brief Returns linear step.
01415   Expr *getStep() { return *varlist_end(); }
01416   /// \brief Returns linear step.
01417   const Expr *getStep() const { return *varlist_end(); }
01418 
01419   StmtRange children() {
01420     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01421                      reinterpret_cast<Stmt **>(varlist_end() + 1));
01422   }
01423 
01424   static bool classof(const OMPClause *T) {
01425     return T->getClauseKind() == OMPC_linear;
01426   }
01427 };
01428 
01429 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
01430 /// directives.
01431 ///
01432 /// \code
01433 /// #pragma omp simd aligned(a,b : 8)
01434 /// \endcode
01435 /// In this example directive '#pragma omp simd' has clause 'aligned'
01436 /// with variables 'a', 'b' and alignment '8'.
01437 ///
01438 class OMPAlignedClause : public OMPVarListClause<OMPAlignedClause> {
01439   friend class OMPClauseReader;
01440   /// \brief Location of ':'.
01441   SourceLocation ColonLoc;
01442 
01443   /// \brief Sets the alignment for clause.
01444   void setAlignment(Expr *A) { *varlist_end() = A; }
01445 
01446   /// \brief Build 'aligned' clause with given number of variables \a NumVars.
01447   ///
01448   /// \param StartLoc Starting location of the clause.
01449   /// \param LParenLoc Location of '('.
01450   /// \param ColonLoc Location of ':'.
01451   /// \param EndLoc Ending location of the clause.
01452   /// \param NumVars Number of variables.
01453   ///
01454   OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
01455                    SourceLocation ColonLoc, SourceLocation EndLoc,
01456                    unsigned NumVars)
01457       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
01458                                            EndLoc, NumVars),
01459         ColonLoc(ColonLoc) {}
01460 
01461   /// \brief Build an empty clause.
01462   ///
01463   /// \param NumVars Number of variables.
01464   ///
01465   explicit OMPAlignedClause(unsigned NumVars)
01466       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
01467                                            SourceLocation(), SourceLocation(),
01468                                            NumVars),
01469         ColonLoc(SourceLocation()) {}
01470 
01471 public:
01472   /// \brief Creates clause with a list of variables \a VL and alignment \a A.
01473   ///
01474   /// \param C AST Context.
01475   /// \param StartLoc Starting location of the clause.
01476   /// \param LParenLoc Location of '('.
01477   /// \param ColonLoc Location of ':'.
01478   /// \param EndLoc Ending location of the clause.
01479   /// \param VL List of references to the variables.
01480   /// \param A Alignment.
01481   static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
01482                                   SourceLocation LParenLoc,
01483                                   SourceLocation ColonLoc,
01484                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
01485                                   Expr *A);
01486 
01487   /// \brief Creates an empty clause with the place for \a NumVars variables.
01488   ///
01489   /// \param C AST context.
01490   /// \param NumVars Number of variables.
01491   ///
01492   static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
01493 
01494   /// \brief Sets the location of ':'.
01495   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
01496   /// \brief Returns the location of ':'.
01497   SourceLocation getColonLoc() const { return ColonLoc; }
01498 
01499   /// \brief Returns alignment.
01500   Expr *getAlignment() { return *varlist_end(); }
01501   /// \brief Returns alignment.
01502   const Expr *getAlignment() const { return *varlist_end(); }
01503 
01504   StmtRange children() {
01505     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01506                      reinterpret_cast<Stmt **>(varlist_end() + 1));
01507   }
01508 
01509   static bool classof(const OMPClause *T) {
01510     return T->getClauseKind() == OMPC_aligned;
01511   }
01512 };
01513 
01514 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
01515 ///
01516 /// \code
01517 /// #pragma omp parallel copyin(a,b)
01518 /// \endcode
01519 /// In this example directive '#pragma omp parallel' has clause 'copyin'
01520 /// with the variables 'a' and 'b'.
01521 ///
01522 class OMPCopyinClause : public OMPVarListClause<OMPCopyinClause> {
01523   /// \brief Build clause with number of variables \a N.
01524   ///
01525   /// \param StartLoc Starting location of the clause.
01526   /// \param LParenLoc Location of '('.
01527   /// \param EndLoc Ending location of the clause.
01528   /// \param N Number of the variables in the clause.
01529   ///
01530   OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
01531                   SourceLocation EndLoc, unsigned N)
01532       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
01533                                           EndLoc, N) {}
01534 
01535   /// \brief Build an empty clause.
01536   ///
01537   /// \param N Number of variables.
01538   ///
01539   explicit OMPCopyinClause(unsigned N)
01540       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
01541                                           SourceLocation(), SourceLocation(),
01542                                           N) {}
01543 
01544 public:
01545   /// \brief Creates clause with a list of variables \a VL.
01546   ///
01547   /// \param C AST context.
01548   /// \param StartLoc Starting location of the clause.
01549   /// \param LParenLoc Location of '('.
01550   /// \param EndLoc Ending location of the clause.
01551   /// \param VL List of references to the variables.
01552   ///
01553   static OMPCopyinClause *Create(const ASTContext &C, SourceLocation StartLoc,
01554                                  SourceLocation LParenLoc,
01555                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
01556   /// \brief Creates an empty clause with \a N variables.
01557   ///
01558   /// \param C AST context.
01559   /// \param N The number of variables.
01560   ///
01561   static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
01562 
01563   StmtRange children() {
01564     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01565                      reinterpret_cast<Stmt **>(varlist_end()));
01566   }
01567 
01568   static bool classof(const OMPClause *T) {
01569     return T->getClauseKind() == OMPC_copyin;
01570   }
01571 };
01572 
01573 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
01574 /// directives.
01575 ///
01576 /// \code
01577 /// #pragma omp single copyprivate(a,b)
01578 /// \endcode
01579 /// In this example directive '#pragma omp single' has clause 'copyprivate'
01580 /// with the variables 'a' and 'b'.
01581 ///
01582 class OMPCopyprivateClause : public OMPVarListClause<OMPCopyprivateClause> {
01583   /// \brief Build clause with number of variables \a N.
01584   ///
01585   /// \param StartLoc Starting location of the clause.
01586   /// \param LParenLoc Location of '('.
01587   /// \param EndLoc Ending location of the clause.
01588   /// \param N Number of the variables in the clause.
01589   ///
01590   OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
01591                        SourceLocation EndLoc, unsigned N)
01592       : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
01593                                                LParenLoc, EndLoc, N) {}
01594 
01595   /// \brief Build an empty clause.
01596   ///
01597   /// \param N Number of variables.
01598   ///
01599   explicit OMPCopyprivateClause(unsigned N)
01600       : OMPVarListClause<OMPCopyprivateClause>(
01601             OMPC_copyprivate, SourceLocation(), SourceLocation(),
01602             SourceLocation(), N) {}
01603 
01604 public:
01605   /// \brief Creates clause with a list of variables \a VL.
01606   ///
01607   /// \param C AST context.
01608   /// \param StartLoc Starting location of the clause.
01609   /// \param LParenLoc Location of '('.
01610   /// \param EndLoc Ending location of the clause.
01611   /// \param VL List of references to the variables.
01612   ///
01613   static OMPCopyprivateClause *
01614   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
01615          SourceLocation EndLoc, ArrayRef<Expr *> VL);
01616   /// \brief Creates an empty clause with \a N variables.
01617   ///
01618   /// \param C AST context.
01619   /// \param N The number of variables.
01620   ///
01621   static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
01622 
01623   StmtRange children() {
01624     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01625                      reinterpret_cast<Stmt **>(varlist_end()));
01626   }
01627 
01628   static bool classof(const OMPClause *T) {
01629     return T->getClauseKind() == OMPC_copyprivate;
01630   }
01631 };
01632 
01633 /// \brief This represents implicit clause 'flush' for the '#pragma omp flush'
01634 /// directive.
01635 /// This clause does not exist by itself, it can be only as a part of 'omp
01636 /// flush' directive. This clause is introduced to keep the original structure
01637 /// of \a OMPExecutableDirective class and its derivatives and to use the
01638 /// existing infrastructure of clauses with the list of variables.
01639 ///
01640 /// \code
01641 /// #pragma omp flush(a,b)
01642 /// \endcode
01643 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
01644 /// with the variables 'a' and 'b'.
01645 ///
01646 class OMPFlushClause : public OMPVarListClause<OMPFlushClause> {
01647   /// \brief Build clause with number of variables \a N.
01648   ///
01649   /// \param StartLoc Starting location of the clause.
01650   /// \param LParenLoc Location of '('.
01651   /// \param EndLoc Ending location of the clause.
01652   /// \param N Number of the variables in the clause.
01653   ///
01654   OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
01655                  SourceLocation EndLoc, unsigned N)
01656       : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
01657                                          EndLoc, N) {}
01658 
01659   /// \brief Build an empty clause.
01660   ///
01661   /// \param N Number of variables.
01662   ///
01663   explicit OMPFlushClause(unsigned N)
01664       : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
01665                                          SourceLocation(), SourceLocation(),
01666                                          N) {}
01667 
01668 public:
01669   /// \brief Creates clause with a list of variables \a VL.
01670   ///
01671   /// \param C AST context.
01672   /// \param StartLoc Starting location of the clause.
01673   /// \param LParenLoc Location of '('.
01674   /// \param EndLoc Ending location of the clause.
01675   /// \param VL List of references to the variables.
01676   ///
01677   static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
01678                                 SourceLocation LParenLoc, SourceLocation EndLoc,
01679                                 ArrayRef<Expr *> VL);
01680   /// \brief Creates an empty clause with \a N variables.
01681   ///
01682   /// \param C AST context.
01683   /// \param N The number of variables.
01684   ///
01685   static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
01686 
01687   StmtRange children() {
01688     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
01689                      reinterpret_cast<Stmt **>(varlist_end()));
01690   }
01691 
01692   static bool classof(const OMPClause *T) {
01693     return T->getClauseKind() == OMPC_flush;
01694   }
01695 };
01696 
01697 } // end namespace clang
01698 
01699 #endif
01700