1 //===-- lib/Semantics/check-acc-structure.h ---------------------*- 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 // OpenACC 3.1 structure validity check list
8 //    1. invalid clauses on directive
9 //    2. invalid repeated clauses on directive
10 //    3. invalid nesting of regions
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef FORTRAN_SEMANTICS_CHECK_ACC_STRUCTURE_H_
15 #define FORTRAN_SEMANTICS_CHECK_ACC_STRUCTURE_H_
16 
17 #include "check-directive-structure.h"
18 #include "flang/Common/enum-set.h"
19 #include "flang/Parser/parse-tree.h"
20 #include "flang/Semantics/semantics.h"
21 #include "llvm/Frontend/OpenACC/ACC.h.inc"
22 
23 using AccDirectiveSet = Fortran::common::EnumSet<llvm::acc::Directive,
24     llvm::acc::Directive_enumSize>;
25 
26 using AccClauseSet =
27     Fortran::common::EnumSet<llvm::acc::Clause, llvm::acc::Clause_enumSize>;
28 
29 #define GEN_FLANG_DIRECTIVE_CLAUSE_SETS
30 #include "llvm/Frontend/OpenACC/ACC.inc"
31 
32 namespace Fortran::semantics {
33 
34 class AccStructureChecker
35     : public DirectiveStructureChecker<llvm::acc::Directive, llvm::acc::Clause,
36           parser::AccClause, llvm::acc::Clause_enumSize> {
37 public:
AccStructureChecker(SemanticsContext & context)38   AccStructureChecker(SemanticsContext &context)
39       : DirectiveStructureChecker(context,
40 #define GEN_FLANG_DIRECTIVE_CLAUSE_MAP
41 #include "llvm/Frontend/OpenACC/ACC.inc"
42         ) {
43   }
44 
45   // Construct and directives
46   void Enter(const parser::OpenACCBlockConstruct &);
47   void Leave(const parser::OpenACCBlockConstruct &);
48   void Enter(const parser::OpenACCCombinedConstruct &);
49   void Leave(const parser::OpenACCCombinedConstruct &);
50   void Enter(const parser::OpenACCLoopConstruct &);
51   void Leave(const parser::OpenACCLoopConstruct &);
52   void Enter(const parser::OpenACCRoutineConstruct &);
53   void Leave(const parser::OpenACCRoutineConstruct &);
54   void Enter(const parser::OpenACCStandaloneConstruct &);
55   void Leave(const parser::OpenACCStandaloneConstruct &);
56   void Enter(const parser::OpenACCStandaloneDeclarativeConstruct &);
57   void Leave(const parser::OpenACCStandaloneDeclarativeConstruct &);
58   void Enter(const parser::OpenACCWaitConstruct &);
59   void Leave(const parser::OpenACCWaitConstruct &);
60   void Enter(const parser::OpenACCAtomicConstruct &);
61   void Leave(const parser::OpenACCAtomicConstruct &);
62   void Enter(const parser::OpenACCCacheConstruct &);
63   void Leave(const parser::OpenACCCacheConstruct &);
64 
65   // Clauses
66   void Leave(const parser::AccClauseList &);
67   void Enter(const parser::AccClause &);
68 
69 #define GEN_FLANG_CLAUSE_CHECK_ENTER
70 #include "llvm/Frontend/OpenACC/ACC.inc"
71 
72 private:
73 
74   bool CheckAllowedModifier(llvm::acc::Clause clause);
75   bool IsComputeConstruct(llvm::acc::Directive directive) const;
76   bool IsInsideComputeConstruct() const;
77   void CheckNotInComputeConstruct();
78   llvm::StringRef getClauseName(llvm::acc::Clause clause) override;
79   llvm::StringRef getDirectiveName(llvm::acc::Directive directive) override;
80 };
81 
82 } // namespace Fortran::semantics
83 
84 #endif // FORTRAN_SEMANTICS_CHECK_ACC_STRUCTURE_H_
85