1*f4a2713aSLionel Sambuc //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===// 2*f4a2713aSLionel Sambuc // 3*f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4*f4a2713aSLionel Sambuc // 5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7*f4a2713aSLionel Sambuc // 8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9*f4a2713aSLionel Sambuc /// \file 10*f4a2713aSLionel Sambuc /// \brief This file implements OMPThreadPrivateDecl class. 11*f4a2713aSLionel Sambuc /// 12*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13*f4a2713aSLionel Sambuc 14*f4a2713aSLionel Sambuc #include "clang/AST/ASTContext.h" 15*f4a2713aSLionel Sambuc #include "clang/AST/DeclBase.h" 16*f4a2713aSLionel Sambuc #include "clang/AST/Decl.h" 17*f4a2713aSLionel Sambuc #include "clang/AST/DeclOpenMP.h" 18*f4a2713aSLionel Sambuc #include "clang/AST/Expr.h" 19*f4a2713aSLionel Sambuc 20*f4a2713aSLionel Sambuc using namespace clang; 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 23*f4a2713aSLionel Sambuc // OMPThreadPrivateDecl Implementation. 24*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambuc void OMPThreadPrivateDecl::anchor() { } 27*f4a2713aSLionel Sambuc 28*f4a2713aSLionel Sambuc OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C, 29*f4a2713aSLionel Sambuc DeclContext *DC, 30*f4a2713aSLionel Sambuc SourceLocation L, 31*f4a2713aSLionel Sambuc ArrayRef<Expr *> VL) { 32*f4a2713aSLionel Sambuc unsigned Size = sizeof(OMPThreadPrivateDecl) + 33*f4a2713aSLionel Sambuc (VL.size() * sizeof(Expr *)); 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc void *Mem = C.Allocate(Size, llvm::alignOf<OMPThreadPrivateDecl>()); 36*f4a2713aSLionel Sambuc OMPThreadPrivateDecl *D = new (Mem) OMPThreadPrivateDecl(OMPThreadPrivate, 37*f4a2713aSLionel Sambuc DC, L); 38*f4a2713aSLionel Sambuc D->NumVars = VL.size(); 39*f4a2713aSLionel Sambuc D->setVars(VL); 40*f4a2713aSLionel Sambuc return D; 41*f4a2713aSLionel Sambuc } 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C, 44*f4a2713aSLionel Sambuc unsigned ID, 45*f4a2713aSLionel Sambuc unsigned N) { 46*f4a2713aSLionel Sambuc unsigned Size = sizeof(OMPThreadPrivateDecl) + (N * sizeof(Expr *)); 47*f4a2713aSLionel Sambuc 48*f4a2713aSLionel Sambuc void *Mem = AllocateDeserializedDecl(C, ID, Size); 49*f4a2713aSLionel Sambuc OMPThreadPrivateDecl *D = new (Mem) OMPThreadPrivateDecl(OMPThreadPrivate, 50*f4a2713aSLionel Sambuc 0, SourceLocation()); 51*f4a2713aSLionel Sambuc D->NumVars = N; 52*f4a2713aSLionel Sambuc return D; 53*f4a2713aSLionel Sambuc } 54*f4a2713aSLionel Sambuc 55*f4a2713aSLionel Sambuc void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) { 56*f4a2713aSLionel Sambuc assert(VL.size() == NumVars && 57*f4a2713aSLionel Sambuc "Number of variables is not the same as the preallocated buffer"); 58*f4a2713aSLionel Sambuc Expr **Vars = reinterpret_cast<Expr **>(this + 1); 59*f4a2713aSLionel Sambuc std::copy(VL.begin(), VL.end(), Vars); 60*f4a2713aSLionel Sambuc } 61*f4a2713aSLionel Sambuc 62