1139f7f9bSDimitry Andric //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
2139f7f9bSDimitry Andric //
3139f7f9bSDimitry Andric // The LLVM Compiler Infrastructure
4139f7f9bSDimitry Andric //
5139f7f9bSDimitry Andric // This file is distributed under the University of Illinois Open Source
6139f7f9bSDimitry Andric // License. See LICENSE.TXT for details.
7139f7f9bSDimitry Andric //
8139f7f9bSDimitry Andric //===----------------------------------------------------------------------===//
9139f7f9bSDimitry Andric /// \file
104ba319b5SDimitry Andric /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
11e7145dcbSDimitry Andric /// classes.
12139f7f9bSDimitry Andric ///
13139f7f9bSDimitry Andric //===----------------------------------------------------------------------===//
14139f7f9bSDimitry Andric
15139f7f9bSDimitry Andric #include "clang/AST/ASTContext.h"
16139f7f9bSDimitry Andric #include "clang/AST/Decl.h"
1759d1ed5bSDimitry Andric #include "clang/AST/DeclBase.h"
18139f7f9bSDimitry Andric #include "clang/AST/DeclOpenMP.h"
19139f7f9bSDimitry Andric #include "clang/AST/Expr.h"
20139f7f9bSDimitry Andric
21139f7f9bSDimitry Andric using namespace clang;
22139f7f9bSDimitry Andric
23139f7f9bSDimitry Andric //===----------------------------------------------------------------------===//
24139f7f9bSDimitry Andric // OMPThreadPrivateDecl Implementation.
25139f7f9bSDimitry Andric //===----------------------------------------------------------------------===//
26139f7f9bSDimitry Andric
anchor()27139f7f9bSDimitry Andric void OMPThreadPrivateDecl::anchor() { }
28139f7f9bSDimitry Andric
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<Expr * > VL)29139f7f9bSDimitry Andric OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
30139f7f9bSDimitry Andric DeclContext *DC,
31139f7f9bSDimitry Andric SourceLocation L,
32f785676fSDimitry Andric ArrayRef<Expr *> VL) {
330623d748SDimitry Andric OMPThreadPrivateDecl *D =
340623d748SDimitry Andric new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
3559d1ed5bSDimitry Andric OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
36139f7f9bSDimitry Andric D->NumVars = VL.size();
37139f7f9bSDimitry Andric D->setVars(VL);
38139f7f9bSDimitry Andric return D;
39139f7f9bSDimitry Andric }
40139f7f9bSDimitry Andric
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)41139f7f9bSDimitry Andric OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
42139f7f9bSDimitry Andric unsigned ID,
43139f7f9bSDimitry Andric unsigned N) {
440623d748SDimitry Andric OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
4559d1ed5bSDimitry Andric OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
46139f7f9bSDimitry Andric D->NumVars = N;
47139f7f9bSDimitry Andric return D;
48139f7f9bSDimitry Andric }
49139f7f9bSDimitry Andric
setVars(ArrayRef<Expr * > VL)50f785676fSDimitry Andric void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
51139f7f9bSDimitry Andric assert(VL.size() == NumVars &&
52139f7f9bSDimitry Andric "Number of variables is not the same as the preallocated buffer");
530623d748SDimitry Andric std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
54139f7f9bSDimitry Andric }
55f785676fSDimitry Andric
56e7145dcbSDimitry Andric //===----------------------------------------------------------------------===//
57*b5893f02SDimitry Andric // OMPRequiresDecl Implementation.
58*b5893f02SDimitry Andric //===----------------------------------------------------------------------===//
59*b5893f02SDimitry Andric
anchor()60*b5893f02SDimitry Andric void OMPRequiresDecl::anchor() {}
61*b5893f02SDimitry Andric
Create(ASTContext & C,DeclContext * DC,SourceLocation L,ArrayRef<OMPClause * > CL)62*b5893f02SDimitry Andric OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
63*b5893f02SDimitry Andric SourceLocation L,
64*b5893f02SDimitry Andric ArrayRef<OMPClause *> CL) {
65*b5893f02SDimitry Andric OMPRequiresDecl *D =
66*b5893f02SDimitry Andric new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
67*b5893f02SDimitry Andric OMPRequiresDecl(OMPRequires, DC, L);
68*b5893f02SDimitry Andric D->NumClauses = CL.size();
69*b5893f02SDimitry Andric D->setClauses(CL);
70*b5893f02SDimitry Andric return D;
71*b5893f02SDimitry Andric }
72*b5893f02SDimitry Andric
CreateDeserialized(ASTContext & C,unsigned ID,unsigned N)73*b5893f02SDimitry Andric OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
74*b5893f02SDimitry Andric unsigned N) {
75*b5893f02SDimitry Andric OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
76*b5893f02SDimitry Andric OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
77*b5893f02SDimitry Andric D->NumClauses = N;
78*b5893f02SDimitry Andric return D;
79*b5893f02SDimitry Andric }
80*b5893f02SDimitry Andric
setClauses(ArrayRef<OMPClause * > CL)81*b5893f02SDimitry Andric void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
82*b5893f02SDimitry Andric assert(CL.size() == NumClauses &&
83*b5893f02SDimitry Andric "Number of clauses is not the same as the preallocated buffer");
84*b5893f02SDimitry Andric std::uninitialized_copy(CL.begin(), CL.end(),
85*b5893f02SDimitry Andric getTrailingObjects<OMPClause *>());
86*b5893f02SDimitry Andric }
87*b5893f02SDimitry Andric
88*b5893f02SDimitry Andric //===----------------------------------------------------------------------===//
89e7145dcbSDimitry Andric // OMPDeclareReductionDecl Implementation.
90e7145dcbSDimitry Andric //===----------------------------------------------------------------------===//
91e7145dcbSDimitry Andric
OMPDeclareReductionDecl(Kind DK,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType Ty,OMPDeclareReductionDecl * PrevDeclInScope)92*b5893f02SDimitry Andric OMPDeclareReductionDecl::OMPDeclareReductionDecl(
93*b5893f02SDimitry Andric Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
94*b5893f02SDimitry Andric QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
95*b5893f02SDimitry Andric : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
96*b5893f02SDimitry Andric PrevDeclInScope(PrevDeclInScope) {
97*b5893f02SDimitry Andric setInitializer(nullptr, CallInit);
98*b5893f02SDimitry Andric }
99*b5893f02SDimitry Andric
anchor()100e7145dcbSDimitry Andric void OMPDeclareReductionDecl::anchor() {}
101e7145dcbSDimitry Andric
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,QualType T,OMPDeclareReductionDecl * PrevDeclInScope)102e7145dcbSDimitry Andric OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
103e7145dcbSDimitry Andric ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
104e7145dcbSDimitry Andric QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
105e7145dcbSDimitry Andric return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
106e7145dcbSDimitry Andric T, PrevDeclInScope);
107e7145dcbSDimitry Andric }
108e7145dcbSDimitry Andric
109e7145dcbSDimitry Andric OMPDeclareReductionDecl *
CreateDeserialized(ASTContext & C,unsigned ID)110e7145dcbSDimitry Andric OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
111e7145dcbSDimitry Andric return new (C, ID) OMPDeclareReductionDecl(
112e7145dcbSDimitry Andric OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
113e7145dcbSDimitry Andric QualType(), /*PrevDeclInScope=*/nullptr);
114e7145dcbSDimitry Andric }
115e7145dcbSDimitry Andric
getPrevDeclInScope()116e7145dcbSDimitry Andric OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
117e7145dcbSDimitry Andric return cast_or_null<OMPDeclareReductionDecl>(
118e7145dcbSDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource()));
119e7145dcbSDimitry Andric }
120e7145dcbSDimitry Andric const OMPDeclareReductionDecl *
getPrevDeclInScope() const121e7145dcbSDimitry Andric OMPDeclareReductionDecl::getPrevDeclInScope() const {
122e7145dcbSDimitry Andric return cast_or_null<OMPDeclareReductionDecl>(
123e7145dcbSDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource()));
124e7145dcbSDimitry Andric }
125e7145dcbSDimitry Andric
126e7145dcbSDimitry Andric //===----------------------------------------------------------------------===//
127e7145dcbSDimitry Andric // OMPCapturedExprDecl Implementation.
128e7145dcbSDimitry Andric //===----------------------------------------------------------------------===//
129e7145dcbSDimitry Andric
anchor()130e7145dcbSDimitry Andric void OMPCapturedExprDecl::anchor() {}
131e7145dcbSDimitry Andric
Create(ASTContext & C,DeclContext * DC,IdentifierInfo * Id,QualType T,SourceLocation StartLoc)132e7145dcbSDimitry Andric OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
13344290647SDimitry Andric IdentifierInfo *Id, QualType T,
13444290647SDimitry Andric SourceLocation StartLoc) {
1354ba319b5SDimitry Andric return new (C, DC) OMPCapturedExprDecl(
1364ba319b5SDimitry Andric C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
137e7145dcbSDimitry Andric }
138e7145dcbSDimitry Andric
CreateDeserialized(ASTContext & C,unsigned ID)139e7145dcbSDimitry Andric OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
140e7145dcbSDimitry Andric unsigned ID) {
1414ba319b5SDimitry Andric return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
1424ba319b5SDimitry Andric /*TInfo=*/nullptr, SourceLocation());
143e7145dcbSDimitry Andric }
144e7145dcbSDimitry Andric
getSourceRange() const14544290647SDimitry Andric SourceRange OMPCapturedExprDecl::getSourceRange() const {
14644290647SDimitry Andric assert(hasInit());
147*b5893f02SDimitry Andric return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
14844290647SDimitry Andric }
149