Debian Codegraph @

clang/lib/AST/DeclOpenMP.cpp

raw
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
20 using namespace clang;
21
22 //===----------------------------------------------------------------------===//
23 // OMPThreadPrivateDecl Implementation.
24 //===----------------------------------------------------------------------===//
25
26 void OMPThreadPrivateDecl::anchor() {}
27
28 OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
29 DeclContext *DC,
30 SourceLocation L,
31 ArrayRef<Expr *> VL) {
32 auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
33 C, DC, {}, VL.size(), L);
34 D->setVars(VL);
35 return D;
36 }
37
38 OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
39 GlobalDeclID ID,
40 unsigned N) {
41 return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(
42 C, ID, 0, N);
43 }
44
45 void 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(VL, getVars().begin());
49 }
50
51 //===----------------------------------------------------------------------===//
52 // OMPGroupPrivateDecl Implementation.
53 //===----------------------------------------------------------------------===//
54
55 void OMPGroupPrivateDecl::anchor() {}
56
57 OMPGroupPrivateDecl *OMPGroupPrivateDecl::Create(ASTContext &C, DeclContext *DC,
58 SourceLocation L,
59 ArrayRef<Expr *> VL) {
60 auto *D = OMPDeclarativeDirective::createDirective<OMPGroupPrivateDecl>(
61 C, DC, {}, VL.size(), L);
62 D->setVars(VL);
63 return D;
64 }
65
66 OMPGroupPrivateDecl *OMPGroupPrivateDecl::CreateDeserialized(ASTContext &C,
67 GlobalDeclID ID,
68 unsigned N) {
69 return OMPDeclarativeDirective::createEmptyDirective<OMPGroupPrivateDecl>(
70 C, ID, 0, N);
71 }
72
73 void 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(VL, getVars().begin());
77 }
78
79 //===----------------------------------------------------------------------===//
80 // OMPAllocateDecl Implementation.
81 //===----------------------------------------------------------------------===//
82
83 void OMPAllocateDecl::anchor() { }
84
85 OMPAllocateDecl *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, CL, VL.size(), L);
90 D->setVars(VL);
91 return D;
92 }
93
94 OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C,
95 GlobalDeclID ID,
96 unsigned NVars,
97 unsigned NClauses) {
98 return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
99 C, ID, NClauses, NVars, SourceLocation());
100 }
101
102 void 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(VL, getVars().begin());
106 }
107
108 //===----------------------------------------------------------------------===//
109 // OMPRequiresDecl Implementation.
110 //===----------------------------------------------------------------------===//
111
112 void OMPRequiresDecl::anchor() {}
113
114 OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
115 SourceLocation L,
116 ArrayRef<OMPClause *> CL) {
117 return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0,
118 L);
119 }
120
121 OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C,
122 GlobalDeclID ID,
123 unsigned N) {
124 return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
125 C, ID, N, 0, SourceLocation());
126 }
127
128 //===----------------------------------------------------------------------===//
129 // OMPDeclareReductionDecl Implementation.
130 //===----------------------------------------------------------------------===//
131
132 OMPDeclareReductionDecl::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(nullptr, OMPDeclareReductionInitKind::Call);
138 }
139
140 void OMPDeclareReductionDecl::anchor() {}
141
142 OMPDeclareReductionDecl *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
149 OMPDeclareReductionDecl *
150 OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
151 return new (C, ID) OMPDeclareReductionDecl(
152 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
153 QualType(), /*PrevDeclInScope=*/nullptr);
154 }
155
156 OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
157 return cast_or_null<OMPDeclareReductionDecl>(
158 PrevDeclInScope.get(getASTContext().getExternalSource()));
159 }
160 const OMPDeclareReductionDecl *
161 OMPDeclareReductionDecl::getPrevDeclInScope() const {
162 return cast_or_null<OMPDeclareReductionDecl>(
163 PrevDeclInScope.get(getASTContext().getExternalSource()));
164 }
165
166 //===----------------------------------------------------------------------===//
167 // OMPDeclareMapperDecl Implementation.
168 //===----------------------------------------------------------------------===//
169
170 void OMPDeclareMapperDecl::anchor() {}
171
172 OMPDeclareMapperDecl *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, 1, L, Name, T, VarName, PrevDeclInScope);
178 }
179
180 OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
181 GlobalDeclID ID,
182 unsigned N) {
183 return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(
184 C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(),
185 DeclarationName(), /*PrevDeclInScope=*/nullptr);
186 }
187
188 OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
189 return cast_or_null<OMPDeclareMapperDecl>(
190 PrevDeclInScope.get(getASTContext().getExternalSource()));
191 }
192
193 const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
194 return cast_or_null<OMPDeclareMapperDecl>(
195 PrevDeclInScope.get(getASTContext().getExternalSource()));
196 }
197
198 //===----------------------------------------------------------------------===//
199 // OMPCapturedExprDecl Implementation.
200 //===----------------------------------------------------------------------===//
201
202 void OMPCapturedExprDecl::anchor() {}
203
204 OMPCapturedExprDecl *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
211 OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
212 GlobalDeclID ID) {
213 return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
214 /*TInfo=*/nullptr, SourceLocation());
215 }
216
217 SourceRange OMPCapturedExprDecl::getSourceRange() const {
218 assert(hasInit());
219 return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
220 }