DeclOpenMP.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
  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. /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
  11. /// classes.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #include "clang/AST/ASTContext.h"
  15. #include "clang/AST/Decl.h"
  16. #include "clang/AST/DeclBase.h"
  17. #include "clang/AST/DeclOpenMP.h"
  18. #include "clang/AST/Expr.h"
  19. using namespace clang;
  20. //===----------------------------------------------------------------------===//
  21. // OMPThreadPrivateDecl Implementation.
  22. //===----------------------------------------------------------------------===//
  23. void OMPThreadPrivateDecl::anchor() { }
  24. OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
  25. DeclContext *DC,
  26. SourceLocation L,
  27. ArrayRef<Expr *> VL) {
  28. OMPThreadPrivateDecl *D =
  29. new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
  30. OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
  31. D->NumVars = VL.size();
  32. D->setVars(VL);
  33. return D;
  34. }
  35. OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
  36. unsigned ID,
  37. unsigned N) {
  38. OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
  39. OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
  40. D->NumVars = N;
  41. return D;
  42. }
  43. void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
  44. assert(VL.size() == NumVars &&
  45. "Number of variables is not the same as the preallocated buffer");
  46. std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
  47. }
  48. //===----------------------------------------------------------------------===//
  49. // OMPRequiresDecl Implementation.
  50. //===----------------------------------------------------------------------===//
  51. void OMPRequiresDecl::anchor() {}
  52. OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
  53. SourceLocation L,
  54. ArrayRef<OMPClause *> CL) {
  55. OMPRequiresDecl *D =
  56. new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
  57. OMPRequiresDecl(OMPRequires, DC, L);
  58. D->NumClauses = CL.size();
  59. D->setClauses(CL);
  60. return D;
  61. }
  62. OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
  63. unsigned N) {
  64. OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
  65. OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
  66. D->NumClauses = N;
  67. return D;
  68. }
  69. void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
  70. assert(CL.size() == NumClauses &&
  71. "Number of clauses is not the same as the preallocated buffer");
  72. std::uninitialized_copy(CL.begin(), CL.end(),
  73. getTrailingObjects<OMPClause *>());
  74. }
  75. //===----------------------------------------------------------------------===//
  76. // OMPDeclareReductionDecl Implementation.
  77. //===----------------------------------------------------------------------===//
  78. OMPDeclareReductionDecl::OMPDeclareReductionDecl(
  79. Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
  80. QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
  81. : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
  82. PrevDeclInScope(PrevDeclInScope) {
  83. setInitializer(nullptr, CallInit);
  84. }
  85. void OMPDeclareReductionDecl::anchor() {}
  86. OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
  87. ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
  88. QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
  89. return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
  90. T, PrevDeclInScope);
  91. }
  92. OMPDeclareReductionDecl *
  93. OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
  94. return new (C, ID) OMPDeclareReductionDecl(
  95. OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
  96. QualType(), /*PrevDeclInScope=*/nullptr);
  97. }
  98. OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
  99. return cast_or_null<OMPDeclareReductionDecl>(
  100. PrevDeclInScope.get(getASTContext().getExternalSource()));
  101. }
  102. const OMPDeclareReductionDecl *
  103. OMPDeclareReductionDecl::getPrevDeclInScope() const {
  104. return cast_or_null<OMPDeclareReductionDecl>(
  105. PrevDeclInScope.get(getASTContext().getExternalSource()));
  106. }
  107. //===----------------------------------------------------------------------===//
  108. // OMPCapturedExprDecl Implementation.
  109. //===----------------------------------------------------------------------===//
  110. void OMPCapturedExprDecl::anchor() {}
  111. OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
  112. IdentifierInfo *Id, QualType T,
  113. SourceLocation StartLoc) {
  114. return new (C, DC) OMPCapturedExprDecl(
  115. C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
  116. }
  117. OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
  118. unsigned ID) {
  119. return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
  120. /*TInfo=*/nullptr, SourceLocation());
  121. }
  122. SourceRange OMPCapturedExprDecl::getSourceRange() const {
  123. assert(hasInit());
  124. return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
  125. }