[Mangler] Change the Swift mangler into a symbol builder.

This commit changes the Swift mangler from a utility that writes tokens into a
stream into a name-builder that has two phases: "building a name", and "ready".
This clear separation is needed for the implementation of the compression layer.

Users of the mangler can continue to build the name using the mangleXXX methods,
but to access the results the users of the mangler need to call the finalize()
method. This method can write the result into a stream, like before, or return
an std::string.
This commit is contained in:
Nadav Rotem
2015-12-25 21:36:21 -08:00
parent c26f97fa78
commit 07d4558c1c
27 changed files with 243 additions and 269 deletions

View File

@@ -3648,13 +3648,10 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
for (auto TD : localTypeDecls) {
hasLocalTypes = true;
SmallString<32> MangledName;
llvm::raw_svector_ostream Stream(MangledName);
{
Mangle::Mangler DebugMangler(Stream, false);
Mangle::Mangler DebugMangler(false);
DebugMangler.mangleType(TD->getDeclaredType(),
ResilienceExpansion::Minimal, 0);
}
auto MangledName = DebugMangler.finalize();
assert(!MangledName.empty() && "Mangled type came back empty!");
localTypeGenerator.insert(MangledName, {
addDeclRef(TD), TD->getLocalDiscriminator()