From: Fariborz Jahanian Date: Tue, 13 Nov 2007 19:21:13 +0000 (+0000) Subject: Order of methods are OK and generated .c file can be compiled. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a3279ddb8b0cdb7444410bc91e2c7419efaedd8;p=clang Order of methods are OK and generated .c file can be compiled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44060 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 37d499df9c..ac1b6d3d01 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -137,7 +137,7 @@ namespace { void SynthesizeIvarOffsetComputation(ObjcImplementationDecl *IDecl, ObjcIvarDecl *ivar, std::string &Result); - void WriteObjcMetaData(std::string &Result); + void RewriteImplementations(std::string &Result); }; } @@ -173,9 +173,6 @@ void RewriteTest::HandleTopLevelDecl(Decl *D) { } else if (ObjcProtocolDecl *PD = dyn_cast(D)) { RewriteProtocolDecl(PD); } - else if (ObjcImplementationDecl *MD = dyn_cast(D)) { - RewriteImplementationDecl(MD); - } // If we have a decl in the main file, see if we should rewrite it. if (SM->getDecomposedFileLoc(Loc).first == MainFileID) return HandleDeclInMainFile(D); @@ -213,7 +210,7 @@ RewriteTest::~RewriteTest() { // Rewrite Objective-c meta data* std::string ResultStr; - WriteObjcMetaData(ResultStr); + RewriteImplementations(ResultStr); // Get the buffer corresponding to MainFileID. If we haven't changed it, then // we are done. @@ -380,6 +377,12 @@ void RewriteTest::RewriteProtocolDecl(ObjcProtocolDecl *PDecl) { void RewriteTest::RewriteObjcMethodDecl(ObjcMethodDecl *OMD, std::string &ResultStr) { + static bool includeObjc = false; + if (!includeObjc) { + ResultStr += "#include \n"; + includeObjc = true; + } + ResultStr += "\nstatic "; ResultStr += OMD->getResultType().getAsString(); ResultStr += "\n_"; @@ -419,6 +422,7 @@ void RewriteTest::RewriteObjcMethodDecl(ObjcMethodDecl *OMD, if (OMD->isInstance()) { QualType selfTy = Context->getObjcInterfaceType(OMD->getClassInterface()); selfTy = Context->getPointerType(selfTy); + ResultStr += "struct "; ResultStr += selfTy.getAsString(); } else @@ -1706,18 +1710,25 @@ void RewriteTest::RewriteObjcClassMetaData(ObjcImplementationDecl *IDecl, Result += "};\n"; } -void RewriteTest::WriteObjcMetaData(std::string &Result) { +/// RewriteImplementations - This routine rewrites all method implementations +/// and emits meta-data. + +void RewriteTest::RewriteImplementations(std::string &Result) { int ClsDefCount = ClassImplementation.size(); int CatDefCount = CategoryImplementation.size(); + if (ClsDefCount == 0 && CatDefCount == 0) return; + // Rewrite implemented methods + for (int i = 0; i < ClsDefCount; i++) + RewriteImplementationDecl(ClassImplementation[i]); // TODO: This is temporary until we decide how to access objc types in a // c program Result += "#include \n"; // This is needed for use of offsetof Result += "#include \n"; - + // For each implemented class, write out all its meta data. for (int i = 0; i < ClsDefCount; i++) RewriteObjcClassMetaData(ClassImplementation[i], Result); @@ -1788,5 +1799,6 @@ void RewriteTest::WriteObjcMetaData(std::string &Result) { Result += "\t" + utostr(OBJC_ABI_VERSION) + ", sizeof(struct _objc_module), \"\", &_OBJC_SYMBOLS\n"; Result += "};\n\n"; + }