From 3d2120989aef981beff05a16b27ebfa9fe8fd10a Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Thu, 19 Apr 2018 07:07:47 -0700 Subject: [PATCH] [flang] Move ConvertToAssignment into class StmtFunctionStmt. Original-commit: flang-compiler/f18@e3eaca38fd0c30765474c2a46ae4d6c36796af07 Reviewed-on: https://github.com/flang-compiler/f18/pull/60 --- flang/lib/parser/parse-tree.cc | 19 +++++++++++++++++++ flang/lib/parser/parse-tree.h | 1 + flang/lib/semantics/rewrite-parse-tree.cc | 28 ++++------------------------ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/flang/lib/parser/parse-tree.cc b/flang/lib/parser/parse-tree.cc index 53037a7..8eaa82d 100644 --- a/flang/lib/parser/parse-tree.cc +++ b/flang/lib/parser/parse-tree.cc @@ -46,5 +46,24 @@ DataRef::DataRef(std::list &&prl) : u{std::move(prl.front().name)} { Expr::Expr(Designator &&x) : u{Indirection(std::move(x))} {} Expr::Expr(FunctionReference &&x) : u{Indirection(std::move(x))} {} + +// R1544 stmt-function-stmt +// Convert this stmt-function-stmt to an array element assignment statement. +Statement StmtFunctionStmt::ConvertToAssignment() { + auto &funcName = std::get(t); + auto &funcArgs = std::get>(t); + auto &funcExpr = std::get>(t).thing; + ArrayElement arrayElement{funcName, std::list{}}; + for (Name &arg : funcArgs) { + arrayElement.subscripts.push_back(SectionSubscript{ + Scalar{Integer{Indirection{Expr{Indirection{Designator{arg}}}}}}}); + } + auto &&variable = Variable{ + Indirection{Designator{DataRef{Indirection{std::move(arrayElement)}}}}}; + return Statement{std::nullopt, + ActionStmt{Indirection{ + AssignmentStmt{std::move(variable), std::move(funcExpr)}}}}; +} + } // namespace parser } // namespace Fortran diff --git a/flang/lib/parser/parse-tree.h b/flang/lib/parser/parse-tree.h index bcf5177..d0a2643 100644 --- a/flang/lib/parser/parse-tree.h +++ b/flang/lib/parser/parse-tree.h @@ -3114,6 +3114,7 @@ WRAPPER_CLASS(ReturnStmt, std::optional); struct StmtFunctionStmt { TUPLE_CLASS_BOILERPLATE(StmtFunctionStmt); std::tuple, Scalar> t; + Statement ConvertToAssignment(); }; // Compiler directives diff --git a/flang/lib/semantics/rewrite-parse-tree.cc b/flang/lib/semantics/rewrite-parse-tree.cc index 62d9ec7..6eb526f1 100644 --- a/flang/lib/semantics/rewrite-parse-tree.cc +++ b/flang/lib/semantics/rewrite-parse-tree.cc @@ -53,7 +53,10 @@ public: bool Pre(parser::ExecutionPart &x) { auto origFirst = x.v.begin(); // insert each elem before origFirst for (stmtFuncType &sf : stmtFuncsToConvert) { - x.v.insert(origFirst, ConvertToAssignment(sf)); + auto &&stmt = sf.statement->ConvertToAssignment(); + stmt.source = sf.source; + x.v.insert(origFirst, + parser::ExecutionPartConstruct{parser::ExecutableConstruct{stmt}}); } stmtFuncsToConvert.clear(); return true; @@ -62,29 +65,6 @@ public: private: const symbolMap &symbols_; std::list stmtFuncsToConvert; - - // Convert a statement function statement to an ExecutionPartConstruct - // containing an array element assignment statement. - static parser::ExecutionPartConstruct ConvertToAssignment(stmtFuncType &x) { - parser::StmtFunctionStmt &sf{*x.statement}; - auto &funcName = std::get(sf.t); - auto &funcArgs = std::get>(sf.t); - auto &funcExpr = std::get>(sf.t).thing; - parser::ArrayElement arrayElement{ - funcName, std::list{}}; - for (parser::Name &arg : funcArgs) { - arrayElement.subscripts.push_back(parser::SectionSubscript{ - parser::Scalar{parser::Integer{parser::Indirection{ - parser::Expr{parser::Indirection{parser::Designator{arg}}}}}}}); - } - auto &&variable = parser::Variable{parser::Indirection{parser::Designator{ - parser::DataRef{parser::Indirection{std::move(arrayElement)}}}}}; - auto &&stmt = parser::Statement{std::nullopt, - parser::ActionStmt{parser::Indirection{ - parser::AssignmentStmt{std::move(variable), std::move(funcExpr)}}}}; - stmt.source = x.source; - return parser::ExecutionPartConstruct{parser::ExecutableConstruct{stmt}}; - } }; static void CollectSymbols(Scope &scope, symbolMap &symbols) { -- 2.7.4