summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-10-16 00:29:27 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-10-16 00:29:27 +0000
commit1cee0adea3d010c5f7e9b18f456881d07df7e6d4 (patch)
tree63f586807988e3d888560ef795973f03f13cc1f2 /clang/lib
parent51651089ab587aca965b62f0763a6a3ae05e3fe2 (diff)
downloadbcm5719-llvm-1cee0adea3d010c5f7e9b18f456881d07df7e6d4.tar.gz
bcm5719-llvm-1cee0adea3d010c5f7e9b18f456881d07df7e6d4.zip
Fix a rewriting bug of rewriting properties declared in
protocols. // rdar: //8558702 llvm-svn: 116652
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Rewrite/RewriteObjC.cpp49
1 files changed, 25 insertions, 24 deletions
diff --git a/clang/lib/Rewrite/RewriteObjC.cpp b/clang/lib/Rewrite/RewriteObjC.cpp
index 4c929a246b9..98070914968 100644
--- a/clang/lib/Rewrite/RewriteObjC.cpp
+++ b/clang/lib/Rewrite/RewriteObjC.cpp
@@ -247,7 +247,8 @@ namespace {
ObjCCategoryImplDecl *CID);
void RewriteInterfaceDecl(ObjCInterfaceDecl *Dcl);
void RewriteImplementationDecl(Decl *Dcl);
- void RewriteObjCMethodDecl(ObjCMethodDecl *MDecl, std::string &ResultStr);
+ void RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
+ ObjCMethodDecl *MDecl, std::string &ResultStr);
void RewriteTypeIntoString(QualType T, std::string &ResultStr,
const FunctionType *&FPRetType);
void RewriteByRefString(std::string &ResultStr, const std::string &Name,
@@ -344,8 +345,7 @@ namespace {
std::string &Result);
void SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl,
std::string &Result);
- void SynthesizeIvarOffsetComputation(ObjCContainerDecl *IDecl,
- ObjCIvarDecl *ivar,
+ void SynthesizeIvarOffsetComputation(ObjCIvarDecl *ivar,
std::string &Result);
void RewriteImplementations();
void SynthesizeMetaDataIntoBuffer(std::string &Result);
@@ -733,8 +733,8 @@ void RewriteObjC::RewriteInclude() {
}
}
-static std::string getIvarAccessString(ObjCInterfaceDecl *ClassDecl,
- ObjCIvarDecl *OID) {
+static std::string getIvarAccessString(ObjCIvarDecl *OID) {
+ const ObjCInterfaceDecl *ClassDecl = OID->getContainingInterface();
std::string S;
S = "((struct ";
S += ClassDecl->getIdentifier()->getName();
@@ -762,7 +762,6 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID,
// Generate the 'getter' function.
ObjCPropertyDecl *PD = PID->getPropertyDecl();
- ObjCInterfaceDecl *ClassDecl = PD->getGetterMethodDecl()->getClassInterface();
ObjCIvarDecl *OID = PID->getPropertyIvarDecl();
if (!OID)
@@ -778,7 +777,8 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID,
Getr = "\nextern \"C\" __declspec(dllimport) "
"id objc_getProperty(id, SEL, long, bool);\n";
}
- RewriteObjCMethodDecl(PD->getGetterMethodDecl(), Getr);
+ RewriteObjCMethodDecl(OID->getContainingInterface(),
+ PD->getGetterMethodDecl(), Getr);
Getr += "{ ";
// Synthesize an explicit cast to gain access to the ivar.
// See objc-act.c:objc_synthesize_new_getter() for details.
@@ -812,11 +812,11 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID,
Getr += ";\n";
Getr += "return (_TYPE)";
Getr += "objc_getProperty(self, _cmd, ";
- SynthesizeIvarOffsetComputation(ClassDecl, OID, Getr);
+ SynthesizeIvarOffsetComputation(OID, Getr);
Getr += ", 1)";
}
else
- Getr += "return " + getIvarAccessString(ClassDecl, OID);
+ Getr += "return " + getIvarAccessString(OID);
Getr += "; }";
InsertText(onePastSemiLoc, Getr);
if (PD->isReadOnly())
@@ -833,13 +833,14 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID,
"void objc_setProperty (id, SEL, long, id, bool, bool);\n";
}
- RewriteObjCMethodDecl(PD->getSetterMethodDecl(), Setr);
+ RewriteObjCMethodDecl(OID->getContainingInterface(),
+ PD->getSetterMethodDecl(), Setr);
Setr += "{ ";
// Synthesize an explicit cast to initialize the ivar.
// See objc-act.c:objc_synthesize_new_setter() for details.
if (GenSetProperty) {
Setr += "objc_setProperty (self, _cmd, ";
- SynthesizeIvarOffsetComputation(ClassDecl, OID, Setr);
+ SynthesizeIvarOffsetComputation(OID, Setr);
Setr += ", (id)";
Setr += PD->getName();
Setr += ", ";
@@ -853,7 +854,7 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID,
Setr += "0)";
}
else {
- Setr += getIvarAccessString(ClassDecl, OID) + " = ";
+ Setr += getIvarAccessString(OID) + " = ";
Setr += PD->getName();
}
Setr += "; }";
@@ -1018,7 +1019,8 @@ void RewriteObjC::RewriteTypeIntoString(QualType T, std::string &ResultStr,
ResultStr += T.getAsString(Context->PrintingPolicy);
}
-void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD,
+void RewriteObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
+ ObjCMethodDecl *OMD,
std::string &ResultStr) {
//fprintf(stderr,"In RewriteObjCMethodDecl\n");
const FunctionType *FPRetType = 0;
@@ -1034,7 +1036,7 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD,
else
NameStr += "_C_";
- NameStr += OMD->getClassInterface()->getNameAsString();
+ NameStr += IDecl->getNameAsString();
NameStr += "_";
if (ObjCCategoryImplDecl *CID =
@@ -1060,14 +1062,14 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD,
// invisible arguments
if (OMD->isInstanceMethod()) {
- QualType selfTy = Context->getObjCInterfaceType(OMD->getClassInterface());
+ QualType selfTy = Context->getObjCInterfaceType(IDecl);
selfTy = Context->getPointerType(selfTy);
if (!LangOpts.Microsoft) {
- if (ObjCSynthesizedStructs.count(OMD->getClassInterface()))
+ if (ObjCSynthesizedStructs.count(const_cast<ObjCInterfaceDecl*>(IDecl)))
ResultStr += "struct ";
}
// When rewriting for Microsoft, explicitly omit the structure name.
- ResultStr += OMD->getClassInterface()->getNameAsString();
+ ResultStr += IDecl->getNameAsString();
ResultStr += " *";
}
else
@@ -1135,7 +1137,7 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) {
I != E; ++I) {
std::string ResultStr;
ObjCMethodDecl *OMD = *I;
- RewriteObjCMethodDecl(OMD, ResultStr);
+ RewriteObjCMethodDecl(OMD->getClassInterface(), OMD, ResultStr);
SourceLocation LocStart = OMD->getLocStart();
SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart();
@@ -1150,7 +1152,7 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) {
I != E; ++I) {
std::string ResultStr;
ObjCMethodDecl *OMD = *I;
- RewriteObjCMethodDecl(OMD, ResultStr);
+ RewriteObjCMethodDecl(OMD->getClassInterface(), OMD, ResultStr);
SourceLocation LocStart = OMD->getLocStart();
SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart();
@@ -3706,8 +3708,7 @@ void RewriteObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl,
/// SynthesizeIvarOffsetComputation - This rutine synthesizes computation of
/// ivar offset.
-void RewriteObjC::SynthesizeIvarOffsetComputation(ObjCContainerDecl *IDecl,
- ObjCIvarDecl *ivar,
+void RewriteObjC::SynthesizeIvarOffsetComputation(ObjCIvarDecl *ivar,
std::string &Result) {
if (ivar->isBitField()) {
// FIXME: The hack below doesn't work for bitfields. For now, we simply
@@ -3715,7 +3716,7 @@ void RewriteObjC::SynthesizeIvarOffsetComputation(ObjCContainerDecl *IDecl,
Result += "0";
} else {
Result += "__OFFSETOFIVAR__(struct ";
- Result += IDecl->getNameAsString();
+ Result += ivar->getContainingInterface()->getNameAsString();
if (LangOpts.Microsoft)
Result += "_IMPL";
Result += ", ";
@@ -3798,7 +3799,7 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
QuoteDoublequotes(TmpString, StrEncoding);
Result += StrEncoding;
Result += "\", ";
- SynthesizeIvarOffsetComputation(IDecl, *IVI, Result);
+ SynthesizeIvarOffsetComputation(*IVI, Result);
Result += "}\n";
for (++IVI; IVI != IVE; ++IVI) {
Result += "\t ,{\"";
@@ -3809,7 +3810,7 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
QuoteDoublequotes(TmpString, StrEncoding);
Result += StrEncoding;
Result += "\", ";
- SynthesizeIvarOffsetComputation(IDecl, (*IVI), Result);
+ SynthesizeIvarOffsetComputation((*IVI), Result);
Result += "}\n";
}
OpenPOWER on IntegriCloud