mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
@availability: implement serialization and AST printing
Swift SVN r16010
This commit is contained in:
@@ -467,7 +467,7 @@ public:
|
||||
: DeclAttribute(DAK_asmname, AtLoc, Range, Implicit),
|
||||
Name(Name) {}
|
||||
|
||||
AsmnameAttr(StringRef Name)
|
||||
AsmnameAttr(StringRef Name, bool Implicit)
|
||||
: AsmnameAttr(Name, SourceLoc(), SourceRange(), /*Implicit=*/true) {}
|
||||
|
||||
/// The symbol name.
|
||||
|
||||
@@ -964,11 +964,22 @@ namespace decls_block {
|
||||
|
||||
using AsmnameDeclAttrLayout = BCRecordLayout<
|
||||
Asmname_DECL_ATTR,
|
||||
BCFixed<1>, // implicit flag
|
||||
BCBlob // asmname
|
||||
>;
|
||||
|
||||
using AvailabilityDeclAttrLayout = BCRecordLayout<
|
||||
Availability_DECL_ATTR,
|
||||
BCFixed<1>, // implicit flag
|
||||
BCFixed<1>, // is unconditionally unavailable?
|
||||
BCVBR<5>, // number of bytes in platform string
|
||||
BCVBR<5>, // number of bytes in message string
|
||||
BCBlob // platform, followed by message
|
||||
>;
|
||||
|
||||
using ObjCDeclAttrLayout = BCRecordLayout<
|
||||
ObjC_DECL_ATTR,
|
||||
BCFixed<1>, // implicit flag
|
||||
ObjCDeclAttrKindField, // kind
|
||||
BCArray<IdentifierIDField>
|
||||
>;
|
||||
|
||||
@@ -109,14 +109,16 @@ void DeclAttribute::print(ASTPrinter &Printer) const {
|
||||
Printer << "@availability(";
|
||||
auto Attr = cast<AvailabilityAttr>(this);
|
||||
if (!Attr->hasPlatform())
|
||||
Printer << '*';
|
||||
Printer << "*";
|
||||
else
|
||||
Printer << Attr->Platform;
|
||||
|
||||
Printer << ", unavailable";
|
||||
|
||||
if (!Attr->Message.empty()) {
|
||||
Printer << ", message=\"" << Attr->Message << "\"";
|
||||
}
|
||||
Printer << ')';
|
||||
Printer << ")";
|
||||
break;
|
||||
}
|
||||
case DAK_class_protocol:
|
||||
|
||||
@@ -1387,14 +1387,33 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext,
|
||||
DeclAttribute *Attr = nullptr;
|
||||
switch (recordID) {
|
||||
case decls_block::Asmname_DECL_ATTR:
|
||||
Attr = new (ctx) AsmnameAttr(blobData);
|
||||
bool isImplicit;
|
||||
serialization::decls_block::AsmnameDeclAttrLayout::readRecord(
|
||||
scratch, isImplicit);
|
||||
Attr = new (ctx) AsmnameAttr(blobData, isImplicit);
|
||||
break;
|
||||
|
||||
case decls_block::Availability_DECL_ATTR: {
|
||||
bool isImplicit;
|
||||
bool isUnavailable;
|
||||
unsigned platformSize;
|
||||
unsigned messageSize;
|
||||
serialization::decls_block::AvailabilityDeclAttrLayout::readRecord(
|
||||
scratch, isImplicit, isUnavailable, platformSize, messageSize);
|
||||
StringRef platform = blobData.substr(0, platformSize);
|
||||
blobData = blobData.drop_front(platformSize);
|
||||
StringRef message = blobData;
|
||||
Attr = new (ctx) AvailabilityAttr(SourceLoc(), SourceRange(), platform,
|
||||
message, isUnavailable, isImplicit);
|
||||
break;
|
||||
}
|
||||
|
||||
case decls_block::ObjC_DECL_ATTR: {
|
||||
bool isImplicit;
|
||||
uint8_t kind;
|
||||
ArrayRef<uint64_t> rawNameIDs;
|
||||
serialization::decls_block::ObjCDeclAttrLayout::readRecord(
|
||||
scratch, kind, rawNameIDs);
|
||||
scratch, isImplicit, kind, rawNameIDs);
|
||||
|
||||
SmallVector<Identifier, 4> names;
|
||||
for (auto nameID : rawNameIDs)
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
// This is a template-only header; eventually it should move to llvm/Support.
|
||||
#include "clang/Basic/OnDiskHashTable.h"
|
||||
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Bitcode/BitstreamWriter.h"
|
||||
#include "llvm/Config/config.h"
|
||||
@@ -1258,9 +1259,26 @@ void Serializer::writeDeclAttribute(const DeclAttribute *DA) {
|
||||
#include "swift/AST/Attr.def"
|
||||
|
||||
case DAK_asmname: {
|
||||
auto *theAttr = cast<AsmnameAttr>(DA);
|
||||
auto abbrCode = DeclTypeAbbrCodes[AsmnameDeclAttrLayout::Code];
|
||||
AsmnameDeclAttrLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
cast<AsmnameAttr>(DA)->Name);
|
||||
theAttr->isImplicit(),
|
||||
theAttr->Name);
|
||||
return;
|
||||
}
|
||||
case DAK_availability: {
|
||||
auto *theAttr = cast<AvailabilityAttr>(DA);
|
||||
llvm::SmallString<32> blob;
|
||||
blob.append(theAttr->Platform);
|
||||
blob.append(theAttr->Message);
|
||||
auto abbrCode = DeclTypeAbbrCodes[AvailabilityDeclAttrLayout::Code];
|
||||
AvailabilityDeclAttrLayout::emitRecord(
|
||||
Out, ScratchRecord, abbrCode,
|
||||
theAttr->isImplicit(),
|
||||
theAttr->IsUnvailable,
|
||||
theAttr->Platform.size(),
|
||||
theAttr->Message.size(),
|
||||
blob);
|
||||
return;
|
||||
}
|
||||
case DAK_objc: {
|
||||
@@ -1272,11 +1290,10 @@ void Serializer::writeDeclAttribute(const DeclAttribute *DA) {
|
||||
auto abbrCode = DeclTypeAbbrCodes[ObjCDeclAttrLayout::Code];
|
||||
ObjCDeclAttrLayout::emitRecord(
|
||||
Out, ScratchRecord, abbrCode,
|
||||
theAttr->isImplicit(),
|
||||
getRawStableObjCDeclAttrKind(theAttr->getKind()), names);
|
||||
return;
|
||||
}
|
||||
case DAK_availability:
|
||||
llvm_unreachable("not yet serialized");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2378,9 +2395,7 @@ void Serializer::writeAllDeclsAndTypes() {
|
||||
registerDeclTypeAbbr<DeclContextLayout>();
|
||||
registerDeclTypeAbbr<XRefLayout>();
|
||||
|
||||
registerDeclTypeAbbr<AsmnameDeclAttrLayout>();
|
||||
registerDeclTypeAbbr<ObjCDeclAttrLayout>();
|
||||
#define SIMPLE_DECL_ATTR(X, NAME, ...)\
|
||||
#define DECL_ATTR(X, NAME, ...) \
|
||||
registerDeclTypeAbbr<NAME##DeclAttrLayout>();
|
||||
#include "swift/AST/Attr.def"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user