diff options
author | Steve Naroff <snaroff@apple.com> | 2007-11-14 19:25:57 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2007-11-14 19:25:57 +0000 |
commit | fea763e8b02eb907c399883117179e898f2abbf8 (patch) | |
tree | 2b5fc44d8a373444e987033a763b25f683c428bd /Driver/RewriteTest.cpp | |
parent | 583e008bbfbb937524d567ad6450b8f0e8485bca (diff) |
Fairly major surgery to RewriteTest::SynthesizeObjcInternalStruct().
This allows us to handle funky stuff like...
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
@interface NSLayoutManager : NSObject <NSCoding, NSGlyphStorage> {
#else /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 */
@interface NSLayoutManager : NSObject <NSCoding> {
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 */
...which now rewrites to...
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
#ifndef _REWRITER_typedef_NSLayoutManager
#define _REWRITER_typedef_NSLayoutManager
typedef struct objc_object NSLayoutManager;
#endif
struct NSLayoutManager {
struct NSObject _NSObject;
#else /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 */
// @interface NSLayoutManager : NSObject <NSCoding> {
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 */
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44129 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/RewriteTest.cpp')
-rw-r--r-- | Driver/RewriteTest.cpp | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 773e1fb0ab..07b66275ec 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -545,15 +545,6 @@ void RewriteTest::RewriteImplementationDecl(NamedDecl *OID) { } void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) { - - SourceLocation LocStart = ClassDecl->getLocStart(); - SourceLocation LocEnd = ClassDecl->getLocEnd(); - - const char *startBuf = SM->getCharacterData(LocStart); - const char *endBuf = SM->getCharacterData(LocEnd); - - endBuf += Lexer::MeasureTokenLength(LocEnd, *SM); - std::string ResultStr; if (!ObjcForwardDecls.count(ClassDecl)) { // we haven't seen a forward decl - generate a typedef. @@ -572,8 +563,6 @@ void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) { } SynthesizeObjcInternalStruct(ClassDecl, ResultStr); - Rewrite.ReplaceText(LocStart, endBuf-startBuf, - ResultStr.c_str(), ResultStr.size()); RewriteProperties(ClassDecl->getNumPropertyDecl(), ClassDecl->getPropertyDecl()); RewriteMethodDeclarations(ClassDecl->getNumInstanceMethods(), @@ -1158,51 +1147,62 @@ void RewriteTest::SynthesizeObjcInternalStruct(ObjcInterfaceDecl *CDecl, if (NumIvars <= 0 && (!RCDecl || !ObjcSynthesizedStructs.count(RCDecl))) return; - Result += "\nstruct "; - Result += CDecl->getName(); - if (RCDecl && ObjcSynthesizedStructs.count(RCDecl)) { - Result += " {\n struct "; - Result += RCDecl->getName(); - Result += " _"; - Result += RCDecl->getName(); - Result += ";\n"; - } - else - Result += " {"; - + Result += "\nstruct "; + Result += CDecl->getName(); + + SourceLocation LocStart = CDecl->getLocStart(); + SourceLocation LocEnd = CDecl->getLocEnd(); + + const char *startBuf = SM->getCharacterData(LocStart); + const char *endBuf = SM->getCharacterData(LocEnd); + if (NumIvars > 0) { - SourceLocation LocStart = CDecl->getLocStart(); - SourceLocation LocEnd = CDecl->getLocEnd(); - - const char *startBuf = SM->getCharacterData(LocStart); - const char *endBuf = SM->getCharacterData(LocEnd); - startBuf = strchr(startBuf, '{'); - assert((startBuf && endBuf) + const char *cursor = strchr(startBuf, '{'); + assert((cursor && endBuf) && "SynthesizeObjcInternalStruct - malformed @interface"); - startBuf++; // past '{' - while (startBuf < endBuf) { - if (*startBuf == '@') { - startBuf = strchr(startBuf, 'p'); + + // rewrite the original header *without* disturbing the '{' + Rewrite.ReplaceText(LocStart, cursor-startBuf-1, + Result.c_str(), Result.size()); + if (RCDecl && ObjcSynthesizedStructs.count(RCDecl)) { + Result = "\n struct "; + Result += RCDecl->getName(); + Result += " _"; + Result += RCDecl->getName(); + Result += ";\n"; + + // insert the super class structure definition. + SourceLocation OnePastCurly = LocStart.getFileLocWithOffset(cursor-startBuf+1); + Rewrite.InsertText(OnePastCurly, Result.c_str(), Result.size()); + } + cursor++; // past '{' + + // Now comment out any visibility specifiers. + while (cursor < endBuf) { + if (*cursor == '@') { + SourceLocation atLoc = LocStart.getFileLocWithOffset(cursor-startBuf); + cursor = strchr(cursor, 'p'); // FIXME: presence of @public, etc. inside comment results in // this transformation as well, which is still correct c-code. - if (!strncmp(startBuf, "public", strlen("public"))) { - startBuf += strlen("public"); - Result += "/* @public */"; - } - else if (!strncmp(startBuf, "private", strlen("private"))) { - startBuf += strlen("private"); - Result += "/* @private */"; - } - else if (!strncmp(startBuf, "protected", strlen("protected"))) { - startBuf += strlen("protected"); - Result += "/* @protected */"; - } + if (!strncmp(cursor, "public", strlen("public")) || + !strncmp(cursor, "private", strlen("private")) || + !strncmp(cursor, "protected", strlen("private"))) + Rewrite.InsertText(atLoc, "// ", 3); } - Result += *startBuf++; + cursor++; } + // Don't forget to add a ';'!! + Rewrite.InsertText(LocEnd.getFileLocWithOffset(1), ";", 1); + } else { // we don't have any instance variables - insert super struct. + endBuf += Lexer::MeasureTokenLength(LocEnd, *SM); + Result += " {\n struct "; + Result += RCDecl->getName(); + Result += " _"; + Result += RCDecl->getName(); + Result += ";\n};\n"; + Rewrite.ReplaceText(LocStart, endBuf-startBuf, + Result.c_str(), Result.size()); } - - Result += "};\n"; // Mark this struct as having been generated. if (!ObjcSynthesizedStructs.insert(CDecl)) assert(false && "struct already synthesize- SynthesizeObjcInternalStruct"); |