xref: /netbsd-src/external/apache2/llvm/dist/clang/lib/AST/DeclOpenMP.cpp (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
17330f729Sjoerg //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg /// \file
97330f729Sjoerg /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
107330f729Sjoerg /// classes.
117330f729Sjoerg ///
127330f729Sjoerg //===----------------------------------------------------------------------===//
137330f729Sjoerg 
147330f729Sjoerg #include "clang/AST/ASTContext.h"
157330f729Sjoerg #include "clang/AST/Decl.h"
167330f729Sjoerg #include "clang/AST/DeclBase.h"
177330f729Sjoerg #include "clang/AST/DeclOpenMP.h"
187330f729Sjoerg #include "clang/AST/Expr.h"
197330f729Sjoerg 
207330f729Sjoerg using namespace clang;
217330f729Sjoerg 
227330f729Sjoerg //===----------------------------------------------------------------------===//
237330f729Sjoerg // OMPThreadPrivateDecl Implementation.
247330f729Sjoerg //===----------------------------------------------------------------------===//
257330f729Sjoerg 
anchor()267330f729Sjoerg void OMPThreadPrivateDecl::anchor() {}
277330f729Sjoerg 
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<Expr * > VL)287330f729Sjoerg OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
297330f729Sjoerg                                                    DeclContext *DC,
307330f729Sjoerg                                                    SourceLocation L,
317330f729Sjoerg                                                    ArrayRef<Expr *> VL) {
32*e038c9c4Sjoerg   auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
33*e038c9c4Sjoerg       C, DC, llvm::None, VL.size(), L);
347330f729Sjoerg   D->setVars(VL);
357330f729Sjoerg   return D;
367330f729Sjoerg }
377330f729Sjoerg 
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)387330f729Sjoerg OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
397330f729Sjoerg                                                                unsigned ID,
407330f729Sjoerg                                                                unsigned N) {
41*e038c9c4Sjoerg   return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(
42*e038c9c4Sjoerg       C, ID, 0, N);
437330f729Sjoerg }
447330f729Sjoerg 
setVars(ArrayRef<Expr * > VL)457330f729Sjoerg void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
46*e038c9c4Sjoerg   assert(VL.size() == Data->getNumChildren() &&
477330f729Sjoerg          "Number of variables is not the same as the preallocated buffer");
48*e038c9c4Sjoerg   llvm::copy(VL, getVars().begin());
497330f729Sjoerg }
507330f729Sjoerg 
517330f729Sjoerg //===----------------------------------------------------------------------===//
527330f729Sjoerg // OMPAllocateDecl Implementation.
537330f729Sjoerg //===----------------------------------------------------------------------===//
547330f729Sjoerg 
anchor()557330f729Sjoerg void OMPAllocateDecl::anchor() { }
567330f729Sjoerg 
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<Expr * > VL,ArrayRef<OMPClause * > CL)577330f729Sjoerg OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
587330f729Sjoerg                                          SourceLocation L, ArrayRef<Expr *> VL,
597330f729Sjoerg                                          ArrayRef<OMPClause *> CL) {
60*e038c9c4Sjoerg   auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>(
61*e038c9c4Sjoerg       C, DC, CL, VL.size(), L);
627330f729Sjoerg   D->setVars(VL);
637330f729Sjoerg   return D;
647330f729Sjoerg }
657330f729Sjoerg 
CreateDeserialized(ASTContext & C,unsigned ID,unsigned NVars,unsigned NClauses)667330f729Sjoerg OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
677330f729Sjoerg                                                      unsigned NVars,
687330f729Sjoerg                                                      unsigned NClauses) {
69*e038c9c4Sjoerg   return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
70*e038c9c4Sjoerg       C, ID, NClauses, NVars, SourceLocation());
717330f729Sjoerg }
727330f729Sjoerg 
setVars(ArrayRef<Expr * > VL)737330f729Sjoerg void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
74*e038c9c4Sjoerg   assert(VL.size() == Data->getNumChildren() &&
757330f729Sjoerg          "Number of variables is not the same as the preallocated buffer");
76*e038c9c4Sjoerg   llvm::copy(VL, getVars().begin());
777330f729Sjoerg }
787330f729Sjoerg 
797330f729Sjoerg //===----------------------------------------------------------------------===//
807330f729Sjoerg // OMPRequiresDecl Implementation.
817330f729Sjoerg //===----------------------------------------------------------------------===//
827330f729Sjoerg 
anchor()837330f729Sjoerg void OMPRequiresDecl::anchor() {}
847330f729Sjoerg 
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<OMPClause * > CL)857330f729Sjoerg OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
867330f729Sjoerg                                          SourceLocation L,
877330f729Sjoerg                                          ArrayRef<OMPClause *> CL) {
88*e038c9c4Sjoerg   return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0,
89*e038c9c4Sjoerg                                                                    L);
907330f729Sjoerg }
917330f729Sjoerg 
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)927330f729Sjoerg OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
937330f729Sjoerg                                                      unsigned N) {
94*e038c9c4Sjoerg   return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
95*e038c9c4Sjoerg       C, ID, N, 0, SourceLocation());
967330f729Sjoerg }
977330f729Sjoerg 
987330f729Sjoerg //===----------------------------------------------------------------------===//
997330f729Sjoerg // OMPDeclareReductionDecl Implementation.
1007330f729Sjoerg //===----------------------------------------------------------------------===//
1017330f729Sjoerg 
OMPDeclareReductionDecl(Kind DK,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType Ty,OMPDeclareReductionDecl * PrevDeclInScope)1027330f729Sjoerg OMPDeclareReductionDecl::OMPDeclareReductionDecl(
1037330f729Sjoerg     Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
1047330f729Sjoerg     QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
1057330f729Sjoerg     : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
1067330f729Sjoerg       PrevDeclInScope(PrevDeclInScope) {
1077330f729Sjoerg   setInitializer(nullptr, CallInit);
1087330f729Sjoerg }
1097330f729Sjoerg 
anchor()1107330f729Sjoerg void OMPDeclareReductionDecl::anchor() {}
1117330f729Sjoerg 
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType T,OMPDeclareReductionDecl * PrevDeclInScope)1127330f729Sjoerg OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
1137330f729Sjoerg     ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
1147330f729Sjoerg     QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
1157330f729Sjoerg   return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
1167330f729Sjoerg                                              T, PrevDeclInScope);
1177330f729Sjoerg }
1187330f729Sjoerg 
1197330f729Sjoerg OMPDeclareReductionDecl *
CreateDeserialized(ASTContext & C,unsigned ID)1207330f729Sjoerg OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1217330f729Sjoerg   return new (C, ID) OMPDeclareReductionDecl(
1227330f729Sjoerg       OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
1237330f729Sjoerg       QualType(), /*PrevDeclInScope=*/nullptr);
1247330f729Sjoerg }
1257330f729Sjoerg 
getPrevDeclInScope()1267330f729Sjoerg OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
1277330f729Sjoerg   return cast_or_null<OMPDeclareReductionDecl>(
1287330f729Sjoerg       PrevDeclInScope.get(getASTContext().getExternalSource()));
1297330f729Sjoerg }
1307330f729Sjoerg const OMPDeclareReductionDecl *
getPrevDeclInScope() const1317330f729Sjoerg OMPDeclareReductionDecl::getPrevDeclInScope() const {
1327330f729Sjoerg   return cast_or_null<OMPDeclareReductionDecl>(
1337330f729Sjoerg       PrevDeclInScope.get(getASTContext().getExternalSource()));
1347330f729Sjoerg }
1357330f729Sjoerg 
1367330f729Sjoerg //===----------------------------------------------------------------------===//
1377330f729Sjoerg // OMPDeclareMapperDecl Implementation.
1387330f729Sjoerg //===----------------------------------------------------------------------===//
1397330f729Sjoerg 
anchor()1407330f729Sjoerg void OMPDeclareMapperDecl::anchor() {}
1417330f729Sjoerg 
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType T,DeclarationName VarName,ArrayRef<OMPClause * > Clauses,OMPDeclareMapperDecl * PrevDeclInScope)142*e038c9c4Sjoerg OMPDeclareMapperDecl *OMPDeclareMapperDecl::Create(
143*e038c9c4Sjoerg     ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
144*e038c9c4Sjoerg     QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses,
1457330f729Sjoerg     OMPDeclareMapperDecl *PrevDeclInScope) {
146*e038c9c4Sjoerg   return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(
147*e038c9c4Sjoerg       C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope);
1487330f729Sjoerg }
1497330f729Sjoerg 
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)1507330f729Sjoerg OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
1517330f729Sjoerg                                                                unsigned ID,
1527330f729Sjoerg                                                                unsigned N) {
153*e038c9c4Sjoerg   return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(
154*e038c9c4Sjoerg       C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(),
155*e038c9c4Sjoerg       DeclarationName(), /*PrevDeclInScope=*/nullptr);
1567330f729Sjoerg }
1577330f729Sjoerg 
getPrevDeclInScope()1587330f729Sjoerg OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
1597330f729Sjoerg   return cast_or_null<OMPDeclareMapperDecl>(
1607330f729Sjoerg       PrevDeclInScope.get(getASTContext().getExternalSource()));
1617330f729Sjoerg }
1627330f729Sjoerg 
getPrevDeclInScope() const1637330f729Sjoerg const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
1647330f729Sjoerg   return cast_or_null<OMPDeclareMapperDecl>(
1657330f729Sjoerg       PrevDeclInScope.get(getASTContext().getExternalSource()));
1667330f729Sjoerg }
1677330f729Sjoerg 
1687330f729Sjoerg //===----------------------------------------------------------------------===//
1697330f729Sjoerg // OMPCapturedExprDecl Implementation.
1707330f729Sjoerg //===----------------------------------------------------------------------===//
1717330f729Sjoerg 
anchor()1727330f729Sjoerg void OMPCapturedExprDecl::anchor() {}
1737330f729Sjoerg 
Create(ASTContext & C,DeclContext * DC,IdentifierInfo * Id,QualType T,SourceLocation StartLoc)1747330f729Sjoerg OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
1757330f729Sjoerg                                                  IdentifierInfo *Id, QualType T,
1767330f729Sjoerg                                                  SourceLocation StartLoc) {
1777330f729Sjoerg   return new (C, DC) OMPCapturedExprDecl(
1787330f729Sjoerg       C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
1797330f729Sjoerg }
1807330f729Sjoerg 
CreateDeserialized(ASTContext & C,unsigned ID)1817330f729Sjoerg OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
1827330f729Sjoerg                                                              unsigned ID) {
1837330f729Sjoerg   return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
1847330f729Sjoerg                                          /*TInfo=*/nullptr, SourceLocation());
1857330f729Sjoerg }
1867330f729Sjoerg 
getSourceRange() const1877330f729Sjoerg SourceRange OMPCapturedExprDecl::getSourceRange() const {
1887330f729Sjoerg   assert(hasInit());
1897330f729Sjoerg   return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
1907330f729Sjoerg }
191