clang 22.0.0git
DeclOpenACC.h
Go to the documentation of this file.
1//=- DeclOpenACC.h - Classes for representing OpenACC directives -*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file defines OpenACC nodes for declarative directives.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECLOPENACC_H
15#define LLVM_CLANG_AST_DECLOPENACC_H
16
18#include "clang/AST/Decl.h"
21#include "llvm/ADT/STLExtras.h"
22
23namespace clang {
24
25// A base class for the declaration constructs, which manages the clauses and
26// basic source location information. Currently not part of the Decl inheritence
27// tree, as we should never have a reason to store one of these.
28class OpenACCConstructDecl : public Decl {
29 friend class ASTDeclReader;
30 friend class ASTDeclWriter;
31 // The directive kind, each implementation of this interface is expected to
32 // handle a specific kind.
34 SourceLocation DirectiveLoc;
35 SourceLocation EndLoc;
36 /// The list of clauses. This is stored here as an ArrayRef, as this is the
37 /// most convienient place to access the list, however the list itself should
38 /// be stored in leaf nodes, likely in trailing-storage.
40
41protected:
43 SourceLocation StartLoc, SourceLocation DirLoc,
44 SourceLocation EndLoc)
45 : Decl(DeclKind, DC, StartLoc), DirKind(K), DirectiveLoc(DirLoc),
46 EndLoc(EndLoc) {}
47
48 OpenACCConstructDecl(Kind DeclKind) : Decl(DeclKind, EmptyShell{}) {}
49
51 assert(Clauses.empty() && "Cannot change clause list");
52 Clauses = NewClauses;
53 }
54
55public:
56 OpenACCDirectiveKind getDirectiveKind() const { return DirKind; }
57 SourceLocation getDirectiveLoc() const { return DirectiveLoc; }
58 virtual SourceRange getSourceRange() const override LLVM_READONLY {
59 return SourceRange(getLocation(), EndLoc);
60 }
61
62 ArrayRef<const OpenACCClause *> clauses() const { return Clauses; }
63 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
64 static bool classofKind(Kind K);
65};
66
68 : public OpenACCConstructDecl,
69 private llvm::TrailingObjects<OpenACCDeclareDecl, const OpenACCClause *> {
70 friend TrailingObjects;
71 friend class ASTDeclReader;
72 friend class ASTDeclWriter;
73
74 OpenACCDeclareDecl(unsigned NumClauses)
75 : OpenACCConstructDecl(OpenACCDeclare) {
76 std::uninitialized_value_construct_n(getTrailingObjects(), NumClauses);
77 setClauseList(getTrailingObjects(NumClauses));
78 }
79
81 SourceLocation DirLoc, SourceLocation EndLoc,
84 StartLoc, DirLoc, EndLoc) {
85 // Initialize the trailing storage.
86 llvm::uninitialized_copy(Clauses, getTrailingObjects());
87
88 setClauseList(getTrailingObjects(Clauses.size()));
89 }
90
91public:
92 static OpenACCDeclareDecl *Create(ASTContext &Ctx, DeclContext *DC,
93 SourceLocation StartLoc,
94 SourceLocation DirLoc,
95 SourceLocation EndLoc,
96 ArrayRef<const OpenACCClause *> Clauses);
97 static OpenACCDeclareDecl *
98 CreateDeserialized(ASTContext &Ctx, GlobalDeclID ID, unsigned NumClauses);
99 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
100 static bool classofKind(Kind K) { return K == OpenACCDeclare; }
101};
102
103// Reprents a 'routine' directive with a name. When this has no name, it is
104// represented as an attribute.
106 : public OpenACCConstructDecl,
107 private llvm::TrailingObjects<OpenACCRoutineDecl, const OpenACCClause *> {
108 friend TrailingObjects;
109 friend class ASTDeclReader;
110 friend class ASTDeclWriter;
111
112 Expr *FuncRef = nullptr;
113 SourceRange ParensLoc;
114
115 OpenACCRoutineDecl(unsigned NumClauses)
116 : OpenACCConstructDecl(OpenACCRoutine) {
117 std::uninitialized_value_construct_n(getTrailingObjects(), NumClauses);
118 setClauseList(getTrailingObjects(NumClauses));
119 }
120
122 SourceLocation DirLoc, SourceLocation LParenLoc,
123 Expr *FuncRef, SourceLocation RParenLoc,
124 SourceLocation EndLoc,
127 StartLoc, DirLoc, EndLoc),
128 FuncRef(FuncRef), ParensLoc(LParenLoc, RParenLoc) {
129 assert(LParenLoc.isValid() &&
130 "Cannot represent implicit name with this declaration");
131 // Initialize the trailing storage.
132 llvm::uninitialized_copy(Clauses, getTrailingObjects());
133 setClauseList(getTrailingObjects(Clauses.size()));
134 }
135
136public:
137 static OpenACCRoutineDecl *
138 Create(ASTContext &Ctx, DeclContext *DC, SourceLocation StartLoc,
139 SourceLocation DirLoc, SourceLocation LParenLoc, Expr *FuncRef,
140 SourceLocation RParenLoc, SourceLocation EndLoc,
141 ArrayRef<const OpenACCClause *> Clauses);
142 static OpenACCRoutineDecl *
143 CreateDeserialized(ASTContext &Ctx, GlobalDeclID ID, unsigned NumClauses);
144 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
145 static bool classofKind(Kind K) { return K == OpenACCRoutine; }
146
147 const Expr *getFunctionReference() const { return FuncRef; }
148 Expr *getFunctionReference() { return FuncRef; }
149
150 SourceLocation getLParenLoc() const { return ParensLoc.getBegin(); }
151 SourceLocation getRParenLoc() const { return ParensLoc.getEnd(); }
152};
153} // namespace clang
154
155#endif
Defines the clang::ASTContext interface.
static char ID
Definition: Arena.cpp:183
const Decl * D
Defines some OpenACC-specific enums and functions.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1449
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
SourceLocation getLocation() const
Definition: DeclBase.h:439
This represents one expression.
Definition: Expr.h:112
static bool classofKind(Kind K)
Definition: DeclOpenACC.cpp:20
OpenACCDirectiveKind getDirectiveKind() const
Definition: DeclOpenACC.h:56
void setClauseList(MutableArrayRef< const OpenACCClause * > NewClauses)
Definition: DeclOpenACC.h:50
OpenACCConstructDecl(Kind DeclKind, DeclContext *DC, OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation EndLoc)
Definition: DeclOpenACC.h:42
static bool classof(const Decl *D)
Definition: DeclOpenACC.h:63
ArrayRef< const OpenACCClause * > clauses() const
Definition: DeclOpenACC.h:62
OpenACCConstructDecl(Kind DeclKind)
Definition: DeclOpenACC.h:48
SourceLocation getDirectiveLoc() const
Definition: DeclOpenACC.h:57
virtual SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclOpenACC.h:58
static OpenACCDeclareDecl * CreateDeserialized(ASTContext &Ctx, GlobalDeclID ID, unsigned NumClauses)
Definition: DeclOpenACC.cpp:36
static bool classofKind(Kind K)
Definition: DeclOpenACC.h:100
static bool classof(const Decl *D)
Definition: DeclOpenACC.h:99
SourceLocation getRParenLoc() const
Definition: DeclOpenACC.h:151
static OpenACCRoutineDecl * CreateDeserialized(ASTContext &Ctx, GlobalDeclID ID, unsigned NumClauses)
Definition: DeclOpenACC.cpp:55
static bool classof(const Decl *D)
Definition: DeclOpenACC.h:144
const Expr * getFunctionReference() const
Definition: DeclOpenACC.h:147
static bool classofKind(Kind K)
Definition: DeclOpenACC.h:145
SourceLocation getLParenLoc() const
Definition: DeclOpenACC.h:150
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
The JSON file list parser is used to communicate input to InstallAPI.
OpenACCDirectiveKind
Definition: OpenACCKinds.h:28
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:102