• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- include/flang/Semantics/attr.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 //===----------------------------------------------------------------------===//
8 
9 #ifndef FORTRAN_SEMANTICS_ATTR_H_
10 #define FORTRAN_SEMANTICS_ATTR_H_
11 
12 #include "flang/Common/enum-set.h"
13 #include "flang/Common/idioms.h"
14 #include <cinttypes>
15 #include <string>
16 
17 namespace llvm {
18 class raw_ostream;
19 }
20 
21 namespace Fortran::semantics {
22 
23 // All available attributes.
ENUM_CLASS(Attr,ABSTRACT,ALLOCATABLE,ASYNCHRONOUS,BIND_C,CONTIGUOUS,DEFERRED,ELEMENTAL,EXTENDS,EXTERNAL,IMPURE,INTENT_IN,INTENT_INOUT,INTENT_OUT,INTRINSIC,MODULE,NON_OVERRIDABLE,NON_RECURSIVE,NOPASS,OPTIONAL,PARAMETER,PASS,POINTER,PRIVATE,PROTECTED,PUBLIC,PURE,RECURSIVE,SAVE,TARGET,VALUE,VOLATILE)24 ENUM_CLASS(Attr, ABSTRACT, ALLOCATABLE, ASYNCHRONOUS, BIND_C, CONTIGUOUS,
25     DEFERRED, ELEMENTAL, EXTENDS, EXTERNAL, IMPURE, INTENT_IN, INTENT_INOUT,
26     INTENT_OUT, INTRINSIC, MODULE, NON_OVERRIDABLE, NON_RECURSIVE, NOPASS,
27     OPTIONAL, PARAMETER, PASS, POINTER, PRIVATE, PROTECTED, PUBLIC, PURE,
28     RECURSIVE, SAVE, TARGET, VALUE, VOLATILE)
29 
30 // Set of attributes
31 class Attrs : public common::EnumSet<Attr, Attr_enumSize> {
32 private:
33   using enumSetType = common::EnumSet<Attr, Attr_enumSize>;
34 
35 public:
36   using enumSetType::enumSetType;
37   Attrs(const enumSetType &attrs) : enumSetType(attrs) {}
38   Attrs(enumSetType &&attrs) : enumSetType(std::move(attrs)) {}
39   constexpr bool HasAny(const Attrs &x) const { return !(*this & x).none(); }
40   constexpr bool HasAll(const Attrs &x) const { return (~*this & x).none(); }
41   // Internal error if any of these attributes are not in allowed.
42   void CheckValid(const Attrs &allowed) const;
43 
44 private:
45   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Attrs &);
46 };
47 
48 // Return string representation of attr that matches Fortran source.
49 std::string AttrToString(Attr attr);
50 
51 llvm::raw_ostream &operator<<(llvm::raw_ostream &o, Attr attr);
52 llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const Attrs &attrs);
53 } // namespace Fortran::semantics
54 #endif // FORTRAN_SEMANTICS_ATTR_H_
55