mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Start serializing out DeclAttribute objects using generalized serialization logic.
To generalize our serialization logic for more attributes, serialize each DeclAttribute object in a separate bitcode record. For simple declaration attributes (no arguments), all of this serialization logic can be fully automatically generated, and is done so in this patch. This currently includes @final, but will expand over time. To illustrate the plumbing end-to-end, move the serialization logic for asmnmame over to the new mechanism. Swift SVN r15933
This commit is contained in:
@@ -1229,6 +1229,36 @@ static bool isForced(const Decl *D,
|
||||
return false;
|
||||
}
|
||||
|
||||
void Serializer::writeDeclAttribute(const DeclAttribute *DA) {
|
||||
using namespace decls_block;
|
||||
|
||||
switch (DA->getKind()) {
|
||||
case DAK_Count:
|
||||
llvm_unreachable("cannot serialize DAK_Count");
|
||||
return;
|
||||
|
||||
#define SIMPLE_DECL_ATTR(NAME, CLASS, ...)\
|
||||
case DAK_##NAME: {\
|
||||
auto abbrCode = DeclTypeAbbrCodes[CLASS##DeclAttrLayout::Code];\
|
||||
CLASS##DeclAttrLayout::emitRecord(Out, ScratchRecord, abbrCode);\
|
||||
return;\
|
||||
}
|
||||
#include "swift/AST/Attr.def"
|
||||
|
||||
case DAK_asmname: {
|
||||
auto abbrCode = DeclTypeAbbrCodes[AsmnameDeclAttrLayout::Code];
|
||||
AsmnameDeclAttrLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
cast<AsmnameAttr>(DA)->Name);
|
||||
return;
|
||||
}
|
||||
case DAK_objc:
|
||||
// FIXME: migrate serialization.
|
||||
return;
|
||||
case DAK_availability:
|
||||
llvm_unreachable("not yet serialized");
|
||||
}
|
||||
}
|
||||
|
||||
void Serializer::writeDecl(const Decl *D) {
|
||||
using namespace decls_block;
|
||||
|
||||
@@ -1242,6 +1272,13 @@ void Serializer::writeDecl(const Decl *D) {
|
||||
|
||||
assert(!D->hasClangNode() && "imported decls should use cross-references");
|
||||
|
||||
// Emit attributes (if any).
|
||||
auto &Attrs = D->getAttrs();
|
||||
if (Attrs.begin() != Attrs.end()) {
|
||||
for (auto Attr : Attrs)
|
||||
writeDeclAttribute(Attr);
|
||||
}
|
||||
|
||||
switch (D->getKind()) {
|
||||
case DeclKind::Import:
|
||||
llvm_unreachable("import decls should not be serialized");
|
||||
@@ -1631,12 +1668,6 @@ void Serializer::writeDecl(const Decl *D) {
|
||||
addDeclRef(fn->getOverriddenDecl()),
|
||||
addDeclRef(fn->getAccessorStorageDecl()),
|
||||
nameComponents);
|
||||
|
||||
if (auto AsmA = fn->getAttrs().getAttribute<AsmnameAttr>()) {
|
||||
FuncAsmNameLayout::emitRecord(Out, ScratchRecord,
|
||||
DeclTypeAbbrCodes[FuncAsmNameLayout::Code],
|
||||
AsmA->Name);
|
||||
}
|
||||
|
||||
writeGenericParams(fn->getGenericParams(), DeclTypeAbbrCodes);
|
||||
|
||||
@@ -2294,7 +2325,6 @@ void Serializer::writeAllDeclsAndTypes() {
|
||||
registerDeclTypeAbbr<ConstructorLayout>();
|
||||
registerDeclTypeAbbr<VarLayout>();
|
||||
registerDeclTypeAbbr<FuncLayout>();
|
||||
registerDeclTypeAbbr<FuncAsmNameLayout>();
|
||||
registerDeclTypeAbbr<PatternBindingLayout>();
|
||||
registerDeclTypeAbbr<ProtocolLayout>();
|
||||
registerDeclTypeAbbr<PrefixOperatorLayout>();
|
||||
@@ -2332,6 +2362,11 @@ void Serializer::writeAllDeclsAndTypes() {
|
||||
registerDeclTypeAbbr<InheritedProtocolConformanceLayout>();
|
||||
registerDeclTypeAbbr<DeclContextLayout>();
|
||||
registerDeclTypeAbbr<XRefLayout>();
|
||||
|
||||
registerDeclTypeAbbr<AsmnameDeclAttrLayout>();
|
||||
#define SIMPLE_DECL_ATTR(X, NAME, ...)\
|
||||
registerDeclTypeAbbr<NAME##DeclAttrLayout>();
|
||||
#include "swift/AST/Attr.def"
|
||||
}
|
||||
|
||||
while (!DeclsAndTypesToWrite.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user