[Serialization] Use existing logic to print a hierarchical module name

No intended functionality change.
This commit is contained in:
Jordan Rose
2019-08-19 16:29:21 -07:00
parent 12fc3537a8
commit c6f033d400
3 changed files with 11 additions and 14 deletions

View File

@@ -193,7 +193,7 @@ public:
/// This is a convenience function that writes the entire name, in forward
/// order, to \p out.
void printForward(raw_ostream &out) const;
void printForward(raw_ostream &out, StringRef delim = ".") const;
};
private:

View File

@@ -1200,11 +1200,12 @@ ModuleDecl::ReverseFullNameIterator::operator++() {
}
void
ModuleDecl::ReverseFullNameIterator::printForward(raw_ostream &out) const {
ModuleDecl::ReverseFullNameIterator::printForward(raw_ostream &out,
StringRef delim) const {
SmallVector<StringRef, 8> elements(*this, {});
swift::interleave(swift::reversed(elements),
[&out](StringRef next) { out << next; },
[&out] { out << '.'; });
[&out, delim] { out << delim; });
}
void

View File

@@ -993,23 +993,19 @@ void Serializer::writeHeader(const SerializationOptions &options) {
}
}
using ImportPathBlob = llvm::SmallString<64>;
static void flattenImportPath(const ModuleDecl::ImportedModule &import,
ImportPathBlob &out) {
SmallVector<StringRef, 4> reverseSubmoduleNames(
import.second->getReverseFullModuleName(), {});
interleave(reverseSubmoduleNames.rbegin(), reverseSubmoduleNames.rend(),
[&out](StringRef next) { out.append(next); },
[&out] { out.push_back('\0'); });
SmallVectorImpl<char> &out) {
llvm::raw_svector_ostream outStream(out);
import.second->getReverseFullModuleName().printForward(outStream,
StringRef("\0", 1));
if (import.first.empty())
return;
out.push_back('\0');
outStream << '\0';
assert(import.first.size() == 1 && "can only handle top-level decl imports");
auto accessPathElem = import.first.front();
out.append(accessPathElem.first.str());
outStream << accessPathElem.first.str();
}
uint64_t getRawModTimeOrHash(const SerializationOptions::FileDependency &dep) {
@@ -1122,7 +1118,7 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
continue;
}
ImportPathBlob importPath;
SmallString<64> importPath;
flattenImportPath(import, importPath);
serialization::ImportControl stableImportControl;