1 //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// \brief This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
13 //===----------------------------------------------------------------------===//
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclBase.h"
18 #include "clang/AST/DeclOpenMP.h"
19 #include "clang/AST/Expr.h"
21 using namespace clang;
23 //===----------------------------------------------------------------------===//
24 // OMPThreadPrivateDecl Implementation.
25 //===----------------------------------------------------------------------===//
27 void OMPThreadPrivateDecl::anchor() { }
29 OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
32 ArrayRef<Expr *> VL) {
33 OMPThreadPrivateDecl *D =
34 new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
35 OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
36 D->NumVars = VL.size();
41 OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
44 OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
45 OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
50 void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
51 assert(VL.size() == NumVars &&
52 "Number of variables is not the same as the preallocated buffer");
53 std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
56 //===----------------------------------------------------------------------===//
57 // OMPDeclareReductionDecl Implementation.
58 //===----------------------------------------------------------------------===//
60 void OMPDeclareReductionDecl::anchor() {}
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,
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);
76 OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
77 return cast_or_null<OMPDeclareReductionDecl>(
78 PrevDeclInScope.get(getASTContext().getExternalSource()));
80 const OMPDeclareReductionDecl *
81 OMPDeclareReductionDecl::getPrevDeclInScope() const {
82 return cast_or_null<OMPDeclareReductionDecl>(
83 PrevDeclInScope.get(getASTContext().getExternalSource()));
86 //===----------------------------------------------------------------------===//
87 // OMPCapturedExprDecl Implementation.
88 //===----------------------------------------------------------------------===//
90 void OMPCapturedExprDecl::anchor() {}
92 OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
93 IdentifierInfo *Id, QualType T,
94 SourceLocation StartLoc) {
95 return new (C, DC) OMPCapturedExprDecl(C, DC, Id, T, StartLoc);
98 OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
101 OMPCapturedExprDecl(C, nullptr, nullptr, QualType(), SourceLocation());
104 SourceRange OMPCapturedExprDecl::getSourceRange() const {
106 return SourceRange(getInit()->getLocStart(), getInit()->getLocEnd());