From 63423667fe1cde98ce3e9bed6d717d6f78dcc4e4 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Thu, 1 Aug 2019 11:41:05 -0700 Subject: [PATCH] [flang] Clean up some usage of std::optional lambda results Original-commit: flang-compiler/f18@9a66f9da9767d19875a229dbef2532b57b7a79a6 Reviewed-on: https://github.com/flang-compiler/f18/pull/611 Tree-same-pre-rewrite: false --- flang/lib/evaluate/characteristics.cc | 2 +- flang/lib/evaluate/expression.cc | 5 +++-- flang/lib/evaluate/fold.cc | 11 +++++------ flang/lib/evaluate/shape.cc | 15 ++++++++------- flang/lib/evaluate/shape.h | 5 ++--- flang/lib/evaluate/tools.cc | 6 +++--- flang/lib/evaluate/tools.h | 7 ++++--- flang/lib/semantics/expression.cc | 2 +- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/flang/lib/evaluate/characteristics.cc b/flang/lib/evaluate/characteristics.cc index 68ec79a..fbedc11 100644 --- a/flang/lib/evaluate/characteristics.cc +++ b/flang/lib/evaluate/characteristics.cc @@ -438,7 +438,7 @@ std::optional Procedure::Characterize( [&](const semantics::HostAssocDetails &assoc) { return Characterize(assoc.symbol(), intrinsics); }, - [](const auto &) -> std::optional { return std::nullopt; }, + [](const auto &) { return std::optional{}; }, }, symbol.details()); } diff --git a/flang/lib/evaluate/expression.cc b/flang/lib/evaluate/expression.cc index 7a91f370..4d07e9b 100644 --- a/flang/lib/evaluate/expression.cc +++ b/flang/lib/evaluate/expression.cc @@ -85,11 +85,12 @@ std::optional ExpressionBase::GetType() const { return Result::GetType(); } else { return std::visit( - [&](const auto &x) -> std::optional { + [&](const auto &x) { if constexpr (!common::HasMember) { return x.GetType(); + } else { + return std::optional{}; } - return std::nullopt; }, derived().u); } diff --git a/flang/lib/evaluate/fold.cc b/flang/lib/evaluate/fold.cc index e4e44bf..5e315cb 100644 --- a/flang/lib/evaluate/fold.cc +++ b/flang/lib/evaluate/fold.cc @@ -430,10 +430,9 @@ Expr> LBOUND(FoldingContext &context, if (symbol.Rank() == rank) { lowerBoundsAreOne = false; if (dim.has_value()) { - if (auto lb{ - GetLowerBound(context, *named, static_cast(*dim))}) { - return Fold(context, ConvertToType(std::move(*lb))); - } + return Fold(context, + ConvertToType( + GetLowerBound(context, *named, static_cast(*dim)))); } else if (auto lbounds{ AsConstantShape(GetLowerBounds(context, *named))}) { return Fold(context, @@ -1448,8 +1447,8 @@ std::optional> GetConstantComponent(FoldingContext &context, [&](Component &base) { return GetConstantComponent(context, base); }, - [&](CoarrayRef &) -> std::optional> { - return std::nullopt; + [&](CoarrayRef &) { + return std::optional>{}; }, }, component.base().u)}) { diff --git a/flang/lib/evaluate/shape.cc b/flang/lib/evaluate/shape.cc index cca7f46..d7d2b1a9 100644 --- a/flang/lib/evaluate/shape.cc +++ b/flang/lib/evaluate/shape.cc @@ -190,7 +190,7 @@ bool ContainsAnyImpliedDoIndex(const ExtentExpr &expr) { return Visitor{0}.Traverse(expr); } -MaybeExtentExpr GetLowerBound( +ExtentExpr GetLowerBound( FoldingContext &context, const NamedEntity &base, int dimension) { const Symbol &symbol{ResolveAssociations(base.GetLastSymbol())}; if (const auto *details{symbol.detailsIf()}) { @@ -208,7 +208,9 @@ MaybeExtentExpr GetLowerBound( } } } - return std::nullopt; + // When we don't know that we don't know the lower bound at compilation + // time, then we do know it, and it's one. (See LBOUND, 16.9.109). + return ExtentExpr{1}; } Shape GetLowerBounds(FoldingContext &context, const NamedEntity &base) { @@ -300,11 +302,10 @@ MaybeExtentExpr GetExtent(FoldingContext &context, const Subscript &subscript, subscript.u); } -MaybeExtentExpr GetUpperBound(FoldingContext &context, MaybeExtentExpr &&lower, - MaybeExtentExpr &&extent) { - if (lower.has_value() && extent.has_value()) { - return Fold( - context, std::move(*extent) - std::move(*lower) + ExtentExpr{1}); +MaybeExtentExpr GetUpperBound( + FoldingContext &context, ExtentExpr &&lower, MaybeExtentExpr &&extent) { + if (extent.has_value()) { + return Fold(context, std::move(*extent) - std::move(lower) + ExtentExpr{1}); } else { return std::nullopt; } diff --git a/flang/lib/evaluate/shape.h b/flang/lib/evaluate/shape.h index 3614d02..114cb41 100644 --- a/flang/lib/evaluate/shape.h +++ b/flang/lib/evaluate/shape.h @@ -61,14 +61,13 @@ inline int GetRank(const Shape &s) { return static_cast(s.size()); } // The dimension argument to these inquiries is zero-based, // unlike the DIM= arguments to many intrinsics. -MaybeExtentExpr GetLowerBound( - FoldingContext &, const NamedEntity &, int dimension); +ExtentExpr GetLowerBound(FoldingContext &, const NamedEntity &, int dimension); Shape GetLowerBounds(FoldingContext &, const NamedEntity &); MaybeExtentExpr GetExtent(FoldingContext &, const NamedEntity &, int dimension); MaybeExtentExpr GetExtent( FoldingContext &, const Subscript &, const NamedEntity &, int dimension); MaybeExtentExpr GetUpperBound( - FoldingContext &, MaybeExtentExpr &&lower, MaybeExtentExpr &&extent); + FoldingContext &, ExtentExpr &&lower, MaybeExtentExpr &&extent); MaybeExtentExpr GetUpperBound( FoldingContext &, const NamedEntity &, int dimension); Shape GetUpperBounds(FoldingContext &, const NamedEntity &); diff --git a/flang/lib/evaluate/tools.cc b/flang/lib/evaluate/tools.cc index 4caf70d..dff2cf6 100644 --- a/flang/lib/evaluate/tools.cc +++ b/flang/lib/evaluate/tools.cc @@ -489,17 +489,17 @@ std::optional> Relate(parser::ContextualMessages &messages, } else { messages.Say( "CHARACTER operands do not have same KIND"_err_en_US); - return std::optional>{}; + return std::nullopt; } }, std::move(cx.u), std::move(cy.u)); }, // Default case - [&](auto &&, auto &&) -> std::optional> { + [&](auto &&, auto &&) { // TODO: defined operator messages.Say( "relational operands do not have comparable types"_err_en_US); - return std::nullopt; + return std::optional>{}; }, }, std::move(x.u), std::move(y.u)); diff --git a/flang/lib/evaluate/tools.h b/flang/lib/evaluate/tools.h index 7d048ed..0b3dc38 100644 --- a/flang/lib/evaluate/tools.h +++ b/flang/lib/evaluate/tools.h @@ -40,7 +40,7 @@ std::optional> AsVariable(const Expr &expr) { return std::visit( [](const auto &x) -> std::optional> { if constexpr (common::HasMember, Variant>) { - return std::make_optional>(x); + return Variable{x}; } return std::nullopt; }, @@ -217,8 +217,9 @@ std::optional ExtractDataRef(const Designator &d) { [](const auto &x) -> std::optional { if constexpr (common::HasMember) { return DataRef{x}; + } else { + return std::nullopt; } - return std::nullopt; }, d.u); } @@ -245,7 +246,7 @@ template std::optional ExtractNamedEntity(const A &x) { [](Component &&component) -> std::optional { return NamedEntity{std::move(component)}; }, - [](auto &&) -> std::optional { return std::nullopt; }, + [](auto &&) { return std::optional{}; }, }, std::move(dataRef->u)); } else { diff --git a/flang/lib/semantics/expression.cc b/flang/lib/semantics/expression.cc index e306759..fe24818 100644 --- a/flang/lib/semantics/expression.cc +++ b/flang/lib/semantics/expression.cc @@ -754,7 +754,7 @@ std::optional ExpressionAnalyzer::AnalyzeSectionSubscript( }, [&](const auto &s) -> std::optional { if (auto subscriptExpr{AsSubscript(Analyze(s))}) { - return {Subscript{std::move(*subscriptExpr)}}; + return Subscript{std::move(*subscriptExpr)}; } else { return std::nullopt; } -- 2.7.4