@@ -32,7 +32,7 @@ using namespace parser::literals;
32
32
class RewriteMutator {
33
33
public:
34
34
RewriteMutator (SemanticsContext &context)
35
- : errorOnUnresolvedName_{!context.AnyFatalError ()},
35
+ : context_{context}, errorOnUnresolvedName_{!context.AnyFatalError ()},
36
36
messages_{context.messages ()} {}
37
37
38
38
// Default action for a parse tree node is to visit children.
@@ -42,6 +42,7 @@ class RewriteMutator {
42
42
void Post (parser::Name &);
43
43
void Post (parser::SpecificationPart &);
44
44
bool Pre (parser::ExecutionPart &);
45
+ bool Pre (parser::ActionStmt &);
45
46
void Post (parser::ReadStmt &);
46
47
void Post (parser::WriteStmt &);
47
48
@@ -66,6 +67,7 @@ class RewriteMutator {
66
67
private:
67
68
using stmtFuncType =
68
69
parser::Statement<common::Indirection<parser::StmtFunctionStmt>>;
70
+ SemanticsContext &context_;
69
71
bool errorOnUnresolvedName_{true };
70
72
parser::Messages &messages_;
71
73
std::list<stmtFuncType> stmtFuncsToConvert_;
@@ -130,6 +132,29 @@ bool RewriteMutator::Pre(parser::ExecutionPart &x) {
130
132
return true ;
131
133
}
132
134
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
+
133
158
// When a namelist group name appears (without NML=) in a READ or WRITE
134
159
// statement in such a way that it can be misparsed as a format expression,
135
160
// rewrite the I/O statement's parse tree node as if the namelist group
0 commit comments