@@ -32,7 +32,7 @@ using namespace parser::literals;
3232class RewriteMutator {
3333public:
3434 RewriteMutator (SemanticsContext &context)
35- : errorOnUnresolvedName_{!context.AnyFatalError ()},
35+ : context_{context}, errorOnUnresolvedName_{!context.AnyFatalError ()},
3636 messages_{context.messages ()} {}
3737
3838 // Default action for a parse tree node is to visit children.
@@ -42,6 +42,7 @@ class RewriteMutator {
4242 void Post (parser::Name &);
4343 void Post (parser::SpecificationPart &);
4444 bool Pre (parser::ExecutionPart &);
45+ bool Pre (parser::ActionStmt &);
4546 void Post (parser::ReadStmt &);
4647 void Post (parser::WriteStmt &);
4748
@@ -66,6 +67,7 @@ class RewriteMutator {
6667private:
6768 using stmtFuncType =
6869 parser::Statement<common::Indirection<parser::StmtFunctionStmt>>;
70+ SemanticsContext &context_;
6971 bool errorOnUnresolvedName_{true };
7072 parser::Messages &messages_;
7173 std::list<stmtFuncType> stmtFuncsToConvert_;
@@ -130,6 +132,29 @@ bool RewriteMutator::Pre(parser::ExecutionPart &x) {
130132 return true ;
131133}
132134
135+ // Rewrite PRINT NML -> WRITE(*,NML=NML)
136+ bool RewriteMutator::Pre (parser::ActionStmt &x) {
137+ if (auto *print{std::get_if<common::Indirection<parser::PrintStmt>>(&x.u )};
138+ print &&
139+ std::get<std::list<parser::OutputItem>>(print->value ().t ).empty ()) {
140+ auto &format{std::get<parser::Format>(print->value ().t )};
141+ if (std::holds_alternative<parser::Expr>(format.u )) {
142+ if (auto *name{parser::Unwrap<parser::Name>(format)}; name &&
143+ name->symbol && name->symbol ->GetUltimate ().has <NamelistDetails>() &&
144+ context_.IsEnabled (common::LanguageFeature::PrintNamelist)) {
145+ context_.Warn (common::LanguageFeature::PrintNamelist, name->source ,
146+ " nonstandard: namelist in PRINT statement" _port_en_US);
147+ std::list<parser::IoControlSpec> controls;
148+ controls.emplace_back (std::move (*name));
149+ x.u = common::Indirection<parser::WriteStmt>::Make (
150+ parser::IoUnit{parser::Star{}}, std::optional<parser::Format>{},
151+ std::move (controls), std::list<parser::OutputItem>{});
152+ }
153+ }
154+ }
155+ return true ;
156+ }
157+
133158// When a namelist group name appears (without NML=) in a READ or WRITE
134159// statement in such a way that it can be misparsed as a format expression,
135160// rewrite the I/O statement's parse tree node as if the namelist group
0 commit comments