diff options
author | Steve Naroff <snaroff@apple.com> | 2008-12-02 15:48:25 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-12-02 15:48:25 +0000 |
commit | eb0646c8df1c5c8de62b622d13d0c9f19aa29277 (patch) | |
tree | 5c6c2f2c1b12417e37076b98a558fa30f8ccd372 /Driver/RewriteObjC.cpp | |
parent | cee63fbf0e64ac526582312bf8cf33263fc5c16e (diff) |
More work to rewrite synthesize properties (<rdar://problem/6213955>)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60414 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/RewriteObjC.cpp')
-rw-r--r-- | Driver/RewriteObjC.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp index 6979736659..7f55d793d7 100644 --- a/Driver/RewriteObjC.cpp +++ b/Driver/RewriteObjC.cpp @@ -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) { |