[cfe-commits] r94087 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp lib/Frontend/RewriteObjC.cpp lib/Sema/SemaDeclObjC.cpp test/Rewriter/rewrite-protocol-type-1.m
Fariborz Jahanian
fjahanian at apple.com
Thu Jan 21 09:36:01 PST 2010
Author: fjahanian
Date: Thu Jan 21 11:36:00 2010
New Revision: 94087
URL: http://llvm.org/viewvc/llvm-project?rev=94087&view=rev
Log:
Patch to implement rewriting of properties.
Fixes radar 7562952.
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
cfe/trunk/lib/Frontend/RewriteObjC.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/Rewriter/rewrite-protocol-type-1.m
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=94087&r1=94086&r2=94087&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Jan 21 11:36:00 2010
@@ -1204,6 +1204,7 @@
enum SetterKind { Assign, Retain, Copy };
enum PropertyControl { None, Required, Optional };
private:
+ SourceLocation AtLoc; // location of @propery
QualType DeclType;
unsigned PropertyAttributes : 8;
@@ -1218,8 +1219,8 @@
ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property
ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
- QualType T)
- : NamedDecl(ObjCProperty, DC, L, Id), DeclType(T),
+ SourceLocation AtLocation, QualType T)
+ : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T),
PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
GetterName(Selector()),
SetterName(Selector()),
@@ -1227,8 +1228,12 @@
public:
static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
- IdentifierInfo *Id, QualType T,
+ IdentifierInfo *Id, SourceLocation AtLocation,
+ QualType T,
PropertyControl propControl = None);
+ SourceLocation getAtLoc() const { return AtLoc; }
+ void setAtLoc(SourceLocation L) { AtLoc = L; }
+
QualType getType() const { return DeclType; }
void setType(QualType T) { DeclType = T; }
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=94087&r1=94086&r2=94087&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Thu Jan 21 11:36:00 2010
@@ -790,9 +790,10 @@
ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
IdentifierInfo *Id,
+ SourceLocation AtLoc,
QualType T,
PropertyControl propControl) {
- return new (C) ObjCPropertyDecl(DC, L, Id, T);
+ return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
}
Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=94087&r1=94086&r2=94087&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Thu Jan 21 11:36:00 2010
@@ -326,6 +326,7 @@
void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
VisitNamedDecl(D);
+ D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
D->setType(Reader.GetType(Record[Idx++]));
// FIXME: stable encoding
D->setPropertyAttributes(
@@ -705,7 +706,8 @@
D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
break;
case pch::DECL_OBJC_PROPERTY:
- D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
+ D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
+ QualType());
break;
case pch::DECL_OBJC_PROPERTY_IMPL:
D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=94087&r1=94086&r2=94087&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Thu Jan 21 11:36:00 2010
@@ -315,6 +315,7 @@
void PCHDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
VisitNamedDecl(D);
+ Writer.AddSourceLocation(D->getAtLoc(), Record);
Writer.AddTypeRef(D->getType(), Record);
// FIXME: stable encoding
Record.push_back((unsigned)D->getPropertyAttributes());
Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=94087&r1=94086&r2=94087&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Thu Jan 21 11:36:00 2010
@@ -833,6 +833,10 @@
}
void RewriteObjC::RewriteMethodDeclaration(ObjCMethodDecl *Method) {
+ // When method is a synthesized one, such as a getter/setter there is
+ // nothing to rewrite.
+ if (Method->isSynthesized())
+ return;
SourceLocation LocStart = Method->getLocStart();
SourceLocation LocEnd = Method->getLocEnd();
@@ -846,10 +850,9 @@
}
void RewriteObjC::RewriteProperty(ObjCPropertyDecl *prop) {
- SourceLocation Loc = prop->getLocation();
+ SourceLocation Loc = prop->getAtLoc();
ReplaceText(Loc, 0, "// ", 3);
-
// FIXME: handle properties that are declared across multiple lines.
}
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=94087&r1=94086&r2=94087&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Jan 21 11:36:00 2010
@@ -2186,7 +2186,8 @@
assert(DC && "ClassDecl is not a DeclContext");
ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC,
FD.D.getIdentifierLoc(),
- FD.D.getIdentifier(), T);
+ FD.D.getIdentifier(),
+ AtLoc, T);
DeclContext::lookup_result Found = DC->lookup(PDecl->getDeclName());
if (Found.first != Found.second && isa<ObjCPropertyDecl>(*Found.first)) {
Diag(PDecl->getLocation(), diag::err_duplicate_property);
Modified: cfe/trunk/test/Rewriter/rewrite-protocol-type-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-protocol-type-1.m?rev=94087&r1=94086&r2=94087&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-protocol-type-1.m (original)
+++ cfe/trunk/test/Rewriter/rewrite-protocol-type-1.m Thu Jan 21 11:36:00 2010
@@ -22,3 +22,6 @@
return p3;
}
+ at interface Foo
+ at property int (*hashFunction)(const void *item, int (*size)(const void *item));
+ at end
More information about the cfe-commits
mailing list