Use actual Identifiers for private discriminators, rather than strings.

This is useful both for caching purposes and for comparison of discriminators
(something the debugger will need to do when looking up a particular decl).

No observable functionality change.

Swift SVN r21610
This commit is contained in:
Jordan Rose
2014-08-30 17:26:59 +00:00
parent ea26f65b62
commit fcfd44c756
9 changed files with 43 additions and 36 deletions

View File

@@ -1377,11 +1377,13 @@ ArtificialMainKind SourceFile::getArtificialMainKind() const {
return ArtificialMainKind::None;
}
void
SourceFile::getDiscriminatorForPrivateValue(SmallVectorImpl<char> &buffer,
const ValueDecl *D) const {
Identifier
SourceFile::getDiscriminatorForPrivateValue(const ValueDecl *D) const {
assert(D->getDeclContext()->getModuleScopeContext() == this);
if (!PrivateDiscriminator.empty())
return PrivateDiscriminator;
StringRef name = getFilename();
if (name.empty()) {
assert(1 == std::count_if(getParentModule()->getFiles().begin(),
@@ -1391,8 +1393,8 @@ SourceFile::getDiscriminatorForPrivateValue(SmallVectorImpl<char> &buffer,
}) && "can't promise uniqueness if multiple source files are nameless");
// We still need a discriminator.
buffer.push_back('_');
return;
PrivateDiscriminator = getASTContext().Id_Underscore;
return PrivateDiscriminator;
}
// Use a hash of the basename of the source file as our discriminator.
@@ -1406,7 +1408,7 @@ SourceFile::getDiscriminatorForPrivateValue(SmallVectorImpl<char> &buffer,
hash.final(result);
// Make sure the whole thing is a valid identifier.
buffer.push_back('_');
SmallString<33> buffer{"_"};
// Write the hash as a hex string.
// FIXME: This should go into llvm/ADT/StringExtras.h.
@@ -1416,7 +1418,9 @@ SourceFile::getDiscriminatorForPrivateValue(SmallVectorImpl<char> &buffer,
buffer.push_back(llvm::hexdigit(byte >> 4, /*lowercase=*/false));
buffer.push_back(llvm::hexdigit(byte & 0xF, /*lowercase=*/false));
}
// FIXME: Cache the result?
PrivateDiscriminator = getASTContext().getIdentifier(buffer);
return PrivateDiscriminator;
}
//===----------------------------------------------------------------------===//