@@ -109,15 +109,14 @@ bool ModFileWriter::WriteAll() {
109
109
}
110
110
111
111
void ModFileWriter::WriteAll (const Scope &scope) {
112
- for (const auto &child : scope.children ()) {
112
+ for (const Scope &child : scope.children ()) {
113
113
WriteOne (child);
114
114
}
115
115
}
116
116
117
117
void ModFileWriter::WriteOne (const Scope &scope) {
118
118
if (scope.kind () == Scope::Kind::Module) {
119
- auto *symbol{scope.symbol ()};
120
- if (!symbol->test (Symbol::Flag::ModFile)) {
119
+ if (const auto *symbol{scope.symbol ()}) {
121
120
Write (*symbol);
122
121
}
123
122
WriteAll (scope); // write out submodules
@@ -134,7 +133,7 @@ static std::string ModFileName(const SourceName &name,
134
133
// Write the module file for symbol, which must be a module or submodule.
135
134
void ModFileWriter::Write (const Symbol &symbol) {
136
135
const auto &module {symbol.get <ModuleDetails>()};
137
- if (module .moduleFileHash ()) {
136
+ if (symbol. test (Symbol::Flag::ModFile) || module .moduleFileHash ()) {
138
137
return ; // already written
139
138
}
140
139
const auto *ancestor{module .ancestor ()};
@@ -372,16 +371,19 @@ void ModFileWriter::PutSymbols(
372
371
CollectSymbols (scope, sorted, uses, modules);
373
372
// Write module files for dependencies first so that their
374
373
// hashes are known.
375
- for (auto ref : modules) {
374
+ for (const Symbol &mod : modules) {
376
375
if (hermeticModules) {
377
- hermeticModules->insert (*ref );
376
+ hermeticModules->insert (mod );
378
377
} else {
379
- Write (*ref);
380
- needs_ << ModHeader::need
381
- << CheckSumString (
382
- ref->get <ModuleDetails>().moduleFileHash ().value ())
383
- << (ref->owner ().IsIntrinsicModules () ? " i " : " n " )
384
- << ref->name ().ToString () << ' \n ' ;
378
+ Write (mod);
379
+ // It's possible that the module's file already existed and
380
+ // without its own hash due to being embedded in a hermetic
381
+ // module file.
382
+ if (auto hash{mod.get <ModuleDetails>().moduleFileHash ()}) {
383
+ needs_ << ModHeader::need << CheckSumString (*hash)
384
+ << (mod.owner ().IsIntrinsicModules () ? " i " : " n " )
385
+ << mod.name ().ToString () << ' \n ' ;
386
+ }
385
387
}
386
388
}
387
389
std::string buf; // stuff after CONTAINS in derived type
@@ -855,25 +857,25 @@ void CollectSymbols(const Scope &scope, SymbolVector &sorted,
855
857
auto symbols{scope.GetSymbols ()};
856
858
std::size_t commonSize{scope.commonBlocks ().size ()};
857
859
sorted.reserve (symbols.size () + commonSize);
858
- for (SymbolRef symbol : symbols) {
859
- const auto *generic{symbol-> detailsIf <GenericDetails>()};
860
+ for (const Symbol & symbol : symbols) {
861
+ const auto *generic{symbol. detailsIf <GenericDetails>()};
860
862
if (generic) {
861
863
uses.insert (uses.end (), generic->uses ().begin (), generic->uses ().end ());
862
- for (auto ref : generic->uses ()) {
863
- modules.insert (GetUsedModule (ref-> get <UseDetails>()));
864
+ for (const Symbol &used : generic->uses ()) {
865
+ modules.insert (GetUsedModule (used. get <UseDetails>()));
864
866
}
865
- } else if (const auto *use{symbol-> detailsIf <UseDetails>()}) {
867
+ } else if (const auto *use{symbol. detailsIf <UseDetails>()}) {
866
868
modules.insert (GetUsedModule (*use));
867
869
}
868
- if (symbol-> test (Symbol::Flag::ParentComp)) {
869
- } else if (symbol-> has <NamelistDetails>()) {
870
+ if (symbol. test (Symbol::Flag::ParentComp)) {
871
+ } else if (symbol. has <NamelistDetails>()) {
870
872
namelist.push_back (symbol);
871
873
} else if (generic) {
872
874
if (generic->specific () &&
873
- &generic->specific ()->owner () == &symbol-> owner ()) {
875
+ &generic->specific ()->owner () == &symbol. owner ()) {
874
876
sorted.push_back (*generic->specific ());
875
877
} else if (generic->derivedType () &&
876
- &generic->derivedType ()->owner () == &symbol-> owner ()) {
878
+ &generic->derivedType ()->owner () == &symbol. owner ()) {
877
879
sorted.push_back (*generic->derivedType ());
878
880
}
879
881
generics.push_back (symbol);
0 commit comments