Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1 | //===--- 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 Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame^] | 10 | /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 11 | /// classes. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 16 | #include "clang/AST/Decl.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclBase.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclOpenMP.h" |
| 19 | #include "clang/AST/Expr.h" |
| 20 | |
| 21 | using namespace clang; |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | // OMPThreadPrivateDecl Implementation. |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
| 27 | void OMPThreadPrivateDecl::anchor() { } |
| 28 | |
| 29 | OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C, |
| 30 | DeclContext *DC, |
| 31 | SourceLocation L, |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 32 | ArrayRef<Expr *> VL) { |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 33 | OMPThreadPrivateDecl *D = |
| 34 | new (C, DC, additionalSizeToAlloc<Expr *>(VL.size())) |
| 35 | OMPThreadPrivateDecl(OMPThreadPrivate, DC, L); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 36 | D->NumVars = VL.size(); |
| 37 | D->setVars(VL); |
| 38 | return D; |
| 39 | } |
| 40 | |
| 41 | OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C, |
| 42 | unsigned ID, |
| 43 | unsigned N) { |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 44 | OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 45 | OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 46 | D->NumVars = N; |
| 47 | return D; |
| 48 | } |
| 49 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 50 | void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 51 | assert(VL.size() == NumVars && |
| 52 | "Number of variables is not the same as the preallocated buffer"); |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 53 | std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 54 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 55 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 56 | //===----------------------------------------------------------------------===// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 57 | // OMPDeclareReductionDecl Implementation. |
| 58 | //===----------------------------------------------------------------------===// |
| 59 | |
| 60 | void OMPDeclareReductionDecl::anchor() {} |
| 61 | |
| 62 | OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create( |
| 63 | ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, |
| 64 | QualType T, OMPDeclareReductionDecl *PrevDeclInScope) { |
| 65 | return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name, |
| 66 | T, PrevDeclInScope); |
| 67 | } |
| 68 | |
| 69 | OMPDeclareReductionDecl * |
| 70 | OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 71 | return new (C, ID) OMPDeclareReductionDecl( |
| 72 | OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(), |
| 73 | QualType(), /*PrevDeclInScope=*/nullptr); |
| 74 | } |
| 75 | |
| 76 | OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() { |
| 77 | return cast_or_null<OMPDeclareReductionDecl>( |
| 78 | PrevDeclInScope.get(getASTContext().getExternalSource())); |
| 79 | } |
| 80 | const OMPDeclareReductionDecl * |
| 81 | OMPDeclareReductionDecl::getPrevDeclInScope() const { |
| 82 | return cast_or_null<OMPDeclareReductionDecl>( |
| 83 | PrevDeclInScope.get(getASTContext().getExternalSource())); |
| 84 | } |
| 85 | |
| 86 | //===----------------------------------------------------------------------===// |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 87 | // OMPCapturedExprDecl Implementation. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 88 | //===----------------------------------------------------------------------===// |
| 89 | |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 90 | void OMPCapturedExprDecl::anchor() {} |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 91 | |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 92 | OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC, |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 93 | IdentifierInfo *Id, QualType T, |
| 94 | SourceLocation StartLoc) { |
| 95 | return new (C, DC) OMPCapturedExprDecl(C, DC, Id, T, StartLoc); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 98 | OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C, |
| 99 | unsigned ID) { |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 100 | return new (C, ID) |
| 101 | OMPCapturedExprDecl(C, nullptr, nullptr, QualType(), SourceLocation()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 104 | SourceRange OMPCapturedExprDecl::getSourceRange() const { |
| 105 | assert(hasInit()); |
| 106 | return SourceRange(getInit()->getLocStart(), getInit()->getLocEnd()); |
| 107 | } |