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),
|
: DeclAttribute(DAK_asmname, AtLoc, Range, Implicit),
|
||||||
Name(Name) {}
|
Name(Name) {}
|
||||||
|
|
||||||
AsmnameAttr(StringRef Name)
|
AsmnameAttr(StringRef Name, bool Implicit)
|
||||||
: AsmnameAttr(Name, SourceLoc(), SourceRange(), /*Implicit=*/true) {}
|
: AsmnameAttr(Name, SourceLoc(), SourceRange(), /*Implicit=*/true) {}
|
||||||
|
|
||||||
/// The symbol name.
|
/// The symbol name.
|
||||||
|
|||||||
@@ -964,11 +964,22 @@ namespace decls_block {
|
|||||||
|
|
||||||
using AsmnameDeclAttrLayout = BCRecordLayout<
|
using AsmnameDeclAttrLayout = BCRecordLayout<
|
||||||
Asmname_DECL_ATTR,
|
Asmname_DECL_ATTR,
|
||||||
BCBlob // asmname
|
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<
|
using ObjCDeclAttrLayout = BCRecordLayout<
|
||||||
ObjC_DECL_ATTR,
|
ObjC_DECL_ATTR,
|
||||||
|
BCFixed<1>, // implicit flag
|
||||||
ObjCDeclAttrKindField, // kind
|
ObjCDeclAttrKindField, // kind
|
||||||
BCArray<IdentifierIDField>
|
BCArray<IdentifierIDField>
|
||||||
>;
|
>;
|
||||||
|
|||||||
@@ -109,14 +109,16 @@ void DeclAttribute::print(ASTPrinter &Printer) const {
|
|||||||
Printer << "@availability(";
|
Printer << "@availability(";
|
||||||
auto Attr = cast<AvailabilityAttr>(this);
|
auto Attr = cast<AvailabilityAttr>(this);
|
||||||
if (!Attr->hasPlatform())
|
if (!Attr->hasPlatform())
|
||||||
Printer << '*';
|
Printer << "*";
|
||||||
else
|
else
|
||||||
Printer << Attr->Platform;
|
Printer << Attr->Platform;
|
||||||
|
|
||||||
|
Printer << ", unavailable";
|
||||||
|
|
||||||
if (!Attr->Message.empty()) {
|
if (!Attr->Message.empty()) {
|
||||||
Printer << ", message=\""<< Attr->Message << "\"";
|
Printer << ", message=\"" << Attr->Message << "\"";
|
||||||
}
|
}
|
||||||
Printer << ')';
|
Printer << ")";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DAK_class_protocol:
|
case DAK_class_protocol:
|
||||||
|
|||||||
@@ -1387,14 +1387,33 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext,
|
|||||||
DeclAttribute *Attr = nullptr;
|
DeclAttribute *Attr = nullptr;
|
||||||
switch (recordID) {
|
switch (recordID) {
|
||||||
case decls_block::Asmname_DECL_ATTR:
|
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;
|
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: {
|
case decls_block::ObjC_DECL_ATTR: {
|
||||||
|
bool isImplicit;
|
||||||
uint8_t kind;
|
uint8_t kind;
|
||||||
ArrayRef<uint64_t> rawNameIDs;
|
ArrayRef<uint64_t> rawNameIDs;
|
||||||
serialization::decls_block::ObjCDeclAttrLayout::readRecord(
|
serialization::decls_block::ObjCDeclAttrLayout::readRecord(
|
||||||
scratch, kind, rawNameIDs);
|
scratch, isImplicit, kind, rawNameIDs);
|
||||||
|
|
||||||
SmallVector<Identifier, 4> names;
|
SmallVector<Identifier, 4> names;
|
||||||
for (auto nameID : rawNameIDs)
|
for (auto nameID : rawNameIDs)
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
// This is a template-only header; eventually it should move to llvm/Support.
|
// This is a template-only header; eventually it should move to llvm/Support.
|
||||||
#include "clang/Basic/OnDiskHashTable.h"
|
#include "clang/Basic/OnDiskHashTable.h"
|
||||||
|
|
||||||
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/StringExtras.h"
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/Bitcode/BitstreamWriter.h"
|
#include "llvm/Bitcode/BitstreamWriter.h"
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
@@ -1258,9 +1259,26 @@ void Serializer::writeDeclAttribute(const DeclAttribute *DA) {
|
|||||||
#include "swift/AST/Attr.def"
|
#include "swift/AST/Attr.def"
|
||||||
|
|
||||||
case DAK_asmname: {
|
case DAK_asmname: {
|
||||||
|
auto *theAttr = cast<AsmnameAttr>(DA);
|
||||||
auto abbrCode = DeclTypeAbbrCodes[AsmnameDeclAttrLayout::Code];
|
auto abbrCode = DeclTypeAbbrCodes[AsmnameDeclAttrLayout::Code];
|
||||||
AsmnameDeclAttrLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
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;
|
return;
|
||||||
}
|
}
|
||||||
case DAK_objc: {
|
case DAK_objc: {
|
||||||
@@ -1272,11 +1290,10 @@ void Serializer::writeDeclAttribute(const DeclAttribute *DA) {
|
|||||||
auto abbrCode = DeclTypeAbbrCodes[ObjCDeclAttrLayout::Code];
|
auto abbrCode = DeclTypeAbbrCodes[ObjCDeclAttrLayout::Code];
|
||||||
ObjCDeclAttrLayout::emitRecord(
|
ObjCDeclAttrLayout::emitRecord(
|
||||||
Out, ScratchRecord, abbrCode,
|
Out, ScratchRecord, abbrCode,
|
||||||
|
theAttr->isImplicit(),
|
||||||
getRawStableObjCDeclAttrKind(theAttr->getKind()), names);
|
getRawStableObjCDeclAttrKind(theAttr->getKind()), names);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case DAK_availability:
|
|
||||||
llvm_unreachable("not yet serialized");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2378,10 +2395,8 @@ void Serializer::writeAllDeclsAndTypes() {
|
|||||||
registerDeclTypeAbbr<DeclContextLayout>();
|
registerDeclTypeAbbr<DeclContextLayout>();
|
||||||
registerDeclTypeAbbr<XRefLayout>();
|
registerDeclTypeAbbr<XRefLayout>();
|
||||||
|
|
||||||
registerDeclTypeAbbr<AsmnameDeclAttrLayout>();
|
#define DECL_ATTR(X, NAME, ...) \
|
||||||
registerDeclTypeAbbr<ObjCDeclAttrLayout>();
|
registerDeclTypeAbbr<NAME##DeclAttrLayout>();
|
||||||
#define SIMPLE_DECL_ATTR(X, NAME, ...)\
|
|
||||||
registerDeclTypeAbbr<NAME##DeclAttrLayout>();
|
|
||||||
#include "swift/AST/Attr.def"
|
#include "swift/AST/Attr.def"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user