2019-03-18 17:19:41 +01:00
|
|
|
// Copyright (c) 2019, Arm Ltd. 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 "check-stop.h"
|
|
|
|
#include "semantics.h"
|
|
|
|
#include "tools.h"
|
|
|
|
#include "../common/Fortran.h"
|
|
|
|
#include "../evaluate/expression.h"
|
|
|
|
#include "../parser/parse-tree.h"
|
|
|
|
#include <optional>
|
|
|
|
|
2019-04-11 20:27:50 +02:00
|
|
|
namespace Fortran::semantics {
|
|
|
|
|
|
|
|
void StopChecker::Enter(const parser::StopStmt &stmt) {
|
2019-04-11 22:43:35 +02:00
|
|
|
const auto &stopCode{std::get<std::optional<parser::StopCode>>(stmt.t)};
|
|
|
|
const auto &scalarLogicalExpr{
|
|
|
|
std::get<std::optional<parser::ScalarLogicalExpr>>(stmt.t)};
|
2019-03-18 17:19:41 +01:00
|
|
|
|
2019-04-11 22:43:35 +02:00
|
|
|
if (stopCode.has_value()) {
|
|
|
|
const parser::CharBlock &source{stopCode.value().v.thing.source};
|
|
|
|
const auto &expr{*(stopCode.value().v.thing.typedExpr)};
|
2019-03-18 17:19:41 +01:00
|
|
|
|
2019-04-11 20:27:50 +02:00
|
|
|
if (!(ExprIsScalar(expr))) {
|
2019-03-18 17:19:41 +01:00
|
|
|
context_.Say(source, "Stop code must be a scalar"_err_en_US);
|
|
|
|
} else {
|
2019-04-11 20:27:50 +02:00
|
|
|
if (ExprHasTypeCategory(expr, common::TypeCategory::Integer)) {
|
2019-03-18 17:19:41 +01:00
|
|
|
// C1171 default kind
|
2019-04-11 22:25:45 +02:00
|
|
|
if (!(ExprTypeKindIsDefault(expr, context_))) {
|
2019-03-18 17:19:41 +01:00
|
|
|
context_.Say(
|
|
|
|
source, "Integer stop code must be of default kind"_err_en_US);
|
|
|
|
}
|
2019-04-11 20:27:50 +02:00
|
|
|
} else if (ExprHasTypeCategory(expr, common::TypeCategory::Character)) {
|
2019-03-18 17:19:41 +01:00
|
|
|
// R1162 spells scalar-DEFAULT-char-expr
|
2019-04-11 22:25:45 +02:00
|
|
|
if (!(ExprTypeKindIsDefault(expr, context_))) {
|
2019-03-18 17:19:41 +01:00
|
|
|
context_.Say(
|
|
|
|
source, "Character stop code must be of default kind"_err_en_US);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
context_.Say(
|
|
|
|
source, "Stop code must be of INTEGER or CHARACTER type"_err_en_US);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 22:43:35 +02:00
|
|
|
if (scalarLogicalExpr.has_value()) {
|
|
|
|
const parser::CharBlock &source{
|
|
|
|
scalarLogicalExpr.value().thing.thing.value().source};
|
|
|
|
const auto &expr{
|
|
|
|
*(scalarLogicalExpr.value().thing.thing.value().typedExpr)};
|
2019-03-18 17:19:41 +01:00
|
|
|
|
2019-04-11 20:27:50 +02:00
|
|
|
if (!(ExprIsScalar(expr))) {
|
2019-03-18 17:19:41 +01:00
|
|
|
context_.Say(source,
|
|
|
|
"The optional QUIET parameter value must be a scalar"_err_en_US);
|
|
|
|
} else {
|
2019-04-11 20:27:50 +02:00
|
|
|
if (!(ExprHasTypeCategory(expr, common::TypeCategory::Logical))) {
|
2019-03-18 17:19:41 +01:00
|
|
|
context_.Say(source,
|
|
|
|
"The optional QUIET parameter value must be of LOGICAL type"_err_en_US);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 20:27:50 +02:00
|
|
|
|
|
|
|
} // namespace Fortran::semantics
|