AST: Refactor get*UnsafePointerDecl() lookups onto the AST context.

These types are needed by enough of the stack now that it makes sense to centralize their lookup and caching onto the AST context like other core types.

Swift SVN r19029
This commit is contained in:
Joe Groff
2014-06-20 03:02:29 +00:00
parent e269523e48
commit dba8a23d64
12 changed files with 81 additions and 62 deletions

View File

@@ -83,6 +83,15 @@ struct ASTContext::Implementation {
/// The declaration of Swift.ImplicitlyUnwrappedOptional<T>.None.
EnumElementDecl *ImplicitlyUnwrappedOptionalNoneDecl = nullptr;
/// The declaration of Swift.UnsafePointer<T>.
NominalTypeDecl *UnsafePointerDecl = nullptr;
/// The declaration of Swift.ConstUnsafePointer<T>.
NominalTypeDecl *ConstUnsafePointerDecl = nullptr;
/// The declaration of Swift.AutoreleasingUnsafePointer<T>.
NominalTypeDecl *AutoreleasingUnsafePointerDecl = nullptr;
// Declare cached declarations for each of the known declarations.
#define FUNC_DECL(Name, Id) FuncDecl *Get##Name = nullptr;
#include "swift/AST/KnownDecls.def"
@@ -520,6 +529,29 @@ EnumElementDecl *ASTContext::getImplicitlyUnwrappedOptionalNoneDecl() const {
return Impl.ImplicitlyUnwrappedOptionalNoneDecl;
}
NominalTypeDecl *ASTContext::getUnsafePointerDecl() const {
if (!Impl.UnsafePointerDecl)
Impl.UnsafePointerDecl = findSyntaxSugarImpl(*this, "UnsafePointer");
return Impl.UnsafePointerDecl;
}
NominalTypeDecl *ASTContext::getConstUnsafePointerDecl() const {
if (!Impl.ConstUnsafePointerDecl)
Impl.ConstUnsafePointerDecl
= findSyntaxSugarImpl(*this, "ConstUnsafePointer");
return Impl.ConstUnsafePointerDecl;
}
NominalTypeDecl *ASTContext::getAutoreleasingUnsafePointerDecl() const {
if (!Impl.AutoreleasingUnsafePointerDecl)
Impl.AutoreleasingUnsafePointerDecl
= findSyntaxSugarImpl(*this, "AutoreleasingUnsafePointer");
return Impl.AutoreleasingUnsafePointerDecl;
}
ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
// Check whether we've already looked for and cached this protocol.
unsigned index = (unsigned)kind;