10b57cec5SDimitry Andric //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric /// \file
90b57cec5SDimitry Andric /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
100b57cec5SDimitry Andric /// classes.
110b57cec5SDimitry Andric ///
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric
140b57cec5SDimitry Andric #include "clang/AST/ASTContext.h"
150b57cec5SDimitry Andric #include "clang/AST/Decl.h"
160b57cec5SDimitry Andric #include "clang/AST/DeclBase.h"
170b57cec5SDimitry Andric #include "clang/AST/DeclOpenMP.h"
180b57cec5SDimitry Andric #include "clang/AST/Expr.h"
190b57cec5SDimitry Andric
200b57cec5SDimitry Andric using namespace clang;
210b57cec5SDimitry Andric
220b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
230b57cec5SDimitry Andric // OMPThreadPrivateDecl Implementation.
240b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
250b57cec5SDimitry Andric
anchor()260b57cec5SDimitry Andric void OMPThreadPrivateDecl::anchor() {}
270b57cec5SDimitry Andric
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<Expr * > VL)280b57cec5SDimitry Andric OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
290b57cec5SDimitry Andric DeclContext *DC,
300b57cec5SDimitry Andric SourceLocation L,
310b57cec5SDimitry Andric ArrayRef<Expr *> VL) {
32*af732203SDimitry Andric auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
33*af732203SDimitry Andric C, DC, llvm::None, VL.size(), L);
340b57cec5SDimitry Andric D->setVars(VL);
350b57cec5SDimitry Andric return D;
360b57cec5SDimitry Andric }
370b57cec5SDimitry Andric
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)380b57cec5SDimitry Andric OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
390b57cec5SDimitry Andric unsigned ID,
400b57cec5SDimitry Andric unsigned N) {
41*af732203SDimitry Andric return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(
42*af732203SDimitry Andric C, ID, 0, N);
430b57cec5SDimitry Andric }
440b57cec5SDimitry Andric
setVars(ArrayRef<Expr * > VL)450b57cec5SDimitry Andric void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
46*af732203SDimitry Andric assert(VL.size() == Data->getNumChildren() &&
470b57cec5SDimitry Andric "Number of variables is not the same as the preallocated buffer");
48*af732203SDimitry Andric llvm::copy(VL, getVars().begin());
490b57cec5SDimitry Andric }
500b57cec5SDimitry Andric
510b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
520b57cec5SDimitry Andric // OMPAllocateDecl Implementation.
530b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
540b57cec5SDimitry Andric
anchor()550b57cec5SDimitry Andric void OMPAllocateDecl::anchor() { }
560b57cec5SDimitry Andric
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<Expr * > VL,ArrayRef<OMPClause * > CL)570b57cec5SDimitry Andric OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
580b57cec5SDimitry Andric SourceLocation L, ArrayRef<Expr *> VL,
590b57cec5SDimitry Andric ArrayRef<OMPClause *> CL) {
60*af732203SDimitry Andric auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>(
61*af732203SDimitry Andric C, DC, CL, VL.size(), L);
620b57cec5SDimitry Andric D->setVars(VL);
630b57cec5SDimitry Andric return D;
640b57cec5SDimitry Andric }
650b57cec5SDimitry Andric
CreateDeserialized(ASTContext & C,unsigned ID,unsigned NVars,unsigned NClauses)660b57cec5SDimitry Andric OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
670b57cec5SDimitry Andric unsigned NVars,
680b57cec5SDimitry Andric unsigned NClauses) {
69*af732203SDimitry Andric return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
70*af732203SDimitry Andric C, ID, NClauses, NVars, SourceLocation());
710b57cec5SDimitry Andric }
720b57cec5SDimitry Andric
setVars(ArrayRef<Expr * > VL)730b57cec5SDimitry Andric void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
74*af732203SDimitry Andric assert(VL.size() == Data->getNumChildren() &&
750b57cec5SDimitry Andric "Number of variables is not the same as the preallocated buffer");
76*af732203SDimitry Andric llvm::copy(VL, getVars().begin());
770b57cec5SDimitry Andric }
780b57cec5SDimitry Andric
790b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
800b57cec5SDimitry Andric // OMPRequiresDecl Implementation.
810b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
820b57cec5SDimitry Andric
anchor()830b57cec5SDimitry Andric void OMPRequiresDecl::anchor() {}
840b57cec5SDimitry Andric
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<OMPClause * > CL)850b57cec5SDimitry Andric OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
860b57cec5SDimitry Andric SourceLocation L,
870b57cec5SDimitry Andric ArrayRef<OMPClause *> CL) {
88*af732203SDimitry Andric return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0,
89*af732203SDimitry Andric L);
900b57cec5SDimitry Andric }
910b57cec5SDimitry Andric
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)920b57cec5SDimitry Andric OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
930b57cec5SDimitry Andric unsigned N) {
94*af732203SDimitry Andric return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
95*af732203SDimitry Andric C, ID, N, 0, SourceLocation());
960b57cec5SDimitry Andric }
970b57cec5SDimitry Andric
980b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
990b57cec5SDimitry Andric // OMPDeclareReductionDecl Implementation.
1000b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
1010b57cec5SDimitry Andric
OMPDeclareReductionDecl(Kind DK,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType Ty,OMPDeclareReductionDecl * PrevDeclInScope)1020b57cec5SDimitry Andric OMPDeclareReductionDecl::OMPDeclareReductionDecl(
1030b57cec5SDimitry Andric Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
1040b57cec5SDimitry Andric QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
1050b57cec5SDimitry Andric : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
1060b57cec5SDimitry Andric PrevDeclInScope(PrevDeclInScope) {
1070b57cec5SDimitry Andric setInitializer(nullptr, CallInit);
1080b57cec5SDimitry Andric }
1090b57cec5SDimitry Andric
anchor()1100b57cec5SDimitry Andric void OMPDeclareReductionDecl::anchor() {}
1110b57cec5SDimitry Andric
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType T,OMPDeclareReductionDecl * PrevDeclInScope)1120b57cec5SDimitry Andric OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
1130b57cec5SDimitry Andric ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
1140b57cec5SDimitry Andric QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
1150b57cec5SDimitry Andric return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
1160b57cec5SDimitry Andric T, PrevDeclInScope);
1170b57cec5SDimitry Andric }
1180b57cec5SDimitry Andric
1190b57cec5SDimitry Andric OMPDeclareReductionDecl *
CreateDeserialized(ASTContext & C,unsigned ID)1200b57cec5SDimitry Andric OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1210b57cec5SDimitry Andric return new (C, ID) OMPDeclareReductionDecl(
1220b57cec5SDimitry Andric OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
1230b57cec5SDimitry Andric QualType(), /*PrevDeclInScope=*/nullptr);
1240b57cec5SDimitry Andric }
1250b57cec5SDimitry Andric
getPrevDeclInScope()1260b57cec5SDimitry Andric OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
1270b57cec5SDimitry Andric return cast_or_null<OMPDeclareReductionDecl>(
1280b57cec5SDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource()));
1290b57cec5SDimitry Andric }
1300b57cec5SDimitry Andric const OMPDeclareReductionDecl *
getPrevDeclInScope() const1310b57cec5SDimitry Andric OMPDeclareReductionDecl::getPrevDeclInScope() const {
1320b57cec5SDimitry Andric return cast_or_null<OMPDeclareReductionDecl>(
1330b57cec5SDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource()));
1340b57cec5SDimitry Andric }
1350b57cec5SDimitry Andric
1360b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
1370b57cec5SDimitry Andric // OMPDeclareMapperDecl Implementation.
1380b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
1390b57cec5SDimitry Andric
anchor()1400b57cec5SDimitry Andric void OMPDeclareMapperDecl::anchor() {}
1410b57cec5SDimitry Andric
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType T,DeclarationName VarName,ArrayRef<OMPClause * > Clauses,OMPDeclareMapperDecl * PrevDeclInScope)142*af732203SDimitry Andric OMPDeclareMapperDecl *OMPDeclareMapperDecl::Create(
143*af732203SDimitry Andric ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
144*af732203SDimitry Andric QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses,
1450b57cec5SDimitry Andric OMPDeclareMapperDecl *PrevDeclInScope) {
146*af732203SDimitry Andric return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(
147*af732203SDimitry Andric C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope);
1480b57cec5SDimitry Andric }
1490b57cec5SDimitry Andric
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)1500b57cec5SDimitry Andric OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
1510b57cec5SDimitry Andric unsigned ID,
1520b57cec5SDimitry Andric unsigned N) {
153*af732203SDimitry Andric return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(
154*af732203SDimitry Andric C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(),
155*af732203SDimitry Andric DeclarationName(), /*PrevDeclInScope=*/nullptr);
1560b57cec5SDimitry Andric }
1570b57cec5SDimitry Andric
getPrevDeclInScope()1580b57cec5SDimitry Andric OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
1590b57cec5SDimitry Andric return cast_or_null<OMPDeclareMapperDecl>(
1600b57cec5SDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource()));
1610b57cec5SDimitry Andric }
1620b57cec5SDimitry Andric
getPrevDeclInScope() const1630b57cec5SDimitry Andric const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
1640b57cec5SDimitry Andric return cast_or_null<OMPDeclareMapperDecl>(
1650b57cec5SDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource()));
1660b57cec5SDimitry Andric }
1670b57cec5SDimitry Andric
1680b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
1690b57cec5SDimitry Andric // OMPCapturedExprDecl Implementation.
1700b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
1710b57cec5SDimitry Andric
anchor()1720b57cec5SDimitry Andric void OMPCapturedExprDecl::anchor() {}
1730b57cec5SDimitry Andric
Create(ASTContext & C,DeclContext * DC,IdentifierInfo * Id,QualType T,SourceLocation StartLoc)1740b57cec5SDimitry Andric OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
1750b57cec5SDimitry Andric IdentifierInfo *Id, QualType T,
1760b57cec5SDimitry Andric SourceLocation StartLoc) {
1770b57cec5SDimitry Andric return new (C, DC) OMPCapturedExprDecl(
1780b57cec5SDimitry Andric C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
1790b57cec5SDimitry Andric }
1800b57cec5SDimitry Andric
CreateDeserialized(ASTContext & C,unsigned ID)1810b57cec5SDimitry Andric OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
1820b57cec5SDimitry Andric unsigned ID) {
1830b57cec5SDimitry Andric return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
1840b57cec5SDimitry Andric /*TInfo=*/nullptr, SourceLocation());
1850b57cec5SDimitry Andric }
1860b57cec5SDimitry Andric
getSourceRange() const1870b57cec5SDimitry Andric SourceRange OMPCapturedExprDecl::getSourceRange() const {
1880b57cec5SDimitry Andric assert(hasInit());
1890b57cec5SDimitry Andric return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
1900b57cec5SDimitry Andric }
191