clang  8.0.0svn
DeclOpenMP.cpp
Go to the documentation of this file.
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 /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
11 /// classes.
12 ///
13 //===----------------------------------------------------------------------===//
14 
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"
20 
21 using namespace clang;
22 
23 //===----------------------------------------------------------------------===//
24 // OMPThreadPrivateDecl Implementation.
25 //===----------------------------------------------------------------------===//
26 
27 void OMPThreadPrivateDecl::anchor() { }
28 
30  DeclContext *DC,
32  ArrayRef<Expr *> VL) {
34  new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
35  OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
36  D->NumVars = VL.size();
37  D->setVars(VL);
38  return D;
39 }
40 
42  unsigned ID,
43  unsigned N) {
44  OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
45  OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
46  D->NumVars = N;
47  return D;
48 }
49 
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 *>());
54 }
55 
56 //===----------------------------------------------------------------------===//
57 // OMPDeclareReductionDecl Implementation.
58 //===----------------------------------------------------------------------===//
59 
60 OMPDeclareReductionDecl::OMPDeclareReductionDecl(
62  QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
63  : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
64  PrevDeclInScope(PrevDeclInScope) {
65  setInitializer(nullptr, CallInit);
66 }
67 
68 void OMPDeclareReductionDecl::anchor() {}
69 
72  QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
73  return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
74  T, PrevDeclInScope);
75 }
76 
79  return new (C, ID) OMPDeclareReductionDecl(
80  OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
81  QualType(), /*PrevDeclInScope=*/nullptr);
82 }
83 
85  return cast_or_null<OMPDeclareReductionDecl>(
86  PrevDeclInScope.get(getASTContext().getExternalSource()));
87 }
90  return cast_or_null<OMPDeclareReductionDecl>(
91  PrevDeclInScope.get(getASTContext().getExternalSource()));
92 }
93 
94 //===----------------------------------------------------------------------===//
95 // OMPCapturedExprDecl Implementation.
96 //===----------------------------------------------------------------------===//
97 
98 void OMPCapturedExprDecl::anchor() {}
99 
102  SourceLocation StartLoc) {
103  return new (C, DC) OMPCapturedExprDecl(
104  C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
105 }
106 
108  unsigned ID) {
109  return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
110  /*TInfo=*/nullptr, SourceLocation());
111 }
112 
114  assert(hasInit());
115  return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
116 }
Defines the clang::ASTContext interface.
A (possibly-)qualified type.
Definition: Type.h:642
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:409
static OMPDeclareReductionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, QualType T, OMPDeclareReductionDecl *PrevDeclInScope)
Create declare reduction node.
Definition: DeclOpenMP.cpp:70
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:413
One of these records is kept for each identifier that is lexed.
static OMPThreadPrivateDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Definition: DeclOpenMP.cpp:41
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
friend class DeclContext
Definition: DeclBase.h:242
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclOpenMP.cpp:113
static OMPCapturedExprDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclOpenMP.cpp:107
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
int Id
Definition: ASTDiff.cpp:191
OMPDeclareReductionDecl * getPrevDeclInScope()
Get reference to previous declare reduction construct in the same scope with the same name...
Definition: DeclOpenMP.cpp:84
Encodes a location in the source.
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:102
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:216
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:376
This file defines OpenMP nodes for declarative directives.
static OMPCapturedExprDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, QualType T, SourceLocation StartLoc)
Definition: DeclOpenMP.cpp:100
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1267
static OMPThreadPrivateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr *> VL)
Definition: DeclOpenMP.cpp:29
DeclarationName - The name of a declaration.
static OMPDeclareReductionDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create deserialized declare reduction node.
Definition: DeclOpenMP.cpp:78
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
A trivial tuple used to represent a source range.
This represents &#39;#pragma omp threadprivate ...&#39; directive.
Definition: DeclOpenMP.h:39