• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
14 namespace Fortran::semantics {
15 
CheckValid(const Attrs & allowed) const16 void Attrs::CheckValid(const Attrs &allowed) const {
17   if (!allowed.HasAll(*this)) {
18     common::die("invalid attribute");
19   }
20 }
21 
AttrToString(Attr attr)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 EnumToString(attr);
34   }
35 }
36 
operator <<(llvm::raw_ostream & o,Attr attr)37 llvm::raw_ostream &operator<<(llvm::raw_ostream &o, Attr attr) {
38   return o << AttrToString(attr);
39 }
40 
operator <<(llvm::raw_ostream & o,const Attrs & attrs)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 << ", ";
49       }
50       o << attr;
51       ++seen;
52     }
53   }
54   return o;
55 }
56 } // namespace Fortran::semantics
57