[cfe-commits] r43151 - in /cfe/trunk: Driver/RewriteTest.cpp Sema/SemaDecl.cpp include/clang/AST/DeclObjC.h
Fariborz Jahanian
fjahanian at apple.com
Thu Oct 18 15:09:03 PDT 2007
Author: fjahanian
Date: Thu Oct 18 17:09:03 2007
New Revision: 43151
URL: http://llvm.org/viewvc/llvm-project?rev=43151&view=rev
Log:
Patch to rewrite ivar tables metadata for classes defined.
Modified:
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/AST/DeclObjC.h
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=43151&r1=43150&r2=43151&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Thu Oct 18 17:09:03 2007
@@ -45,6 +45,7 @@
void RewriteFunctionBody(Stmt *S);
void RewriteAtEncode(ObjCEncodeExpr *Exp);
+ void WriteObjcClassMetaData(ObjcImplementationDecl *IDecl);
void WriteObjcMetaData();
~RewriteTest();
@@ -119,7 +120,7 @@
if (*CI)
RewriteFunctionBody(*CI);
}
-
+
void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) {
// Create a new string expression.
QualType StrType = Context->getPointerType(Context->CharTy);
@@ -129,11 +130,66 @@
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
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=43151&r1=43150&r2=43151&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Oct 18 17:09:03 2007
@@ -1225,8 +1225,6 @@
}
}
- ObjcImplementationDecl* IMPDecl =
- new ObjcImplementationDecl(AtClassImplLoc, ClassName, SDecl);
if (!IDecl) {
// Legacy case of @implementation with no corresponding @interface.
// Build, chain & install the interface decl into the identifier.
@@ -1238,6 +1236,9 @@
TUScope->AddDecl(IDecl);
}
+ ObjcImplementationDecl* IMPDecl =
+ new ObjcImplementationDecl(AtClassImplLoc, ClassName, IDecl, SDecl);
+
// Check that there is no duplicate implementation of this class.
if (!ObjcImplementations.insert(ClassName))
Diag(ClassLoc, diag::err_dup_implementation_class, ClassName->getName());
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=43151&r1=43150&r2=43151&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Oct 18 17:09:03 2007
@@ -540,7 +540,9 @@
/// from the class interface to the class implementation (but I digress:-)
///
class ObjcImplementationDecl : public NamedDecl {
-
+ /// Class interface for this category implementation
+ ObjcInterfaceDecl *ClassInterface;
+
/// Implementation Class's super class.
ObjcInterfaceDecl *SuperClass;
@@ -558,8 +560,10 @@
public:
ObjcImplementationDecl(SourceLocation L, IdentifierInfo *Id,
- ObjcInterfaceDecl* superDecl)
+ ObjcInterfaceDecl *classInterface,
+ ObjcInterfaceDecl *superDecl)
: NamedDecl(ObjcImplementation, L, Id),
+ ClassInterface(classInterface),
SuperClass(superDecl),
Ivars(0), NumIvars(-1),
InstanceMethods(0), NumInstanceMethods(-1),
@@ -571,6 +575,7 @@
void ObjcAddImplMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers,
ObjcMethodDecl **clsMethods, unsigned numClsMembers);
+ ObjcInterfaceDecl *getClassInterface() const { return ClassInterface; }
ObjcInterfaceDecl *getSuperClass() const { return SuperClass; }
void setSuperClass(ObjcInterfaceDecl * superCls)
@@ -581,6 +586,9 @@
ObjcMethodDecl **getClassMethods() const { return ClassMethods; }
int getNumClassMethods() const { return NumClassMethods; }
+
+ ObjcIvarDecl **getImplDeclIVars() const { return Ivars; }
+ int getImplDeclNumIvars() const { return NumIvars; }
static bool classof(const Decl *D) {
return D->getKind() == ObjcImplementation;
More information about the cfe-commits
mailing list