diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2007-10-18 22:09:03 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2007-10-18 22:09:03 +0000 |
commit | f4d331dd922f92478ebf30e808c0ca97ce49418b (patch) | |
tree | c6073548936dcd0a6f952e8180997ec13b67767a /Driver/RewriteTest.cpp | |
parent | c266acd6d7cefa86005630b0fb5ad62e44435a83 (diff) |
Patch to rewrite ivar tables metadata for classes defined.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43151 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/RewriteTest.cpp')
-rw-r--r-- | Driver/RewriteTest.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 8954a19819..883482c67e 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -45,6 +45,7 @@ namespace { void RewriteFunctionBody(Stmt *S); void RewriteAtEncode(ObjCEncodeExpr *Exp); + void WriteObjcClassMetaData(ObjcImplementationDecl *IDecl); void WriteObjcMetaData(); ~RewriteTest(); @@ -119,7 +120,7 @@ void RewriteTest::RewriteFunctionBody(Stmt *S) { if (*CI) RewriteFunctionBody(*CI); } - + void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) { // Create a new string expression. QualType StrType = Context->getPointerType(Context->CharTy); @@ -129,11 +130,66 @@ void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) { delete Replacement; } +void RewriteTest::WriteObjcClassMetaData(ObjcImplementationDecl *IDecl) { + ObjcInterfaceDecl *CDecl = IDecl->getClassInterface(); + + if (IDecl->getImplDeclNumIvars() > 0 || + CDecl&& CDecl->getIntfDeclNumIvars() > 0) { + static bool objc_ivar = false; + + int NumIvars = IDecl->getImplDeclNumIvars() > 0 + ? IDecl->getImplDeclNumIvars() + : CDecl->getIntfDeclNumIvars(); + + if (!objc_ivar) { + /* struct _objc_ivar { + char *ivar_name; + char *ivar_type; + int ivar_offset; + }; + */ + printf("\nstruct _objc_ivar {\n"); + printf("\tchar *ivar_name;\n"); + printf("\tchar *ivar_type;\n"); + printf("\tint ivar_offset;\n"); + printf("};\n"); + objc_ivar = true; + } + + /* struct _objc_ivar_list { + int ivar_count; + struct _objc_ivar ivar_list[ivar_count]; + }; + */ + printf("\nstatic struct {\n"); + printf("\tint ivar_count;\n"); + printf("\tstruct _objc_ivar ivar_list[%d];\n", NumIvars); + printf("} _OBJC_INSTANCE_VARIABLES_%s " + "__attribute__ ((section (\"__OBJC, __instance_vars\")))= " + "{\n\t%d\n",IDecl->getName(), + NumIvars); + ObjcIvarDecl **Ivars = IDecl->getImplDeclIVars() + ? IDecl->getImplDeclIVars() + : CDecl->getIntfDeclIvars(); + for (int i = 0; i < NumIvars; i++) + // TODO: 1) ivar names may have to go to another section. 2) encode + // ivar_type type of each ivar . 3) compute and add ivar offset. + printf("\t,\"%s\", \"\", 0\n", Ivars[i]->getName()); + printf("};\n"); + } + +} + void RewriteTest::WriteObjcMetaData() { int ClsDefCount = ClassImplementation.size(); int CatDefCount = CategoryImplementation.size(); if (ClsDefCount == 0 && CatDefCount == 0) return; + + // For each defined class, write out all its meta data. + for (int i = 0; i < ClsDefCount; i++) + WriteObjcClassMetaData(ClassImplementation[i]); + // Write objc_symtab metadata /* struct _objc_symtab |