Update 'oneof' syntax.

Give oneof bodies syntax consistent with other NominalTypes. Give oneof elements first-class declaration syntax using the 'case' introducer, as suggested by Jordan. Oneofs can contain 'case' decls, functions, properties, and constructors, but not physical ivars. Non-oneof scopes cannot contain 'case' decls. Add some QoI to the oneof 'case' parser to also parse and complain about things that resemble switch 'case' labels inside decl contexts.

Swift SVN r6211
This commit is contained in:
Joe Groff
2013-07-12 20:42:19 +00:00
parent a93280536d
commit d956fdbd9e
12 changed files with 275 additions and 112 deletions

View File

@@ -933,7 +933,10 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
auto genericParams = maybeReadGenericParams(DC);
auto oneOf = new (ctx) OneOfDecl(SourceLoc(), getIdentifier(nameID),
// FIXME Preserve the isEnum bit.
auto oneOf = new (ctx) OneOfDecl(SourceLoc(),
/*isEnum*/ false,
getIdentifier(nameID),
SourceLoc(), inherited,
genericParams, DC);
declOrOffset = oneOf;
@@ -959,16 +962,22 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
case decls_block::ONEOF_ELEMENT_DECL: {
IdentifierID nameID;
DeclID contextID;
TypeID argTypeID, ctorTypeID;
TypeID argTypeID, resTypeID, ctorTypeID;
bool isImplicit;
decls_block::OneOfElementLayout::readRecord(scratch, nameID, contextID,
argTypeID, ctorTypeID,
argTypeID, resTypeID,
ctorTypeID,
isImplicit);
auto argTy = getType(argTypeID);
auto elem = new (ctx) OneOfElementDecl(SourceLoc(), getIdentifier(nameID),
auto resTy = getType(resTypeID);
auto elem = new (ctx) OneOfElementDecl(SourceLoc(),
SourceLoc(),
getIdentifier(nameID),
TypeLoc::withoutLoc(argTy),
SourceLoc(),
TypeLoc::withoutLoc(resTy),
getDeclContext(contextID));
declOrOffset = elem;