[flang] Clean up some usage of std::optional lambda results

Original-commit: flang-compiler/f18@9a66f9da97
Reviewed-on: https://github.com/flang-compiler/f18/pull/611
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2019-08-01 11:41:05 -07:00
parent 29d3343910
commit 63423667fe
8 changed files with 27 additions and 26 deletions

View file

@ -438,7 +438,7 @@ std::optional<Procedure> Procedure::Characterize(
[&](const semantics::HostAssocDetails &assoc) {
return Characterize(assoc.symbol(), intrinsics);
},
[](const auto &) -> std::optional<Procedure> { return std::nullopt; },
[](const auto &) { return std::optional<Procedure>{}; },
},
symbol.details());
}

View file

@ -85,11 +85,12 @@ std::optional<DynamicType> ExpressionBase<A>::GetType() const {
return Result::GetType();
} else {
return std::visit(
[&](const auto &x) -> std::optional<DynamicType> {
[&](const auto &x) {
if constexpr (!common::HasMember<decltype(x), TypelessExpression>) {
return x.GetType();
} else {
return std::optional<DynamicType>{};
}
return std::nullopt;
},
derived().u);
}

View file

@ -430,10 +430,9 @@ Expr<Type<TypeCategory::Integer, KIND>> LBOUND(FoldingContext &context,
if (symbol.Rank() == rank) {
lowerBoundsAreOne = false;
if (dim.has_value()) {
if (auto lb{
GetLowerBound(context, *named, static_cast<int>(*dim))}) {
return Fold(context, ConvertToType<T>(std::move(*lb)));
}
return Fold(context,
ConvertToType<T>(
GetLowerBound(context, *named, static_cast<int>(*dim))));
} else if (auto lbounds{
AsConstantShape(GetLowerBounds(context, *named))}) {
return Fold(context,
@ -1448,8 +1447,8 @@ std::optional<Constant<T>> GetConstantComponent(FoldingContext &context,
[&](Component &base) {
return GetConstantComponent<SomeDerived>(context, base);
},
[&](CoarrayRef &) -> std::optional<Constant<SomeDerived>> {
return std::nullopt;
[&](CoarrayRef &) {
return std::optional<Constant<SomeDerived>>{};
},
},
component.base().u)}) {

View file

@ -190,7 +190,7 @@ bool ContainsAnyImpliedDoIndex(const ExtentExpr &expr) {
return Visitor<MyVisitor>{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<semantics::ObjectEntityDetails>()}) {
@ -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;
}

View file

@ -61,14 +61,13 @@ inline int GetRank(const Shape &s) { return static_cast<int>(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 &);

View file

@ -489,17 +489,17 @@ std::optional<Expr<LogicalResult>> Relate(parser::ContextualMessages &messages,
} else {
messages.Say(
"CHARACTER operands do not have same KIND"_err_en_US);
return std::optional<Expr<LogicalResult>>{};
return std::nullopt;
}
},
std::move(cx.u), std::move(cy.u));
},
// Default case
[&](auto &&, auto &&) -> std::optional<Expr<LogicalResult>> {
[&](auto &&, auto &&) {
// TODO: defined operator
messages.Say(
"relational operands do not have comparable types"_err_en_US);
return std::nullopt;
return std::optional<Expr<LogicalResult>>{};
},
},
std::move(x.u), std::move(y.u));

View file

@ -40,7 +40,7 @@ std::optional<Variable<A>> AsVariable(const Expr<A> &expr) {
return std::visit(
[](const auto &x) -> std::optional<Variable<A>> {
if constexpr (common::HasMember<std::decay_t<decltype(x)>, Variant>) {
return std::make_optional<Variable<A>>(x);
return Variable<A>{x};
}
return std::nullopt;
},
@ -217,8 +217,9 @@ std::optional<DataRef> ExtractDataRef(const Designator<T> &d) {
[](const auto &x) -> std::optional<DataRef> {
if constexpr (common::HasMember<decltype(x), decltype(DataRef::u)>) {
return DataRef{x};
} else {
return std::nullopt;
}
return std::nullopt;
},
d.u);
}
@ -245,7 +246,7 @@ template<typename A> std::optional<NamedEntity> ExtractNamedEntity(const A &x) {
[](Component &&component) -> std::optional<NamedEntity> {
return NamedEntity{std::move(component)};
},
[](auto &&) -> std::optional<NamedEntity> { return std::nullopt; },
[](auto &&) { return std::optional<NamedEntity>{}; },
},
std::move(dataRef->u));
} else {

View file

@ -754,7 +754,7 @@ std::optional<Subscript> ExpressionAnalyzer::AnalyzeSectionSubscript(
},
[&](const auto &s) -> std::optional<Subscript> {
if (auto subscriptExpr{AsSubscript(Analyze(s))}) {
return {Subscript{std::move(*subscriptExpr)}};
return Subscript{std::move(*subscriptExpr)};
} else {
return std::nullopt;
}