r174672 - objective-C modern translator. More fixups for
Fariborz Jahanian
fjahanian at apple.com
Thu Feb 7 14:50:40 PST 2013
Author: fjahanian
Date: Thu Feb 7 16:50:40 2013
New Revision: 174672
URL: http://llvm.org/viewvc/llvm-project?rev=174672&view=rev
Log:
objective-C modern translator. More fixups for
modern meta-data abi translation. Still wip.
// rdar://13138459
Modified:
cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp
cfe/trunk/test/Rewriter/modern-write-bf-abi.mm
Modified: cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp?rev=174672&r1=174671&r2=174672&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp Thu Feb 7 16:50:40 2013
@@ -153,6 +153,7 @@ namespace {
// This container maps an <class, group number for ivar> tuple to the type
// of the struct where the bitfield belongs.
llvm::DenseMap<std::pair<const ObjCInterfaceDecl*, unsigned>, QualType> GroupRecordType;
+ SmallVector<FunctionDecl*, 32> FunctionDefinitionsSeen;
// This maps an original source AST to it's rewritten form. This allows
// us to avoid rewriting the same node twice (which is very uncommon).
@@ -203,6 +204,18 @@ namespace {
}
}
+ if (FunctionDecl *FDecl = dyn_cast<FunctionDecl>(*I)) {
+ // Under modern abi, we cannot translate body of the function
+ // yet until all class extensions and its implementation is seen.
+ // This is because they may introduce new bitfields which must go
+ // into their grouping struct.
+ if (FDecl->isThisDeclarationADefinition() &&
+ // Not c functions defined inside an objc container.
+ !FDecl->isTopLevelDeclInObjCContainer()) {
+ FunctionDefinitionsSeen.push_back(FDecl);
+ break;
+ }
+ }
HandleTopLevelSingleDecl(*I);
}
return true;
@@ -5268,7 +5281,7 @@ void RewriteModernObjC::RewriteByRefVar(
flag |= BLOCK_FIELD_IS_OBJECT;
std::string HF = SynthesizeByrefCopyDestroyHelper(ND, flag);
if (!HF.empty())
- InsertText(FunLocStart, HF);
+ Preamble += HF;
}
// struct __Block_byref_ND ND =
@@ -6023,6 +6036,14 @@ void RewriteModernObjC::HandleTranslatio
RewriteInclude();
+ for (unsigned i = 0, e = FunctionDefinitionsSeen.size(); i < e; i++) {
+ // translation of function bodies were postponed untill all class and
+ // their extensions and implementations are seen. This is because, we
+ // cannot build grouping structs for bitfields untill they are all seen.
+ FunctionDecl *FDecl = FunctionDefinitionsSeen[i];
+ HandleTopLevelSingleDecl(FDecl);
+ }
+
// Here's a great place to add any extra declarations that may be needed.
// Write out meta data for each @protocol(<expr>).
for (llvm::SmallPtrSet<ObjCProtocolDecl *,8>::iterator I = ProtocolExprDecls.begin(),
@@ -6044,7 +6065,7 @@ void RewriteModernObjC::HandleTranslatio
// private ivars.
RewriteInterfaceDecl(CDecl);
}
-
+
// Get the buffer corresponding to MainFileID. If we haven't changed it, then
// we are done.
if (const RewriteBuffer *RewriteBuf =
Modified: cfe/trunk/test/Rewriter/modern-write-bf-abi.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/modern-write-bf-abi.mm?rev=174672&r1=174671&r2=174672&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/modern-write-bf-abi.mm (original)
+++ cfe/trunk/test/Rewriter/modern-write-bf-abi.mm Thu Feb 7 16:50:40 2013
@@ -50,3 +50,51 @@ BOOL objc_collectingEnabled();
return *newArray->_list;
}
@end
+
+// Test2
+ at interface Super {
+ int ivar_super_a : 5;
+}
+ at end
+
+ at interface A : Super {
+ at public
+ int ivar_a : 5;
+}
+ at end
+
+int f0(A *a) {
+ return a->ivar_a;
+}
+
+ at interface A () {
+ at public
+ int ivar_ext_a : 5;
+ int ivar_ext_b : 5;
+}@end
+
+int f1(A *a) {
+ return a->ivar_ext_a + a->ivar_a;
+}
+
+ at interface A () {
+ at public
+ int ivar_ext2_a : 5;
+ int ivar_ext2_b : 5;
+}@end
+
+int f2(A* a) {
+ return a->ivar_ext2_a + a->ivar_ext_a + a->ivar_a;
+}
+
+ at implementation A {
+ at public
+ int ivar_b : 5;
+ int ivar_c : 5;
+ int ivar_d : 5;
+}
+ at end
+
+int f3(A *a) {
+ return a->ivar_d + a->ivar_ext2_a + a->ivar_ext_a + a->ivar_a;
+}
More information about the cfe-commits
mailing list