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