blob: b77a67cbf38dad7f78478e6a67838961cafdca76 [file] [log] [blame]
Alexey Bataeva769e072013-03-22 06:34:35 +00001//===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010/// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
Alexey Bataev90c228f2016-02-08 09:29:13 +000011/// classes.
Alexey Bataeva769e072013-03-22 06:34:35 +000012///
13//===----------------------------------------------------------------------===//
14
15#include "clang/AST/ASTContext.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000016#include "clang/AST/Decl.h"
Chandler Carruth5553d0d2014-01-07 11:51:46 +000017#include "clang/AST/DeclBase.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000018#include "clang/AST/DeclOpenMP.h"
19#include "clang/AST/Expr.h"
20
21using namespace clang;
22
23//===----------------------------------------------------------------------===//
24// OMPThreadPrivateDecl Implementation.
25//===----------------------------------------------------------------------===//
26
27void OMPThreadPrivateDecl::anchor() { }
28
29OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
30 DeclContext *DC,
31 SourceLocation L,
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000032 ArrayRef<Expr *> VL) {
James Y Knight967eb202015-12-29 22:13:13 +000033 OMPThreadPrivateDecl *D =
34 new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
35 OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
Alexey Bataeva769e072013-03-22 06:34:35 +000036 D->NumVars = VL.size();
37 D->setVars(VL);
38 return D;
39}
40
41OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
42 unsigned ID,
43 unsigned N) {
James Y Knight967eb202015-12-29 22:13:13 +000044 OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
Craig Topper36250ad2014-05-12 05:36:57 +000045 OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
Alexey Bataeva769e072013-03-22 06:34:35 +000046 D->NumVars = N;
47 return D;
48}
49
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000050void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
Alexey Bataeva769e072013-03-22 06:34:35 +000051 assert(VL.size() == NumVars &&
52 "Number of variables is not the same as the preallocated buffer");
James Y Knight967eb202015-12-29 22:13:13 +000053 std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
Alexey Bataeva769e072013-03-22 06:34:35 +000054}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000055
Alexey Bataev90c228f2016-02-08 09:29:13 +000056//===----------------------------------------------------------------------===//
Kelvin Li1408f912018-09-26 04:28:39 +000057// OMPRequiresDecl Implementation.
58//===----------------------------------------------------------------------===//
59
60void OMPRequiresDecl::anchor() {}
61
62OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
63 SourceLocation L,
64 ArrayRef<OMPClause *> CL) {
65 OMPRequiresDecl *D =
66 new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
67 OMPRequiresDecl(OMPRequires, DC, L);
68 D->NumClauses = CL.size();
69 D->setClauses(CL);
70 return D;
71}
72
73OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
74 unsigned N) {
75 OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
76 OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
77 D->NumClauses = N;
78 return D;
79}
80
81void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
82 assert(CL.size() == NumClauses &&
83 "Number of clauses is not the same as the preallocated buffer");
84 std::uninitialized_copy(CL.begin(), CL.end(),
85 getTrailingObjects<OMPClause *>());
86}
87
88//===----------------------------------------------------------------------===//
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000089// OMPDeclareReductionDecl Implementation.
90//===----------------------------------------------------------------------===//
91
Erich Keanec9d29902018-08-01 21:16:54 +000092OMPDeclareReductionDecl::OMPDeclareReductionDecl(
93 Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
94 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
95 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
96 PrevDeclInScope(PrevDeclInScope) {
97 setInitializer(nullptr, CallInit);
98}
99
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000100void OMPDeclareReductionDecl::anchor() {}
101
102OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
103 ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
104 QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
105 return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
106 T, PrevDeclInScope);
107}
108
109OMPDeclareReductionDecl *
110OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
111 return new (C, ID) OMPDeclareReductionDecl(
112 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
113 QualType(), /*PrevDeclInScope=*/nullptr);
114}
115
116OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
117 return cast_or_null<OMPDeclareReductionDecl>(
118 PrevDeclInScope.get(getASTContext().getExternalSource()));
119}
120const OMPDeclareReductionDecl *
121OMPDeclareReductionDecl::getPrevDeclInScope() const {
122 return cast_or_null<OMPDeclareReductionDecl>(
123 PrevDeclInScope.get(getASTContext().getExternalSource()));
124}
125
126//===----------------------------------------------------------------------===//
Alexey Bataev4244be22016-02-11 05:35:55 +0000127// OMPCapturedExprDecl Implementation.
Alexey Bataev90c228f2016-02-08 09:29:13 +0000128//===----------------------------------------------------------------------===//
129
Alexey Bataev4244be22016-02-11 05:35:55 +0000130void OMPCapturedExprDecl::anchor() {}
Alexey Bataev90c228f2016-02-08 09:29:13 +0000131
Alexey Bataev4244be22016-02-11 05:35:55 +0000132OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
Alexey Bataeva7206b92016-12-20 16:51:02 +0000133 IdentifierInfo *Id, QualType T,
134 SourceLocation StartLoc) {
Erich Keaneed6bc342018-06-01 13:04:26 +0000135 return new (C, DC) OMPCapturedExprDecl(
136 C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
Alexey Bataev90c228f2016-02-08 09:29:13 +0000137}
138
Alexey Bataev4244be22016-02-11 05:35:55 +0000139OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
140 unsigned ID) {
Erich Keaneed6bc342018-06-01 13:04:26 +0000141 return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
142 /*TInfo=*/nullptr, SourceLocation());
Alexey Bataev90c228f2016-02-08 09:29:13 +0000143}
144
Alexey Bataeva7206b92016-12-20 16:51:02 +0000145SourceRange OMPCapturedExprDecl::getSourceRange() const {
146 assert(hasInit());
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000147 return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
Alexey Bataeva7206b92016-12-20 16:51:02 +0000148}