Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 1 | //===--- RewriteTest.cpp - Playground for the code rewriter ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Hacks and fun related to the code rewriter. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ASTConsumers.h" |
Chris Lattner | 8a12c27 | 2007-10-11 18:38:32 +0000 | [diff] [blame] | 15 | #include "clang/Rewrite/Rewriter.h" |
Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 16 | #include "clang/AST/AST.h" |
| 17 | #include "clang/AST/ASTConsumer.h" |
Chris Lattner | 8a12c27 | 2007-10-11 18:38:32 +0000 | [diff] [blame] | 18 | #include "clang/Basic/SourceManager.h" |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 19 | #include "clang/Basic/IdentifierTable.h" |
Chris Lattner | 158ecb9 | 2007-10-25 17:07:24 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringExtras.h" |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallPtrSet.h" |
Steve Naroff | 2feac5e | 2007-10-30 03:43:13 +0000 | [diff] [blame] | 22 | #include "clang/Lex/Lexer.h" |
Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 23 | using namespace clang; |
Chris Lattner | 158ecb9 | 2007-10-25 17:07:24 +0000 | [diff] [blame] | 24 | using llvm::utostr; |
Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 25 | |
Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 26 | namespace { |
Chris Lattner | 8a12c27 | 2007-10-11 18:38:32 +0000 | [diff] [blame] | 27 | class RewriteTest : public ASTConsumer { |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 28 | Rewriter Rewrite; |
Chris Lattner | 01c5748 | 2007-10-17 22:35:30 +0000 | [diff] [blame] | 29 | ASTContext *Context; |
Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 30 | SourceManager *SM; |
Chris Lattner | 8a12c27 | 2007-10-11 18:38:32 +0000 | [diff] [blame] | 31 | unsigned MainFileID; |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 32 | SourceLocation LastIncLoc; |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 33 | llvm::SmallVector<ObjcImplementationDecl *, 8> ClassImplementation; |
| 34 | llvm::SmallVector<ObjcCategoryImplDecl *, 8> CategoryImplementation; |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 35 | llvm::SmallPtrSet<ObjcInterfaceDecl*, 8> ObjcSynthesizedStructs; |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 36 | |
| 37 | FunctionDecl *MsgSendFunctionDecl; |
| 38 | FunctionDecl *GetClassFunctionDecl; |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 39 | FunctionDecl *SelGetUidFunctionDecl; |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 40 | |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 41 | static const int OBJC_ABI_VERSION =7 ; |
Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 42 | public: |
Chris Lattner | 01c5748 | 2007-10-17 22:35:30 +0000 | [diff] [blame] | 43 | void Initialize(ASTContext &context, unsigned mainFileID) { |
| 44 | Context = &context; |
| 45 | SM = &Context->SourceMgr; |
Chris Lattner | 8a12c27 | 2007-10-11 18:38:32 +0000 | [diff] [blame] | 46 | MainFileID = mainFileID; |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 47 | MsgSendFunctionDecl = 0; |
Steve Naroff | c000609 | 2007-10-24 01:09:48 +0000 | [diff] [blame] | 48 | GetClassFunctionDecl = 0; |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 49 | SelGetUidFunctionDecl = 0; |
Chris Lattner | 01c5748 | 2007-10-17 22:35:30 +0000 | [diff] [blame] | 50 | Rewrite.setSourceMgr(Context->SourceMgr); |
Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 51 | } |
Chris Lattner | 8a12c27 | 2007-10-11 18:38:32 +0000 | [diff] [blame] | 52 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 53 | // Top Level Driver code. |
| 54 | virtual void HandleTopLevelDecl(Decl *D); |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 55 | void HandleDeclInMainFile(Decl *D); |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 56 | ~RewriteTest(); |
| 57 | |
| 58 | // Syntactic Rewriting. |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 59 | void RewriteInclude(SourceLocation Loc); |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 60 | void RewriteTabs(); |
| 61 | void RewriteForwardClassDecl(ObjcClassDecl *Dcl); |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 62 | void RewriteInterfaceDecl(ObjcInterfaceDecl *Dcl); |
Steve Naroff | 423cb56 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 63 | void RewriteCategoryDecl(ObjcCategoryDecl *Dcl); |
Steve Naroff | 752d6ef | 2007-10-30 16:42:30 +0000 | [diff] [blame] | 64 | void RewriteProtocolDecl(ObjcProtocolDecl *Dcl); |
Steve Naroff | 423cb56 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 65 | void RewriteMethods(int nMethods, ObjcMethodDecl **Methods); |
Steve Naroff | 09b266e | 2007-10-30 23:14:51 +0000 | [diff] [blame] | 66 | void RewriteFunctionDecl(FunctionDecl *FD); |
Steve Naroff | 9165ad3 | 2007-10-31 04:38:33 +0000 | [diff] [blame] | 67 | bool functionReferencesAnyObjcQualifiedInterfaceTypes( |
| 68 | const FunctionTypeProto *proto); |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 69 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 70 | // Expression Rewriting. |
Chris Lattner | e64b777 | 2007-10-24 16:57:36 +0000 | [diff] [blame] | 71 | Stmt *RewriteFunctionBody(Stmt *S); |
| 72 | Stmt *RewriteAtEncode(ObjCEncodeExpr *Exp); |
| 73 | Stmt *RewriteMessageExpr(ObjCMessageExpr *Exp); |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 74 | CallExpr *SynthesizeCallToFunctionDecl(FunctionDecl *FD, |
| 75 | Expr **args, unsigned nargs); |
Steve Naroff | 09b266e | 2007-10-30 23:14:51 +0000 | [diff] [blame] | 76 | void SynthMsgSendFunctionDecl(); |
| 77 | void SynthGetClassFunctionDecl(); |
| 78 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 79 | // Metadata emission. |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 80 | void HandleObjcMetaDataEmission(); |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 81 | void RewriteObjcClassMetaData(ObjcImplementationDecl *IDecl, |
| 82 | std::string &Result); |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 83 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 84 | void RewriteObjcCategoryImplDecl(ObjcCategoryImplDecl *CDecl, |
| 85 | std::string &Result); |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 86 | |
| 87 | void RewriteObjcMethodsMetaData(ObjcMethodDecl **Methods, |
| 88 | int NumMethods, |
Fariborz Jahanian | 8e991ba | 2007-10-25 00:14:44 +0000 | [diff] [blame] | 89 | bool IsInstanceMethod, |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 90 | const char *prefix, |
Chris Lattner | 158ecb9 | 2007-10-25 17:07:24 +0000 | [diff] [blame] | 91 | const char *ClassName, |
| 92 | std::string &Result); |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 93 | |
| 94 | void RewriteObjcProtocolsMetaData(ObjcProtocolDecl **Protocols, |
| 95 | int NumProtocols, |
| 96 | const char *prefix, |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 97 | const char *ClassName, |
| 98 | std::string &Result); |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 99 | void SynthesizeObjcInternalStruct(ObjcInterfaceDecl *CDecl, |
| 100 | std::string &Result); |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 101 | void SynthesizeIvarOffsetComputation(ObjcImplementationDecl *IDecl, |
| 102 | ObjcIvarDecl *ivar, |
| 103 | std::string &Result); |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 104 | void WriteObjcMetaData(std::string &Result); |
Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 105 | }; |
| 106 | } |
| 107 | |
Chris Lattner | 8a12c27 | 2007-10-11 18:38:32 +0000 | [diff] [blame] | 108 | ASTConsumer *clang::CreateCodeRewriterTest() { return new RewriteTest(); } |
Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame] | 109 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 110 | //===----------------------------------------------------------------------===// |
| 111 | // Top Level Driver Code |
| 112 | //===----------------------------------------------------------------------===// |
| 113 | |
Chris Lattner | 8a12c27 | 2007-10-11 18:38:32 +0000 | [diff] [blame] | 114 | void RewriteTest::HandleTopLevelDecl(Decl *D) { |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 115 | // Two cases: either the decl could be in the main file, or it could be in a |
| 116 | // #included file. If the former, rewrite it now. If the later, check to see |
| 117 | // if we rewrote the #include/#import. |
| 118 | SourceLocation Loc = D->getLocation(); |
| 119 | Loc = SM->getLogicalLoc(Loc); |
| 120 | |
| 121 | // If this is for a builtin, ignore it. |
| 122 | if (Loc.isInvalid()) return; |
| 123 | |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 124 | // Look for built-in declarations that we need to refer during the rewrite. |
| 125 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
Steve Naroff | 09b266e | 2007-10-30 23:14:51 +0000 | [diff] [blame] | 126 | RewriteFunctionDecl(FD); |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 127 | } else if (ObjcInterfaceDecl *MD = dyn_cast<ObjcInterfaceDecl>(D)) { |
| 128 | RewriteInterfaceDecl(MD); |
Steve Naroff | 423cb56 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 129 | } else if (ObjcCategoryDecl *CD = dyn_cast<ObjcCategoryDecl>(D)) { |
| 130 | RewriteCategoryDecl(CD); |
Steve Naroff | 752d6ef | 2007-10-30 16:42:30 +0000 | [diff] [blame] | 131 | } else if (ObjcProtocolDecl *PD = dyn_cast<ObjcProtocolDecl>(D)) { |
| 132 | RewriteProtocolDecl(PD); |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 133 | } |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 134 | // If we have a decl in the main file, see if we should rewrite it. |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 135 | if (SM->getDecomposedFileLoc(Loc).first == MainFileID) |
| 136 | return HandleDeclInMainFile(D); |
| 137 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 138 | // Otherwise, see if there is a #import in the main file that should be |
| 139 | // rewritten. |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 140 | RewriteInclude(Loc); |
| 141 | } |
| 142 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 143 | /// HandleDeclInMainFile - This is called for each top-level decl defined in the |
| 144 | /// main file of the input. |
| 145 | void RewriteTest::HandleDeclInMainFile(Decl *D) { |
| 146 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 147 | if (Stmt *Body = FD->getBody()) |
| 148 | FD->setBody(RewriteFunctionBody(Body)); |
| 149 | |
| 150 | if (ObjcImplementationDecl *CI = dyn_cast<ObjcImplementationDecl>(D)) |
| 151 | ClassImplementation.push_back(CI); |
| 152 | else if (ObjcCategoryImplDecl *CI = dyn_cast<ObjcCategoryImplDecl>(D)) |
| 153 | CategoryImplementation.push_back(CI); |
| 154 | else if (ObjcClassDecl *CD = dyn_cast<ObjcClassDecl>(D)) |
| 155 | RewriteForwardClassDecl(CD); |
| 156 | // Nothing yet. |
| 157 | } |
| 158 | |
| 159 | RewriteTest::~RewriteTest() { |
| 160 | // Get the top-level buffer that this corresponds to. |
| 161 | RewriteTabs(); |
| 162 | |
| 163 | // Get the buffer corresponding to MainFileID. If we haven't changed it, then |
| 164 | // we are done. |
| 165 | if (const RewriteBuffer *RewriteBuf = |
| 166 | Rewrite.getRewriteBufferFor(MainFileID)) { |
| 167 | printf("Changed:\n"); |
| 168 | std::string S(RewriteBuf->begin(), RewriteBuf->end()); |
| 169 | printf("%s\n", S.c_str()); |
| 170 | } else { |
| 171 | printf("No changes\n"); |
| 172 | } |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 173 | |
| 174 | } |
| 175 | |
| 176 | /// HandleObjcMetaDataEmission - main routine to generate objective-c's |
| 177 | /// metadata. |
| 178 | void RewriteTest::HandleObjcMetaDataEmission() { |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 179 | // Rewrite Objective-c meta data* |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 180 | std::string ResultStr; |
| 181 | WriteObjcMetaData(ResultStr); |
| 182 | // For now just print the string out. |
| 183 | printf("%s", ResultStr.c_str()); |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | //===----------------------------------------------------------------------===// |
| 187 | // Syntactic (non-AST) Rewriting Code |
| 188 | //===----------------------------------------------------------------------===// |
| 189 | |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 190 | void RewriteTest::RewriteInclude(SourceLocation Loc) { |
| 191 | // Rip up the #include stack to the main file. |
| 192 | SourceLocation IncLoc = Loc, NextLoc = Loc; |
| 193 | do { |
| 194 | IncLoc = Loc; |
| 195 | Loc = SM->getLogicalLoc(NextLoc); |
| 196 | NextLoc = SM->getIncludeLoc(Loc); |
| 197 | } while (!NextLoc.isInvalid()); |
| 198 | |
| 199 | // Loc is now the location of the #include filename "foo" or <foo/bar.h>. |
| 200 | // IncLoc indicates the header that was included if it is useful. |
| 201 | IncLoc = SM->getLogicalLoc(IncLoc); |
| 202 | if (SM->getDecomposedFileLoc(Loc).first != MainFileID || |
| 203 | Loc == LastIncLoc) |
| 204 | return; |
| 205 | LastIncLoc = Loc; |
| 206 | |
| 207 | unsigned IncCol = SM->getColumnNumber(Loc); |
| 208 | SourceLocation LineStartLoc = Loc.getFileLocWithOffset(-IncCol+1); |
| 209 | |
| 210 | // Replace the #import with #include. |
| 211 | Rewrite.ReplaceText(LineStartLoc, IncCol-1, "#include ", strlen("#include ")); |
| 212 | } |
| 213 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 214 | void RewriteTest::RewriteTabs() { |
| 215 | std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID); |
| 216 | const char *MainBufStart = MainBuf.first; |
| 217 | const char *MainBufEnd = MainBuf.second; |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 218 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 219 | // Loop over the whole file, looking for tabs. |
| 220 | for (const char *BufPtr = MainBufStart; BufPtr != MainBufEnd; ++BufPtr) { |
| 221 | if (*BufPtr != '\t') |
| 222 | continue; |
| 223 | |
| 224 | // Okay, we found a tab. This tab will turn into at least one character, |
| 225 | // but it depends on which 'virtual column' it is in. Compute that now. |
| 226 | unsigned VCol = 0; |
| 227 | while (BufPtr-VCol != MainBufStart && BufPtr[-VCol-1] != '\t' && |
| 228 | BufPtr[-VCol-1] != '\n' && BufPtr[-VCol-1] != '\r') |
| 229 | ++VCol; |
| 230 | |
| 231 | // Okay, now that we know the virtual column, we know how many spaces to |
| 232 | // insert. We assume 8-character tab-stops. |
| 233 | unsigned Spaces = 8-(VCol & 7); |
| 234 | |
| 235 | // Get the location of the tab. |
| 236 | SourceLocation TabLoc = |
| 237 | SourceLocation::getFileLoc(MainFileID, BufPtr-MainBufStart); |
| 238 | |
| 239 | // Rewrite the single tab character into a sequence of spaces. |
| 240 | Rewrite.ReplaceText(TabLoc, 1, " ", Spaces); |
| 241 | } |
Chris Lattner | 8a12c27 | 2007-10-11 18:38:32 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 245 | void RewriteTest::RewriteForwardClassDecl(ObjcClassDecl *ClassDecl) { |
| 246 | int numDecls = ClassDecl->getNumForwardDecls(); |
| 247 | ObjcInterfaceDecl **ForwardDecls = ClassDecl->getForwardDecls(); |
| 248 | |
| 249 | // Get the start location and compute the semi location. |
| 250 | SourceLocation startLoc = ClassDecl->getLocation(); |
| 251 | const char *startBuf = SM->getCharacterData(startLoc); |
| 252 | const char *semiPtr = strchr(startBuf, ';'); |
| 253 | |
| 254 | // Translate to typedef's that forward reference structs with the same name |
| 255 | // as the class. As a convenience, we include the original declaration |
| 256 | // as a comment. |
| 257 | std::string typedefString; |
| 258 | typedefString += "// "; |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 259 | typedefString.append(startBuf, semiPtr-startBuf+1); |
| 260 | typedefString += "\n"; |
| 261 | for (int i = 0; i < numDecls; i++) { |
| 262 | ObjcInterfaceDecl *ForwardDecl = ForwardDecls[i]; |
| 263 | typedefString += "typedef struct "; |
| 264 | typedefString += ForwardDecl->getName(); |
| 265 | typedefString += " "; |
| 266 | typedefString += ForwardDecl->getName(); |
| 267 | typedefString += ";\n"; |
| 268 | } |
| 269 | |
| 270 | // Replace the @class with typedefs corresponding to the classes. |
| 271 | Rewrite.ReplaceText(startLoc, semiPtr-startBuf+1, |
| 272 | typedefString.c_str(), typedefString.size()); |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Steve Naroff | 423cb56 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 275 | void RewriteTest::RewriteMethods(int nMethods, ObjcMethodDecl **Methods) { |
| 276 | for (int i = 0; i < nMethods; i++) { |
| 277 | ObjcMethodDecl *Method = Methods[i]; |
| 278 | SourceLocation Loc = Method->getLocStart(); |
| 279 | |
| 280 | Rewrite.ReplaceText(Loc, 0, "// ", 3); |
| 281 | |
| 282 | // FIXME: handle methods that are declared across multiple lines. |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void RewriteTest::RewriteCategoryDecl(ObjcCategoryDecl *CatDecl) { |
| 287 | SourceLocation LocStart = CatDecl->getLocStart(); |
| 288 | |
| 289 | // FIXME: handle category headers that are declared across multiple lines. |
| 290 | Rewrite.ReplaceText(LocStart, 0, "// ", 3); |
| 291 | |
| 292 | RewriteMethods(CatDecl->getNumInstanceMethods(), |
| 293 | CatDecl->getInstanceMethods()); |
| 294 | RewriteMethods(CatDecl->getNumClassMethods(), |
| 295 | CatDecl->getClassMethods()); |
| 296 | // Lastly, comment out the @end. |
| 297 | Rewrite.ReplaceText(CatDecl->getAtEndLoc(), 0, "// ", 3); |
| 298 | } |
| 299 | |
Steve Naroff | 752d6ef | 2007-10-30 16:42:30 +0000 | [diff] [blame] | 300 | void RewriteTest::RewriteProtocolDecl(ObjcProtocolDecl *PDecl) { |
| 301 | SourceLocation LocStart = PDecl->getLocStart(); |
| 302 | |
| 303 | // FIXME: handle protocol headers that are declared across multiple lines. |
| 304 | Rewrite.ReplaceText(LocStart, 0, "// ", 3); |
| 305 | |
| 306 | RewriteMethods(PDecl->getNumInstanceMethods(), |
| 307 | PDecl->getInstanceMethods()); |
| 308 | RewriteMethods(PDecl->getNumClassMethods(), |
| 309 | PDecl->getClassMethods()); |
| 310 | // Lastly, comment out the @end. |
| 311 | Rewrite.ReplaceText(PDecl->getAtEndLoc(), 0, "// ", 3); |
| 312 | } |
| 313 | |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 314 | void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) { |
Steve Naroff | f908a87 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 315 | |
| 316 | SourceLocation LocStart = ClassDecl->getLocStart(); |
| 317 | SourceLocation LocEnd = ClassDecl->getLocEnd(); |
| 318 | |
| 319 | const char *startBuf = SM->getCharacterData(LocStart); |
| 320 | const char *endBuf = SM->getCharacterData(LocEnd); |
| 321 | |
Steve Naroff | 2feac5e | 2007-10-30 03:43:13 +0000 | [diff] [blame] | 322 | endBuf += Lexer::MeasureTokenLength(LocEnd, *SM); |
Steve Naroff | f908a87 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 323 | |
| 324 | std::string ResultStr; |
| 325 | SynthesizeObjcInternalStruct(ClassDecl, ResultStr); |
| 326 | |
Steve Naroff | 2feac5e | 2007-10-30 03:43:13 +0000 | [diff] [blame] | 327 | Rewrite.ReplaceText(LocStart, endBuf-startBuf, |
Steve Naroff | f908a87 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 328 | ResultStr.c_str(), ResultStr.size()); |
| 329 | |
Steve Naroff | 423cb56 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 330 | RewriteMethods(ClassDecl->getNumInstanceMethods(), |
| 331 | ClassDecl->getInstanceMethods()); |
| 332 | RewriteMethods(ClassDecl->getNumClassMethods(), |
| 333 | ClassDecl->getClassMethods()); |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 334 | |
Steve Naroff | 2feac5e | 2007-10-30 03:43:13 +0000 | [diff] [blame] | 335 | // Lastly, comment out the @end. |
| 336 | Rewrite.ReplaceText(ClassDecl->getAtEndLoc(), 0, "// ", 3); |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 339 | //===----------------------------------------------------------------------===// |
| 340 | // Function Body / Expression rewriting |
| 341 | //===----------------------------------------------------------------------===// |
| 342 | |
Chris Lattner | e64b777 | 2007-10-24 16:57:36 +0000 | [diff] [blame] | 343 | Stmt *RewriteTest::RewriteFunctionBody(Stmt *S) { |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 344 | // Otherwise, just rewrite all children. |
| 345 | for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end(); |
| 346 | CI != E; ++CI) |
Chris Lattner | 5075477 | 2007-10-17 21:28:00 +0000 | [diff] [blame] | 347 | if (*CI) |
Chris Lattner | e64b777 | 2007-10-24 16:57:36 +0000 | [diff] [blame] | 348 | *CI = RewriteFunctionBody(*CI); |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 349 | |
| 350 | // Handle specific things. |
| 351 | if (ObjCEncodeExpr *AtEncode = dyn_cast<ObjCEncodeExpr>(S)) |
| 352 | return RewriteAtEncode(AtEncode); |
| 353 | |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 354 | if (ObjCMessageExpr *MessExpr = dyn_cast<ObjCMessageExpr>(S)) { |
| 355 | // Before we rewrite it, put the original message expression in a comment. |
| 356 | SourceLocation startLoc = MessExpr->getLocStart(); |
| 357 | SourceLocation endLoc = MessExpr->getLocEnd(); |
| 358 | |
| 359 | const char *startBuf = SM->getCharacterData(startLoc); |
| 360 | const char *endBuf = SM->getCharacterData(endLoc); |
| 361 | |
| 362 | std::string messString; |
| 363 | messString += "// "; |
| 364 | messString.append(startBuf, endBuf-startBuf+1); |
| 365 | messString += "\n"; |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 366 | |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 367 | // FIXME: Missing definition of Rewrite.InsertText(clang::SourceLocation, char const*, unsigned int). |
| 368 | // Rewrite.InsertText(startLoc, messString.c_str(), messString.size()); |
| 369 | // Tried this, but it didn't work either... |
Steve Naroff | 752d6ef | 2007-10-30 16:42:30 +0000 | [diff] [blame] | 370 | // Rewrite.ReplaceText(startLoc, 0, messString.c_str(), messString.size()); |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 371 | return RewriteMessageExpr(MessExpr); |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 372 | } |
Chris Lattner | e64b777 | 2007-10-24 16:57:36 +0000 | [diff] [blame] | 373 | // Return this stmt unmodified. |
| 374 | return S; |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 375 | } |
Fariborz Jahanian | f4d331d | 2007-10-18 22:09:03 +0000 | [diff] [blame] | 376 | |
Chris Lattner | e64b777 | 2007-10-24 16:57:36 +0000 | [diff] [blame] | 377 | Stmt *RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) { |
Chris Lattner | 01c5748 | 2007-10-17 22:35:30 +0000 | [diff] [blame] | 378 | // Create a new string expression. |
| 379 | QualType StrType = Context->getPointerType(Context->CharTy); |
Anders Carlsson | 85f9bce | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 380 | std::string StrEncoding; |
| 381 | Context->getObjcEncodingForType(Exp->getEncodedType(), StrEncoding); |
| 382 | Expr *Replacement = new StringLiteral(StrEncoding.c_str(), |
| 383 | StrEncoding.length(), false, StrType, |
Chris Lattner | 01c5748 | 2007-10-17 22:35:30 +0000 | [diff] [blame] | 384 | SourceLocation(), SourceLocation()); |
| 385 | Rewrite.ReplaceStmt(Exp, Replacement); |
Chris Lattner | e64b777 | 2007-10-24 16:57:36 +0000 | [diff] [blame] | 386 | delete Exp; |
| 387 | return Replacement; |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 390 | CallExpr *RewriteTest::SynthesizeCallToFunctionDecl( |
| 391 | FunctionDecl *FD, Expr **args, unsigned nargs) { |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 392 | // Get the type, we will need to reference it in a couple spots. |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 393 | QualType msgSendType = FD->getType(); |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 394 | |
| 395 | // Create a reference to the objc_msgSend() declaration. |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 396 | DeclRefExpr *DRE = new DeclRefExpr(FD, msgSendType, SourceLocation()); |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 397 | |
| 398 | // Now, we cast the reference to a pointer to the objc_msgSend type. |
Chris Lattner | f04da13 | 2007-10-24 17:06:59 +0000 | [diff] [blame] | 399 | QualType pToFunc = Context->getPointerType(msgSendType); |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 400 | ImplicitCastExpr *ICE = new ImplicitCastExpr(pToFunc, DRE); |
| 401 | |
| 402 | const FunctionType *FT = msgSendType->getAsFunctionType(); |
Chris Lattner | e64b777 | 2007-10-24 16:57:36 +0000 | [diff] [blame] | 403 | |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 404 | return new CallExpr(ICE, args, nargs, FT->getResultType(), SourceLocation()); |
| 405 | } |
| 406 | |
Steve Naroff | 9165ad3 | 2007-10-31 04:38:33 +0000 | [diff] [blame] | 407 | bool RewriteTest::functionReferencesAnyObjcQualifiedInterfaceTypes( |
| 408 | const FunctionTypeProto *proto) { |
Steve Naroff | 498856c | 2007-10-31 16:03:04 +0000 | [diff] [blame] | 409 | QualType resultType = proto->getResultType(); |
| 410 | |
| 411 | if (resultType == Context->getObjcIdType()) { |
| 412 | // FIXME: we don't currently represent "id <Protocol>" in the type system. |
| 413 | // Implement a heuristic here (until we do). |
| 414 | } else if (const PointerType *pType = resultType->getAsPointerType()) { |
Steve Naroff | 9165ad3 | 2007-10-31 04:38:33 +0000 | [diff] [blame] | 415 | Type *pointeeType = pType->getPointeeType().getTypePtr(); |
| 416 | if (isa<ObjcQualifiedInterfaceType>(pointeeType)) |
| 417 | return true; // we have "Class <Protocol> *". |
| 418 | } |
| 419 | // Now check arguments. |
| 420 | for (unsigned i = 0; i < proto->getNumArgs(); i++) { |
Steve Naroff | 498856c | 2007-10-31 16:03:04 +0000 | [diff] [blame] | 421 | QualType argType = proto->getArgType(i); |
| 422 | if (argType == Context->getObjcIdType()) { |
| 423 | // FIXME: we don't currently represent "id <Protocol>" in the type system. |
| 424 | // Implement a heuristic here (until we do). |
| 425 | } else if (const PointerType *pType = argType->getAsPointerType()) { |
Steve Naroff | 9165ad3 | 2007-10-31 04:38:33 +0000 | [diff] [blame] | 426 | Type *pointeeType = pType->getPointeeType().getTypePtr(); |
| 427 | if (isa<ObjcQualifiedInterfaceType>(pointeeType)) |
| 428 | return true; |
| 429 | } |
| 430 | } |
Steve Naroff | 9165ad3 | 2007-10-31 04:38:33 +0000 | [diff] [blame] | 431 | return false; |
| 432 | } |
| 433 | |
Steve Naroff | 09b266e | 2007-10-30 23:14:51 +0000 | [diff] [blame] | 434 | void RewriteTest::RewriteFunctionDecl(FunctionDecl *FD) { |
| 435 | // declared in <objc/objc.h> |
Steve Naroff | 9165ad3 | 2007-10-31 04:38:33 +0000 | [diff] [blame] | 436 | if (strcmp(FD->getName(), "sel_getUid") == 0) { |
Steve Naroff | 09b266e | 2007-10-30 23:14:51 +0000 | [diff] [blame] | 437 | SelGetUidFunctionDecl = FD; |
Steve Naroff | 9165ad3 | 2007-10-31 04:38:33 +0000 | [diff] [blame] | 438 | return; |
| 439 | } |
Steve Naroff | 498856c | 2007-10-31 16:03:04 +0000 | [diff] [blame] | 440 | return; // FIXME: remove when the code below is ready. |
Steve Naroff | 9165ad3 | 2007-10-31 04:38:33 +0000 | [diff] [blame] | 441 | // Check for ObjC 'id' and class types that have been adorned with protocol |
| 442 | // information (id<p>, C<p>*). The protocol references need to be rewritten! |
| 443 | const FunctionType *funcType = FD->getType()->getAsFunctionType(); |
| 444 | assert(funcType && "missing function type"); |
| 445 | const FunctionTypeProto *proto = dyn_cast<FunctionTypeProto>(funcType); |
| 446 | if (proto && functionReferencesAnyObjcQualifiedInterfaceTypes(proto)) { |
| 447 | // FIXME: Rewrite function decl... |
| 448 | } |
Steve Naroff | 09b266e | 2007-10-30 23:14:51 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | // SynthMsgSendFunctionDecl - id objc_msgSend(id self, SEL op, ...); |
| 452 | void RewriteTest::SynthMsgSendFunctionDecl() { |
| 453 | IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSend"); |
| 454 | llvm::SmallVector<QualType, 16> ArgTys; |
| 455 | QualType argT = Context->getObjcIdType(); |
| 456 | assert(!argT.isNull() && "Can't find 'id' type"); |
| 457 | ArgTys.push_back(argT); |
| 458 | argT = Context->getObjcSelType(); |
| 459 | assert(!argT.isNull() && "Can't find 'SEL' type"); |
| 460 | ArgTys.push_back(argT); |
| 461 | QualType msgSendType = Context->getFunctionType(Context->getObjcIdType(), |
| 462 | &ArgTys[0], ArgTys.size(), |
| 463 | true /*isVariadic*/); |
| 464 | MsgSendFunctionDecl = new FunctionDecl(SourceLocation(), |
| 465 | msgSendIdent, msgSendType, |
| 466 | FunctionDecl::Extern, false, 0); |
| 467 | } |
| 468 | |
| 469 | // SynthGetClassFunctionDecl - id objc_getClass(const char *name); |
| 470 | void RewriteTest::SynthGetClassFunctionDecl() { |
| 471 | IdentifierInfo *getClassIdent = &Context->Idents.get("objc_getClass"); |
| 472 | llvm::SmallVector<QualType, 16> ArgTys; |
| 473 | ArgTys.push_back(Context->getPointerType( |
| 474 | Context->CharTy.getQualifiedType(QualType::Const))); |
| 475 | QualType getClassType = Context->getFunctionType(Context->getObjcIdType(), |
| 476 | &ArgTys[0], ArgTys.size(), |
| 477 | false /*isVariadic*/); |
| 478 | GetClassFunctionDecl = new FunctionDecl(SourceLocation(), |
| 479 | getClassIdent, getClassType, |
| 480 | FunctionDecl::Extern, false, 0); |
| 481 | } |
| 482 | |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 483 | Stmt *RewriteTest::RewriteMessageExpr(ObjCMessageExpr *Exp) { |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 484 | assert(SelGetUidFunctionDecl && "Can't find sel_getUid() decl"); |
Steve Naroff | 09b266e | 2007-10-30 23:14:51 +0000 | [diff] [blame] | 485 | if (!MsgSendFunctionDecl) |
| 486 | SynthMsgSendFunctionDecl(); |
| 487 | if (!GetClassFunctionDecl) |
| 488 | SynthGetClassFunctionDecl(); |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 489 | |
| 490 | // Synthesize a call to objc_msgSend(). |
| 491 | llvm::SmallVector<Expr*, 8> MsgExprs; |
| 492 | IdentifierInfo *clsName = Exp->getClassName(); |
| 493 | |
| 494 | // Derive/push the receiver/selector, 2 implicit arguments to objc_msgSend(). |
| 495 | if (clsName) { // class message. |
| 496 | llvm::SmallVector<Expr*, 8> ClsExprs; |
| 497 | QualType argType = Context->getPointerType(Context->CharTy); |
| 498 | ClsExprs.push_back(new StringLiteral(clsName->getName(), |
| 499 | clsName->getLength(), |
| 500 | false, argType, SourceLocation(), |
| 501 | SourceLocation())); |
| 502 | CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl, |
| 503 | &ClsExprs[0], ClsExprs.size()); |
| 504 | MsgExprs.push_back(Cls); |
| 505 | } else // instance message. |
| 506 | MsgExprs.push_back(Exp->getReceiver()); |
| 507 | |
| 508 | // Create a call to sel_getUid("selName"), it will be the 2nd argument. |
| 509 | llvm::SmallVector<Expr*, 8> SelExprs; |
| 510 | QualType argType = Context->getPointerType(Context->CharTy); |
| 511 | SelExprs.push_back(new StringLiteral(Exp->getSelector().getName().c_str(), |
| 512 | Exp->getSelector().getName().size(), |
| 513 | false, argType, SourceLocation(), |
| 514 | SourceLocation())); |
| 515 | CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, |
| 516 | &SelExprs[0], SelExprs.size()); |
| 517 | MsgExprs.push_back(SelExp); |
| 518 | |
| 519 | // Now push any user supplied arguments. |
| 520 | for (unsigned i = 0; i < Exp->getNumArgs(); i++) { |
| 521 | MsgExprs.push_back(Exp->getArg(i)); |
| 522 | // We've transferred the ownership to MsgExprs. Null out the argument in |
| 523 | // the original expression, since we will delete it below. |
| 524 | Exp->setArg(i, 0); |
| 525 | } |
| 526 | CallExpr *MessExp = SynthesizeCallToFunctionDecl(MsgSendFunctionDecl, |
| 527 | &MsgExprs[0], MsgExprs.size()); |
| 528 | // Now do the actual rewrite. |
| 529 | Rewrite.ReplaceStmt(Exp, MessExp); |
| 530 | |
Chris Lattner | e64b777 | 2007-10-24 16:57:36 +0000 | [diff] [blame] | 531 | delete Exp; |
Steve Naroff | 934f276 | 2007-10-24 22:48:43 +0000 | [diff] [blame] | 532 | return MessExp; |
Steve Naroff | ebf2b56 | 2007-10-23 23:50:29 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 535 | /// SynthesizeObjcInternalStruct - Rewrite one internal struct corresponding to |
| 536 | /// an objective-c class with ivars. |
| 537 | void RewriteTest::SynthesizeObjcInternalStruct(ObjcInterfaceDecl *CDecl, |
| 538 | std::string &Result) { |
| 539 | assert(CDecl && "Class missing in SynthesizeObjcInternalStruct"); |
| 540 | assert(CDecl->getName() && "Name missing in SynthesizeObjcInternalStruct"); |
| 541 | ObjcInterfaceDecl *RCDecl = CDecl->getSuperClass(); |
| 542 | if (RCDecl && !ObjcSynthesizedStructs.count(RCDecl)) { |
| 543 | // Do it for the root |
| 544 | SynthesizeObjcInternalStruct(RCDecl, Result); |
| 545 | } |
| 546 | |
| 547 | int NumIvars = CDecl->getIntfDeclNumIvars(); |
| 548 | if (NumIvars <= 0 && (!RCDecl || !ObjcSynthesizedStructs.count(RCDecl))) |
| 549 | return; |
| 550 | |
| 551 | Result += "\nstruct _interface_"; |
| 552 | Result += CDecl->getName(); |
| 553 | Result += " {\n"; |
| 554 | if (RCDecl && ObjcSynthesizedStructs.count(RCDecl)) { |
| 555 | Result += "\tstruct _interface_"; |
| 556 | Result += RCDecl->getName(); |
| 557 | Result += " _"; |
| 558 | Result += RCDecl->getName(); |
| 559 | Result += ";\n"; |
| 560 | } |
| 561 | |
| 562 | ObjcIvarDecl **Ivars = CDecl->getIntfDeclIvars(); |
| 563 | for (int i = 0; i < NumIvars; i++) { |
| 564 | Result += "\t"; |
| 565 | std::string Name = Ivars[i]->getName(); |
| 566 | Ivars[i]->getType().getAsStringInternal(Name); |
| 567 | Result += Name; |
| 568 | Result += ";\n"; |
| 569 | } |
| 570 | Result += "};\n"; |
| 571 | // Mark this struct as having been generated. |
| 572 | if (!ObjcSynthesizedStructs.insert(CDecl)) |
| 573 | assert(true && "struct already synthesize- SynthesizeObjcInternalStruct"); |
| 574 | } |
| 575 | |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 576 | // RewriteObjcMethodsMetaData - Rewrite methods metadata for instance or |
| 577 | /// class methods. |
| 578 | void RewriteTest::RewriteObjcMethodsMetaData(ObjcMethodDecl **Methods, |
| 579 | int NumMethods, |
Fariborz Jahanian | 8e991ba | 2007-10-25 00:14:44 +0000 | [diff] [blame] | 580 | bool IsInstanceMethod, |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 581 | const char *prefix, |
Chris Lattner | 158ecb9 | 2007-10-25 17:07:24 +0000 | [diff] [blame] | 582 | const char *ClassName, |
| 583 | std::string &Result) { |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 584 | static bool objc_impl_method = false; |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 585 | if (NumMethods > 0 && !objc_impl_method) { |
| 586 | /* struct _objc_method { |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 587 | SEL _cmd; |
| 588 | char *method_types; |
| 589 | void *_imp; |
| 590 | } |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 591 | */ |
Chris Lattner | 158ecb9 | 2007-10-25 17:07:24 +0000 | [diff] [blame] | 592 | Result += "\nstruct _objc_method {\n"; |
| 593 | Result += "\tSEL _cmd;\n"; |
| 594 | Result += "\tchar *method_types;\n"; |
| 595 | Result += "\tvoid *_imp;\n"; |
| 596 | Result += "};\n"; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 597 | |
| 598 | /* struct _objc_method_list { |
| 599 | struct _objc_method_list *next_method; |
| 600 | int method_count; |
| 601 | struct _objc_method method_list[]; |
| 602 | } |
| 603 | */ |
| 604 | Result += "\nstruct _objc_method_list {\n"; |
| 605 | Result += "\tstruct _objc_method_list *next_method;\n"; |
| 606 | Result += "\tint method_count;\n"; |
| 607 | Result += "\tstruct _objc_method method_list[];\n};\n"; |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 608 | objc_impl_method = true; |
Fariborz Jahanian | 776d6ff | 2007-10-19 00:36:46 +0000 | [diff] [blame] | 609 | } |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 610 | // Build _objc_method_list for class's methods if needed |
| 611 | if (NumMethods > 0) { |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 612 | Result += "\nstatic struct _objc_method_list _OBJC_"; |
Chris Lattner | 158ecb9 | 2007-10-25 17:07:24 +0000 | [diff] [blame] | 613 | Result += prefix; |
| 614 | Result += IsInstanceMethod ? "INSTANCE" : "CLASS"; |
| 615 | Result += "_METHODS_"; |
| 616 | Result += ClassName; |
| 617 | Result += " __attribute__ ((section (\"__OBJC, __"; |
| 618 | Result += IsInstanceMethod ? "inst" : "cls"; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 619 | Result += "_meth\")))= "; |
| 620 | Result += "{\n\t0, " + utostr(NumMethods) + "\n"; |
| 621 | |
| 622 | Result += "\t,{{(SEL)\""; |
| 623 | Result += Methods[0]->getSelector().getName().c_str(); |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 624 | std::string MethodTypeString; |
| 625 | Context->getObjcEncodingForMethodDecl(Methods[0], MethodTypeString); |
| 626 | Result += "\", \""; |
| 627 | Result += MethodTypeString; |
| 628 | Result += "\", 0}\n"; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 629 | for (int i = 1; i < NumMethods; i++) { |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 630 | // TODO: Need method address as 3rd initializer. |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 631 | Result += "\t ,{(SEL)\""; |
| 632 | Result += Methods[i]->getSelector().getName().c_str(); |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 633 | std::string MethodTypeString; |
| 634 | Context->getObjcEncodingForMethodDecl(Methods[i], MethodTypeString); |
| 635 | Result += "\", \""; |
| 636 | Result += MethodTypeString; |
| 637 | Result += "\", 0}\n"; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 638 | } |
| 639 | Result += "\t }\n};\n"; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 640 | } |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /// RewriteObjcProtocolsMetaData - Rewrite protocols meta-data. |
| 644 | void RewriteTest::RewriteObjcProtocolsMetaData(ObjcProtocolDecl **Protocols, |
| 645 | int NumProtocols, |
| 646 | const char *prefix, |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 647 | const char *ClassName, |
| 648 | std::string &Result) { |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 649 | static bool objc_protocol_methods = false; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 650 | if (NumProtocols > 0) { |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 651 | for (int i = 0; i < NumProtocols; i++) { |
| 652 | ObjcProtocolDecl *PDecl = Protocols[i]; |
| 653 | // Output struct protocol_methods holder of method selector and type. |
| 654 | if (!objc_protocol_methods && |
| 655 | (PDecl->getNumInstanceMethods() > 0 |
| 656 | || PDecl->getNumClassMethods() > 0)) { |
| 657 | /* struct protocol_methods { |
| 658 | SEL _cmd; |
| 659 | char *method_types; |
| 660 | } |
| 661 | */ |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 662 | Result += "\nstruct protocol_methods {\n"; |
| 663 | Result += "\tSEL _cmd;\n"; |
| 664 | Result += "\tchar *method_types;\n"; |
| 665 | Result += "};\n"; |
| 666 | |
| 667 | /* struct _objc_protocol_method_list { |
| 668 | int protocol_method_count; |
| 669 | struct protocol_methods protocols[]; |
| 670 | } |
| 671 | */ |
| 672 | Result += "\nstruct _objc_protocol_method_list {\n"; |
| 673 | Result += "\tint protocol_method_count;\n"; |
| 674 | Result += "\tstruct protocol_methods protocols[];\n};\n"; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 675 | objc_protocol_methods = true; |
| 676 | } |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 677 | |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 678 | // Output instance methods declared in this protocol. |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 679 | int NumMethods = PDecl->getNumInstanceMethods(); |
| 680 | if (NumMethods > 0) { |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 681 | Result += "\nstatic struct _objc_protocol_method_list " |
| 682 | "_OBJC_PROTOCOL_INSTANCE_METHODS_"; |
| 683 | Result += PDecl->getName(); |
| 684 | Result += " __attribute__ ((section (\"__OBJC, __cat_inst_meth\")))= " |
| 685 | "{\n\t" + utostr(NumMethods) + "\n"; |
| 686 | |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 687 | ObjcMethodDecl **Methods = PDecl->getInstanceMethods(); |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 688 | Result += "\t,{{(SEL)\""; |
| 689 | Result += Methods[0]->getSelector().getName().c_str(); |
| 690 | Result += "\", \"\"}\n"; |
| 691 | |
| 692 | for (int i = 1; i < NumMethods; i++) { |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 693 | Result += "\t ,{(SEL)\""; |
| 694 | Result += Methods[i]->getSelector().getName().c_str(); |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 695 | std::string MethodTypeString; |
| 696 | Context->getObjcEncodingForMethodDecl(Methods[i], MethodTypeString); |
| 697 | Result += "\", \""; |
| 698 | Result += MethodTypeString; |
| 699 | Result += "\"}\n"; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 700 | } |
| 701 | Result += "\t }\n};\n"; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | // Output class methods declared in this protocol. |
| 705 | NumMethods = PDecl->getNumClassMethods(); |
| 706 | if (NumMethods > 0) { |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 707 | Result += "\nstatic struct _objc_protocol_method_list " |
| 708 | "_OBJC_PROTOCOL_CLASS_METHODS_"; |
| 709 | Result += PDecl->getName(); |
| 710 | Result += " __attribute__ ((section (\"__OBJC, __cat_cls_meth\")))= " |
| 711 | "{\n\t"; |
| 712 | Result += utostr(NumMethods); |
| 713 | Result += "\n"; |
| 714 | |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 715 | ObjcMethodDecl **Methods = PDecl->getClassMethods(); |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 716 | Result += "\t,{{(SEL)\""; |
| 717 | Result += Methods[0]->getSelector().getName().c_str(); |
| 718 | Result += "\", \"\"}\n"; |
| 719 | |
| 720 | for (int i = 1; i < NumMethods; i++) { |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 721 | Result += "\t ,{(SEL)\""; |
| 722 | Result += Methods[i]->getSelector().getName().c_str(); |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 723 | std::string MethodTypeString; |
| 724 | Context->getObjcEncodingForMethodDecl(Methods[i], MethodTypeString); |
| 725 | Result += "\", \""; |
| 726 | Result += MethodTypeString; |
| 727 | Result += "\"}\n"; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 728 | } |
| 729 | Result += "\t }\n};\n"; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 730 | } |
| 731 | // Output: |
| 732 | /* struct _objc_protocol { |
| 733 | // Objective-C 1.0 extensions |
| 734 | struct _objc_protocol_extension *isa; |
| 735 | char *protocol_name; |
| 736 | struct _objc_protocol **protocol_list; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 737 | struct _objc_protocol_method_list *instance_methods; |
| 738 | struct _objc_protocol_method_list *class_methods; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 739 | }; |
| 740 | */ |
| 741 | static bool objc_protocol = false; |
| 742 | if (!objc_protocol) { |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 743 | Result += "\nstruct _objc_protocol {\n"; |
| 744 | Result += "\tstruct _objc_protocol_extension *isa;\n"; |
| 745 | Result += "\tchar *protocol_name;\n"; |
| 746 | Result += "\tstruct _objc_protocol **protocol_list;\n"; |
| 747 | Result += "\tstruct _objc_protocol_method_list *instance_methods;\n"; |
| 748 | Result += "\tstruct _objc_protocol_method_list *class_methods;\n"; |
| 749 | Result += "};\n"; |
| 750 | |
| 751 | /* struct _objc_protocol_list { |
| 752 | struct _objc_protocol_list *next; |
| 753 | int protocol_count; |
| 754 | struct _objc_protocol *class_protocols[]; |
| 755 | } |
| 756 | */ |
| 757 | Result += "\nstruct _objc_protocol_list {\n"; |
| 758 | Result += "\tstruct _objc_protocol_list *next;\n"; |
| 759 | Result += "\tint protocol_count;\n"; |
| 760 | Result += "\tstruct _objc_protocol *class_protocols[];\n"; |
| 761 | Result += "};\n"; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 762 | objc_protocol = true; |
| 763 | } |
| 764 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 765 | Result += "\nstatic struct _objc_protocol _OBJC_PROTOCOL_"; |
| 766 | Result += PDecl->getName(); |
| 767 | Result += " __attribute__ ((section (\"__OBJC, __protocol\")))= " |
| 768 | "{\n\t0, \""; |
| 769 | Result += PDecl->getName(); |
| 770 | Result += "\", 0, "; |
| 771 | if (PDecl->getInstanceMethods() > 0) { |
| 772 | Result += "&_OBJC_PROTOCOL_INSTANCE_METHODS_"; |
| 773 | Result += PDecl->getName(); |
| 774 | Result += ", "; |
| 775 | } |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 776 | else |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 777 | Result += "0, "; |
| 778 | if (PDecl->getClassMethods() > 0) { |
| 779 | Result += "&_OBJC_PROTOCOL_CLASS_METHODS_"; |
| 780 | Result += PDecl->getName(); |
| 781 | Result += "\n"; |
| 782 | } |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 783 | else |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 784 | Result += "0\n"; |
| 785 | Result += "};\n"; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 786 | } |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 787 | // Output the top lovel protocol meta-data for the class. |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 788 | Result += "\nstatic struct _objc_protocol_list _OBJC_"; |
| 789 | Result += prefix; |
| 790 | Result += "_PROTOCOLS_"; |
| 791 | Result += ClassName; |
| 792 | Result += " __attribute__ ((section (\"__OBJC, __cat_cls_meth\")))= " |
| 793 | "{\n\t0, "; |
| 794 | Result += utostr(NumProtocols); |
| 795 | Result += "\n"; |
| 796 | |
| 797 | Result += "\t,{&_OBJC_PROTOCOL_"; |
| 798 | Result += Protocols[0]->getName(); |
| 799 | Result += " \n"; |
| 800 | |
| 801 | for (int i = 1; i < NumProtocols; i++) { |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 802 | ObjcProtocolDecl *PDecl = Protocols[i]; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 803 | Result += "\t ,&_OBJC_PROTOCOL_"; |
| 804 | Result += PDecl->getName(); |
| 805 | Result += "\n"; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 806 | } |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 807 | Result += "\t }\n};\n"; |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
| 811 | /// RewriteObjcCategoryImplDecl - Rewrite metadata for each category |
| 812 | /// implementation. |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 813 | void RewriteTest::RewriteObjcCategoryImplDecl(ObjcCategoryImplDecl *IDecl, |
| 814 | std::string &Result) { |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 815 | ObjcInterfaceDecl *ClassDecl = IDecl->getClassInterface(); |
| 816 | // Find category declaration for this implementation. |
| 817 | ObjcCategoryDecl *CDecl; |
| 818 | for (CDecl = ClassDecl->getCategoryList(); CDecl; |
| 819 | CDecl = CDecl->getNextClassCategory()) |
| 820 | if (CDecl->getIdentifier() == IDecl->getIdentifier()) |
| 821 | break; |
| 822 | assert(CDecl && "RewriteObjcCategoryImplDecl - bad category"); |
| 823 | |
| 824 | char *FullCategoryName = (char*)alloca( |
| 825 | strlen(ClassDecl->getName()) + strlen(IDecl->getName()) + 2); |
| 826 | sprintf(FullCategoryName, "%s_%s", ClassDecl->getName(), IDecl->getName()); |
| 827 | |
| 828 | // Build _objc_method_list for class's instance methods if needed |
| 829 | RewriteObjcMethodsMetaData(IDecl->getInstanceMethods(), |
| 830 | IDecl->getNumInstanceMethods(), |
Fariborz Jahanian | 8e991ba | 2007-10-25 00:14:44 +0000 | [diff] [blame] | 831 | true, |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 832 | "CATEGORY_", FullCategoryName, Result); |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 833 | |
| 834 | // Build _objc_method_list for class's class methods if needed |
| 835 | RewriteObjcMethodsMetaData(IDecl->getClassMethods(), |
| 836 | IDecl->getNumClassMethods(), |
Fariborz Jahanian | 8e991ba | 2007-10-25 00:14:44 +0000 | [diff] [blame] | 837 | false, |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 838 | "CATEGORY_", FullCategoryName, Result); |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 839 | |
| 840 | // Protocols referenced in class declaration? |
| 841 | RewriteObjcProtocolsMetaData(CDecl->getReferencedProtocols(), |
| 842 | CDecl->getNumReferencedProtocols(), |
| 843 | "CATEGORY", |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 844 | FullCategoryName, Result); |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 845 | |
| 846 | /* struct _objc_category { |
| 847 | char *category_name; |
| 848 | char *class_name; |
| 849 | struct _objc_method_list *instance_methods; |
| 850 | struct _objc_method_list *class_methods; |
| 851 | struct _objc_protocol_list *protocols; |
| 852 | // Objective-C 1.0 extensions |
| 853 | uint32_t size; // sizeof (struct _objc_category) |
| 854 | struct _objc_property_list *instance_properties; // category's own |
| 855 | // @property decl. |
| 856 | }; |
| 857 | */ |
| 858 | |
| 859 | static bool objc_category = false; |
| 860 | if (!objc_category) { |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 861 | Result += "\nstruct _objc_category {\n"; |
| 862 | Result += "\tchar *category_name;\n"; |
| 863 | Result += "\tchar *class_name;\n"; |
| 864 | Result += "\tstruct _objc_method_list *instance_methods;\n"; |
| 865 | Result += "\tstruct _objc_method_list *class_methods;\n"; |
| 866 | Result += "\tstruct _objc_protocol_list *protocols;\n"; |
| 867 | Result += "\tunsigned int size;\n"; |
| 868 | Result += "\tstruct _objc_property_list *instance_properties;\n"; |
| 869 | Result += "};\n"; |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 870 | objc_category = true; |
Fariborz Jahanian | e887c09 | 2007-10-22 21:41:37 +0000 | [diff] [blame] | 871 | } |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 872 | Result += "\nstatic struct _objc_category _OBJC_CATEGORY_"; |
| 873 | Result += FullCategoryName; |
| 874 | Result += " __attribute__ ((section (\"__OBJC, __category\")))= {\n\t\""; |
| 875 | Result += IDecl->getName(); |
| 876 | Result += "\"\n\t, \""; |
| 877 | Result += ClassDecl->getName(); |
| 878 | Result += "\"\n"; |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 879 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 880 | if (IDecl->getNumInstanceMethods() > 0) { |
| 881 | Result += "\t, (struct _objc_method_list *)" |
| 882 | "&_OBJC_CATEGORY_INSTANCE_METHODS_"; |
| 883 | Result += FullCategoryName; |
| 884 | Result += "\n"; |
| 885 | } |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 886 | else |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 887 | Result += "\t, 0\n"; |
| 888 | if (IDecl->getNumClassMethods() > 0) { |
| 889 | Result += "\t, (struct _objc_method_list *)" |
| 890 | "&_OBJC_CATEGORY_CLASS_METHODS_"; |
| 891 | Result += FullCategoryName; |
| 892 | Result += "\n"; |
| 893 | } |
| 894 | else |
| 895 | Result += "\t, 0\n"; |
| 896 | |
| 897 | if (CDecl->getNumReferencedProtocols() > 0) { |
| 898 | Result += "\t, (struct _objc_protocol_list *)&_OBJC_CATEGORY_PROTOCOLS_"; |
| 899 | Result += FullCategoryName; |
| 900 | Result += "\n"; |
| 901 | } |
| 902 | else |
| 903 | Result += "\t, 0\n"; |
| 904 | Result += "\t, sizeof(struct _objc_category), 0\n};\n"; |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 907 | /// SynthesizeIvarOffsetComputation - This rutine synthesizes computation of |
| 908 | /// ivar offset. |
| 909 | void RewriteTest::SynthesizeIvarOffsetComputation(ObjcImplementationDecl *IDecl, |
| 910 | ObjcIvarDecl *ivar, |
| 911 | std::string &Result) { |
| 912 | Result += "offsetof(struct _interface_"; |
| 913 | Result += IDecl->getName(); |
| 914 | Result += ", "; |
| 915 | Result += ivar->getName(); |
| 916 | Result += ")"; |
| 917 | } |
| 918 | |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 919 | //===----------------------------------------------------------------------===// |
| 920 | // Meta Data Emission |
| 921 | //===----------------------------------------------------------------------===// |
| 922 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 923 | void RewriteTest::RewriteObjcClassMetaData(ObjcImplementationDecl *IDecl, |
| 924 | std::string &Result) { |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 925 | ObjcInterfaceDecl *CDecl = IDecl->getClassInterface(); |
| 926 | |
| 927 | // Build _objc_ivar_list metadata for classes ivars if needed |
| 928 | int NumIvars = IDecl->getImplDeclNumIvars() > 0 |
| 929 | ? IDecl->getImplDeclNumIvars() |
| 930 | : (CDecl ? CDecl->getIntfDeclNumIvars() : 0); |
| 931 | |
Fariborz Jahanian | 4d733d3 | 2007-10-26 23:09:28 +0000 | [diff] [blame] | 932 | SynthesizeObjcInternalStruct(CDecl, Result); |
| 933 | |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 934 | if (NumIvars > 0) { |
| 935 | static bool objc_ivar = false; |
| 936 | if (!objc_ivar) { |
| 937 | /* struct _objc_ivar { |
| 938 | char *ivar_name; |
| 939 | char *ivar_type; |
| 940 | int ivar_offset; |
| 941 | }; |
| 942 | */ |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 943 | Result += "\nstruct _objc_ivar {\n"; |
| 944 | Result += "\tchar *ivar_name;\n"; |
| 945 | Result += "\tchar *ivar_type;\n"; |
| 946 | Result += "\tint ivar_offset;\n"; |
| 947 | Result += "};\n"; |
| 948 | |
| 949 | /* struct _objc_ivar_list { |
| 950 | int ivar_count; |
| 951 | struct _objc_ivar ivar_list[]; |
| 952 | }; |
| 953 | */ |
| 954 | Result += "\nstruct _objc_ivar_list {\n"; |
| 955 | Result += "\tint ivar_count;\n"; |
| 956 | Result += "\tstruct _objc_ivar ivar_list[];\n};\n"; |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 957 | objc_ivar = true; |
| 958 | } |
| 959 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 960 | Result += "\nstatic struct _objc_ivar_list _OBJC_INSTANCE_VARIABLES_"; |
| 961 | Result += IDecl->getName(); |
| 962 | Result += " __attribute__ ((section (\"__OBJC, __instance_vars\")))= " |
| 963 | "{\n\t"; |
| 964 | Result += utostr(NumIvars); |
| 965 | Result += "\n"; |
| 966 | |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 967 | ObjcIvarDecl **Ivars = IDecl->getImplDeclIVars() |
| 968 | ? IDecl->getImplDeclIVars() |
| 969 | : CDecl->getIntfDeclIvars(); |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 970 | Result += "\t,{{\""; |
| 971 | Result += Ivars[0]->getName(); |
Fariborz Jahanian | 160eb65 | 2007-10-29 17:16:25 +0000 | [diff] [blame] | 972 | Result += "\", \""; |
| 973 | std::string StrEncoding; |
| 974 | Context->getObjcEncodingForType(Ivars[0]->getType(), StrEncoding); |
| 975 | Result += StrEncoding; |
| 976 | Result += "\", "; |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 977 | SynthesizeIvarOffsetComputation(IDecl, Ivars[0], Result); |
| 978 | Result += "}\n"; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 979 | for (int i = 1; i < NumIvars; i++) { |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 980 | Result += "\t ,{\""; |
| 981 | Result += Ivars[i]->getName(); |
Fariborz Jahanian | 160eb65 | 2007-10-29 17:16:25 +0000 | [diff] [blame] | 982 | Result += "\", \""; |
| 983 | std::string StrEncoding; |
| 984 | Context->getObjcEncodingForType(Ivars[i]->getType(), StrEncoding); |
| 985 | Result += StrEncoding; |
| 986 | Result += "\", "; |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 987 | SynthesizeIvarOffsetComputation(IDecl, Ivars[i], Result); |
| 988 | Result += "}\n"; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | Result += "\t }\n};\n"; |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | // Build _objc_method_list for class's instance methods if needed |
| 995 | RewriteObjcMethodsMetaData(IDecl->getInstanceMethods(), |
| 996 | IDecl->getNumInstanceMethods(), |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 997 | true, |
| 998 | "", IDecl->getName(), Result); |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 999 | |
| 1000 | // Build _objc_method_list for class's class methods if needed |
| 1001 | RewriteObjcMethodsMetaData(IDecl->getClassMethods(), |
Fariborz Jahanian | 8e991ba | 2007-10-25 00:14:44 +0000 | [diff] [blame] | 1002 | IDecl->getNumClassMethods(), |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1003 | false, |
| 1004 | "", IDecl->getName(), Result); |
| 1005 | |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 1006 | // Protocols referenced in class declaration? |
| 1007 | RewriteObjcProtocolsMetaData(CDecl->getReferencedProtocols(), |
| 1008 | CDecl->getNumIntfRefProtocols(), |
| 1009 | "CLASS", |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1010 | CDecl->getName(), Result); |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 1011 | |
Fariborz Jahanian | 9f0a1cb | 2007-10-23 00:02:02 +0000 | [diff] [blame] | 1012 | |
Fariborz Jahanian | deef518 | 2007-10-23 18:53:48 +0000 | [diff] [blame] | 1013 | // Declaration of class/meta-class metadata |
| 1014 | /* struct _objc_class { |
| 1015 | struct _objc_class *isa; // or const char *root_class_name when metadata |
Fariborz Jahanian | 9f0a1cb | 2007-10-23 00:02:02 +0000 | [diff] [blame] | 1016 | const char *super_class_name; |
| 1017 | char *name; |
| 1018 | long version; |
| 1019 | long info; |
| 1020 | long instance_size; |
Fariborz Jahanian | deef518 | 2007-10-23 18:53:48 +0000 | [diff] [blame] | 1021 | struct _objc_ivar_list *ivars; |
| 1022 | struct _objc_method_list *methods; |
Fariborz Jahanian | 9f0a1cb | 2007-10-23 00:02:02 +0000 | [diff] [blame] | 1023 | struct objc_cache *cache; |
| 1024 | struct objc_protocol_list *protocols; |
| 1025 | const char *ivar_layout; |
| 1026 | struct _objc_class_ext *ext; |
| 1027 | }; |
| 1028 | */ |
Fariborz Jahanian | deef518 | 2007-10-23 18:53:48 +0000 | [diff] [blame] | 1029 | static bool objc_class = false; |
| 1030 | if (!objc_class) { |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1031 | Result += "\nstruct _objc_class {\n"; |
| 1032 | Result += "\tstruct _objc_class *isa;\n"; |
| 1033 | Result += "\tconst char *super_class_name;\n"; |
| 1034 | Result += "\tchar *name;\n"; |
| 1035 | Result += "\tlong version;\n"; |
| 1036 | Result += "\tlong info;\n"; |
| 1037 | Result += "\tlong instance_size;\n"; |
| 1038 | Result += "\tstruct _objc_ivar_list *ivars;\n"; |
| 1039 | Result += "\tstruct _objc_method_list *methods;\n"; |
| 1040 | Result += "\tstruct objc_cache *cache;\n"; |
| 1041 | Result += "\tstruct _objc_protocol_list *protocols;\n"; |
| 1042 | Result += "\tconst char *ivar_layout;\n"; |
| 1043 | Result += "\tstruct _objc_class_ext *ext;\n"; |
| 1044 | Result += "};\n"; |
Fariborz Jahanian | deef518 | 2007-10-23 18:53:48 +0000 | [diff] [blame] | 1045 | objc_class = true; |
Fariborz Jahanian | 9f0a1cb | 2007-10-23 00:02:02 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | // Meta-class metadata generation. |
| 1049 | ObjcInterfaceDecl *RootClass = 0; |
| 1050 | ObjcInterfaceDecl *SuperClass = CDecl->getSuperClass(); |
| 1051 | while (SuperClass) { |
| 1052 | RootClass = SuperClass; |
| 1053 | SuperClass = SuperClass->getSuperClass(); |
| 1054 | } |
| 1055 | SuperClass = CDecl->getSuperClass(); |
| 1056 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1057 | Result += "\nstatic struct _objc_class _OBJC_METACLASS_"; |
| 1058 | Result += CDecl->getName(); |
| 1059 | Result += " __attribute__ ((section (\"__OBJC, __meta_class\")))= " |
| 1060 | "{\n\t(struct _objc_class *)\""; |
| 1061 | Result += (RootClass ? RootClass->getName() : CDecl->getName()); |
| 1062 | Result += "\""; |
| 1063 | |
| 1064 | if (SuperClass) { |
| 1065 | Result += ", \""; |
| 1066 | Result += SuperClass->getName(); |
| 1067 | Result += "\", \""; |
| 1068 | Result += CDecl->getName(); |
| 1069 | Result += "\""; |
| 1070 | } |
| 1071 | else { |
| 1072 | Result += ", 0, \""; |
| 1073 | Result += CDecl->getName(); |
| 1074 | Result += "\""; |
| 1075 | } |
Fariborz Jahanian | 9f0a1cb | 2007-10-23 00:02:02 +0000 | [diff] [blame] | 1076 | // TODO: 'ivars' field for root class is currently set to 0. |
| 1077 | // 'info' field is initialized to CLS_META(2) for metaclass |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1078 | Result += ", 0,2, sizeof(struct _objc_class), 0"; |
| 1079 | if (CDecl->getNumClassMethods() > 0) { |
| 1080 | Result += "\n\t, &_OBJC_CLASS_METHODS_"; |
| 1081 | Result += CDecl->getName(); |
| 1082 | Result += "\n"; |
| 1083 | } |
Fariborz Jahanian | 9f0a1cb | 2007-10-23 00:02:02 +0000 | [diff] [blame] | 1084 | else |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1085 | Result += ", 0\n"; |
| 1086 | if (CDecl->getNumIntfRefProtocols() > 0) { |
| 1087 | Result += "\t,0, &_OBJC_CLASS_PROTOCOLS_"; |
| 1088 | Result += CDecl->getName(); |
| 1089 | Result += ",0,0\n"; |
| 1090 | } |
Fariborz Jahanian | 454cb01 | 2007-10-24 20:54:23 +0000 | [diff] [blame] | 1091 | else |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1092 | Result += "\t,0,0,0,0\n"; |
| 1093 | Result += "};\n"; |
Fariborz Jahanian | deef518 | 2007-10-23 18:53:48 +0000 | [diff] [blame] | 1094 | |
| 1095 | // class metadata generation. |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1096 | Result += "\nstatic struct _objc_class _OBJC_CLASS_"; |
| 1097 | Result += CDecl->getName(); |
| 1098 | Result += " __attribute__ ((section (\"__OBJC, __class\")))= " |
| 1099 | "{\n\t&_OBJC_METACLASS_"; |
| 1100 | Result += CDecl->getName(); |
| 1101 | if (SuperClass) { |
| 1102 | Result += ", \""; |
| 1103 | Result += SuperClass->getName(); |
| 1104 | Result += "\", \""; |
| 1105 | Result += CDecl->getName(); |
| 1106 | Result += "\""; |
| 1107 | } |
| 1108 | else { |
| 1109 | Result += ", 0, \""; |
| 1110 | Result += CDecl->getName(); |
| 1111 | Result += "\""; |
| 1112 | } |
Fariborz Jahanian | deef518 | 2007-10-23 18:53:48 +0000 | [diff] [blame] | 1113 | // 'info' field is initialized to CLS_CLASS(1) for class |
Fariborz Jahanian | 4d733d3 | 2007-10-26 23:09:28 +0000 | [diff] [blame] | 1114 | Result += ", 0,1"; |
| 1115 | if (!ObjcSynthesizedStructs.count(CDecl)) |
| 1116 | Result += ",0"; |
| 1117 | else { |
| 1118 | // class has size. Must synthesize its size. |
| 1119 | Result += ",sizeof(struct _interface_"; |
| 1120 | Result += CDecl->getName(); |
| 1121 | Result += ")"; |
| 1122 | } |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1123 | if (NumIvars > 0) { |
| 1124 | Result += ", &_OBJC_INSTANCE_VARIABLES_"; |
| 1125 | Result += CDecl->getName(); |
| 1126 | Result += "\n\t"; |
| 1127 | } |
Fariborz Jahanian | deef518 | 2007-10-23 18:53:48 +0000 | [diff] [blame] | 1128 | else |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1129 | Result += ",0"; |
| 1130 | if (IDecl->getNumInstanceMethods() > 0) { |
| 1131 | Result += ", &_OBJC_INSTANCE_METHODS_"; |
| 1132 | Result += CDecl->getName(); |
| 1133 | Result += ", 0\n\t"; |
| 1134 | } |
Fariborz Jahanian | deef518 | 2007-10-23 18:53:48 +0000 | [diff] [blame] | 1135 | else |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1136 | Result += ",0,0"; |
| 1137 | if (CDecl->getNumIntfRefProtocols() > 0) { |
| 1138 | Result += ", &_OBJC_CLASS_PROTOCOLS_"; |
| 1139 | Result += CDecl->getName(); |
| 1140 | Result += ", 0,0\n"; |
| 1141 | } |
Fariborz Jahanian | deef518 | 2007-10-23 18:53:48 +0000 | [diff] [blame] | 1142 | else |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1143 | Result += ",0,0,0\n"; |
| 1144 | Result += "};\n"; |
Fariborz Jahanian | 9f0a1cb | 2007-10-23 00:02:02 +0000 | [diff] [blame] | 1145 | } |
Fariborz Jahanian | f4d331d | 2007-10-18 22:09:03 +0000 | [diff] [blame] | 1146 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1147 | void RewriteTest::WriteObjcMetaData(std::string &Result) { |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 1148 | int ClsDefCount = ClassImplementation.size(); |
| 1149 | int CatDefCount = CategoryImplementation.size(); |
| 1150 | if (ClsDefCount == 0 && CatDefCount == 0) |
| 1151 | return; |
Fariborz Jahanian | f4d331d | 2007-10-18 22:09:03 +0000 | [diff] [blame] | 1152 | |
Fariborz Jahanian | 454cb01 | 2007-10-24 20:54:23 +0000 | [diff] [blame] | 1153 | // TODO: This is temporary until we decide how to access objc types in a |
| 1154 | // c program |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 1155 | Result += "#include <Objc/objc.h>\n"; |
| 1156 | // This is needed for use of offsetof |
| 1157 | Result += "#include <stddef.h>\n"; |
Fariborz Jahanian | 454cb01 | 2007-10-24 20:54:23 +0000 | [diff] [blame] | 1158 | |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 1159 | // For each implemented class, write out all its meta data. |
Fariborz Jahanian | f4d331d | 2007-10-18 22:09:03 +0000 | [diff] [blame] | 1160 | for (int i = 0; i < ClsDefCount; i++) |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1161 | RewriteObjcClassMetaData(ClassImplementation[i], Result); |
Fariborz Jahanian | 2e6d935 | 2007-10-24 19:23:36 +0000 | [diff] [blame] | 1162 | |
| 1163 | // For each implemented category, write out all its meta data. |
| 1164 | for (int i = 0; i < CatDefCount; i++) |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1165 | RewriteObjcCategoryImplDecl(CategoryImplementation[i], Result); |
Fariborz Jahanian | f4d331d | 2007-10-18 22:09:03 +0000 | [diff] [blame] | 1166 | |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 1167 | // Write objc_symtab metadata |
| 1168 | /* |
| 1169 | struct _objc_symtab |
| 1170 | { |
| 1171 | long sel_ref_cnt; |
| 1172 | SEL *refs; |
| 1173 | short cls_def_cnt; |
| 1174 | short cat_def_cnt; |
| 1175 | void *defs[cls_def_cnt + cat_def_cnt]; |
| 1176 | }; |
| 1177 | */ |
| 1178 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1179 | Result += "\nstruct _objc_symtab {\n"; |
| 1180 | Result += "\tlong sel_ref_cnt;\n"; |
| 1181 | Result += "\tSEL *refs;\n"; |
| 1182 | Result += "\tshort cls_def_cnt;\n"; |
| 1183 | Result += "\tshort cat_def_cnt;\n"; |
| 1184 | Result += "\tvoid *defs[" + utostr(ClsDefCount + CatDefCount)+ "];\n"; |
| 1185 | Result += "};\n\n"; |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 1186 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1187 | Result += "static struct _objc_symtab " |
| 1188 | "_OBJC_SYMBOLS __attribute__((section (\"__OBJC, __symbols\")))= {\n"; |
| 1189 | Result += "\t0, 0, " + utostr(ClsDefCount) |
| 1190 | + ", " + utostr(CatDefCount) + "\n"; |
| 1191 | for (int i = 0; i < ClsDefCount; i++) { |
| 1192 | Result += "\t,&_OBJC_CLASS_"; |
| 1193 | Result += ClassImplementation[i]->getName(); |
| 1194 | Result += "\n"; |
| 1195 | } |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 1196 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1197 | for (int i = 0; i < CatDefCount; i++) { |
| 1198 | Result += "\t,&_OBJC_CATEGORY_"; |
| 1199 | Result += CategoryImplementation[i]->getClassInterface()->getName(); |
| 1200 | Result += "_"; |
| 1201 | Result += CategoryImplementation[i]->getName(); |
| 1202 | Result += "\n"; |
| 1203 | } |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 1204 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1205 | Result += "};\n\n"; |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 1206 | |
| 1207 | // Write objc_module metadata |
| 1208 | |
| 1209 | /* |
| 1210 | struct _objc_module { |
| 1211 | long version; |
| 1212 | long size; |
| 1213 | const char *name; |
| 1214 | struct _objc_symtab *symtab; |
| 1215 | } |
| 1216 | */ |
| 1217 | |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1218 | Result += "\nstruct _objc_module {\n"; |
| 1219 | Result += "\tlong version;\n"; |
| 1220 | Result += "\tlong size;\n"; |
| 1221 | Result += "\tconst char *name;\n"; |
| 1222 | Result += "\tstruct _objc_symtab *symtab;\n"; |
| 1223 | Result += "};\n\n"; |
| 1224 | Result += "static struct _objc_module " |
| 1225 | "_OBJC_MODULES __attribute__ ((section (\"__OBJC, __module_info\")))= {\n"; |
Fariborz Jahanian | 26e4cd3 | 2007-10-26 19:46:17 +0000 | [diff] [blame] | 1226 | Result += "\t" + utostr(OBJC_ABI_VERSION) + |
| 1227 | ", sizeof(struct _objc_module), \"\", &_OBJC_SYMBOLS\n"; |
Fariborz Jahanian | ccd87b0 | 2007-10-25 20:55:25 +0000 | [diff] [blame] | 1228 | Result += "};\n\n"; |
Fariborz Jahanian | 545b9ae | 2007-10-18 19:23:00 +0000 | [diff] [blame] | 1229 | } |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 1230 | |