2018-05-01 12:50:34 -07: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-03-22 17:08:20 -07:00
|
|
|
#include "symbol.h"
|
|
|
|
#include "scope.h"
|
2018-06-18 11:03:43 -07:00
|
|
|
#include "../common/idioms.h"
|
2018-11-16 12:43:08 -08:00
|
|
|
#include <ostream>
|
|
|
|
#include <string>
|
2018-03-22 17:08:20 -07:00
|
|
|
|
2018-03-23 12:24:29 -07:00
|
|
|
namespace Fortran::semantics {
|
2018-03-22 17:08:20 -07:00
|
|
|
|
2018-05-03 15:57:56 -07:00
|
|
|
std::ostream &operator<<(std::ostream &os, const parser::CharBlock &name) {
|
|
|
|
return os << name.ToString();
|
|
|
|
}
|
|
|
|
|
2018-08-02 16:21:27 -07:00
|
|
|
const Scope *ModuleDetails::parent() const {
|
2018-11-16 12:43:08 -08:00
|
|
|
return isSubmodule_ && scope_ ? &scope_->parent() : nullptr;
|
2018-08-02 16:21:27 -07:00
|
|
|
}
|
|
|
|
const Scope *ModuleDetails::ancestor() const {
|
2018-11-16 12:43:08 -08:00
|
|
|
if (!isSubmodule_ || !scope_) {
|
2018-08-02 16:21:27 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for (auto *scope{scope_};;) {
|
|
|
|
auto *parent{&scope->parent()};
|
|
|
|
if (parent->kind() != Scope::Kind::Module) {
|
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
scope = parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void ModuleDetails::set_scope(const Scope *scope) {
|
|
|
|
CHECK(!scope_);
|
|
|
|
bool scopeIsSubmodule{scope->parent().kind() == Scope::Kind::Module};
|
|
|
|
CHECK(isSubmodule_ == scopeIsSubmodule);
|
|
|
|
scope_ = scope;
|
|
|
|
}
|
|
|
|
|
2018-04-12 12:59:42 -07:00
|
|
|
void EntityDetails::set_type(const DeclTypeSpec &type) {
|
|
|
|
CHECK(!type_);
|
2018-12-11 14:51:08 -08:00
|
|
|
type_ = &type;
|
2018-04-12 12:59:42 -07:00
|
|
|
}
|
|
|
|
|
2018-06-05 12:18:35 -07:00
|
|
|
void ObjectEntityDetails::set_type(const DeclTypeSpec &type) {
|
|
|
|
CHECK(!type_);
|
2018-12-11 14:51:08 -08:00
|
|
|
type_ = &type;
|
2018-06-05 12:18:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectEntityDetails::set_shape(const ArraySpec &shape) {
|
2018-04-12 12:59:42 -07:00
|
|
|
CHECK(shape_.empty());
|
|
|
|
for (const auto &shapeSpec : shape) {
|
2018-11-06 17:18:06 -08:00
|
|
|
shape_.emplace_back(shapeSpec.Clone());
|
2018-04-12 12:59:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-05 12:18:35 -07:00
|
|
|
ProcEntityDetails::ProcEntityDetails(const EntityDetails &d) {
|
2018-07-17 07:02:30 -07:00
|
|
|
if (auto type{d.type()}) {
|
2018-06-06 11:41:42 -07:00
|
|
|
interface_.set_type(*type);
|
2018-06-05 12:18:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-03 15:57:56 -07:00
|
|
|
const Symbol &UseDetails::module() const {
|
|
|
|
// owner is a module so it must have a symbol:
|
|
|
|
return *symbol_->owner().symbol();
|
|
|
|
}
|
|
|
|
|
2018-08-29 11:38:12 -07:00
|
|
|
UseErrorDetails::UseErrorDetails(const UseDetails &useDetails) {
|
|
|
|
add_occurrence(useDetails.location(), *useDetails.module().scope());
|
|
|
|
}
|
|
|
|
UseErrorDetails &UseErrorDetails::add_occurrence(
|
|
|
|
const SourceName &location, const Scope &module) {
|
2018-11-16 12:43:08 -08:00
|
|
|
occurrences_.push_back(std::make_pair(location, &module));
|
2018-08-29 11:38:12 -07:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-12-26 13:31:13 -08:00
|
|
|
GenericDetails::GenericDetails(const SymbolList &specificProcs) {
|
2018-05-22 16:12:56 -07:00
|
|
|
for (const auto *proc : specificProcs) {
|
2018-12-26 13:31:13 -08:00
|
|
|
add_specificProc(*proc);
|
2018-05-22 16:12:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 08:21:19 -07:00
|
|
|
void GenericDetails::set_specific(Symbol &specific) {
|
2018-05-22 16:12:56 -07:00
|
|
|
CHECK(!specific_);
|
2018-06-22 08:21:19 -07:00
|
|
|
specific_ = &specific;
|
|
|
|
}
|
|
|
|
void GenericDetails::set_derivedType(Symbol &derivedType) {
|
|
|
|
CHECK(!derivedType_);
|
|
|
|
derivedType_ = &derivedType;
|
2018-05-22 16:12:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const Symbol *GenericDetails::CheckSpecific() const {
|
2018-06-19 16:06:41 -07:00
|
|
|
if (specific_) {
|
2018-05-22 16:12:56 -07:00
|
|
|
for (const auto *proc : specificProcs_) {
|
2018-06-19 16:06:41 -07:00
|
|
|
if (proc == specific_) {
|
2018-05-22 16:12:56 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2018-06-19 16:06:41 -07:00
|
|
|
return specific_;
|
2018-05-22 16:12:56 -07:00
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:16:42 -07:00
|
|
|
// The name of the kind of details for this symbol.
|
|
|
|
// This is primarily for debugging.
|
2018-07-19 13:28:24 -07:00
|
|
|
std::string DetailsToString(const Details &details) {
|
2018-04-17 14:16:42 -07:00
|
|
|
return std::visit(
|
2018-06-18 11:03:43 -07:00
|
|
|
common::visitors{
|
2018-05-22 16:12:56 -07:00
|
|
|
[](const UnknownDetails &) { return "Unknown"; },
|
|
|
|
[](const MainProgramDetails &) { return "MainProgram"; },
|
|
|
|
[](const ModuleDetails &) { return "Module"; },
|
|
|
|
[](const SubprogramDetails &) { return "Subprogram"; },
|
|
|
|
[](const SubprogramNameDetails &) { return "SubprogramName"; },
|
|
|
|
[](const EntityDetails &) { return "Entity"; },
|
2018-06-05 12:18:35 -07:00
|
|
|
[](const ObjectEntityDetails &) { return "ObjectEntity"; },
|
|
|
|
[](const ProcEntityDetails &) { return "ProcEntity"; },
|
2018-06-22 08:21:19 -07:00
|
|
|
[](const DerivedTypeDetails &) { return "DerivedType"; },
|
2018-05-22 16:12:56 -07:00
|
|
|
[](const UseDetails &) { return "Use"; },
|
|
|
|
[](const UseErrorDetails &) { return "UseError"; },
|
2018-10-18 07:55:48 -07:00
|
|
|
[](const HostAssocDetails &) { return "HostAssoc"; },
|
2018-05-22 16:12:56 -07:00
|
|
|
[](const GenericDetails &) { return "Generic"; },
|
2018-08-31 16:20:00 -07:00
|
|
|
[](const ProcBindingDetails &) { return "ProcBinding"; },
|
|
|
|
[](const GenericBindingDetails &) { return "GenericBinding"; },
|
|
|
|
[](const FinalProcDetails &) { return "FinalProc"; },
|
2018-09-04 10:28:27 -07:00
|
|
|
[](const TypeParamDetails &) { return "TypeParam"; },
|
2018-09-25 08:53:53 -07:00
|
|
|
[](const MiscDetails &) { return "Misc"; },
|
2018-05-22 16:12:56 -07:00
|
|
|
[](const auto &) { return "unknown"; },
|
2018-04-17 14:16:42 -07:00
|
|
|
},
|
2018-05-03 15:57:56 -07:00
|
|
|
details);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string Symbol::GetDetailsName() const {
|
|
|
|
return DetailsToString(details_);
|
|
|
|
}
|
|
|
|
|
2018-11-05 14:36:11 -08:00
|
|
|
void Symbol::set_details(Details &&details) {
|
2018-05-14 13:51:13 -07:00
|
|
|
CHECK(CanReplaceDetails(details));
|
2018-11-05 14:36:11 -08:00
|
|
|
details_ = std::move(details);
|
2018-05-14 13:51:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Symbol::CanReplaceDetails(const Details &details) const {
|
|
|
|
if (has<UnknownDetails>()) {
|
|
|
|
return true; // can always replace UnknownDetails
|
|
|
|
} else {
|
2018-06-05 12:18:35 -07:00
|
|
|
return std::visit(
|
2018-06-18 11:03:43 -07:00
|
|
|
common::visitors{
|
2018-06-05 12:18:35 -07:00
|
|
|
[](const UseErrorDetails &) { return true; },
|
|
|
|
[=](const ObjectEntityDetails &) { return has<EntityDetails>(); },
|
|
|
|
[=](const ProcEntityDetails &) { return has<EntityDetails>(); },
|
|
|
|
[=](const SubprogramDetails &) {
|
|
|
|
return has<SubprogramNameDetails>();
|
|
|
|
},
|
|
|
|
[](const auto &) { return false; },
|
|
|
|
},
|
|
|
|
details);
|
2018-05-14 13:51:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 16:12:56 -07:00
|
|
|
Symbol &Symbol::GetUltimate() {
|
|
|
|
return const_cast<Symbol &>(static_cast<const Symbol *>(this)->GetUltimate());
|
|
|
|
}
|
2018-05-03 15:57:56 -07:00
|
|
|
const Symbol &Symbol::GetUltimate() const {
|
2018-07-17 07:02:30 -07:00
|
|
|
if (const auto *details{detailsIf<UseDetails>()}) {
|
2018-05-03 15:57:56 -07:00
|
|
|
return details->symbol().GetUltimate();
|
2018-10-18 07:55:48 -07:00
|
|
|
} else if (const auto *details{detailsIf<HostAssocDetails>()}) {
|
|
|
|
return details->symbol().GetUltimate();
|
2018-05-03 15:57:56 -07:00
|
|
|
} else {
|
|
|
|
return *this;
|
|
|
|
}
|
2018-04-17 14:16:42 -07:00
|
|
|
}
|
|
|
|
|
2018-11-06 17:18:06 -08:00
|
|
|
DeclTypeSpec *Symbol::GetType() {
|
|
|
|
return const_cast<DeclTypeSpec *>(
|
|
|
|
const_cast<const Symbol *>(this)->GetType());
|
|
|
|
}
|
|
|
|
|
2018-06-26 15:01:42 -07:00
|
|
|
const DeclTypeSpec *Symbol::GetType() const {
|
|
|
|
return std::visit(
|
|
|
|
common::visitors{
|
2018-12-11 14:51:08 -08:00
|
|
|
[](const EntityDetails &x) { return x.type(); },
|
|
|
|
[](const ObjectEntityDetails &x) { return x.type(); },
|
2018-06-26 15:01:42 -07:00
|
|
|
[](const ProcEntityDetails &x) { return x.interface().type(); },
|
2018-12-11 14:51:08 -08:00
|
|
|
[](const TypeParamDetails &x) { return x.type(); },
|
2018-10-18 07:55:48 -07:00
|
|
|
[](const auto &) -> const DeclTypeSpec * { return nullptr; },
|
2018-06-26 15:01:42 -07:00
|
|
|
},
|
|
|
|
details_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Symbol::SetType(const DeclTypeSpec &type) {
|
|
|
|
std::visit(
|
|
|
|
common::visitors{
|
|
|
|
[&](EntityDetails &x) { x.set_type(type); },
|
|
|
|
[&](ObjectEntityDetails &x) { x.set_type(type); },
|
|
|
|
[&](ProcEntityDetails &x) { x.interface().set_type(type); },
|
2018-09-04 10:28:27 -07:00
|
|
|
[&](TypeParamDetails &x) { x.set_type(type); },
|
2018-06-26 15:01:42 -07:00
|
|
|
[](auto &) {},
|
|
|
|
},
|
|
|
|
details_);
|
|
|
|
}
|
|
|
|
|
2018-10-26 11:57:08 -07:00
|
|
|
bool Symbol::IsSubprogram() const {
|
2018-05-14 13:51:13 -07:00
|
|
|
return std::visit(
|
2018-06-18 11:03:43 -07:00
|
|
|
common::visitors{
|
2018-06-05 12:18:35 -07:00
|
|
|
[](const SubprogramDetails &) { return true; },
|
|
|
|
[](const SubprogramNameDetails &) { return true; },
|
|
|
|
[](const GenericDetails &) { return true; },
|
2018-10-26 11:57:08 -07:00
|
|
|
[](const UseDetails &x) { return x.symbol().IsSubprogram(); },
|
2018-06-05 12:18:35 -07:00
|
|
|
[](const auto &) { return false; },
|
2018-05-14 13:51:13 -07:00
|
|
|
},
|
|
|
|
details_);
|
|
|
|
}
|
|
|
|
|
2018-06-05 12:18:35 -07:00
|
|
|
bool Symbol::HasExplicitInterface() const {
|
|
|
|
return std::visit(
|
2018-06-18 11:03:43 -07:00
|
|
|
common::visitors{
|
2018-06-05 12:18:35 -07:00
|
|
|
[](const SubprogramDetails &) { return true; },
|
|
|
|
[](const SubprogramNameDetails &) { return true; },
|
|
|
|
[](const ProcEntityDetails &x) { return x.HasExplicitInterface(); },
|
|
|
|
[](const UseDetails &x) { return x.symbol().HasExplicitInterface(); },
|
|
|
|
[](const auto &) { return false; },
|
|
|
|
},
|
|
|
|
details_);
|
|
|
|
}
|
|
|
|
|
2018-10-26 11:57:08 -07:00
|
|
|
bool Symbol::IsSeparateModuleProc() const {
|
2018-10-26 07:34:50 -07:00
|
|
|
if (attrs().test(Attr::MODULE)) {
|
|
|
|
if (auto *details{detailsIf<SubprogramDetails>()}) {
|
|
|
|
return details->isInterface();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-18 09:34:59 -07:00
|
|
|
int Symbol::Rank() const {
|
|
|
|
return std::visit(
|
|
|
|
common::visitors{
|
|
|
|
[](const SubprogramDetails &sd) {
|
|
|
|
if (sd.isFunction()) {
|
|
|
|
return sd.result().Rank();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[](const GenericDetails &) {
|
|
|
|
return 0; /*TODO*/
|
|
|
|
},
|
|
|
|
[](const UseDetails &x) { return x.symbol().Rank(); },
|
2018-10-18 07:55:48 -07:00
|
|
|
[](const HostAssocDetails &x) { return x.symbol().Rank(); },
|
2018-09-18 09:34:59 -07:00
|
|
|
[](const ObjectEntityDetails &oed) {
|
|
|
|
return static_cast<int>(oed.shape().size());
|
|
|
|
},
|
|
|
|
[](const auto &) { return 0; },
|
|
|
|
},
|
|
|
|
details_);
|
|
|
|
}
|
|
|
|
|
2018-06-05 12:18:35 -07:00
|
|
|
ObjectEntityDetails::ObjectEntityDetails(const EntityDetails &d)
|
2018-06-22 08:21:19 -07:00
|
|
|
: isDummy_{d.isDummy()}, type_{d.type()} {}
|
2018-06-05 12:18:35 -07:00
|
|
|
|
2018-04-12 12:59:42 -07:00
|
|
|
std::ostream &operator<<(std::ostream &os, const EntityDetails &x) {
|
2018-06-05 12:18:35 -07:00
|
|
|
if (x.type()) {
|
|
|
|
os << " type: " << *x.type();
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const ObjectEntityDetails &x) {
|
2018-04-12 12:59:42 -07:00
|
|
|
if (x.type()) {
|
|
|
|
os << " type: " << *x.type();
|
|
|
|
}
|
|
|
|
if (!x.shape().empty()) {
|
|
|
|
os << " shape:";
|
|
|
|
for (const auto &s : x.shape()) {
|
|
|
|
os << ' ' << s;
|
|
|
|
}
|
|
|
|
}
|
2018-12-06 06:59:37 -08:00
|
|
|
if (x.init_) {
|
|
|
|
x.init_->AsFortran(os << " init:");
|
2018-11-06 17:18:06 -08:00
|
|
|
}
|
2018-04-12 12:59:42 -07:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2018-06-05 12:18:35 -07:00
|
|
|
bool ProcEntityDetails::HasExplicitInterface() const {
|
2018-07-17 07:02:30 -07:00
|
|
|
if (auto *symbol{interface_.symbol()}) {
|
2018-06-05 12:18:35 -07:00
|
|
|
return symbol->HasExplicitInterface();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const ProcEntityDetails &x) {
|
2018-07-17 07:02:30 -07:00
|
|
|
if (auto *symbol{x.interface_.symbol()}) {
|
2018-06-05 12:18:35 -07:00
|
|
|
os << ' ' << symbol->name().ToString();
|
2018-07-17 07:02:30 -07:00
|
|
|
} else if (auto *type{x.interface_.type()}) {
|
2018-06-05 12:18:35 -07:00
|
|
|
os << ' ' << *type;
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2018-06-22 08:21:19 -07:00
|
|
|
std::ostream &operator<<(std::ostream &os, const DerivedTypeDetails &x) {
|
2018-09-07 15:25:10 -07:00
|
|
|
if (const Symbol * extends{x.extends()}) {
|
2018-09-06 08:01:49 -07:00
|
|
|
os << " extends:" << extends->name();
|
|
|
|
}
|
|
|
|
if (x.sequence()) {
|
|
|
|
os << " sequence";
|
|
|
|
}
|
2018-06-22 08:21:19 -07:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:16:42 -07:00
|
|
|
static std::ostream &DumpType(std::ostream &os, const Symbol &symbol) {
|
2018-06-26 15:01:42 -07:00
|
|
|
if (const auto *type{symbol.GetType()}) {
|
|
|
|
os << *type << ' ';
|
2018-04-17 14:16:42 -07:00
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2018-05-03 15:57:56 -07:00
|
|
|
std::ostream &operator<<(std::ostream &os, const Details &details) {
|
|
|
|
os << DetailsToString(details);
|
2018-03-22 17:08:20 -07:00
|
|
|
std::visit(
|
2018-06-18 11:03:43 -07:00
|
|
|
common::visitors{
|
2018-04-18 15:06:35 -07:00
|
|
|
[&](const UnknownDetails &x) {},
|
|
|
|
[&](const MainProgramDetails &x) {},
|
2018-08-02 16:21:27 -07:00
|
|
|
[&](const ModuleDetails &x) {
|
|
|
|
if (x.isSubmodule()) {
|
2018-11-16 12:43:08 -08:00
|
|
|
os << " (";
|
|
|
|
if (x.ancestor()) {
|
|
|
|
auto &ancestor{x.ancestor()->name()};
|
|
|
|
os << ancestor;
|
|
|
|
if (x.parent()) {
|
|
|
|
auto &parent{x.parent()->name()};
|
|
|
|
if (ancestor != parent) {
|
|
|
|
os << ':' << parent;
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 16:21:27 -07:00
|
|
|
}
|
|
|
|
os << ")";
|
|
|
|
}
|
|
|
|
},
|
2018-03-22 17:08:20 -07:00
|
|
|
[&](const SubprogramDetails &x) {
|
2018-04-18 15:06:35 -07:00
|
|
|
os << " (";
|
2018-03-22 17:08:20 -07:00
|
|
|
int n = 0;
|
2018-04-17 14:16:42 -07:00
|
|
|
for (const auto &dummy : x.dummyArgs()) {
|
2018-03-22 17:08:20 -07:00
|
|
|
if (n++ > 0) os << ", ";
|
2018-04-17 14:16:42 -07:00
|
|
|
DumpType(os, *dummy);
|
2018-05-03 15:57:56 -07:00
|
|
|
os << dummy->name();
|
2018-03-22 17:08:20 -07:00
|
|
|
}
|
|
|
|
os << ')';
|
2018-04-17 14:16:42 -07:00
|
|
|
if (x.isFunction()) {
|
|
|
|
os << " result(";
|
|
|
|
DumpType(os, x.result());
|
2018-05-03 15:57:56 -07:00
|
|
|
os << x.result().name() << ')';
|
2018-03-22 17:08:20 -07:00
|
|
|
}
|
2018-05-14 13:51:13 -07:00
|
|
|
if (x.isInterface()) {
|
|
|
|
os << " interface";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[&](const SubprogramNameDetails &x) {
|
|
|
|
os << ' ' << EnumToString(x.kind());
|
2018-03-22 17:08:20 -07:00
|
|
|
},
|
2018-04-18 15:06:35 -07:00
|
|
|
[&](const EntityDetails &x) { os << x; },
|
2018-06-05 12:18:35 -07:00
|
|
|
[&](const ObjectEntityDetails &x) { os << x; },
|
|
|
|
[&](const ProcEntityDetails &x) { os << x; },
|
2018-06-22 08:21:19 -07:00
|
|
|
[&](const DerivedTypeDetails &x) { os << x; },
|
2018-05-03 15:57:56 -07:00
|
|
|
[&](const UseDetails &x) {
|
|
|
|
os << " from " << x.symbol().name() << " in " << x.module().name();
|
|
|
|
},
|
|
|
|
[&](const UseErrorDetails &x) {
|
|
|
|
os << " uses:";
|
2018-11-16 12:43:08 -08:00
|
|
|
for (const auto &[location, module] : x.occurrences()) {
|
|
|
|
os << " from " << module->name() << " at " << location;
|
2018-05-03 15:57:56 -07:00
|
|
|
}
|
|
|
|
},
|
2018-10-18 07:55:48 -07:00
|
|
|
[](const HostAssocDetails &) {},
|
2018-05-14 13:51:13 -07:00
|
|
|
[&](const GenericDetails &x) {
|
|
|
|
for (const auto *proc : x.specificProcs()) {
|
|
|
|
os << ' ' << proc->name();
|
|
|
|
}
|
|
|
|
},
|
2018-08-31 16:20:00 -07:00
|
|
|
[&](const ProcBindingDetails &x) {
|
|
|
|
os << " => " << x.symbol().name();
|
|
|
|
},
|
2018-12-26 13:31:13 -08:00
|
|
|
[&](const GenericBindingDetails &x) {
|
|
|
|
os << " =>";
|
|
|
|
char sep{' '};
|
|
|
|
for (const auto *proc : x.specificProcs()) {
|
|
|
|
os << sep << proc->name().ToString();
|
|
|
|
sep = ',';
|
|
|
|
}
|
|
|
|
},
|
2018-08-31 16:20:00 -07:00
|
|
|
[&](const FinalProcDetails &) {},
|
2018-09-04 10:28:27 -07:00
|
|
|
[&](const TypeParamDetails &x) {
|
|
|
|
if (x.type()) {
|
|
|
|
os << ' ' << *x.type();
|
|
|
|
}
|
2018-09-05 16:02:41 -07:00
|
|
|
os << ' ' << common::EnumToString(x.attr());
|
2018-12-06 06:59:37 -08:00
|
|
|
if (x.init()) {
|
|
|
|
x.init()->AsFortran(os << " init:");
|
2018-11-06 17:18:06 -08:00
|
|
|
}
|
2018-09-04 10:28:27 -07:00
|
|
|
},
|
2018-09-25 08:53:53 -07:00
|
|
|
[&](const MiscDetails &x) {
|
|
|
|
os << ' ' << MiscDetails::EnumToString(x.kind());
|
|
|
|
},
|
2018-03-22 17:08:20 -07:00
|
|
|
},
|
2018-05-03 15:57:56 -07:00
|
|
|
details);
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2018-06-05 12:18:35 -07:00
|
|
|
std::ostream &operator<<(std::ostream &o, Symbol::Flag flag) {
|
|
|
|
return o << Symbol::EnumToString(flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &o, const Symbol::Flags &flags) {
|
|
|
|
std::size_t n{flags.count()};
|
|
|
|
std::size_t seen{0};
|
|
|
|
for (std::size_t j{0}; seen < n; ++j) {
|
|
|
|
Symbol::Flag flag{static_cast<Symbol::Flag>(j)};
|
|
|
|
if (flags.test(flag)) {
|
|
|
|
if (seen++ > 0) {
|
|
|
|
o << ", ";
|
|
|
|
}
|
|
|
|
o << flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2018-05-03 15:57:56 -07:00
|
|
|
std::ostream &operator<<(std::ostream &os, const Symbol &symbol) {
|
|
|
|
os << symbol.name();
|
|
|
|
if (!symbol.attrs().empty()) {
|
|
|
|
os << ", " << symbol.attrs();
|
|
|
|
}
|
2018-06-05 12:18:35 -07:00
|
|
|
if (!symbol.flags().empty()) {
|
|
|
|
os << " (" << symbol.flags() << ')';
|
|
|
|
}
|
2018-05-03 15:57:56 -07:00
|
|
|
os << ": " << symbol.details_;
|
2018-03-22 17:08:20 -07:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2018-06-26 15:01:42 -07:00
|
|
|
// Output a unique name for a scope by qualifying it with the names of
|
2018-08-27 11:48:49 -07:00
|
|
|
// parent scopes. For scopes without corresponding symbols, use the kind
|
|
|
|
// with an index (e.g. Block1, Block2, etc.).
|
2018-06-26 15:01:42 -07:00
|
|
|
static void DumpUniqueName(std::ostream &os, const Scope &scope) {
|
2018-08-22 16:05:06 -07:00
|
|
|
if (scope.kind() != Scope::Kind::Global) {
|
2018-06-26 15:01:42 -07:00
|
|
|
DumpUniqueName(os, scope.parent());
|
|
|
|
os << '/';
|
|
|
|
if (auto *scopeSymbol{scope.symbol()}) {
|
|
|
|
os << scopeSymbol->name().ToString();
|
|
|
|
} else {
|
2018-08-27 11:48:49 -07:00
|
|
|
int index{1};
|
|
|
|
for (auto &child : scope.parent().children()) {
|
|
|
|
if (child == scope) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (child.kind() == scope.kind()) {
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << Scope::EnumToString(scope.kind()) << index;
|
2018-06-26 15:01:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dump a symbol for UnparseWithSymbols. This will be used for tests so the
|
|
|
|
// format should be reasonably stable.
|
|
|
|
std::ostream &DumpForUnparse(
|
|
|
|
std::ostream &os, const Symbol &symbol, bool isDef) {
|
|
|
|
DumpUniqueName(os, symbol.owner());
|
|
|
|
os << '/' << symbol.name().ToString();
|
|
|
|
if (isDef) {
|
|
|
|
if (!symbol.attrs().empty()) {
|
|
|
|
os << ' ' << symbol.attrs();
|
|
|
|
}
|
|
|
|
if (symbol.test(Symbol::Flag::Implicit)) {
|
|
|
|
os << " (implicit)";
|
|
|
|
}
|
2018-10-18 07:55:48 -07:00
|
|
|
if (symbol.test(Symbol::Flag::LocalityLocal)) {
|
|
|
|
os << " (local)";
|
|
|
|
}
|
|
|
|
if (symbol.test(Symbol::Flag::LocalityLocalInit)) {
|
|
|
|
os << " (local_init)";
|
|
|
|
}
|
|
|
|
if (symbol.test(Symbol::Flag::LocalityShared)) {
|
|
|
|
os << " (shared)";
|
|
|
|
}
|
2018-06-26 15:01:42 -07:00
|
|
|
os << ' ' << symbol.GetDetailsName();
|
|
|
|
if (const auto *type{symbol.GetType()}) {
|
|
|
|
os << ' ' << *type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
2018-10-25 05:55:23 -07:00
|
|
|
}
|