2018-09-15 00:04:50 +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.
|
|
|
|
|
|
|
|
#include "semantics.h"
|
2018-09-19 23:26:02 +02:00
|
|
|
#include "canonicalize-do.h"
|
2018-09-18 02:19:27 +02:00
|
|
|
#include "check-do-concurrent.h"
|
2018-10-23 01:41:26 +02:00
|
|
|
#include "default-kinds.h"
|
2018-09-15 00:04:50 +02:00
|
|
|
#include "mod-file.h"
|
|
|
|
#include "resolve-labels.h"
|
|
|
|
#include "resolve-names.h"
|
|
|
|
#include "rewrite-parse-tree.h"
|
|
|
|
#include "scope.h"
|
|
|
|
#include "symbol.h"
|
2018-10-22 16:37:38 +02:00
|
|
|
#include <ostream>
|
2018-09-15 00:04:50 +02:00
|
|
|
|
|
|
|
namespace Fortran::semantics {
|
|
|
|
|
|
|
|
static void DoDumpSymbols(std::ostream &, const Scope &, int indent = 0);
|
|
|
|
static void PutIndent(std::ostream &, int indent);
|
|
|
|
|
2018-10-23 01:41:26 +02:00
|
|
|
SemanticsContext::SemanticsContext(
|
|
|
|
const IntrinsicTypeDefaultKinds &defaultKinds)
|
|
|
|
: defaultKinds_{defaultKinds},
|
|
|
|
intrinsics_{evaluate::IntrinsicProcTable::Configure(defaultKinds)},
|
|
|
|
foldingContext_{evaluate::FoldingContext{
|
|
|
|
parser::ContextualMessages{parser::CharBlock{}, &messages_}}} {}
|
|
|
|
|
2018-10-22 16:37:38 +02:00
|
|
|
bool SemanticsContext::AnyFatalError() const {
|
|
|
|
return !messages_.empty() &&
|
|
|
|
(warningsAreErrors_ || messages_.AnyFatalError());
|
2018-09-15 00:04:50 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 16:37:38 +02:00
|
|
|
bool Semantics::Perform() {
|
|
|
|
ValidateLabels(context_.messages(), program_);
|
2018-09-15 00:04:50 +02:00
|
|
|
if (AnyFatalError()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-22 16:37:38 +02:00
|
|
|
parser::CanonicalizeDo(program_);
|
|
|
|
ResolveNames(context_, program_);
|
2018-09-15 00:04:50 +02:00
|
|
|
if (AnyFatalError()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-22 16:37:38 +02:00
|
|
|
RewriteParseTree(context_, program_);
|
2018-09-15 00:04:50 +02:00
|
|
|
if (AnyFatalError()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-24 20:10:20 +02:00
|
|
|
CheckDoConcurrentConstraints(context_.messages(), program_);
|
2018-09-18 02:19:27 +02:00
|
|
|
if (AnyFatalError()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-22 16:37:38 +02:00
|
|
|
ModFileWriter writer{context_};
|
|
|
|
writer.WriteAll();
|
|
|
|
if (AnyFatalError()) {
|
2018-09-15 00:04:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-22 16:37:38 +02:00
|
|
|
if (context_.debugExpressions()) {
|
2018-10-23 01:41:26 +02:00
|
|
|
AnalyzeExpressions(program_, context_);
|
2018-10-22 16:37:38 +02:00
|
|
|
}
|
|
|
|
return !AnyFatalError();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Semantics::EmitMessages(std::ostream &os) const {
|
|
|
|
context_.messages().Emit(os, cooked_);
|
2018-09-15 00:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Semantics::DumpSymbols(std::ostream &os) {
|
2018-10-22 16:37:38 +02:00
|
|
|
DoDumpSymbols(os, context_.globalScope());
|
2018-09-15 00:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoDumpSymbols(std::ostream &os, const Scope &scope, int indent) {
|
|
|
|
PutIndent(os, indent);
|
|
|
|
os << Scope::EnumToString(scope.kind()) << " scope:";
|
|
|
|
if (const auto *symbol{scope.symbol()}) {
|
|
|
|
os << ' ' << symbol->name().ToString();
|
|
|
|
}
|
|
|
|
os << '\n';
|
|
|
|
++indent;
|
|
|
|
for (const auto &pair : scope) {
|
|
|
|
const auto &symbol{*pair.second};
|
|
|
|
PutIndent(os, indent);
|
|
|
|
os << symbol << '\n';
|
|
|
|
if (const auto *details{symbol.detailsIf<GenericDetails>()}) {
|
|
|
|
if (const auto &type{details->derivedType()}) {
|
|
|
|
PutIndent(os, indent);
|
|
|
|
os << *type << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto &child : scope.children()) {
|
|
|
|
DoDumpSymbols(os, child, indent);
|
|
|
|
}
|
|
|
|
--indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PutIndent(std::ostream &os, int indent) {
|
|
|
|
for (int i = 0; i < indent; ++i) {
|
|
|
|
os << " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Fortran::semantics
|