1//===-- lib/Semantics/attr.cpp --------------------------------------------===//
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#include "flang/Semantics/attr.h"
10#include "flang/Common/idioms.h"
11#include "llvm/Support/raw_ostream.h"
12#include <stddef.h>
13
14namespace Fortran::semantics {
15
16void Attrs::CheckValid(const Attrs &allowed) const {
17 if (!allowed.HasAll(*this)) {
18 common::die("invalid attribute");
19 }
20}
21
22std::string AttrToString(Attr attr) {
23 switch (attr) {
24 case Attr::BIND_C:
25 return "BIND(C)";
26 case Attr::INTENT_IN:
27 return "INTENT(IN)";
28 case Attr::INTENT_INOUT:
29 return "INTENT(INOUT)";
30 case Attr::INTENT_OUT:
31 return "INTENT(OUT)";
32 default:
33 return std::string{EnumToString(attr)};
34 }
35}
36
37llvm::raw_ostream &operator<<(llvm::raw_ostream &o, Attr attr) {
38 return o << AttrToString(attr);
39}
40
41llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const Attrs &attrs) {
42 std::size_t n{attrs.count()};
43 std::size_t seen{0};
44 for (std::size_t j{0}; seen < n; ++j) {
45 Attr attr{static_cast<Attr>(j)};
46 if (attrs.test(attr)) {
47 if (seen > 0) {
48 o << ", ";
49 }
50 o << attr;
51 ++seen;
52 }
53 }
54 return o;
55}
56} // namespace Fortran::semantics
57

source code of flang/lib/Semantics/attr.cpp