From b74d46910328a169aa5214e6eca269863fef2fb4 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Mon, 17 Sep 2018 11:31:38 -0700 Subject: [PATCH] [flang] some clean-up Original-commit: flang-compiler/f18@b6eb3e990a01889e04e7bade07ed9e6c16548c59 Reviewed-on: https://github.com/flang-compiler/f18/pull/195 Tree-same-pre-rewrite: false --- flang/lib/evaluate/expression.cc | 11 ++++------- flang/lib/evaluate/expression.h | 8 ++++---- flang/lib/evaluate/tools.cc | 14 +++++++------- flang/lib/evaluate/variable.h | 9 +++------ flang/lib/semantics/expression.cc | 27 +++++++++++++-------------- 5 files changed, 31 insertions(+), 38 deletions(-) diff --git a/flang/lib/evaluate/expression.cc b/flang/lib/evaluate/expression.cc index 7085ed227870..da0853339649 100644 --- a/flang/lib/evaluate/expression.cc +++ b/flang/lib/evaluate/expression.cc @@ -493,8 +493,9 @@ Expr Expr>::LEN() const { return AsExpr(Constant{ static_cast(c.value.size())}); }, + [](const Parentheses &x) { return x.left().LEN(); }, [](const Concat &c) { - return c.left().LEN() + c.template right().LEN(); + return c.left().LEN() + c.right().LEN(); }, [](const Extremum &c) { return Expr{ @@ -514,12 +515,8 @@ auto ExpressionBase::ScalarValue() const if (auto *c{std::get_if>(&derived().u)}) { return {c->value}; } - // TODO: every specifically-typed Expr should support Parentheses - if constexpr (common::HasMember, - decltype(derived().u)>) { - if (auto *p{std::get_if>(&derived().u)}) { - return p->left().ScalarValue(); - } + if (auto *p{std::get_if>(&derived().u)}) { + return p->left().ScalarValue(); } } else if constexpr (std::is_same_v) { return std::visit( diff --git a/flang/lib/evaluate/expression.h b/flang/lib/evaluate/expression.h index af9bb8639a50..72b037bed3a2 100644 --- a/flang/lib/evaluate/expression.h +++ b/flang/lib/evaluate/expression.h @@ -520,8 +520,7 @@ public: Expr LEN() const; std::variant, Designator, FunctionReference, - // TODO Parentheses, - Concat, Extremum> + Parentheses, Concat, Extremum> u; }; @@ -594,8 +593,9 @@ public: explicit Expr(bool x) : u{Constant{x}} {} private: - using Operations = std::variant, - Not, LogicalOperation, Relational>; + using Operations = + std::variant, Parentheses, + Not, LogicalOperation, Relational>; using Others = std::variant, Designator, FunctionReference>; diff --git a/flang/lib/evaluate/tools.cc b/flang/lib/evaluate/tools.cc index 414a124c1b9e..13a3e42f3545 100644 --- a/flang/lib/evaluate/tools.cc +++ b/flang/lib/evaluate/tools.cc @@ -105,13 +105,13 @@ std::optional> MixedRealLeft( [&](auto &&rxk) -> Expr { using resultType = ResultType; if constexpr (std::is_same_v, Power>) { - return AsCategoryExpr(AsExpr( - RealToIntPower{std::move(rxk), std::move(iy)})); + return AsCategoryExpr( + RealToIntPower{std::move(rxk), std::move(iy)}); } // G++ 8.1.0 emits bogus warnings about missing return statements if // this statement is wrapped in an "else", as it should be. - return AsCategoryExpr(AsExpr(OPR{ - std::move(rxk), ConvertToType(std::move(iy))})); + return AsCategoryExpr(OPR{ + std::move(rxk), ConvertToType(std::move(iy))}); }, std::move(rx.u))); } @@ -144,7 +144,7 @@ Expr GetComplexPart(const Expr &z, bool isImaginary) { return std::visit( [&](const auto &zk) { static constexpr int kind{ResultType::kind}; - return AsCategoryExpr(AsExpr(ComplexComponent{isImaginary, zk})); + return AsCategoryExpr(ComplexComponent{isImaginary, zk}); }, z.u); } @@ -257,9 +257,9 @@ std::optional> NumericOperation( return Package(std::visit( [&](auto &&ryk) -> Expr { using resultType = ResultType; - return AsCategoryExpr(AsExpr( + return AsCategoryExpr( OPR{ConvertToType(std::move(ix)), - std::move(ryk)})); + std::move(ryk)}); }, std::move(ry.u))); }, diff --git a/flang/lib/evaluate/variable.h b/flang/lib/evaluate/variable.h index a179fe9fe1ae..277063c90765 100644 --- a/flang/lib/evaluate/variable.h +++ b/flang/lib/evaluate/variable.h @@ -276,6 +276,8 @@ struct ActualFunctionArg { explicit ActualFunctionArg(Expr &&x) : u{std::move(x)} {} std::ostream &Dump(std::ostream &) const; + // Subtlety: There is a distinction to be respected here between a variable + // and an expression that is a variable, e.g. X vs. (X). std::variant>, Variable> u; }; @@ -293,13 +295,8 @@ public: explicit ActualSubroutineArg(const Label &l) : u{&l} {} std::ostream &Dump(std::ostream &) const; -private: - using Variables = decltype(Variable::u); - using Others = - std::variant>, const Label *>; - public: - common::CombineVariants u; + std::variant>, Variable, const Label *> u; }; using SubroutineRef = ProcedureRef; diff --git a/flang/lib/semantics/expression.cc b/flang/lib/semantics/expression.cc index de09f4b60c91..bd67d43e164e 100644 --- a/flang/lib/semantics/expression.cc +++ b/flang/lib/semantics/expression.cc @@ -258,7 +258,7 @@ struct RealTypeVisitor { template Result Test() { using Ty = std::tuple_element_t; if (kind == Ty::kind) { - return {AsCategoryExpr(AsExpr(ReadRealLiteral(literal, context)))}; + return {AsCategoryExpr(ReadRealLiteral(literal, context))}; } return std::nullopt; } @@ -643,8 +643,8 @@ MaybeExpr ExprAnalyzer::Analyze(const parser::StructureComponent &sc) { Expr realExpr{std::visit( [&](const auto &z) { using PartType = typename ResultType::Part; - return AsCategoryExpr(AsExpr(Designator{ - ComplexPart{std::move(*dataRef), part}})); + return AsCategoryExpr( + Designator{ComplexPart{std::move(*dataRef), part}}); }, zExpr->u)}; return {AsGenericExpr(std::move(realExpr))}; @@ -679,6 +679,8 @@ MaybeExpr ExprAnalyzer::Analyze(const parser::StructureConstructor &) { } MaybeExpr ExprAnalyzer::Analyze(const parser::FunctionReference &) { + // TODO: C1003: A parenthesized function reference may not return a + // procedure pointer. context.messages.Say("TODO: FunctionReference unimplemented"_err_en_US); return std::nullopt; } @@ -688,20 +690,17 @@ MaybeExpr ExprAnalyzer::Analyze(const parser::Expr::Parentheses &x) { return std::visit( common::visitors{ [&](BOZLiteralConstant &&boz) { - return operand; // ignore parentheses around typeless + return operand; // ignore parentheses around typeless constants + }, + [&](Expr &&) { + // TODO: parenthesized derived type variable + return operand; }, - [&](Expr &&dte) { return operand; }, [](auto &&catExpr) { return std::visit( [](auto &&expr) -> MaybeExpr { using Ty = ResultType; - if constexpr (common::HasMember, - decltype(expr.u)>) { - return {AsGenericExpr( - AsExpr(Parentheses{std::move(expr)}))}; - } - // TODO: support Parentheses in all Expr specializations - return std::nullopt; + return {AsGenericExpr(Parentheses{std::move(expr)})}; }, std::move(catExpr.u)); }}, @@ -811,8 +810,8 @@ MaybeExpr ExprAnalyzer::Analyze(const parser::Expr::Concat &x) { using Ty = ResultType; if constexpr (std::is_same_v>) { - return {AsGenericExpr(AsCategoryExpr(AsExpr( - Concat{std::move(cxk), std::move(cyk)})))}; + return {AsGenericExpr( + Concat{std::move(cxk), std::move(cyk)})}; } else { context.messages.Say( "Operands of // must be the same kind of CHARACTER"_err_en_US);