зеркало из https://github.com/microsoft/clang-1.git
Patch to implement rewriting of properties.
Fixes radar 7562952. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94087 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
45db90de59
Коммит
d0502407c1
|
@ -1204,6 +1204,7 @@ public:
|
||||||
enum SetterKind { Assign, Retain, Copy };
|
enum SetterKind { Assign, Retain, Copy };
|
||||||
enum PropertyControl { None, Required, Optional };
|
enum PropertyControl { None, Required, Optional };
|
||||||
private:
|
private:
|
||||||
|
SourceLocation AtLoc; // location of @propery
|
||||||
QualType DeclType;
|
QualType DeclType;
|
||||||
unsigned PropertyAttributes : 8;
|
unsigned PropertyAttributes : 8;
|
||||||
|
|
||||||
|
@ -1218,8 +1219,8 @@ private:
|
||||||
ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property
|
ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property
|
||||||
|
|
||||||
ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
|
ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
|
||||||
QualType T)
|
SourceLocation AtLocation, QualType T)
|
||||||
: NamedDecl(ObjCProperty, DC, L, Id), DeclType(T),
|
: NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T),
|
||||||
PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
|
PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
|
||||||
GetterName(Selector()),
|
GetterName(Selector()),
|
||||||
SetterName(Selector()),
|
SetterName(Selector()),
|
||||||
|
@ -1227,8 +1228,12 @@ private:
|
||||||
public:
|
public:
|
||||||
static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
|
static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
|
||||||
SourceLocation L,
|
SourceLocation L,
|
||||||
IdentifierInfo *Id, QualType T,
|
IdentifierInfo *Id, SourceLocation AtLocation,
|
||||||
|
QualType T,
|
||||||
PropertyControl propControl = None);
|
PropertyControl propControl = None);
|
||||||
|
SourceLocation getAtLoc() const { return AtLoc; }
|
||||||
|
void setAtLoc(SourceLocation L) { AtLoc = L; }
|
||||||
|
|
||||||
QualType getType() const { return DeclType; }
|
QualType getType() const { return DeclType; }
|
||||||
void setType(QualType T) { DeclType = T; }
|
void setType(QualType T) { DeclType = T; }
|
||||||
|
|
||||||
|
|
|
@ -790,9 +790,10 @@ ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
|
||||||
ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
|
ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
|
||||||
SourceLocation L,
|
SourceLocation L,
|
||||||
IdentifierInfo *Id,
|
IdentifierInfo *Id,
|
||||||
|
SourceLocation AtLoc,
|
||||||
QualType T,
|
QualType T,
|
||||||
PropertyControl propControl) {
|
PropertyControl propControl) {
|
||||||
return new (C) ObjCPropertyDecl(DC, L, Id, T);
|
return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -326,6 +326,7 @@ void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
|
||||||
|
|
||||||
void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
|
void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
|
||||||
VisitNamedDecl(D);
|
VisitNamedDecl(D);
|
||||||
|
D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
|
||||||
D->setType(Reader.GetType(Record[Idx++]));
|
D->setType(Reader.GetType(Record[Idx++]));
|
||||||
// FIXME: stable encoding
|
// FIXME: stable encoding
|
||||||
D->setPropertyAttributes(
|
D->setPropertyAttributes(
|
||||||
|
@ -705,7 +706,8 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
|
||||||
D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
|
D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
|
||||||
break;
|
break;
|
||||||
case pch::DECL_OBJC_PROPERTY:
|
case pch::DECL_OBJC_PROPERTY:
|
||||||
D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
|
D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
|
||||||
|
QualType());
|
||||||
break;
|
break;
|
||||||
case pch::DECL_OBJC_PROPERTY_IMPL:
|
case pch::DECL_OBJC_PROPERTY_IMPL:
|
||||||
D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
|
D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
|
||||||
|
|
|
@ -315,6 +315,7 @@ void PCHDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
|
||||||
|
|
||||||
void PCHDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
|
void PCHDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
|
||||||
VisitNamedDecl(D);
|
VisitNamedDecl(D);
|
||||||
|
Writer.AddSourceLocation(D->getAtLoc(), Record);
|
||||||
Writer.AddTypeRef(D->getType(), Record);
|
Writer.AddTypeRef(D->getType(), Record);
|
||||||
// FIXME: stable encoding
|
// FIXME: stable encoding
|
||||||
Record.push_back((unsigned)D->getPropertyAttributes());
|
Record.push_back((unsigned)D->getPropertyAttributes());
|
||||||
|
|
|
@ -833,6 +833,10 @@ void RewriteObjC::RewriteForwardClassDecl(ObjCClassDecl *ClassDecl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RewriteObjC::RewriteMethodDeclaration(ObjCMethodDecl *Method) {
|
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 LocStart = Method->getLocStart();
|
||||||
SourceLocation LocEnd = Method->getLocEnd();
|
SourceLocation LocEnd = Method->getLocEnd();
|
||||||
|
|
||||||
|
@ -846,10 +850,9 @@ void RewriteObjC::RewriteMethodDeclaration(ObjCMethodDecl *Method) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RewriteObjC::RewriteProperty(ObjCPropertyDecl *prop) {
|
void RewriteObjC::RewriteProperty(ObjCPropertyDecl *prop) {
|
||||||
SourceLocation Loc = prop->getLocation();
|
SourceLocation Loc = prop->getAtLoc();
|
||||||
|
|
||||||
ReplaceText(Loc, 0, "// ", 3);
|
ReplaceText(Loc, 0, "// ", 3);
|
||||||
|
|
||||||
// FIXME: handle properties that are declared across multiple lines.
|
// FIXME: handle properties that are declared across multiple lines.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2186,7 +2186,8 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
|
||||||
assert(DC && "ClassDecl is not a DeclContext");
|
assert(DC && "ClassDecl is not a DeclContext");
|
||||||
ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC,
|
ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC,
|
||||||
FD.D.getIdentifierLoc(),
|
FD.D.getIdentifierLoc(),
|
||||||
FD.D.getIdentifier(), T);
|
FD.D.getIdentifier(),
|
||||||
|
AtLoc, T);
|
||||||
DeclContext::lookup_result Found = DC->lookup(PDecl->getDeclName());
|
DeclContext::lookup_result Found = DC->lookup(PDecl->getDeclName());
|
||||||
if (Found.first != Found.second && isa<ObjCPropertyDecl>(*Found.first)) {
|
if (Found.first != Found.second && isa<ObjCPropertyDecl>(*Found.first)) {
|
||||||
Diag(PDecl->getLocation(), diag::err_duplicate_property);
|
Diag(PDecl->getLocation(), diag::err_duplicate_property);
|
||||||
|
|
|
@ -22,3 +22,6 @@ INTF <MyProto1, MyProto2> * Func1(INTF *p2, INTF<MyProto1, MyProto2> *p3, INTF *
|
||||||
return p3;
|
return p3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface Foo
|
||||||
|
@property int (*hashFunction)(const void *item, int (*size)(const void *item));
|
||||||
|
@end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче