|
| 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 | + |
| 17 | +#include "clang/AST/ASTContext.h" |
| 18 | +#include "clang/AST/Decl.h" |
| 19 | +#include "clang/AST/OpenACCClause.h" |
| 20 | +#include "clang/Basic/OpenACCKinds.h" |
| 21 | + |
| 22 | +namespace clang { |
| 23 | + |
| 24 | +// A base class for the declaration constructs, which manages the clauses and |
| 25 | +// basic source location information. Currently not part of the Decl inheritence |
| 26 | +// tree, as we should never have a reason to store one of these. |
| 27 | +class OpenACCConstructDecl : public Decl { |
| 28 | + friend class ASTDeclReader; |
| 29 | + friend class ASTDeclWriter; |
| 30 | + // The directive kind, each implementation of this interface is expected to |
| 31 | + // handle a specific kind. |
| 32 | + OpenACCDirectiveKind DirKind = OpenACCDirectiveKind::Invalid; |
| 33 | + SourceLocation DirectiveLoc; |
| 34 | + SourceLocation EndLoc; |
| 35 | + /// The list of clauses. This is stored here as an ArrayRef, as this is the |
| 36 | + /// most convienient place to access the list, however the list itself should |
| 37 | + /// be stored in leaf nodes, likely in trailing-storage. |
| 38 | + MutableArrayRef<const OpenACCClause *> Clauses; |
| 39 | + |
| 40 | +protected: |
| 41 | + OpenACCConstructDecl(Kind DeclKind, DeclContext *DC, OpenACCDirectiveKind K, |
| 42 | + SourceLocation StartLoc, SourceLocation DirLoc, |
| 43 | + SourceLocation EndLoc) |
| 44 | + : Decl(DeclKind, DC, StartLoc), DirKind(K), DirectiveLoc(DirLoc), |
| 45 | + EndLoc(EndLoc) {} |
| 46 | + |
| 47 | + OpenACCConstructDecl(Kind DeclKind) : Decl(DeclKind, EmptyShell{}) {} |
| 48 | + |
| 49 | + void setClauseList(MutableArrayRef<const OpenACCClause *> NewClauses) { |
| 50 | + assert(Clauses.empty() && "Cannot change clause list"); |
| 51 | + Clauses = NewClauses; |
| 52 | + } |
| 53 | + |
| 54 | +public: |
| 55 | + OpenACCDirectiveKind getDirectiveKind() const { return DirKind; } |
| 56 | + SourceLocation getDirectiveLoc() const { return DirectiveLoc; } |
| 57 | + virtual SourceRange getSourceRange() const override LLVM_READONLY { |
| 58 | + return SourceRange(getLocation(), EndLoc); |
| 59 | + } |
| 60 | + |
| 61 | + ArrayRef<const OpenACCClause *> clauses() const { return Clauses; } |
| 62 | +}; |
| 63 | + |
| 64 | +class OpenACCDeclareDecl final |
| 65 | + : public OpenACCConstructDecl, |
| 66 | + private llvm::TrailingObjects<OpenACCDeclareDecl, const OpenACCClause *> { |
| 67 | + friend TrailingObjects; |
| 68 | + friend class ASTDeclReader; |
| 69 | + friend class ASTDeclWriter; |
| 70 | + |
| 71 | + OpenACCDeclareDecl(unsigned NumClauses) |
| 72 | + : OpenACCConstructDecl(OpenACCDeclare) { |
| 73 | + std::uninitialized_value_construct( |
| 74 | + getTrailingObjects<const OpenACCClause *>(), |
| 75 | + getTrailingObjects<const OpenACCClause *>() + NumClauses); |
| 76 | + setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(), |
| 77 | + NumClauses)); |
| 78 | + } |
| 79 | + |
| 80 | + OpenACCDeclareDecl(DeclContext *DC, SourceLocation StartLoc, |
| 81 | + SourceLocation DirLoc, SourceLocation EndLoc, |
| 82 | + ArrayRef<const OpenACCClause *> Clauses) |
| 83 | + : OpenACCConstructDecl(OpenACCDeclare, DC, OpenACCDirectiveKind::Declare, |
| 84 | + StartLoc, DirLoc, EndLoc) { |
| 85 | + // Initialize the trailing storage. |
| 86 | + std::uninitialized_copy(Clauses.begin(), Clauses.end(), |
| 87 | + getTrailingObjects<const OpenACCClause *>()); |
| 88 | + |
| 89 | + setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(), |
| 90 | + Clauses.size())); |
| 91 | + } |
| 92 | + |
| 93 | +public: |
| 94 | + static OpenACCDeclareDecl *Create(ASTContext &Ctx, DeclContext *DC, |
| 95 | + SourceLocation StartLoc, |
| 96 | + SourceLocation DirLoc, |
| 97 | + SourceLocation EndLoc, |
| 98 | + ArrayRef<const OpenACCClause *> Clauses); |
| 99 | + static OpenACCDeclareDecl * |
| 100 | + CreateDeserialized(ASTContext &Ctx, GlobalDeclID ID, unsigned NumClauses); |
| 101 | + static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 102 | + static bool classofKind(Kind K) { return K == OpenACCDeclare; } |
| 103 | +}; |
| 104 | +} // namespace clang |
| 105 | + |
| 106 | +#endif |
0 commit comments