[serialization] Add support for oneofs.

Since SILGen support is so poor, the test just uses -parse.

Swift SVN r6136
This commit is contained in:
Jordan Rose
2013-07-10 23:26:00 +00:00
parent 1564fa7f10
commit ca6f08164f
5 changed files with 178 additions and 3 deletions

View File

@@ -896,6 +896,71 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
break;
}
case decls_block::ONEOF_DECL: {
IdentifierID nameID;
DeclID contextID;
bool isImplicit;
ArrayRef<uint64_t> inheritedIDs;
decls_block::OneOfLayout::readRecord(scratch, nameID, contextID,
isImplicit, inheritedIDs);
MutableArrayRef<TypeLoc> inherited;
DeclContext *DC;
{
BCOffsetRAII restoreOffset(DeclTypeCursor);
inherited = getTypes(inheritedIDs);
DC = getDeclContext(contextID);
}
auto genericParams = maybeReadGenericParams(DC);
auto oneOf = new (ctx) OneOfDecl(SourceLoc(), getIdentifier(nameID),
SourceLoc(), inherited,
genericParams, DC);
declOrOffset = oneOf;
if (isImplicit)
oneOf->setImplicit();
if (genericParams)
for (auto &genericParam : *oneOf->getGenericParams())
genericParam.getAsTypeParam()->setDeclContext(oneOf);
SmallVector<ProtocolConformance *, 16> conformanceBuf;
while (ProtocolConformance *conformance = maybeReadConformance())
conformanceBuf.push_back(conformance);
oneOf->setConformances(ctx.AllocateCopy(conformanceBuf));
auto members = readMembers();
assert(members.hasValue() && "could not read oneof members");
oneOf->setMembers(members.getValue(), SourceRange());
break;
}
case decls_block::ONEOF_ELEMENT_DECL: {
IdentifierID nameID;
DeclID contextID;
TypeID argTypeID, ctorTypeID;
bool isImplicit;
decls_block::OneOfElementLayout::readRecord(scratch, nameID, contextID,
argTypeID, ctorTypeID,
isImplicit);
auto argTy = getType(argTypeID);
auto elem = new (ctx) OneOfElementDecl(SourceLoc(), getIdentifier(nameID),
TypeLoc::withoutLoc(argTy),
getDeclContext(contextID));
declOrOffset = elem;
elem->setType(getType(ctorTypeID));
if (isImplicit)
elem->setImplicit();
break;
}
case decls_block::XREF: {
uint8_t kind;
TypeID expectedTypeID;