Expr::Expr(Designator &&x) : u{Indirection<Designator>(std::move(x))} {}
Expr::Expr(FunctionReference &&x)
: u{Indirection<FunctionReference>(std::move(x))} {}
+
+// R1544 stmt-function-stmt
+// Convert this stmt-function-stmt to an array element assignment statement.
+Statement<ActionStmt> StmtFunctionStmt::ConvertToAssignment() {
+ auto &funcName = std::get<Name>(t);
+ auto &funcArgs = std::get<std::list<Name>>(t);
+ auto &funcExpr = std::get<Scalar<Expr>>(t).thing;
+ ArrayElement arrayElement{funcName, std::list<SectionSubscript>{}};
+ 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
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;
private:
const symbolMap &symbols_;
std::list<stmtFuncType> 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<parser::Name>(sf.t);
- auto &funcArgs = std::get<std::list<parser::Name>>(sf.t);
- auto &funcExpr = std::get<parser::Scalar<parser::Expr>>(sf.t).thing;
- parser::ArrayElement arrayElement{
- funcName, std::list<parser::SectionSubscript>{}};
- 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) {