mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #19194 from rudkx/serialization-for-designated-protocols
Add serialization/deserialization support for designated protocols fo…
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
@@ -3378,27 +3378,43 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) {
|
||||
case decls_block::PREFIX_OPERATOR_DECL: {
|
||||
IdentifierID nameID;
|
||||
DeclContextID contextID;
|
||||
DeclID protoID;
|
||||
|
||||
decls_block::PrefixOperatorLayout::readRecord(scratch, nameID,
|
||||
contextID);
|
||||
decls_block::PrefixOperatorLayout::readRecord(scratch, nameID, contextID,
|
||||
protoID);
|
||||
auto DC = getDeclContext(contextID);
|
||||
declOrOffset = createDecl<PrefixOperatorDecl>(DC, SourceLoc(),
|
||||
getIdentifier(nameID),
|
||||
SourceLoc());
|
||||
|
||||
Expected<Decl *> protocol = getDeclChecked(protoID);
|
||||
if (!protocol)
|
||||
return protocol.takeError();
|
||||
|
||||
auto result = createDecl<PrefixOperatorDecl>(
|
||||
DC, SourceLoc(), getIdentifier(nameID), SourceLoc(),
|
||||
cast_or_null<ProtocolDecl>(protocol.get()));
|
||||
|
||||
declOrOffset = result;
|
||||
break;
|
||||
}
|
||||
|
||||
case decls_block::POSTFIX_OPERATOR_DECL: {
|
||||
IdentifierID nameID;
|
||||
DeclContextID contextID;
|
||||
DeclID protoID;
|
||||
|
||||
decls_block::PostfixOperatorLayout::readRecord(scratch, nameID,
|
||||
contextID);
|
||||
decls_block::PostfixOperatorLayout::readRecord(scratch, nameID, contextID,
|
||||
protoID);
|
||||
|
||||
auto DC = getDeclContext(contextID);
|
||||
declOrOffset = createDecl<PostfixOperatorDecl>(DC, SourceLoc(),
|
||||
getIdentifier(nameID),
|
||||
SourceLoc());
|
||||
|
||||
Expected<Decl *> protocol = getDeclChecked(protoID);
|
||||
if (!protocol)
|
||||
return protocol.takeError();
|
||||
|
||||
auto result = createDecl<PostfixOperatorDecl>(
|
||||
DC, SourceLoc(), getIdentifier(nameID), SourceLoc(),
|
||||
cast_or_null<ProtocolDecl>(protocol.get()));
|
||||
|
||||
declOrOffset = result;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3406,9 +3422,10 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) {
|
||||
IdentifierID nameID;
|
||||
DeclContextID contextID;
|
||||
DeclID precedenceGroupID;
|
||||
DeclID protoID;
|
||||
|
||||
decls_block::InfixOperatorLayout::readRecord(scratch, nameID, contextID,
|
||||
precedenceGroupID);
|
||||
precedenceGroupID, protoID);
|
||||
|
||||
PrecedenceGroupDecl *precedenceGroup = nullptr;
|
||||
Identifier precedenceGroupName;
|
||||
@@ -3422,11 +3439,14 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) {
|
||||
|
||||
auto DC = getDeclContext(contextID);
|
||||
|
||||
auto result = createDecl<InfixOperatorDecl>(DC, SourceLoc(),
|
||||
getIdentifier(nameID),
|
||||
SourceLoc(), SourceLoc(),
|
||||
precedenceGroupName,
|
||||
SourceLoc());
|
||||
Expected<Decl *> protocol = getDeclChecked(protoID);
|
||||
if (!protocol)
|
||||
return protocol.takeError();
|
||||
|
||||
auto result = createDecl<InfixOperatorDecl>(
|
||||
DC, SourceLoc(), getIdentifier(nameID), SourceLoc(), SourceLoc(),
|
||||
precedenceGroupName, SourceLoc(),
|
||||
cast_or_null<ProtocolDecl>(protocol.get()));
|
||||
result->setPrecedenceGroup(precedenceGroup);
|
||||
|
||||
declOrOffset = result;
|
||||
|
||||
@@ -2819,10 +2819,11 @@ void Serializer::writeDecl(const Decl *D) {
|
||||
auto contextID = addDeclContextRef(op->getDeclContext());
|
||||
auto nameID = addDeclBaseNameRef(op->getName());
|
||||
auto groupID = addDeclRef(op->getPrecedenceGroup());
|
||||
auto protoID = addDeclRef(op->getDesignatedProtocol());
|
||||
|
||||
unsigned abbrCode = DeclTypeAbbrCodes[InfixOperatorLayout::Code];
|
||||
InfixOperatorLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
nameID, contextID, groupID);
|
||||
InfixOperatorLayout::emitRecord(Out, ScratchRecord, abbrCode, nameID,
|
||||
contextID, groupID, protoID);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2831,11 +2832,12 @@ void Serializer::writeDecl(const Decl *D) {
|
||||
verifyAttrSerializable(op);
|
||||
|
||||
auto contextID = addDeclContextRef(op->getDeclContext());
|
||||
auto protoID = addDeclRef(op->getDesignatedProtocol());
|
||||
|
||||
unsigned abbrCode = DeclTypeAbbrCodes[PrefixOperatorLayout::Code];
|
||||
PrefixOperatorLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
addDeclBaseNameRef(op->getName()),
|
||||
contextID);
|
||||
contextID, protoID);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2844,11 +2846,12 @@ void Serializer::writeDecl(const Decl *D) {
|
||||
verifyAttrSerializable(op);
|
||||
|
||||
auto contextID = addDeclContextRef(op->getDeclContext());
|
||||
auto protoID = addDeclRef(op->getDesignatedProtocol());
|
||||
|
||||
unsigned abbrCode = DeclTypeAbbrCodes[PostfixOperatorLayout::Code];
|
||||
PostfixOperatorLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
addDeclBaseNameRef(op->getName()),
|
||||
contextID);
|
||||
contextID, protoID);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user