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, std::nullopt, VL.size(), L);
34 D->setVars(VL);
35 return D;
36}
37
38OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
39 unsigned ID,
40 unsigned N) {
41 return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(
42 C, ID, 0, 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// OMPAllocateDecl Implementation.
53//===----------------------------------------------------------------------===//
54
55void OMPAllocateDecl::anchor() { }
56
57OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
58 SourceLocation L, ArrayRef<Expr *> VL,
59 ArrayRef<OMPClause *> CL) {
60 auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>(
61 C, DC, Clauses: CL, NumChildren: VL.size(), P&: L);
62 D->setVars(VL);
63 return D;
64}
65
66OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
67 unsigned NVars,
68 unsigned NClauses) {
69 return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
70 C, ID, NumClauses: NClauses, NumChildren: NVars, P: SourceLocation());
71}
72
73void OMPAllocateDecl::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// OMPRequiresDecl Implementation.
81//===----------------------------------------------------------------------===//
82
83void OMPRequiresDecl::anchor() {}
84
85OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
86 SourceLocation L,
87 ArrayRef<OMPClause *> CL) {
88 return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, Clauses: CL, NumChildren: 0,
89 P&: L);
90}
91
92OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
93 unsigned N) {
94 return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
95 C, ID, NumClauses: N, NumChildren: 0, P: SourceLocation());
96}
97
98//===----------------------------------------------------------------------===//
99// OMPDeclareReductionDecl Implementation.
100//===----------------------------------------------------------------------===//
101
102OMPDeclareReductionDecl::OMPDeclareReductionDecl(
103 Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
104 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
105 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
106 PrevDeclInScope(PrevDeclInScope) {
107 setInitializer(E: nullptr, IK: OMPDeclareReductionInitKind::Call);
108}
109
110void OMPDeclareReductionDecl::anchor() {}
111
112OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
113 ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
114 QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
115 return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
116 T, PrevDeclInScope);
117}
118
119OMPDeclareReductionDecl *
120OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
121 return new (C, ID) OMPDeclareReductionDecl(
122 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
123 QualType(), /*PrevDeclInScope=*/nullptr);
124}
125
126OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
127 return cast_or_null<OMPDeclareReductionDecl>(
128 PrevDeclInScope.get(Source: getASTContext().getExternalSource()));
129}
130const OMPDeclareReductionDecl *
131OMPDeclareReductionDecl::getPrevDeclInScope() const {
132 return cast_or_null<OMPDeclareReductionDecl>(
133 PrevDeclInScope.get(Source: getASTContext().getExternalSource()));
134}
135
136//===----------------------------------------------------------------------===//
137// OMPDeclareMapperDecl Implementation.
138//===----------------------------------------------------------------------===//
139
140void OMPDeclareMapperDecl::anchor() {}
141
142OMPDeclareMapperDecl *OMPDeclareMapperDecl::Create(
143 ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
144 QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses,
145 OMPDeclareMapperDecl *PrevDeclInScope) {
146 return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(
147 C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope);
148}
149
150OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
151 unsigned ID,
152 unsigned N) {
153 return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(
154 C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(),
155 DeclarationName(), /*PrevDeclInScope=*/nullptr);
156}
157
158OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
159 return cast_or_null<OMPDeclareMapperDecl>(
160 PrevDeclInScope.get(Source: getASTContext().getExternalSource()));
161}
162
163const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
164 return cast_or_null<OMPDeclareMapperDecl>(
165 PrevDeclInScope.get(Source: getASTContext().getExternalSource()));
166}
167
168//===----------------------------------------------------------------------===//
169// OMPCapturedExprDecl Implementation.
170//===----------------------------------------------------------------------===//
171
172void OMPCapturedExprDecl::anchor() {}
173
174OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
175 IdentifierInfo *Id, QualType T,
176 SourceLocation StartLoc) {
177 return new (C, DC) OMPCapturedExprDecl(
178 C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
179}
180
181OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
182 unsigned ID) {
183 return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
184 /*TInfo=*/nullptr, SourceLocation());
185}
186
187SourceRange OMPCapturedExprDecl::getSourceRange() const {
188 assert(hasInit());
189 return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
190}
191

source code of clang/lib/AST/DeclOpenMP.cpp