[flang] Semantics checker for STOP and ERROR STOP statements - namespaces sorted

Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>

Original-commit: flang-compiler/f18@d608779668
Reviewed-on: https://github.com/flang-compiler/f18/pull/367
Tree-same-pre-rewrite: false
This commit is contained in:
Paul Osmialowski 2019-04-11 19:27:50 +01:00 committed by GitHub
parent 8d1376ca73
commit c145b58d0f
1 changed files with 18 additions and 20 deletions

View File

@ -20,34 +20,32 @@
#include "../parser/parse-tree.h" #include "../parser/parse-tree.h"
#include <optional> #include <optional>
void Fortran::semantics::StopChecker::Enter( namespace Fortran::semantics {
const Fortran::parser::StopStmt &stmt) {
const auto &sc{std::get<std::optional<Fortran::parser::StopCode>>(stmt.t)}; void StopChecker::Enter(const parser::StopStmt &stmt) {
const auto &sle{ const auto &sc{std::get<std::optional<parser::StopCode>>(stmt.t)};
std::get<std::optional<Fortran::parser::ScalarLogicalExpr>>(stmt.t)}; const auto &sle{std::get<std::optional<parser::ScalarLogicalExpr>>(stmt.t)};
if (sc.has_value()) { if (sc.has_value()) {
const Fortran::parser::CharBlock &source{sc.value().v.thing.source}; const parser::CharBlock &source{sc.value().v.thing.source};
const auto &expr{*(sc.value().v.thing.typedExpr)}; const auto &expr{*(sc.value().v.thing.typedExpr)};
if (!(Fortran::semantics::ExprIsScalar(expr))) { if (!(ExprIsScalar(expr))) {
context_.Say(source, "Stop code must be a scalar"_err_en_US); context_.Say(source, "Stop code must be a scalar"_err_en_US);
} else { } else {
if (Fortran::semantics::ExprHasTypeCategory( if (ExprHasTypeCategory(expr, common::TypeCategory::Integer)) {
expr, Fortran::common::TypeCategory::Integer)) {
// C1171 default kind // C1171 default kind
if (!(Fortran::semantics::ExprHasTypeKind(expr, if (!(ExprHasTypeKind(expr,
context_.defaultKinds().GetDefaultKind( context_.defaultKinds().GetDefaultKind(
Fortran::common::TypeCategory::Integer)))) { common::TypeCategory::Integer)))) {
context_.Say( context_.Say(
source, "Integer stop code must be of default kind"_err_en_US); source, "Integer stop code must be of default kind"_err_en_US);
} }
} else if (Fortran::semantics::ExprHasTypeCategory( } else if (ExprHasTypeCategory(expr, common::TypeCategory::Character)) {
expr, Fortran::common::TypeCategory::Character)) {
// R1162 spells scalar-DEFAULT-char-expr // R1162 spells scalar-DEFAULT-char-expr
if (!(Fortran::semantics::ExprHasTypeKind(expr, if (!(ExprHasTypeKind(expr,
context_.defaultKinds().GetDefaultKind( context_.defaultKinds().GetDefaultKind(
Fortran::common::TypeCategory::Character)))) { common::TypeCategory::Character)))) {
context_.Say( context_.Say(
source, "Character stop code must be of default kind"_err_en_US); source, "Character stop code must be of default kind"_err_en_US);
} }
@ -58,19 +56,19 @@ void Fortran::semantics::StopChecker::Enter(
} }
} }
if (sle.has_value()) { if (sle.has_value()) {
const Fortran::parser::CharBlock &source{ const parser::CharBlock &source{sle.value().thing.thing.value().source};
sle.value().thing.thing.value().source};
const auto &expr{*(sle.value().thing.thing.value().typedExpr)}; const auto &expr{*(sle.value().thing.thing.value().typedExpr)};
if (!(Fortran::semantics::ExprIsScalar(expr))) { if (!(ExprIsScalar(expr))) {
context_.Say(source, context_.Say(source,
"The optional QUIET parameter value must be a scalar"_err_en_US); "The optional QUIET parameter value must be a scalar"_err_en_US);
} else { } else {
if (!(Fortran::semantics::ExprHasTypeCategory( if (!(ExprHasTypeCategory(expr, common::TypeCategory::Logical))) {
expr, Fortran::common::TypeCategory::Logical))) {
context_.Say(source, context_.Say(source,
"The optional QUIET parameter value must be of LOGICAL type"_err_en_US); "The optional QUIET parameter value must be of LOGICAL type"_err_en_US);
} }
} }
} }
} }
} // namespace Fortran::semantics