forked from OSchip/llvm-project
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 */ llvm-svn: 44129
This commit is contained in:
parent
0cbe920d7c
commit
dde78986fb
|
@ -545,15 +545,6 @@ void RewriteTest::RewriteImplementationDecl(NamedDecl *OID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) {
|
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;
|
std::string ResultStr;
|
||||||
if (!ObjcForwardDecls.count(ClassDecl)) {
|
if (!ObjcForwardDecls.count(ClassDecl)) {
|
||||||
// we haven't seen a forward decl - generate a typedef.
|
// we haven't seen a forward decl - generate a typedef.
|
||||||
|
@ -572,8 +563,6 @@ void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) {
|
||||||
}
|
}
|
||||||
SynthesizeObjcInternalStruct(ClassDecl, ResultStr);
|
SynthesizeObjcInternalStruct(ClassDecl, ResultStr);
|
||||||
|
|
||||||
Rewrite.ReplaceText(LocStart, endBuf-startBuf,
|
|
||||||
ResultStr.c_str(), ResultStr.size());
|
|
||||||
RewriteProperties(ClassDecl->getNumPropertyDecl(),
|
RewriteProperties(ClassDecl->getNumPropertyDecl(),
|
||||||
ClassDecl->getPropertyDecl());
|
ClassDecl->getPropertyDecl());
|
||||||
RewriteMethodDeclarations(ClassDecl->getNumInstanceMethods(),
|
RewriteMethodDeclarations(ClassDecl->getNumInstanceMethods(),
|
||||||
|
@ -1160,49 +1149,60 @@ void RewriteTest::SynthesizeObjcInternalStruct(ObjcInterfaceDecl *CDecl,
|
||||||
|
|
||||||
Result += "\nstruct ";
|
Result += "\nstruct ";
|
||||||
Result += CDecl->getName();
|
Result += CDecl->getName();
|
||||||
if (RCDecl && ObjcSynthesizedStructs.count(RCDecl)) {
|
|
||||||
Result += " {\n struct ";
|
|
||||||
Result += RCDecl->getName();
|
|
||||||
Result += " _";
|
|
||||||
Result += RCDecl->getName();
|
|
||||||
Result += ";\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Result += " {";
|
|
||||||
|
|
||||||
if (NumIvars > 0) {
|
|
||||||
SourceLocation LocStart = CDecl->getLocStart();
|
SourceLocation LocStart = CDecl->getLocStart();
|
||||||
SourceLocation LocEnd = CDecl->getLocEnd();
|
SourceLocation LocEnd = CDecl->getLocEnd();
|
||||||
|
|
||||||
const char *startBuf = SM->getCharacterData(LocStart);
|
const char *startBuf = SM->getCharacterData(LocStart);
|
||||||
const char *endBuf = SM->getCharacterData(LocEnd);
|
const char *endBuf = SM->getCharacterData(LocEnd);
|
||||||
startBuf = strchr(startBuf, '{');
|
|
||||||
assert((startBuf && endBuf)
|
if (NumIvars > 0) {
|
||||||
|
const char *cursor = strchr(startBuf, '{');
|
||||||
|
assert((cursor && endBuf)
|
||||||
&& "SynthesizeObjcInternalStruct - malformed @interface");
|
&& "SynthesizeObjcInternalStruct - malformed @interface");
|
||||||
startBuf++; // past '{'
|
|
||||||
while (startBuf < endBuf) {
|
// rewrite the original header *without* disturbing the '{'
|
||||||
if (*startBuf == '@') {
|
Rewrite.ReplaceText(LocStart, cursor-startBuf-1,
|
||||||
startBuf = strchr(startBuf, 'p');
|
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
|
// FIXME: presence of @public, etc. inside comment results in
|
||||||
// this transformation as well, which is still correct c-code.
|
// this transformation as well, which is still correct c-code.
|
||||||
if (!strncmp(startBuf, "public", strlen("public"))) {
|
if (!strncmp(cursor, "public", strlen("public")) ||
|
||||||
startBuf += strlen("public");
|
!strncmp(cursor, "private", strlen("private")) ||
|
||||||
Result += "/* @public */";
|
!strncmp(cursor, "protected", strlen("private")))
|
||||||
|
Rewrite.InsertText(atLoc, "// ", 3);
|
||||||
}
|
}
|
||||||
else if (!strncmp(startBuf, "private", strlen("private"))) {
|
cursor++;
|
||||||
startBuf += strlen("private");
|
|
||||||
Result += "/* @private */";
|
|
||||||
}
|
}
|
||||||
else if (!strncmp(startBuf, "protected", strlen("protected"))) {
|
// Don't forget to add a ';'!!
|
||||||
startBuf += strlen("protected");
|
Rewrite.InsertText(LocEnd.getFileLocWithOffset(1), ";", 1);
|
||||||
Result += "/* @protected */";
|
} 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 += *startBuf++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Result += "};\n";
|
|
||||||
// Mark this struct as having been generated.
|
// Mark this struct as having been generated.
|
||||||
if (!ObjcSynthesizedStructs.insert(CDecl))
|
if (!ObjcSynthesizedStructs.insert(CDecl))
|
||||||
assert(false && "struct already synthesize- SynthesizeObjcInternalStruct");
|
assert(false && "struct already synthesize- SynthesizeObjcInternalStruct");
|
||||||
|
|
Loading…
Reference in New Issue