Path: blob/main/contrib/llvm-project/clang/lib/AST/DeclOpenMP.cpp
35260 views
//===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8/// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl9/// classes.10///11//===----------------------------------------------------------------------===//1213#include "clang/AST/ASTContext.h"14#include "clang/AST/Decl.h"15#include "clang/AST/DeclBase.h"16#include "clang/AST/DeclOpenMP.h"17#include "clang/AST/Expr.h"1819using namespace clang;2021//===----------------------------------------------------------------------===//22// OMPThreadPrivateDecl Implementation.23//===----------------------------------------------------------------------===//2425void OMPThreadPrivateDecl::anchor() {}2627OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,28DeclContext *DC,29SourceLocation L,30ArrayRef<Expr *> VL) {31auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(32C, DC, std::nullopt, VL.size(), L);33D->setVars(VL);34return D;35}3637OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,38GlobalDeclID ID,39unsigned N) {40return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(41C, ID, 0, N);42}4344void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {45assert(VL.size() == Data->getNumChildren() &&46"Number of variables is not the same as the preallocated buffer");47llvm::copy(VL, getVars().begin());48}4950//===----------------------------------------------------------------------===//51// OMPAllocateDecl Implementation.52//===----------------------------------------------------------------------===//5354void OMPAllocateDecl::anchor() { }5556OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,57SourceLocation L, ArrayRef<Expr *> VL,58ArrayRef<OMPClause *> CL) {59auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>(60C, DC, CL, VL.size(), L);61D->setVars(VL);62return D;63}6465OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C,66GlobalDeclID ID,67unsigned NVars,68unsigned NClauses) {69return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(70C, ID, NClauses, NVars, SourceLocation());71}7273void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {74assert(VL.size() == Data->getNumChildren() &&75"Number of variables is not the same as the preallocated buffer");76llvm::copy(VL, getVars().begin());77}7879//===----------------------------------------------------------------------===//80// OMPRequiresDecl Implementation.81//===----------------------------------------------------------------------===//8283void OMPRequiresDecl::anchor() {}8485OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,86SourceLocation L,87ArrayRef<OMPClause *> CL) {88return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0,89L);90}9192OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C,93GlobalDeclID ID,94unsigned N) {95return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(96C, ID, N, 0, SourceLocation());97}9899//===----------------------------------------------------------------------===//100// OMPDeclareReductionDecl Implementation.101//===----------------------------------------------------------------------===//102103OMPDeclareReductionDecl::OMPDeclareReductionDecl(104Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,105QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)106: ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),107PrevDeclInScope(PrevDeclInScope) {108setInitializer(nullptr, OMPDeclareReductionInitKind::Call);109}110111void OMPDeclareReductionDecl::anchor() {}112113OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(114ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,115QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {116return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,117T, PrevDeclInScope);118}119120OMPDeclareReductionDecl *121OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {122return new (C, ID) OMPDeclareReductionDecl(123OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),124QualType(), /*PrevDeclInScope=*/nullptr);125}126127OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {128return cast_or_null<OMPDeclareReductionDecl>(129PrevDeclInScope.get(getASTContext().getExternalSource()));130}131const OMPDeclareReductionDecl *132OMPDeclareReductionDecl::getPrevDeclInScope() const {133return cast_or_null<OMPDeclareReductionDecl>(134PrevDeclInScope.get(getASTContext().getExternalSource()));135}136137//===----------------------------------------------------------------------===//138// OMPDeclareMapperDecl Implementation.139//===----------------------------------------------------------------------===//140141void OMPDeclareMapperDecl::anchor() {}142143OMPDeclareMapperDecl *OMPDeclareMapperDecl::Create(144ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,145QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses,146OMPDeclareMapperDecl *PrevDeclInScope) {147return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(148C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope);149}150151OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,152GlobalDeclID ID,153unsigned N) {154return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(155C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(),156DeclarationName(), /*PrevDeclInScope=*/nullptr);157}158159OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {160return cast_or_null<OMPDeclareMapperDecl>(161PrevDeclInScope.get(getASTContext().getExternalSource()));162}163164const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {165return cast_or_null<OMPDeclareMapperDecl>(166PrevDeclInScope.get(getASTContext().getExternalSource()));167}168169//===----------------------------------------------------------------------===//170// OMPCapturedExprDecl Implementation.171//===----------------------------------------------------------------------===//172173void OMPCapturedExprDecl::anchor() {}174175OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,176IdentifierInfo *Id, QualType T,177SourceLocation StartLoc) {178return new (C, DC) OMPCapturedExprDecl(179C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);180}181182OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,183GlobalDeclID ID) {184return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),185/*TInfo=*/nullptr, SourceLocation());186}187188SourceRange OMPCapturedExprDecl::getSourceRange() const {189assert(hasInit());190return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());191}192193194