forked from OSchip/llvm-project
More work to rewrite synthesize properties (<rdar://problem/6213955>)
llvm-svn: 60414
This commit is contained in:
parent
351bb78a10
commit
9af949105a
|
@ -586,9 +586,59 @@ void RewriteObjC::RewriteTabs() {
|
|||
}
|
||||
}
|
||||
|
||||
static std::string getIvarAccessString(ObjCInterfaceDecl *ClassDecl,
|
||||
ObjCIvarDecl *OID) {
|
||||
std::string S;
|
||||
S = "((struct ";
|
||||
S += ClassDecl->getIdentifier()->getName();
|
||||
S += "_IMPL *)self)->";
|
||||
S += OID->getNameAsCString();
|
||||
return S;
|
||||
}
|
||||
|
||||
void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID) {
|
||||
SourceLocation startLoc = PID->getLocStart();
|
||||
InsertText(startLoc, "// ", 3);
|
||||
const char *startBuf = SM->getCharacterData(startLoc);
|
||||
assert((*startBuf == '@') && "bogus @synthesize location");
|
||||
const char *semiBuf = strchr(startBuf, ';');
|
||||
assert((*semiBuf == ';') && "@synthesize: can't find ';'");
|
||||
SourceLocation onePastSemiLoc = startLoc.getFileLocWithOffset(semiBuf-startBuf+1);
|
||||
|
||||
if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
|
||||
return; // FIXME: is this correct?
|
||||
|
||||
// Generate the 'getter' function.
|
||||
std::string Getr;
|
||||
ObjCPropertyDecl *PD = PID->getPropertyDecl();
|
||||
|
||||
RewriteObjCMethodDecl(PD->getGetterMethodDecl(), Getr);
|
||||
ObjCInterfaceDecl *ClassDecl = PD->getGetterMethodDecl()->getClassInterface();
|
||||
|
||||
Getr += "{ ";
|
||||
ObjCIvarDecl *OID = PID->getPropertyIvarDecl();
|
||||
if (OID) {
|
||||
// Synthesize an explicit cast to gain access to the ivar.
|
||||
Getr += "return " + getIvarAccessString(ClassDecl, OID);
|
||||
Getr += "; }";
|
||||
}
|
||||
InsertText(onePastSemiLoc, Getr.c_str(), Getr.size());
|
||||
|
||||
if (PD->isReadOnly())
|
||||
return;
|
||||
|
||||
// Generate the 'setter' function.
|
||||
std::string Setr;
|
||||
RewriteObjCMethodDecl(PD->getSetterMethodDecl(), Setr);
|
||||
|
||||
Setr += "{ ";
|
||||
if (OID) {
|
||||
// Synthesize an explicit cast to initialize the ivar.
|
||||
Setr += getIvarAccessString(ClassDecl, OID) + " = ";
|
||||
Setr += OID->getNameAsCString();
|
||||
Setr += "; }";
|
||||
}
|
||||
InsertText(onePastSemiLoc, Setr.c_str(), Setr.size());
|
||||
}
|
||||
|
||||
void RewriteObjC::RewriteForwardClassDecl(ObjCClassDecl *ClassDecl) {
|
||||
|
|
Loading…
Reference in New Issue