1//===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
10/// classes.
11///
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
20using namespace clang;
21
22//===----------------------------------------------------------------------===//
23// OMPThreadPrivateDecl Implementation.
24//===----------------------------------------------------------------------===//
25
26void OMPThreadPrivateDecl::anchor() {}
27
28OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
29 DeclContext *DC,
30 SourceLocation L,
31 ArrayRef<Expr *> VL) {
32 auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
33 C, DC, Clauses: {}, NumChildren: VL.size(), P&: L);
34 D->setVars(VL);
35 return D;
36}
37
38OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
39 GlobalDeclID ID,
40 unsigned N) {
41 return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(
42 C, ID, NumClauses: 0, NumChildren: N);
43}
44
45void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
46 assert(VL.size() == Data->getNumChildren() &&
47 "Number of variables is not the same as the preallocated buffer");
48 llvm::copy(Range&: VL, Out: getVars().begin());
49}
50
51//===----------------------------------------------------------------------===//
52// OMPGroupPrivateDecl Implementation.
53//===----------------------------------------------------------------------===//
54
55void OMPGroupPrivateDecl::anchor() {}
56
57OMPGroupPrivateDecl *OMPGroupPrivateDecl::Create(ASTContext &C, DeclContext *DC,
58 SourceLocation L,
59 ArrayRef<Expr *> VL) {
60 auto *D = OMPDeclarativeDirective::createDirective<OMPGroupPrivateDecl>(
61 C, DC, Clauses: {}, NumChildren: VL.size(), P&: L);
62 D->setVars(VL);
63 return D;
64}
65
66OMPGroupPrivateDecl *OMPGroupPrivateDecl::CreateDeserialized(ASTContext &C,
67 GlobalDeclID ID,
68 unsigned N) {
69 return OMPDeclarativeDirective::createEmptyDirective<OMPGroupPrivateDecl>(
70 C, ID, NumClauses: 0, NumChildren: N);
71}
72
73void OMPGroupPrivateDecl::setVars(ArrayRef<Expr *> VL) {
74 assert(VL.size() == Data->getNumChildren() &&
75 "Number of variables is not the same as the preallocated buffer");
76 llvm::copy(Range&: VL, Out: getVars().begin());
77}
78
79//===----------------------------------------------------------------------===//
80// OMPAllocateDecl Implementation.
81//===----------------------------------------------------------------------===//
82
83void OMPAllocateDecl::anchor() { }
84
85OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
86 SourceLocation L, ArrayRef<Expr *> VL,
87 ArrayRef<OMPClause *> CL) {
88 auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>(
89 C, DC, Clauses: CL, NumChildren: VL.size(), P&: L);
90 D->setVars(VL);
91 return D;
92}
93
94OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C,
95 GlobalDeclID ID,
96 unsigned NVars,
97 unsigned NClauses) {
98 return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
99 C, ID, NumClauses: NClauses, NumChildren: NVars, P: SourceLocation());
100}
101
102void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
103 assert(VL.size() == Data->getNumChildren() &&
104 "Number of variables is not the same as the preallocated buffer");
105 llvm::copy(Range&: VL, Out: getVars().begin());
106}
107
108//===----------------------------------------------------------------------===//
109// OMPRequiresDecl Implementation.
110//===----------------------------------------------------------------------===//
111
112void OMPRequiresDecl::anchor() {}
113
114OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
115 SourceLocation L,
116 ArrayRef<OMPClause *> CL) {
117 return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, Clauses: CL, NumChildren: 0,
118 P&: L);
119}
120
121OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C,
122 GlobalDeclID ID,
123 unsigned N) {
124 return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
125 C, ID, NumClauses: N, NumChildren: 0, P: SourceLocation());
126}
127
128//===----------------------------------------------------------------------===//
129// OMPDeclareReductionDecl Implementation.
130//===----------------------------------------------------------------------===//
131
132OMPDeclareReductionDecl::OMPDeclareReductionDecl(
133 Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
134 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
135 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
136 PrevDeclInScope(PrevDeclInScope) {
137 setInitializer(E: nullptr, IK: OMPDeclareReductionInitKind::Call);
138}
139
140void OMPDeclareReductionDecl::anchor() {}
141
142OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
143 ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
144 QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
145 return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
146 T, PrevDeclInScope);
147}
148
149OMPDeclareReductionDecl *
150OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
151 return new (C, ID) OMPDeclareReductionDecl(
152 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
153 QualType(), /*PrevDeclInScope=*/nullptr);
154}
155
156OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
157 return cast_or_null<OMPDeclareReductionDecl>(
158 Val: PrevDeclInScope.get(Source: getASTContext().getExternalSource()));
159}
160const OMPDeclareReductionDecl *
161OMPDeclareReductionDecl::getPrevDeclInScope() const {
162 return cast_or_null<OMPDeclareReductionDecl>(
163 Val: PrevDeclInScope.get(Source: getASTContext().getExternalSource()));
164}
165
166//===----------------------------------------------------------------------===//
167// OMPDeclareMapperDecl Implementation.
168//===----------------------------------------------------------------------===//
169
170void OMPDeclareMapperDecl::anchor() {}
171
172OMPDeclareMapperDecl *OMPDeclareMapperDecl::Create(
173 ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
174 QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses,
175 OMPDeclareMapperDecl *PrevDeclInScope) {
176 return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(
177 C, DC, Clauses, NumChildren: 1, P&: L, P&: Name, P&: T, P&: VarName, P&: PrevDeclInScope);
178}
179
180OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
181 GlobalDeclID ID,
182 unsigned N) {
183 return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(
184 C, ID, NumClauses: N, NumChildren: 1, P: SourceLocation(), P: DeclarationName(), P: QualType(),
185 P: DeclarationName(), /*PrevDeclInScope=*/P: nullptr);
186}
187
188OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
189 return cast_or_null<OMPDeclareMapperDecl>(
190 Val: PrevDeclInScope.get(Source: getASTContext().getExternalSource()));
191}
192
193const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
194 return cast_or_null<OMPDeclareMapperDecl>(
195 Val: PrevDeclInScope.get(Source: getASTContext().getExternalSource()));
196}
197
198//===----------------------------------------------------------------------===//
199// OMPCapturedExprDecl Implementation.
200//===----------------------------------------------------------------------===//
201
202void OMPCapturedExprDecl::anchor() {}
203
204OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
205 IdentifierInfo *Id, QualType T,
206 SourceLocation StartLoc) {
207 return new (C, DC) OMPCapturedExprDecl(
208 C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
209}
210
211OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
212 GlobalDeclID ID) {
213 return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
214 /*TInfo=*/nullptr, SourceLocation());
215}
216
217SourceRange OMPCapturedExprDecl::getSourceRange() const {
218 assert(hasInit());
219 return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
220}
221