2018-05-01 21:50:34 +02:00
|
|
|
// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-02-07 01:46:29 +01:00
|
|
|
#include "attr.h"
|
2018-06-18 20:03:43 +02:00
|
|
|
#include "../common/idioms.h"
|
2018-09-15 00:04:50 +02:00
|
|
|
#include <ostream>
|
2018-02-15 00:07:59 +01:00
|
|
|
#include <stddef.h>
|
2018-02-07 01:46:29 +01:00
|
|
|
|
2018-05-02 22:48:12 +02:00
|
|
|
namespace Fortran::semantics {
|
2018-02-07 01:46:29 +01:00
|
|
|
|
2018-02-15 17:27:19 +01:00
|
|
|
void Attrs::CheckValid(const Attrs &allowed) const {
|
|
|
|
if (!allowed.HasAll(*this)) {
|
2018-06-18 20:03:43 +02:00
|
|
|
common::die("invalid attribute");
|
2018-02-07 01:46:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-17 01:23:18 +02:00
|
|
|
std::string AttrToString(Attr attr) {
|
|
|
|
switch (attr) {
|
|
|
|
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-02-15 00:07:59 +01:00
|
|
|
std::ostream &operator<<(std::ostream &o, Attr attr) {
|
2018-07-17 01:23:18 +02:00
|
|
|
return o << AttrToString(attr);
|
2018-02-15 00:07:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &o, const Attrs &attrs) {
|
2018-04-06 19:34:59 +02:00
|
|
|
std::size_t n{attrs.count()};
|
|
|
|
std::size_t seen{0};
|
2018-04-06 01:49:48 +02:00
|
|
|
for (std::size_t j{0}; seen < n; ++j) {
|
|
|
|
Attr attr{static_cast<Attr>(j)};
|
|
|
|
if (attrs.test(attr)) {
|
2018-04-06 19:34:59 +02:00
|
|
|
if (seen > 0) {
|
|
|
|
o << ", ";
|
|
|
|
}
|
|
|
|
o << attr;
|
2018-04-06 01:49:48 +02:00
|
|
|
++seen;
|
2018-02-07 01:46:29 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-15 00:07:59 +01:00
|
|
|
return o;
|
2018-02-07 01:46:29 +01:00
|
|
|
}
|
2018-10-25 14:55:23 +02:00
|
|
|
}
|