Alexey Bataev | c640058 | 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 |
| 10 | /// \brief This file implements OMPThreadPrivateDecl class. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/DeclBase.h" |
| 16 | #include "clang/AST/Decl.h" |
| 17 | #include "clang/AST/DeclOpenMP.h" |
| 18 | #include "clang/AST/Expr.h" |
| 19 | |
| 20 | using namespace clang; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // OMPThreadPrivateDecl Implementation. |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | void OMPThreadPrivateDecl::anchor() { } |
| 27 | |
| 28 | OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C, |
| 29 | DeclContext *DC, |
| 30 | SourceLocation L, |
Alexey Bataev | 6af701f | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 31 | ArrayRef<Expr *> VL) { |
Alexey Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | unsigned Size = sizeof(OMPThreadPrivateDecl) + |
Alexey Bataev | 6af701f | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 33 | (VL.size() * sizeof(Expr *)); |
Alexey Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 34 | |
| 35 | void *Mem = C.Allocate(Size, llvm::alignOf<OMPThreadPrivateDecl>()); |
| 36 | OMPThreadPrivateDecl *D = new (Mem) OMPThreadPrivateDecl(OMPThreadPrivate, |
| 37 | DC, L); |
| 38 | D->NumVars = VL.size(); |
| 39 | D->setVars(VL); |
| 40 | return D; |
| 41 | } |
| 42 | |
| 43 | OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C, |
| 44 | unsigned ID, |
| 45 | unsigned N) { |
Alexey Bataev | 6af701f | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 46 | unsigned Size = sizeof(OMPThreadPrivateDecl) + (N * sizeof(Expr *)); |
Alexey Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 47 | |
| 48 | void *Mem = AllocateDeserializedDecl(C, ID, Size); |
| 49 | OMPThreadPrivateDecl *D = new (Mem) OMPThreadPrivateDecl(OMPThreadPrivate, |
| 50 | 0, SourceLocation()); |
| 51 | D->NumVars = N; |
| 52 | return D; |
| 53 | } |
| 54 | |
Alexey Bataev | 6af701f | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 55 | void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) { |
Alexey Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 56 | assert(VL.size() == NumVars && |
| 57 | "Number of variables is not the same as the preallocated buffer"); |
Alexey Bataev | 6af701f | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 58 | Expr **Vars = reinterpret_cast<Expr **>(this + 1); |
Alexey Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 59 | std::copy(VL.begin(), VL.end(), Vars); |
| 60 | } |