1 //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
13 //===----------------------------------------------------------------------===//
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclBase.h"
18 #include "clang/AST/DeclOpenMP.h"
19 #include "clang/AST/Expr.h"
21 using namespace clang;
23 //===----------------------------------------------------------------------===//
24 // OMPThreadPrivateDecl Implementation.
25 //===----------------------------------------------------------------------===//
27 void OMPThreadPrivateDecl::anchor() { }
29 OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
32 ArrayRef<Expr *> VL) {
33 OMPThreadPrivateDecl *D =
34 new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
35 OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
36 D->NumVars = VL.size();
41 OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
44 OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
45 OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
50 void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
51 assert(VL.size() == NumVars &&
52 "Number of variables is not the same as the preallocated buffer");
53 std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
56 //===----------------------------------------------------------------------===//
57 // OMPRequiresDecl Implementation.
58 //===----------------------------------------------------------------------===//
60 void OMPRequiresDecl::anchor() {}
62 OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
64 ArrayRef<OMPClause *> CL) {
66 new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
67 OMPRequiresDecl(OMPRequires, DC, L);
68 D->NumClauses = CL.size();
73 OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
75 OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
76 OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
81 void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
82 assert(CL.size() == NumClauses &&
83 "Number of clauses is not the same as the preallocated buffer");
84 std::uninitialized_copy(CL.begin(), CL.end(),
85 getTrailingObjects<OMPClause *>());
88 //===----------------------------------------------------------------------===//
89 // OMPDeclareReductionDecl Implementation.
90 //===----------------------------------------------------------------------===//
92 OMPDeclareReductionDecl::OMPDeclareReductionDecl(
93 Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
94 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
95 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
96 PrevDeclInScope(PrevDeclInScope) {
97 setInitializer(nullptr, CallInit);
100 void OMPDeclareReductionDecl::anchor() {}
102 OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
103 ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
104 QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
105 return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
109 OMPDeclareReductionDecl *
110 OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
111 return new (C, ID) OMPDeclareReductionDecl(
112 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
113 QualType(), /*PrevDeclInScope=*/nullptr);
116 OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
117 return cast_or_null<OMPDeclareReductionDecl>(
118 PrevDeclInScope.get(getASTContext().getExternalSource()));
120 const OMPDeclareReductionDecl *
121 OMPDeclareReductionDecl::getPrevDeclInScope() const {
122 return cast_or_null<OMPDeclareReductionDecl>(
123 PrevDeclInScope.get(getASTContext().getExternalSource()));
126 //===----------------------------------------------------------------------===//
127 // OMPCapturedExprDecl Implementation.
128 //===----------------------------------------------------------------------===//
130 void OMPCapturedExprDecl::anchor() {}
132 OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
133 IdentifierInfo *Id, QualType T,
134 SourceLocation StartLoc) {
135 return new (C, DC) OMPCapturedExprDecl(
136 C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
139 OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
141 return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
142 /*TInfo=*/nullptr, SourceLocation());
145 SourceRange OMPCapturedExprDecl::getSourceRange() const {
147 return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());