1//===--- OpenMP.h - Classes for representing 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///
10/// \file
11/// \brief This file defines OpenMP nodes.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_OPENMP_H
16#define LLVM_CLANG_AST_OPENMP_H
17
18#include "clang/AST/DeclBase.h"
19#include "llvm/ADT/ArrayRef.h"
20
21namespace clang {
22
23class DeclRefExpr;
24
25/// \brief This represents '#pragma omp threadprivate ...' directive.
26/// For example, in the following, both 'a' and 'A::b' are threadprivate:
27///
28/// \code
29/// int a;
30/// #pragma omp threadprivate(a)
31/// struct A {
32///   static int b;
33/// #pragma omp threadprivate(b)
34/// };
35/// \endcode
36///
37class OMPThreadPrivateDecl : public Decl {
38  friend class ASTDeclReader;
39  unsigned NumVars;
40
41  virtual void anchor();
42
43  OMPThreadPrivateDecl(Kind DK, DeclContext *DC, SourceLocation L) :
44    Decl(DK, DC, L), NumVars(0) { }
45
46  ArrayRef<const DeclRefExpr *> getVars() const {
47    return ArrayRef<const DeclRefExpr *>(
48                   reinterpret_cast<const DeclRefExpr * const *>(this + 1),
49                   NumVars);
50  }
51
52  llvm::MutableArrayRef<DeclRefExpr *> getVars() {
53    return llvm::MutableArrayRef<DeclRefExpr *>(
54                                 reinterpret_cast<DeclRefExpr **>(this + 1),
55                                 NumVars);
56  }
57
58  void setVars(ArrayRef<DeclRefExpr *> VL);
59
60public:
61  static OMPThreadPrivateDecl *Create(ASTContext &C, DeclContext *DC,
62                                      SourceLocation L,
63                                      ArrayRef<DeclRefExpr *> VL);
64  static OMPThreadPrivateDecl *CreateDeserialized(ASTContext &C,
65                                                  unsigned ID, unsigned N);
66
67  typedef llvm::MutableArrayRef<DeclRefExpr *>::iterator varlist_iterator;
68  typedef ArrayRef<const DeclRefExpr *>::iterator varlist_const_iterator;
69
70  unsigned varlist_size() const { return NumVars; }
71  bool varlist_empty() const { return NumVars == 0; }
72  varlist_iterator varlist_begin() { return getVars().begin(); }
73  varlist_iterator varlist_end() { return getVars().end(); }
74  varlist_const_iterator varlist_begin() const { return getVars().begin(); }
75  varlist_const_iterator varlist_end() const { return getVars().end(); }
76
77  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
78  static bool classofKind(Kind K) { return K == OMPThreadPrivate; }
79};
80
81}  // end namespace clang
82
83#endif
84