summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2015-07-07 03:58:54 +0000
committerDouglas Gregor <dgregor@apple.com>2015-07-07 03:58:54 +0000
commit1ac1b63c9ca898e66aae9775cca6045082907b9a (patch)
treeb9196b185b0185c84e60f99881aaffd69f4da93d /clang/lib/Serialization
parentab209d83be5dadff4f17364a71f323b89e3c63f8 (diff)
downloadbcm5719-llvm-1ac1b63c9ca898e66aae9775cca6045082907b9a.tar.gz
bcm5719-llvm-1ac1b63c9ca898e66aae9775cca6045082907b9a.zip
Implement variance for Objective-C type parameters.
Introduce co- and contra-variance for Objective-C type parameters, which allows us to express that (for example) an NSArray is covariant in its type parameter. This means that NSArray<NSMutableString *> * is a subtype of NSArray<NSString *> *, which is expected of the immutable Foundation collections. Type parameters can be annotated with __covariant or __contravariant to make them co- or contra-variant, respectively. This feature can be detected by __has_feature(objc_generics_variance). Implements rdar://problem/20217490. llvm-svn: 241549
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r--clang/lib/Serialization/ASTReaderDecl.cpp2
-rw-r--r--clang/lib/Serialization/ASTWriterDecl.cpp2
2 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index c54c5697e59..52019fcd328 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -904,7 +904,9 @@ void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
VisitTypedefNameDecl(D);
+ D->Variance = Record[Idx++];
D->Index = Record[Idx++];
+ D->VarianceLoc = ReadSourceLocation(Record, Idx);
D->ColonLoc = ReadSourceLocation(Record, Idx);
}
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 4d3fb78b080..371aea8088a 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -581,7 +581,9 @@ void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
VisitTypedefNameDecl(D);
+ Record.push_back(D->Variance);
Record.push_back(D->Index);
+ Writer.AddSourceLocation(D->VarianceLoc, Record);
Writer.AddSourceLocation(D->ColonLoc, Record);
Code = serialization::DECL_OBJC_TYPE_PARAM;
OpenPOWER on IntegriCloud