Change parsing and representation of extensions to accommodate generic parameters.

The eventual goal for extensions of generic types is to require them
to specify their generic parameters, e.g.,

  extension Array<T> { ... }

rather than today's

  extension Array { ... }

Start parsing (optional) generic parameters here, and update the
representation of ExtensionDecl to accomodate this new grammar
production. Aside from the parser changes, there's no intended
functionality change here.

Swift SVN r20682
This commit is contained in:
Doug Gregor
2014-07-29 19:17:00 +00:00
parent e466b4621b
commit a0bc9274db
13 changed files with 259 additions and 139 deletions

View File

@@ -2524,15 +2524,21 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
if (declOrOffset.isComplete())
return declOrOffset;
auto baseTy = TypeLoc::withoutLoc(getType(baseID));
auto baseTy = getType(baseID);
if (declOrOffset.isComplete())
return declOrOffset;
auto extension = new (ctx) ExtensionDecl(SourceLoc(), baseTy, { }, DC);
auto nominal = baseTy->getAnyNominal();
ExtensionDecl::RefComponent component{nominal->getName(), SourceLoc(),
nominal->getGenericParams()};
auto extension = ExtensionDecl::create(ctx, SourceLoc(), component, { },
DC);
declOrOffset = extension;
if (isImplicit)
extension->setImplicit();
extension->setExtendedType(baseTy);
auto protocols = ctx.Allocate<ProtocolDecl *>(rawProtocolIDs.size());
for_each(protocols, rawProtocolIDs, [this](ProtocolDecl *&p,
@@ -2545,14 +2551,12 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
skipRecord(DeclTypeCursor, decls_block::DECL_CONTEXT);
extension->setConformanceLoader(this, DeclTypeCursor.GetCurrentBitNo());
auto nominal = baseTy.getType()->getAnyNominal();
nominal->addExtension(extension);
extension->setValidated(true);
extension->setCheckedInheritanceClause();
// FIXME: Hack because extensions always get the generic parameters of their
// nominal types.
extension->setGenericParams(nominal->getGenericParams());
extension->setGenericSignature(nominal->getGenericSignature());
break;
}