2019-02-26 23:26:28 +01:00
|
|
|
// Copyright (c) 2019, 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.
|
|
|
|
|
|
|
|
#include "characteristics.h"
|
|
|
|
#include <ostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace std::literals::string_literals;
|
|
|
|
|
|
|
|
namespace Fortran::evaluate::characteristics {
|
|
|
|
|
|
|
|
bool DummyDataObject::operator==(const DummyDataObject &that) const {
|
|
|
|
return attrs == that.attrs && intent == that.intent && type == that.type &&
|
|
|
|
shape == that.shape && coshape == that.coshape;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &DummyDataObject::Dump(std::ostream &o) const {
|
|
|
|
attrs.Dump(o, EnumToString);
|
|
|
|
if (intent != common::Intent::Default) {
|
|
|
|
o << "INTENT(" << common::EnumToString(intent) << ')';
|
|
|
|
}
|
2019-02-27 00:59:25 +01:00
|
|
|
o << type.AsFortran();
|
2019-02-26 23:26:28 +01:00
|
|
|
if (!shape.empty()) {
|
|
|
|
char sep{'('};
|
|
|
|
for (const auto &expr : shape) {
|
|
|
|
o << sep;
|
|
|
|
sep = ',';
|
|
|
|
if (expr.has_value()) {
|
|
|
|
expr->AsFortran(o);
|
|
|
|
} else {
|
|
|
|
o << ':';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
o << ')';
|
|
|
|
}
|
|
|
|
if (!coshape.empty()) {
|
|
|
|
char sep{'['};
|
|
|
|
for (const auto &expr : coshape) {
|
|
|
|
expr.AsFortran(o << sep);
|
|
|
|
sep = ',';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyProcedure::operator==(const DummyProcedure &that) const {
|
|
|
|
return attrs == that.attrs && explicitProcedure == that.explicitProcedure;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &DummyProcedure::Dump(std::ostream &o) const {
|
|
|
|
attrs.Dump(o, EnumToString);
|
2019-03-20 21:44:00 +01:00
|
|
|
explicitProcedure.value().Dump(o);
|
2019-02-26 23:26:28 +01:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &AlternateReturn::Dump(std::ostream &o) const { return o << '*'; }
|
|
|
|
|
|
|
|
bool FunctionResult::operator==(const FunctionResult &that) const {
|
|
|
|
return attrs == that.attrs && type == that.type && rank == that.rank;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &FunctionResult::Dump(std::ostream &o) const {
|
|
|
|
attrs.Dump(o, EnumToString);
|
2019-02-27 00:59:25 +01:00
|
|
|
return o << type.AsFortran() << " rank " << rank;
|
2019-02-26 23:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Procedure::operator==(const Procedure &that) const {
|
|
|
|
return attrs == that.attrs && dummyArguments == that.dummyArguments &&
|
|
|
|
functionResult == that.functionResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &Procedure::Dump(std::ostream &o) const {
|
|
|
|
attrs.Dump(o, EnumToString);
|
|
|
|
if (functionResult.has_value()) {
|
|
|
|
functionResult->Dump(o << "TYPE(") << ") FUNCTION";
|
|
|
|
} else {
|
|
|
|
o << "SUBROUTINE";
|
|
|
|
}
|
|
|
|
char sep{'('};
|
|
|
|
for (const auto &dummy : dummyArguments) {
|
|
|
|
o << sep;
|
|
|
|
sep = ',';
|
|
|
|
std::visit([&](const auto &x) { x.Dump(o); }, dummy);
|
|
|
|
}
|
|
|
|
return o << (sep == '(' ? "()" : ")");
|
|
|
|
}
|
2019-03-20 21:11:49 +01:00
|
|
|
DEFINE_DEFAULT_CONSTRUCTORS_AND_ASSIGNMENTS(DummyProcedure)
|
2019-02-26 23:26:28 +01:00
|
|
|
}
|
2019-03-20 19:38:45 +01:00
|
|
|
DEFINE_DELETER(Fortran::evaluate::characteristics::Procedure)
|