[lldb] Add ability to hide the root name of a value
[llvm-project.git] / flang / lib / Semantics / attr.cpp
bloba447672c39cc2f9798a3a8ceb1cdfa7a68a874ce
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 //===----------------------------------------------------------------------===//
9 #include "flang/Semantics/attr.h"
10 #include "flang/Common/idioms.h"
11 #include "llvm/Support/raw_ostream.h"
12 #include <stddef.h>
14 namespace Fortran::semantics {
16 void Attrs::CheckValid(const Attrs &allowed) const {
17 if (!allowed.HasAll(*this)) {
18 common::die("invalid attribute");
22 std::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)};
37 llvm::raw_ostream &operator<<(llvm::raw_ostream &o, Attr attr) {
38 return o << AttrToString(attr);
41 llvm::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 << ", ";
50 o << attr;
51 ++seen;
54 return o;
56 } // namespace Fortran::semantics