Changeset View
Changeset View
Standalone View
Standalone View
flang/lib/Semantics/mod-file.cpp
Show First 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | std::string ModFileWriter::GetAsString(const Symbol &symbol) { | ||||
if (!str.empty()) { | if (!str.empty()) { | ||||
all << "contains\n" << str; | all << "contains\n" << str; | ||||
} | } | ||||
all << "end\n"; | all << "end\n"; | ||||
return all.str(); | return all.str(); | ||||
} | } | ||||
// Put out the visible symbols from scope. | // Put out the visible symbols from scope. | ||||
void ModFileWriter::PutSymbols(const Scope &scope) { | bool ModFileWriter::PutSymbols(const Scope &scope) { | ||||
std::string buf; | std::string buf; | ||||
llvm::raw_string_ostream typeBindings{ | llvm::raw_string_ostream typeBindings{ | ||||
buf}; // stuff after CONTAINS in derived type | buf}; // stuff after CONTAINS in derived type | ||||
for (const Symbol &symbol : CollectSymbols(scope)) { | for (const Symbol &symbol : CollectSymbols(scope)) { | ||||
PutSymbol(typeBindings, symbol); | PutSymbol(typeBindings, symbol); | ||||
} | } | ||||
if (auto str{typeBindings.str()}; !str.empty()) { | if (auto str{typeBindings.str()}; !str.empty()) { | ||||
CHECK(scope.IsDerivedType()); | CHECK(scope.IsDerivedType()); | ||||
decls_ << "contains\n" << str; | decls_ << "contains\n" << str; | ||||
return true; | |||||
} else { | |||||
return false; | |||||
} | } | ||||
} | } | ||||
// Emit a symbol to decls_, except for bindings in a derived type (type-bound | // Emit a symbol to decls_, except for bindings in a derived type (type-bound | ||||
// procedures, type-bound generics, final procedures) which go to typeBindings. | // procedures, type-bound generics, final procedures) which go to typeBindings. | ||||
void ModFileWriter::PutSymbol( | void ModFileWriter::PutSymbol( | ||||
llvm::raw_ostream &typeBindings, const Symbol &symbol) { | llvm::raw_ostream &typeBindings, const Symbol &symbol) { | ||||
std::visit(common::visitors{ | std::visit(common::visitors{ | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | std::visit(common::visitors{ | ||||
sep = ','; | sep = ','; | ||||
} | } | ||||
decls_ << '\n'; | decls_ << '\n'; | ||||
if (symbol.attrs().test(Attr::BIND_C)) { | if (symbol.attrs().test(Attr::BIND_C)) { | ||||
PutAttrs(decls_, symbol.attrs(), x.bindName(), ""s); | PutAttrs(decls_, symbol.attrs(), x.bindName(), ""s); | ||||
decls_ << "::/" << symbol.name() << "/\n"; | decls_ << "::/" << symbol.name() << "/\n"; | ||||
} | } | ||||
}, | }, | ||||
[&](const FinalProcDetails &) { | |||||
typeBindings << "final::" << symbol.name() << '\n'; | |||||
}, | |||||
[](const HostAssocDetails &) {}, | [](const HostAssocDetails &) {}, | ||||
[](const MiscDetails &) {}, | [](const MiscDetails &) {}, | ||||
[&](const auto &) { PutEntity(decls_, symbol); }, | [&](const auto &) { PutEntity(decls_, symbol); }, | ||||
}, | }, | ||||
symbol.details()); | symbol.details()); | ||||
} | } | ||||
void ModFileWriter::PutDerivedType(const Symbol &typeSymbol) { | void ModFileWriter::PutDerivedType(const Symbol &typeSymbol) { | ||||
Show All 11 Lines | for (const auto &name : details.paramNames()) { | ||||
sep = ','; | sep = ','; | ||||
} | } | ||||
decls_ << ')'; | decls_ << ')'; | ||||
} | } | ||||
decls_ << '\n'; | decls_ << '\n'; | ||||
if (details.sequence()) { | if (details.sequence()) { | ||||
decls_ << "sequence\n"; | decls_ << "sequence\n"; | ||||
} | } | ||||
PutSymbols(typeScope); | bool contains{PutSymbols(typeScope)}; | ||||
if (!details.finals().empty()) { | |||||
const char *sep{contains ? "final::" : "contains\nfinal::"}; | |||||
for (const auto &pair : details.finals()) { | |||||
decls_ << sep << pair.second->name(); | |||||
sep = ","; | |||||
} | |||||
if (*sep == ',') { | |||||
decls_ << '\n'; | |||||
} | |||||
} | |||||
decls_ << "end type\n"; | decls_ << "end type\n"; | ||||
} | } | ||||
// Attributes that may be in a subprogram prefix | // Attributes that may be in a subprogram prefix | ||||
static const Attrs subprogramPrefixAttrs{Attr::ELEMENTAL, Attr::IMPURE, | static const Attrs subprogramPrefixAttrs{Attr::ELEMENTAL, Attr::IMPURE, | ||||
Attr::MODULE, Attr::NON_RECURSIVE, Attr::PURE, Attr::RECURSIVE}; | Attr::MODULE, Attr::NON_RECURSIVE, Attr::PURE, Attr::RECURSIVE}; | ||||
void ModFileWriter::PutSubprogram(const Symbol &symbol) { | void ModFileWriter::PutSubprogram(const Symbol &symbol) { | ||||
▲ Show 20 Lines • Show All 660 Lines • Show Last 20 Lines |