blob: 522caefe3bddf541b07e2c6eda4d6ecdf9337d15 [file] [log] [blame]
Alexey Bataevc6400582013-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
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
20using namespace clang;
21
22//===----------------------------------------------------------------------===//
23// OMPThreadPrivateDecl Implementation.
24//===----------------------------------------------------------------------===//
25
26void OMPThreadPrivateDecl::anchor() { }
27
28OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
29 DeclContext *DC,
30 SourceLocation L,
Alexey Bataev6af701f2013-05-13 04:18:18 +000031 ArrayRef<Expr *> VL) {
Alexey Bataevc6400582013-03-22 06:34:35 +000032 unsigned Size = sizeof(OMPThreadPrivateDecl) +
Alexey Bataev6af701f2013-05-13 04:18:18 +000033 (VL.size() * sizeof(Expr *));
Alexey Bataevc6400582013-03-22 06:34:35 +000034
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
43OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
44 unsigned ID,
45 unsigned N) {
Alexey Bataev6af701f2013-05-13 04:18:18 +000046 unsigned Size = sizeof(OMPThreadPrivateDecl) + (N * sizeof(Expr *));
Alexey Bataevc6400582013-03-22 06:34:35 +000047
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 Bataev6af701f2013-05-13 04:18:18 +000055void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
Alexey Bataevc6400582013-03-22 06:34:35 +000056 assert(VL.size() == NumVars &&
57 "Number of variables is not the same as the preallocated buffer");
Alexey Bataev6af701f2013-05-13 04:18:18 +000058 Expr **Vars = reinterpret_cast<Expr **>(this + 1);
Alexey Bataevc6400582013-03-22 06:34:35 +000059 std::copy(VL.begin(), VL.end(), Vars);
60}