Generate the required AST-level thunk for subscript setters.

An Objective-C subscript setter has a type of the form 

  (this) -> (value, index) -> ()

while a Swift subscript setter has a type of the form

  (this) -> (index) (value) -> ()

Introduce a Swift "thunk" with the latter signature that simply calls
the underlying Objective-C method, and make sure that thunk gets
type-checked and IR-generated appropriately.


Swift SVN r3382
This commit is contained in:
Doug Gregor
2012-12-06 19:28:11 +00:00
parent d3f6890299
commit aa89f9185b
2 changed files with 134 additions and 17 deletions

View File

@@ -473,10 +473,19 @@ void IRGenFunction::emitExternalDefinition(Decl *D) {
case DeclKind::TopLevelCode:
case DeclKind::TypeAlias:
case DeclKind::Var:
case DeclKind::Func:
case DeclKind::Import:
case DeclKind::Subscript:
case DeclKind::Destructor:
llvm_unreachable("Not a valid external definition for IRgen");
case DeclKind::Func:
// The only functions available are subscript setters.
assert(cast<FuncDecl>(D)->isGetterOrSetter() &&
isa<SubscriptDecl>(cast<FuncDecl>(D)->getSetterDecl()) &&
"Not a synthesized setter");
IGM.emitInstanceMethod(cast<FuncDecl>(D));
break;
case DeclKind::Constructor:
if (D->getDeclContext()->getDeclaredTypeOfContext()
->getClassOrBoundGenericClass()) {
@@ -485,14 +494,6 @@ void IRGenFunction::emitExternalDefinition(Decl *D) {
IGM.emitConstructor(cast<ConstructorDecl>(D));
}
break;
case DeclKind::Destructor:
llvm_unreachable("Cannot handle destructors yet");
break;
case DeclKind::Subscript:
llvm_unreachable("Cannot handle subscripts yet");
break;
}
}