2020-02-25 23:11:52 +08:00
|
|
|
//===-- lib/Semantics/attr.cpp --------------------------------------------===//
|
2018-05-02 03:50:34 +08:00
|
|
|
//
|
2019-12-21 04:52:07 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-05-02 03:50:34 +08:00
|
|
|
//
|
2020-01-11 04:12:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-05-02 03:50:34 +08:00
|
|
|
|
2020-02-25 23:11:52 +08:00
|
|
|
#include "flang/Semantics/attr.h"
|
|
|
|
#include "flang/Common/idioms.h"
|
2020-02-28 23:11:03 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2018-02-15 07:07:59 +08:00
|
|
|
#include <stddef.h>
|
2018-02-07 08:46:29 +08:00
|
|
|
|
2018-05-03 04:48:12 +08:00
|
|
|
namespace Fortran::semantics {
|
2018-02-07 08:46:29 +08:00
|
|
|
|
2018-02-16 00:27:19 +08:00
|
|
|
void Attrs::CheckValid(const Attrs &allowed) const {
|
|
|
|
if (!allowed.HasAll(*this)) {
|
2018-06-19 02:03:43 +08:00
|
|
|
common::die("invalid attribute");
|
2018-02-07 08:46:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-17 07:23:18 +08:00
|
|
|
std::string AttrToString(Attr attr) {
|
|
|
|
switch (attr) {
|
2020-03-29 12:00:16 +08:00
|
|
|
case Attr::BIND_C:
|
|
|
|
return "BIND(C)";
|
|
|
|
case Attr::INTENT_IN:
|
|
|
|
return "INTENT(IN)";
|
|
|
|
case Attr::INTENT_INOUT:
|
|
|
|
return "INTENT(INOUT)";
|
|
|
|
case Attr::INTENT_OUT:
|
|
|
|
return "INTENT(OUT)";
|
|
|
|
default:
|
|
|
|
return EnumToString(attr);
|
2018-07-17 07:23:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 23:11:03 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &o, Attr attr) {
|
2018-07-17 07:23:18 +08:00
|
|
|
return o << AttrToString(attr);
|
2018-02-15 07:07:59 +08:00
|
|
|
}
|
|
|
|
|
2020-02-28 23:11:03 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const Attrs &attrs) {
|
2018-04-07 01:34:59 +08:00
|
|
|
std::size_t n{attrs.count()};
|
|
|
|
std::size_t seen{0};
|
2018-04-06 07:49:48 +08:00
|
|
|
for (std::size_t j{0}; seen < n; ++j) {
|
|
|
|
Attr attr{static_cast<Attr>(j)};
|
|
|
|
if (attrs.test(attr)) {
|
2018-04-07 01:34:59 +08:00
|
|
|
if (seen > 0) {
|
|
|
|
o << ", ";
|
|
|
|
}
|
|
|
|
o << attr;
|
2018-04-06 07:49:48 +08:00
|
|
|
++seen;
|
2018-02-07 08:46:29 +08:00
|
|
|
}
|
|
|
|
}
|
2018-02-15 07:07:59 +08:00
|
|
|
return o;
|
2018-02-07 08:46:29 +08:00
|
|
|
}
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::semantics
|