|
12 | 12 | #include "flang/Evaluate/tools.h"
|
13 | 13 | #include "flang/Parser/message.h"
|
14 | 14 | #include "flang/Parser/parsing.h"
|
| 15 | +#include "flang/Parser/unparse.h" |
15 | 16 | #include "flang/Semantics/scope.h"
|
16 | 17 | #include "flang/Semantics/semantics.h"
|
17 | 18 | #include "flang/Semantics/symbol.h"
|
@@ -45,7 +46,8 @@ struct ModHeader {
|
45 | 46 | static std::optional<SourceName> GetSubmoduleParent(const parser::Program &);
|
46 | 47 | static void CollectSymbols(const Scope &, SymbolVector &, SymbolVector &);
|
47 | 48 | static void PutPassName(llvm::raw_ostream &, const std::optional<SourceName> &);
|
48 |
| -static void PutInit(llvm::raw_ostream &, const Symbol &, const MaybeExpr &); |
| 49 | +static void PutInit(llvm::raw_ostream &, const Symbol &, const MaybeExpr &, |
| 50 | + const parser::Expr *); |
49 | 51 | static void PutInit(llvm::raw_ostream &, const MaybeIntExpr &);
|
50 | 52 | static void PutBound(llvm::raw_ostream &, const Bound &);
|
51 | 53 | static void PutShapeSpec(llvm::raw_ostream &, const ShapeSpec &);
|
@@ -399,7 +401,7 @@ void ModFileWriter::PutDECStructure(
|
399 | 401 | }
|
400 | 402 | decls_ << ref->name();
|
401 | 403 | PutShape(decls_, object->shape(), '(', ')');
|
402 |
| - PutInit(decls_, *ref, object->init()); |
| 404 | + PutInit(decls_, *ref, object->init(), nullptr); |
403 | 405 | emittedDECFields_.insert(*ref);
|
404 | 406 | } else if (any) {
|
405 | 407 | break; // any later use of this structure will use RECORD/str/
|
@@ -661,7 +663,7 @@ void ModFileWriter::PutObjectEntity(
|
661 | 663 | symbol.attrs());
|
662 | 664 | PutShape(os, details.shape(), '(', ')');
|
663 | 665 | PutShape(os, details.coshape(), '[', ']');
|
664 |
| - PutInit(os, symbol, details.init()); |
| 666 | + PutInit(os, symbol, details.init(), details.unanalyzedPDTComponentInit()); |
665 | 667 | os << '\n';
|
666 | 668 | }
|
667 | 669 |
|
@@ -715,13 +717,14 @@ void ModFileWriter::PutTypeParam(llvm::raw_ostream &os, const Symbol &symbol) {
|
715 | 717 | os << '\n';
|
716 | 718 | }
|
717 | 719 |
|
718 |
| -void PutInit( |
719 |
| - llvm::raw_ostream &os, const Symbol &symbol, const MaybeExpr &init) { |
720 |
| - if (init) { |
721 |
| - if (symbol.attrs().test(Attr::PARAMETER) || |
722 |
| - symbol.owner().IsDerivedType()) { |
723 |
| - os << (symbol.attrs().test(Attr::POINTER) ? "=>" : "="); |
724 |
| - init->AsFortran(os); |
| 720 | +void PutInit(llvm::raw_ostream &os, const Symbol &symbol, const MaybeExpr &init, |
| 721 | + const parser::Expr *unanalyzed) { |
| 722 | + if (symbol.attrs().test(Attr::PARAMETER) || symbol.owner().IsDerivedType()) { |
| 723 | + const char *assign{symbol.attrs().test(Attr::POINTER) ? "=>" : "="}; |
| 724 | + if (unanalyzed) { |
| 725 | + parser::Unparse(os << assign, *unanalyzed); |
| 726 | + } else if (init) { |
| 727 | + init->AsFortran(os << assign); |
725 | 728 | }
|
726 | 729 | }
|
727 | 730 | }
|
|
0 commit comments