From: Douglas Gregor Date: Wed, 22 Apr 2009 23:20:34 +0000 (+0000) Subject: PCH support for Objective-C property declarations (UNTESTED!) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70e5a14c6076d63833c62d1d6d628c26309897c1;p=clang PCH support for Objective-C property declarations (UNTESTED!) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69843 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 0ffa5df64f..a3b72d3ff1 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -1071,7 +1071,8 @@ public: IdentifierInfo *Id, QualType T, PropertyControl propControl = None); QualType getType() const { return DeclType; } - + void setType(QualType T) { DeclType = T; } + PropertyAttributeKind getPropertyAttributes() const { return PropertyAttributeKind(PropertyAttributes); } diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 3ade493b4e..e2cffb5454 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -303,7 +303,21 @@ void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { VisitNamedDecl(D); - // FIXME: Implement. + D->setType(Reader.GetType(Record[Idx++])); + // FIXME: stable encoding + D->setPropertyAttributes( + (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); + // FIXME: stable encoding + D->setPropertyImplementation( + (ObjCPropertyDecl::PropertyControl)Record[Idx++]); + D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); + D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); + D->setGetterMethodDecl( + cast_or_null(Reader.GetDecl(Record[Idx++]))); + D->setSetterMethodDecl( + cast_or_null(Reader.GetDecl(Record[Idx++]))); + D->setPropertyIvarDecl( + cast_or_null(Reader.GetDecl(Record[Idx++]))); } void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { @@ -2264,7 +2278,7 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { } case pch::DECL_OBJC_PROPERTY: { - // FIXME: Implement. + D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, QualType()); break; } diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 6557ca5c42..a3b1253a66 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -478,7 +478,16 @@ void PCHDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) { void PCHDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { VisitNamedDecl(D); - // FIXME: Implement. + Writer.AddTypeRef(D->getType(), Record); + // FIXME: stable encoding + Record.push_back((unsigned)D->getPropertyAttributes()); + // FIXME: stable encoding + Record.push_back((unsigned)D->getPropertyImplementation()); + Writer.AddDeclarationName(D->getGetterName(), Record); + Writer.AddDeclarationName(D->getSetterName(), Record); + Writer.AddDeclRef(D->getGetterMethodDecl(), Record); + Writer.AddDeclRef(D->getSetterMethodDecl(), Record); + Writer.AddDeclRef(D->getPropertyIvarDecl(), Record); Code = pch::DECL_OBJC_PROPERTY; } @@ -1715,7 +1724,13 @@ void PCHWriter::WriteDeclsBlock(ASTContext &Context) { W.Code = (pch::DeclCode)0; W.Visit(D); if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset); - assert(W.Code && "Unhandled declaration kind while generating PCH"); + + if (!W.Code) { + fprintf(stderr, "Cannot serialize declaration of kind %s\n", + D->getDeclKindName()); + assert(false && "Unhandled declaration kind while generating PCH"); + exit(-1); + } Stream.EmitRecord(W.Code, Record); // If the declaration had any attributes, write them now. diff --git a/test/PCH/objc_property.h b/test/PCH/objc_property.h new file mode 100644 index 0000000000..2432370be4 --- /dev/null +++ b/test/PCH/objc_property.h @@ -0,0 +1,12 @@ +/* For use with the objc_property.m PCH test */ +@interface TestProperties +{ + int value; + float percentage; +} + ++ alloc; + +@property int value; +@property float percentage; +@end diff --git a/test/PCH/objc_property.m b/test/PCH/objc_property.m new file mode 100644 index 0000000000..83bde783a3 --- /dev/null +++ b/test/PCH/objc_property.m @@ -0,0 +1,11 @@ +// Test this without pch. +// FIXME: clang-cc -include %S/objc_property.h -fsyntax-only -verify %s && + +// Test with pch. +// FIXME: clang-cc -x=objective-c -emit-pch -o %t %S/objc_property.h && +// FIXME: clang-cc -include-pch %t -fsyntax-only -verify %s + +void func() { + TestProperties *xx = [TestProperties alloc]; + xx.value = 5; +}