1a769e072SAlexey Bataev //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
2a769e072SAlexey Bataev //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a769e072SAlexey Bataev //
7a769e072SAlexey Bataev //===----------------------------------------------------------------------===//
8a769e072SAlexey Bataev /// \file
99fc8faf9SAdrian Prantl /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
1090c228f0SAlexey Bataev /// classes.
11a769e072SAlexey Bataev ///
12a769e072SAlexey Bataev //===----------------------------------------------------------------------===//
13a769e072SAlexey Bataev
14a769e072SAlexey Bataev #include "clang/AST/ASTContext.h"
15a769e072SAlexey Bataev #include "clang/AST/Decl.h"
165553d0d4SChandler Carruth #include "clang/AST/DeclBase.h"
17a769e072SAlexey Bataev #include "clang/AST/DeclOpenMP.h"
18a769e072SAlexey Bataev #include "clang/AST/Expr.h"
19a769e072SAlexey Bataev
20a769e072SAlexey Bataev using namespace clang;
21a769e072SAlexey Bataev
22a769e072SAlexey Bataev //===----------------------------------------------------------------------===//
23a769e072SAlexey Bataev // OMPThreadPrivateDecl Implementation.
24a769e072SAlexey Bataev //===----------------------------------------------------------------------===//
25a769e072SAlexey Bataev
anchor()26a769e072SAlexey Bataev void OMPThreadPrivateDecl::anchor() {}
27a769e072SAlexey Bataev
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<Expr * > VL)28a769e072SAlexey Bataev OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
29a769e072SAlexey Bataev DeclContext *DC,
30a769e072SAlexey Bataev SourceLocation L,
316f6f3b4bSAlexey Bataev ArrayRef<Expr *> VL) {
32*0af7835eSAlexey Bataev auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
33*0af7835eSAlexey Bataev C, DC, llvm::None, VL.size(), L);
34a769e072SAlexey Bataev D->setVars(VL);
35a769e072SAlexey Bataev return D;
36a769e072SAlexey Bataev }
37a769e072SAlexey Bataev
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)38a769e072SAlexey Bataev OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
39a769e072SAlexey Bataev unsigned ID,
40a769e072SAlexey Bataev unsigned N) {
41*0af7835eSAlexey Bataev return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(
42*0af7835eSAlexey Bataev C, ID, 0, N);
43a769e072SAlexey Bataev }
44a769e072SAlexey Bataev
setVars(ArrayRef<Expr * > VL)456f6f3b4bSAlexey Bataev void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
46*0af7835eSAlexey Bataev assert(VL.size() == Data->getNumChildren() &&
47a769e072SAlexey Bataev "Number of variables is not the same as the preallocated buffer");
48*0af7835eSAlexey Bataev llvm::copy(VL, getVars().begin());
49a769e072SAlexey Bataev }
505ec3eb11SAlexey Bataev
5190c228f0SAlexey Bataev //===----------------------------------------------------------------------===//
5225ed0c07SAlexey Bataev // OMPAllocateDecl Implementation.
5325ed0c07SAlexey Bataev //===----------------------------------------------------------------------===//
5425ed0c07SAlexey Bataev
anchor()5525ed0c07SAlexey Bataev void OMPAllocateDecl::anchor() { }
5625ed0c07SAlexey Bataev
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<Expr * > VL,ArrayRef<OMPClause * > CL)5725ed0c07SAlexey Bataev OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
589cc10fc9SAlexey Bataev SourceLocation L, ArrayRef<Expr *> VL,
599cc10fc9SAlexey Bataev ArrayRef<OMPClause *> CL) {
60*0af7835eSAlexey Bataev auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>(
61*0af7835eSAlexey Bataev C, DC, CL, VL.size(), L);
6225ed0c07SAlexey Bataev D->setVars(VL);
6325ed0c07SAlexey Bataev return D;
6425ed0c07SAlexey Bataev }
6525ed0c07SAlexey Bataev
CreateDeserialized(ASTContext & C,unsigned ID,unsigned NVars,unsigned NClauses)6625ed0c07SAlexey Bataev OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
679cc10fc9SAlexey Bataev unsigned NVars,
689cc10fc9SAlexey Bataev unsigned NClauses) {
69*0af7835eSAlexey Bataev return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
70*0af7835eSAlexey Bataev C, ID, NClauses, NVars, SourceLocation());
7125ed0c07SAlexey Bataev }
7225ed0c07SAlexey Bataev
setVars(ArrayRef<Expr * > VL)7325ed0c07SAlexey Bataev void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
74*0af7835eSAlexey Bataev assert(VL.size() == Data->getNumChildren() &&
7525ed0c07SAlexey Bataev "Number of variables is not the same as the preallocated buffer");
76*0af7835eSAlexey Bataev llvm::copy(VL, getVars().begin());
779cc10fc9SAlexey Bataev }
789cc10fc9SAlexey Bataev
7925ed0c07SAlexey Bataev //===----------------------------------------------------------------------===//
801408f91aSKelvin Li // OMPRequiresDecl Implementation.
811408f91aSKelvin Li //===----------------------------------------------------------------------===//
821408f91aSKelvin Li
anchor()831408f91aSKelvin Li void OMPRequiresDecl::anchor() {}
841408f91aSKelvin Li
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<OMPClause * > CL)851408f91aSKelvin Li OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
861408f91aSKelvin Li SourceLocation L,
871408f91aSKelvin Li ArrayRef<OMPClause *> CL) {
88*0af7835eSAlexey Bataev return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0,
89*0af7835eSAlexey Bataev L);
901408f91aSKelvin Li }
911408f91aSKelvin Li
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)921408f91aSKelvin Li OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
931408f91aSKelvin Li unsigned N) {
94*0af7835eSAlexey Bataev return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
95*0af7835eSAlexey Bataev C, ID, N, 0, SourceLocation());
961408f91aSKelvin Li }
971408f91aSKelvin Li
981408f91aSKelvin Li //===----------------------------------------------------------------------===//
9994a4f0cbSAlexey Bataev // OMPDeclareReductionDecl Implementation.
10094a4f0cbSAlexey Bataev //===----------------------------------------------------------------------===//
10194a4f0cbSAlexey Bataev
OMPDeclareReductionDecl(Kind DK,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType Ty,OMPDeclareReductionDecl * PrevDeclInScope)102c9d2990bSErich Keane OMPDeclareReductionDecl::OMPDeclareReductionDecl(
103c9d2990bSErich Keane Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
104c9d2990bSErich Keane QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
105c9d2990bSErich Keane : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
106c9d2990bSErich Keane PrevDeclInScope(PrevDeclInScope) {
107c9d2990bSErich Keane setInitializer(nullptr, CallInit);
108c9d2990bSErich Keane }
109c9d2990bSErich Keane
anchor()11094a4f0cbSAlexey Bataev void OMPDeclareReductionDecl::anchor() {}
11194a4f0cbSAlexey Bataev
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType T,OMPDeclareReductionDecl * PrevDeclInScope)11294a4f0cbSAlexey Bataev OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
11394a4f0cbSAlexey Bataev ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
11494a4f0cbSAlexey Bataev QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
11594a4f0cbSAlexey Bataev return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
11694a4f0cbSAlexey Bataev T, PrevDeclInScope);
11794a4f0cbSAlexey Bataev }
11894a4f0cbSAlexey Bataev
11994a4f0cbSAlexey Bataev OMPDeclareReductionDecl *
CreateDeserialized(ASTContext & C,unsigned ID)12094a4f0cbSAlexey Bataev OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
12194a4f0cbSAlexey Bataev return new (C, ID) OMPDeclareReductionDecl(
12294a4f0cbSAlexey Bataev OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
12394a4f0cbSAlexey Bataev QualType(), /*PrevDeclInScope=*/nullptr);
12494a4f0cbSAlexey Bataev }
12594a4f0cbSAlexey Bataev
getPrevDeclInScope()12694a4f0cbSAlexey Bataev OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
12794a4f0cbSAlexey Bataev return cast_or_null<OMPDeclareReductionDecl>(
12894a4f0cbSAlexey Bataev PrevDeclInScope.get(getASTContext().getExternalSource()));
12994a4f0cbSAlexey Bataev }
13094a4f0cbSAlexey Bataev const OMPDeclareReductionDecl *
getPrevDeclInScope() const13194a4f0cbSAlexey Bataev OMPDeclareReductionDecl::getPrevDeclInScope() const {
13294a4f0cbSAlexey Bataev return cast_or_null<OMPDeclareReductionDecl>(
13394a4f0cbSAlexey Bataev PrevDeclInScope.get(getASTContext().getExternalSource()));
13494a4f0cbSAlexey Bataev }
13594a4f0cbSAlexey Bataev
13694a4f0cbSAlexey Bataev //===----------------------------------------------------------------------===//
137251e1488SMichael Kruse // OMPDeclareMapperDecl Implementation.
138251e1488SMichael Kruse //===----------------------------------------------------------------------===//
139251e1488SMichael Kruse
anchor()140251e1488SMichael Kruse void OMPDeclareMapperDecl::anchor() {}
141251e1488SMichael Kruse
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType T,DeclarationName VarName,ArrayRef<OMPClause * > Clauses,OMPDeclareMapperDecl * PrevDeclInScope)142*0af7835eSAlexey Bataev OMPDeclareMapperDecl *OMPDeclareMapperDecl::Create(
143*0af7835eSAlexey Bataev ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
144*0af7835eSAlexey Bataev QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses,
145251e1488SMichael Kruse OMPDeclareMapperDecl *PrevDeclInScope) {
146*0af7835eSAlexey Bataev return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(
147*0af7835eSAlexey Bataev C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope);
148251e1488SMichael Kruse }
149251e1488SMichael Kruse
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)150251e1488SMichael Kruse OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
151251e1488SMichael Kruse unsigned ID,
152251e1488SMichael Kruse unsigned N) {
153*0af7835eSAlexey Bataev return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(
154*0af7835eSAlexey Bataev C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(),
155*0af7835eSAlexey Bataev DeclarationName(), /*PrevDeclInScope=*/nullptr);
156251e1488SMichael Kruse }
157251e1488SMichael Kruse
getPrevDeclInScope()158de9ffab1SEric Fiselier OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
159de9ffab1SEric Fiselier return cast_or_null<OMPDeclareMapperDecl>(
160de9ffab1SEric Fiselier PrevDeclInScope.get(getASTContext().getExternalSource()));
161de9ffab1SEric Fiselier }
162de9ffab1SEric Fiselier
getPrevDeclInScope() const163de9ffab1SEric Fiselier const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
164de9ffab1SEric Fiselier return cast_or_null<OMPDeclareMapperDecl>(
165de9ffab1SEric Fiselier PrevDeclInScope.get(getASTContext().getExternalSource()));
166de9ffab1SEric Fiselier }
167de9ffab1SEric Fiselier
168251e1488SMichael Kruse //===----------------------------------------------------------------------===//
1694244be25SAlexey Bataev // OMPCapturedExprDecl Implementation.
17090c228f0SAlexey Bataev //===----------------------------------------------------------------------===//
17190c228f0SAlexey Bataev
anchor()1724244be25SAlexey Bataev void OMPCapturedExprDecl::anchor() {}
17390c228f0SAlexey Bataev
Create(ASTContext & C,DeclContext * DC,IdentifierInfo * Id,QualType T,SourceLocation StartLoc)1744244be25SAlexey Bataev OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
175a7206b9eSAlexey Bataev IdentifierInfo *Id, QualType T,
176a7206b9eSAlexey Bataev SourceLocation StartLoc) {
177ed6bc342SErich Keane return new (C, DC) OMPCapturedExprDecl(
178ed6bc342SErich Keane C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
17990c228f0SAlexey Bataev }
18090c228f0SAlexey Bataev
CreateDeserialized(ASTContext & C,unsigned ID)1814244be25SAlexey Bataev OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
18290c228f0SAlexey Bataev unsigned ID) {
183ed6bc342SErich Keane return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
184ed6bc342SErich Keane /*TInfo=*/nullptr, SourceLocation());
18590c228f0SAlexey Bataev }
18690c228f0SAlexey Bataev
getSourceRange() const187a7206b9eSAlexey Bataev SourceRange OMPCapturedExprDecl::getSourceRange() const {
188a7206b9eSAlexey Bataev assert(hasInit());
1891c301dcbSStephen Kelly return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
190a7206b9eSAlexey Bataev }
191