blob: c0d10a0f418c647a52fc60b9c7b4b0b35397e2b7 [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,
31 ArrayRef<DeclRefExpr *> VL) {
32 unsigned Size = sizeof(OMPThreadPrivateDecl) +
33 (VL.size() * sizeof(DeclRefExpr *));
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
43OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
44 unsigned ID,
45 unsigned N) {
46 unsigned Size = sizeof(OMPThreadPrivateDecl) + (N * sizeof(DeclRefExpr *));
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
55void OMPThreadPrivateDecl::setVars(ArrayRef<DeclRefExpr *> VL) {
56 assert(VL.size() == NumVars &&
57 "Number of variables is not the same as the preallocated buffer");
58 DeclRefExpr **Vars = reinterpret_cast<DeclRefExpr **>(this + 1);
59 std::copy(VL.begin(), VL.end(), Vars);
60}