Introduce the ObjCSelector class to store an Objective-C selector.

We have to work with selectors quite often, so provide an efficient
representation for them. Switch ObjCAttr over to this representation,
which has the nice property that it efficiently represents implicit
@objc attributes with names and allows us to overwrite the Objective-C
name without losing all source information. Addresses
<rdar://problem/16478678>, and sets us up for dealing with selectors
better.

Swift SVN r16327
This commit is contained in:
Doug Gregor
2014-04-14 20:05:35 +00:00
parent 18bf604360
commit cd4ca76b6a
13 changed files with 331 additions and 362 deletions

View File

@@ -1412,30 +1412,19 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
case decls_block::ObjC_DECL_ATTR: {
bool isImplicit;
uint8_t kind;
ArrayRef<uint64_t> rawNameIDs;
uint64_t numArgs;
ArrayRef<uint64_t> rawPieceIDs;
serialization::decls_block::ObjCDeclAttrLayout::readRecord(
scratch, isImplicit, kind, rawNameIDs);
scratch, isImplicit, numArgs, rawPieceIDs);
SmallVector<Identifier, 4> names;
for (auto nameID : rawNameIDs)
names.push_back(getIdentifier(nameID));
SmallVector<Identifier, 4> pieces;
for (auto pieceID : rawPieceIDs)
pieces.push_back(getIdentifier(pieceID));
switch (kind) {
case serialization::ObjCDeclAttrKind::Unnamed:
Attr = ObjCAttr::createUnnamed(ctx, SourceLoc(), SourceLoc());
break;
case serialization::ObjCDeclAttrKind::Nullary:
Attr = ObjCAttr::createNullary(ctx, names[0]);
break;
case serialization::ObjCDeclAttrKind::Selector:
Attr = ObjCAttr::createSelector(ctx, names);
break;
default:
// Unknown kind. Drop the attribute and continue, but log an error.
error();
break;
}
if (numArgs == 0)
Attr = ObjCAttr::create(ctx, Nothing);
else
Attr = ObjCAttr::create(ctx, ObjCSelector(ctx, numArgs-1, pieces));
break;
}