aboutsummaryrefslogtreecommitdiff
path: root/Driver/RewriteTest.cpp
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-03-12 21:09:20 +0000
committerSteve Naroff <snaroff@apple.com>2008-03-12 21:09:20 +0000
commit39bbd9f5918950436821585afc6244b1fe2c7295 (patch)
tree2e6fe31c6a90839ea03a82fb475031fbef8a7e78 /Driver/RewriteTest.cpp
parent199e1a071d8a1fdfb18dabad3c751bdc8b2f4487 (diff)
Avoid using the "unnamed struct field" extension (enabled with -fms-extensions). This feature/extension silently does the wrong thing in g++. As far as I can tell, g++ simply throws the field away entirely (note that it works fine with gcc). Since I am now always casting the object (for other reasons), accessing protected/public fields simply requires the cast refer to the defining class. This solution is simpler all around (thanks to Chris for suggesting it).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48302 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/RewriteTest.cpp')
-rw-r--r--Driver/RewriteTest.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index 4ac943328a..b500cf537a 100644
--- a/Driver/RewriteTest.cpp
+++ b/Driver/RewriteTest.cpp
@@ -774,7 +774,11 @@ Stmt *RewriteTest::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
if (const PointerType *pType = IV->getBase()->getType()->getAsPointerType()) {
ObjCInterfaceType *intT = dyn_cast<ObjCInterfaceType>(pType->getPointeeType());
if (CurMethodDecl->getClassInterface() == intT->getDecl()) {
- std::string RecName = intT->getDecl()->getIdentifier()->getName();
+ // lookup which class implements the instance variable.
+ ObjCInterfaceDecl *clsDeclared = 0;
+ intT->getDecl()->lookupInstanceVariable(D->getIdentifier(), clsDeclared);
+ assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class");
+ std::string RecName = clsDeclared->getIdentifier()->getName();
RecName += "_IMPL";
IdentifierInfo *II = &Context->Idents.get(RecName.c_str());
RecordDecl *RD = new RecordDecl(Decl::Struct, SourceLocation(), II, 0);
@@ -2189,14 +2193,9 @@ void RewriteTest::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl,
if (RCDecl && ObjCSynthesizedStructs.count(RCDecl)) {
Result = "\n struct ";
Result += RCDecl->getName();
- if (LangOpts.Microsoft)
- Result += "_IMPL";
-
- // Note: We don't name the field decl. This simplifies the "codegen" for
- // accessing a superclasses instance variables (and is similar to what gcc
- // does internally). The unnamed struct field feature is enabled with
- // -fms-extensions. If the struct definition were "inlined", we wouldn't
- // need to use this switch. That said, I don't want to inline the def.
+ Result += "_IMPL ";
+ Result += RCDecl->getName();
+ Result += "_IVARS";
Result += ";\n";
// insert the super class structure definition.
@@ -2240,14 +2239,9 @@ void RewriteTest::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl,
endBuf += Lexer::MeasureTokenLength(LocEnd, *SM);
Result += " {\n struct ";
Result += RCDecl->getName();
- if (LangOpts.Microsoft)
- Result += "_IMPL";
-
- // Note: We don't name the field decl. This simplifies the "codegen" for
- // accessing a superclasses instance variables (and is similar to what gcc
- // does internally). The unnamed struct field feature is enabled with
- // -fms-extensions. If the struct definition were "inlined", we wouldn't
- // need to use this switch. That said, I don't want to inline the def.
+ Result += "_IMPL ";
+ Result += RCDecl->getName();
+ Result += "_IVARS";
Result += ";\n};\n";
ReplaceText(LocStart, endBuf-startBuf, Result.c_str(), Result.size());
}