diff options
Diffstat (limited to 'lib/Frontend/RewriteObjC.cpp')
-rw-r--r-- | lib/Frontend/RewriteObjC.cpp | 1167 |
1 files changed, 583 insertions, 584 deletions
diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp index 8d5f4992ae..323804744d 100644 --- a/lib/Frontend/RewriteObjC.cpp +++ b/lib/Frontend/RewriteObjC.cpp @@ -35,14 +35,14 @@ namespace { const LangOptions &LangOpts; unsigned RewriteFailedDiag; unsigned TryFinallyContainsReturnDiag; - + ASTContext *Context; SourceManager *SM; TranslationUnitDecl *TUDecl; FileID MainFileID; const char *MainFileStart, *MainFileEnd; SourceLocation LastIncLoc; - + llvm::SmallVector<ObjCImplementationDecl *, 8> ClassImplementation; llvm::SmallVector<ObjCCategoryImplDecl *, 8> CategoryImplementation; llvm::SmallPtrSet<ObjCInterfaceDecl*, 8> ObjCSynthesizedStructs; @@ -53,9 +53,9 @@ namespace { llvm::SmallVector<int, 8> ObjCBcLabelNo; // Remember all the @protocol(<expr>) expressions. llvm::SmallPtrSet<ObjCProtocolDecl *, 32> ProtocolExprDecls; - + unsigned NumObjCStringLiterals; - + FunctionDecl *MsgSendFunctionDecl; FunctionDecl *MsgSendSuperFunctionDecl; FunctionDecl *MsgSendStretFunctionDecl; @@ -66,25 +66,25 @@ namespace { FunctionDecl *SelGetUidFunctionDecl; FunctionDecl *CFStringFunctionDecl; FunctionDecl *SuperContructorFunctionDecl; - + // ObjC string constant support. VarDecl *ConstantStringClassReference; RecordDecl *NSStringRecord; - + // ObjC foreach break/continue generation support. int BcLabelCount; - + // Needed for super. ObjCMethodDecl *CurMethodDef; RecordDecl *SuperStructDecl; RecordDecl *ConstantStringDecl; - + TypeDecl *ProtocolTypeDecl; QualType getProtocolType(); - + // Needed for header files being rewritten bool IsHeader; - + std::string InFileName; llvm::raw_ostream* OutFile; @@ -96,7 +96,7 @@ namespace { llvm::SmallVector<BlockExpr *, 32> Blocks; llvm::SmallVector<BlockDeclRefExpr *, 32> BlockDeclRefs; llvm::DenseMap<BlockDeclRefExpr *, CallExpr *> BlockCallExprs; - + // Block related declarations. llvm::SmallPtrSet<ValueDecl *, 8> BlockByCopyDecls; llvm::SmallPtrSet<ValueDecl *, 8> BlockByRefDecls; @@ -109,7 +109,7 @@ namespace { // This maps a property to it's synthesied message expression. // This allows us to rewrite chained getters (e.g. o.a.b.c). llvm::DenseMap<ObjCPropertyRefExpr *, Stmt *> PropGetters; - + // 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). // This is needed to support some of the exotic property rewriting. @@ -117,9 +117,9 @@ namespace { FunctionDecl *CurFunctionDef; VarDecl *GlobalVarDecl; - + bool DisableReplaceStmt; - + static const int OBJC_ABI_VERSION =7 ; public: virtual void Initialize(ASTContext &context); @@ -136,12 +136,12 @@ namespace { bool silenceMacroWarn); ~RewriteObjC() {} - + virtual void HandleTranslationUnit(ASTContext &C); - + void ReplaceStmt(Stmt *Old, Stmt *New) { Stmt *ReplacingStmt = ReplacedNodes[Old]; - + if (ReplacingStmt) return; // We can't rewrite the same node twice. @@ -191,15 +191,15 @@ namespace { InsertAfter) || SilenceRewriteMacroWarning) return; - + Diags.Report(Context->getFullLoc(Loc), RewriteFailedDiag); } - + void RemoveText(SourceLocation Loc, unsigned StrLen) { // If removal succeeded or warning disabled return with no warning. if (!Rewrite.RemoveText(Loc, StrLen) || SilenceRewriteMacroWarning) return; - + Diags.Report(Context->getFullLoc(Loc), RewriteFailedDiag); } @@ -210,10 +210,10 @@ namespace { llvm::StringRef(NewStr, NewLength)) || SilenceRewriteMacroWarning) return; - + Diags.Report(Context->getFullLoc(Start), RewriteFailedDiag); } - + // Syntactic Rewriting. void RewritePrologue(SourceLocation Loc); void RewriteInclude(); @@ -238,18 +238,18 @@ namespace { QualType getSuperStructType(); QualType getConstantStringStructType(); bool BufferContainsPPDirectives(const char *startBuf, const char *endBuf); - + // Expression Rewriting. Stmt *RewriteFunctionBodyOrGlobalInitializer(Stmt *S); void CollectPropertySetters(Stmt *S); - + Stmt *CurrentBody; ParentMap *PropParentMap; // created lazily. - + Stmt *RewriteAtEncode(ObjCEncodeExpr *Exp); Stmt *RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, SourceLocation OrigStart); Stmt *RewritePropertyGetter(ObjCPropertyRefExpr *PropRefExpr); - Stmt *RewritePropertySetter(BinaryOperator *BinOp, Expr *newStmt, + Stmt *RewritePropertySetter(BinaryOperator *BinOp, Expr *newStmt, SourceRange SrcRange); Stmt *RewriteAtSelector(ObjCSelectorExpr *Exp); Stmt *RewriteMessageExpr(ObjCMessageExpr *Exp); @@ -263,13 +263,13 @@ namespace { Stmt *RewriteObjCThrowStmt(ObjCAtThrowStmt *S); Stmt *RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S, SourceLocation OrigEnd); - CallExpr *SynthesizeCallToFunctionDecl(FunctionDecl *FD, + CallExpr *SynthesizeCallToFunctionDecl(FunctionDecl *FD, Expr **args, unsigned nargs); Stmt *SynthMessageExpr(ObjCMessageExpr *Exp); Stmt *RewriteBreakStmt(BreakStmt *S); Stmt *RewriteContinueStmt(ContinueStmt *S); void SynthCountByEnumWithState(std::string &buf); - + void SynthMsgSendFunctionDecl(); void SynthMsgSendSuperFunctionDecl(); void SynthMsgSendStretFunctionDecl(); @@ -279,14 +279,14 @@ namespace { void SynthGetMetaClassFunctionDecl(); void SynthSelGetUidFunctionDecl(); void SynthSuperContructorFunctionDecl(); - + // Metadata emission. void RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, std::string &Result); - + void RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *CDecl, std::string &Result); - + template<typename MethodIterator> void RewriteObjCMethodsMetaData(MethodIterator MethodBegin, MethodIterator MethodEnd, @@ -294,69 +294,69 @@ namespace { const char *prefix, const char *ClassName, std::string &Result); - + void RewriteObjCProtocolMetaData(ObjCProtocolDecl *Protocol, const char *prefix, const char *ClassName, std::string &Result); void RewriteObjCProtocolListMetaData(const ObjCList<ObjCProtocolDecl> &Prots, - const char *prefix, + const char *prefix, const char *ClassName, std::string &Result); void SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl, std::string &Result); - void SynthesizeIvarOffsetComputation(ObjCImplementationDecl *IDecl, - ObjCIvarDecl *ivar, + void SynthesizeIvarOffsetComputation(ObjCImplementationDecl *IDecl, + ObjCIvarDecl *ivar, std::string &Result); void RewriteImplementations(); void SynthesizeMetaDataIntoBuffer(std::string &Result); - + // Block rewriting. - void RewriteBlocksInFunctionProtoType(QualType funcType, NamedDecl *D); + void RewriteBlocksInFunctionProtoType(QualType funcType, NamedDecl *D); void CheckFunctionPointerDecl(QualType dType, NamedDecl *ND); - + void InsertBlockLiteralsWithinFunction(FunctionDecl *FD); void InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD); - - // Block specific rewrite rules. + + // Block specific rewrite rules. void RewriteBlockCall(CallExpr *Exp); void RewriteBlockPointerDecl(NamedDecl *VD); Stmt *RewriteBlockDeclRefExpr(BlockDeclRefExpr *VD); void RewriteBlockPointerFunctionArgs(FunctionDecl *FD); - - std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, + + std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, const char *funcName, std::string Tag); - std::string SynthesizeBlockFunc(BlockExpr *CE, int i, + std::string SynthesizeBlockFunc(BlockExpr *CE, int i, const char *funcName, std::string Tag); - std::string SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, + std::string SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, bool hasCopyDisposeHelpers); Stmt *SynthesizeBlockCall(CallExpr *Exp); void SynthesizeBlockLiterals(SourceLocation FunLocStart, const char *FunName); - + void CollectBlockDeclRefInfo(BlockExpr *Exp); void GetBlockCallExprs(Stmt *S); void GetBlockDeclRefExprs(Stmt *S); - + // We avoid calling Type::isBlockPointerType(), since it operates on the // canonical type. We only care if the top-level type is a closure pointer. bool isTopLevelBlockPointerType(QualType T) { return isa<BlockPointerType>(T); } - + // FIXME: This predicate seems like it would be useful to add to ASTContext. bool isObjCType(QualType T) { if (!LangOpts.ObjC1 && !LangOpts.ObjC2) return false; - + QualType OCT = Context->getCanonicalType(T).getUnqualifiedType(); - + if (OCT == Context->getCanonicalType(Context->getObjCIdType()) || OCT == Context->getCanonicalType(Context->getObjCClassType())) return true; - + if (const PointerType *PT = OCT->getAs<PointerType>()) { - if (isa<ObjCInterfaceType>(PT->getPointeeType()) || + if (isa<ObjCInterfaceType>(PT->getPointeeType()) || PT->getPointeeType()->isObjCQualifiedIdType()) return true; } @@ -366,12 +366,12 @@ namespace { void GetExtentOfArgList(const char *Name, const char *&LParen, const char *&RParen); void RewriteCastExpr(CStyleCastExpr *CE); - + FunctionDecl *SynthBlockInitFunctionDecl(const char *name); Stmt *SynthBlockInitExpr(BlockExpr *Exp); - + void QuoteDoublequotes(std::string &From, std::string &To) { - for(unsigned i = 0; i < From.length(); i++) { + for (unsigned i = 0; i < From.length(); i++) { if (From[i] == '"') To += "\\\""; else @@ -381,10 +381,10 @@ namespace { }; } -void RewriteObjC::RewriteBlocksInFunctionProtoType(QualType funcType, - NamedDecl *D) { +void RewriteObjC::RewriteBlocksInFunctionProtoType(QualType funcType, + NamedDecl *D) { if (FunctionProtoType *fproto = dyn_cast<FunctionProtoType>(funcType)) { - for (FunctionProtoType::arg_type_iterator I = fproto->arg_type_begin(), + for (FunctionProtoType::arg_type_iterator I = fproto->arg_type_begin(), E = fproto->arg_type_end(); I && (I != E); ++I) if (isTopLevelBlockPointerType(*I)) { // All the args are checked/rewritten. Don't call twice! @@ -402,17 +402,17 @@ void RewriteObjC::CheckFunctionPointerDecl(QualType funcType, NamedDecl *ND) { static bool IsHeaderFile(const std::string &Filename) { std::string::size_type DotPos = Filename.rfind('.'); - + if (DotPos == std::string::npos) { // no file extension - return false; + return false; } - + std::string Ext = std::string(Filename.begin()+DotPos+1, Filename.end()); // C header: .h // C++ header: .hh or .H; return Ext == "h" || Ext == "hh" || Ext == "H"; -} +} RewriteObjC::RewriteObjC(std::string inFile, llvm::raw_ostream* OS, Diagnostic &D, const LangOptions &LOpts, @@ -420,16 +420,16 @@ RewriteObjC::RewriteObjC(std::string inFile, llvm::raw_ostream* OS, : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(OS), SilenceRewriteMacroWarning(silenceMacroWarn) { IsHeader = IsHeaderFile(inFile); - RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning, + RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning, "rewriting sub-expression within a macro (may not be correct)"); - TryFinallyContainsReturnDiag = Diags.getCustomDiagID(Diagnostic::Warning, + TryFinallyContainsReturnDiag = Diags.getCustomDiagID(Diagnostic::Warning, "rewriter doesn't support user-specified control flow semantics " "for @try/@finally (code may not execute properly)"); } ASTConsumer *clang::CreateObjCRewriter(const std::string& InFile, llvm::raw_ostream* OS, - Diagnostic &Diags, + Diagnostic &Diags, const LangOptions &LOpts, bool SilenceRewriteMacroWarning) { return new RewriteObjC(InFile, OS, Diags, LOpts, SilenceRewriteMacroWarning); @@ -462,15 +462,15 @@ void RewriteObjC::Initialize(ASTContext &context) { PropParentMap = 0; CurrentBody = 0; DisableReplaceStmt = false; - + // Get the ID and start/end of the main file. MainFileID = SM->getMainFileID(); const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID); MainFileStart = MainBuf->getBufferStart(); MainFileEnd = MainBuf->getBufferEnd(); - + Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOptions()); - + // declaring objc_selector outside the parameter list removes a silly // scope related warning... if (IsHeader) @@ -574,7 +574,7 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) { // if we rewrote the #include/#import. SourceLocation Loc = D->getLocation(); Loc = SM->getInstantiationLoc(Loc); - + // If this is for a builtin, ignore it. if (Loc.isInvalid()) return; @@ -593,7 +593,7 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) { RewriteCategoryDecl(CD); } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) { RewriteProtocolDecl(PD); - } else if (ObjCForwardProtocolDecl *FP = + } else if (ObjCForwardProtocolDecl *FP = dyn_cast<ObjCForwardProtocolDecl>(D)){ RewriteForwardProtocolDecl(FP); } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) { @@ -619,7 +619,7 @@ void RewriteObjC::RewriteInclude() { const char *MainBufEnd = MainBuf.second; size_t ImportLen = strlen("import"); size_t IncludeLen = strlen("include"); - + // Loop over the whole file, looking for includes. for (const char *BufPtr = MainBufStart; BufPtr < MainBufEnd; ++BufPtr) { if (*BufPtr == '#') { @@ -630,7 +630,7 @@ void RewriteObjC::RewriteInclude() { return; if (!strncmp(BufPtr, "import", ImportLen)) { // replace import with include - SourceLocation ImportLoc = + SourceLocation ImportLoc = LocStart.getFileLocWithOffset(BufPtr-MainBufStart); ReplaceText(ImportLoc, ImportLen, "include", IncludeLen); BufPtr += ImportLen; @@ -643,27 +643,27 @@ void RewriteObjC::RewriteTabs() { std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID); const char *MainBufStart = MainBuf.first; const char *MainBufEnd = MainBuf.second; - + // Loop over the whole file, looking for tabs. for (const char *BufPtr = MainBufStart; BufPtr != MainBufEnd; ++BufPtr) { if (*BufPtr != '\t') continue; - + // Okay, we found a tab. This tab will turn into at least one character, // but it depends on which 'virtual column' it is in. Compute that now. unsigned VCol = 0; while (BufPtr-VCol != MainBufStart && BufPtr[-VCol-1] != '\t' && BufPtr[-VCol-1] != '\n' && BufPtr[-VCol-1] != '\r') ++VCol; - + // Okay, now that we know the virtual column, we know how many spaces to // insert. We assume 8-character tab-stops. unsigned Spaces = 8-(VCol & 7); - + // Get the location of the tab. SourceLocation TabLoc = SM->getLocForStartOfFile(MainFileID); TabLoc = TabLoc.getFileLocWithOffset(BufPtr-MainBufStart); - + // Rewrite the single tab character into a sequence of spaces. ReplaceText(TabLoc, 1, " ", Spaces); } @@ -693,35 +693,35 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) return; // FIXME: is this correct? - + // Generate the 'getter' function. ObjCPropertyDecl *PD = PID->getPropertyDecl(); ObjCInterfaceDecl *ClassDecl = PD->getGetterMethodDecl()->getClassInterface(); ObjCIvarDecl *OID = PID->getPropertyIvarDecl(); - + if (!OID) return; - + std::string Getr; RewriteObjCMethodDecl(PD->getGetterMethodDecl(), Getr); Getr += "{ "; // Synthesize an explicit cast to gain access to the ivar. - // FIXME: deal with code generation implications for various property - // attributes (copy, retain, nonatomic). + // FIXME: deal with code generation implications for various property + // attributes (copy, retain, nonatomic). // See objc-act.c:objc_synthesize_new_getter() for details. Getr += "return " + getIvarAccessString(ClassDecl, OID); Getr += "; }"; InsertText(onePastSemiLoc, Getr.c_str(), Getr.size()); if (PD->isReadOnly()) return; - + // Generate the 'setter' function. std::string Setr; RewriteObjCMethodDecl(PD->getSetterMethodDecl(), Setr); Setr += "{ "; // Synthesize an explicit cast to initialize the ivar. - // FIXME: deal with code generation implications for various property - // attributes (copy, retain, nonatomic). + // FIXME: deal with code generation implications for various property + // attributes (copy, retain, nonatomic). // See objc-act.c:objc_synthesize_new_setter() for details. Setr += getIvarAccessString(ClassDecl, OID) + " = "; Setr += PD->getNameAsCString(); @@ -734,7 +734,7 @@ void RewriteObjC::RewriteForwardClassDecl(ObjCClassDecl *ClassDecl) { SourceLocation startLoc = ClassDecl->getLocation(); const char *startBuf = SM->getCharacterData(startLoc); const char *semiPtr = strchr(startBuf, ';'); - + // Translate to typedef's that forward reference structs with the same name // as the class. As a convenience, we include the original declaration // as a comment. @@ -755,16 +755,16 @@ void RewriteObjC::RewriteForwardClassDecl(ObjCClassDecl *ClassDecl) { typedefString += ForwardDecl->getNameAsString(); typedefString += ";\n#endif\n"; } - + // Replace the @class with typedefs corresponding to the classes. - ReplaceText(startLoc, semiPtr-startBuf+1, + ReplaceText(startLoc, semiPtr-startBuf+1, typedefString.c_str(), typedefString.size()); } void RewriteObjC::RewriteMethodDeclaration(ObjCMethodDecl *Method) { SourceLocation LocStart = Method->getLocStart(); SourceLocation LocEnd = Method->getLocEnd(); - + if (SM->getInstantiationLineNumber(LocEnd) > SM->getInstantiationLineNumber(LocStart)) { InsertText(LocStart, "#if 0\n", 6); @@ -774,26 +774,25 @@ void RewriteObjC::RewriteMethodDeclaration(ObjCMethodDecl *Method) { } } -void RewriteObjC::RewriteProperty(ObjCPropertyDecl *prop) -{ +void RewriteObjC::RewriteProperty(ObjCPropertyDecl *prop) { SourceLocation Loc = prop->getLocation(); - + ReplaceText(Loc, 0, "// ", 3); - + // FIXME: handle properties that are declared across multiple lines. } void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { SourceLocation LocStart = CatDecl->getLocStart(); - + // FIXME: handle category headers that are declared across multiple lines. ReplaceText(LocStart, 0, "// ", 3); - - for (ObjCCategoryDecl::instmeth_iterator - I = CatDecl->instmeth_begin(), E = CatDecl->instmeth_end(); + + for (ObjCCategoryDecl::instmeth_iterator + I = CatDecl->instmeth_begin(), E = CatDecl->instmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); - for (ObjCCategoryDecl::classmeth_iterator + for (ObjCCategoryDecl::classmeth_iterator I = CatDecl->classmeth_begin(), E = CatDecl->classmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); @@ -804,14 +803,14 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID); - + SourceLocation LocStart = PDecl->getLocStart(); - + // FIXME: handle protocol headers that are declared across multiple lines. ReplaceText(LocStart, 0, "// ", 3); - - for (ObjCProtocolDecl::instmeth_iterator - I = PDecl->instmeth_begin(), E = PDecl->instmeth_end(); + + for (ObjCProtocolDecl::instmeth_iterator + I = PDecl->instmeth_begin(), E = PDecl->instmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); for (ObjCProtocolDecl::classmeth_iterator @@ -832,14 +831,14 @@ void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { SourceLocation OptionalLoc = LocStart.getFileLocWithOffset(p-startBuf); ReplaceText(OptionalLoc, strlen("@optional"), CommentedOptional.c_str(), CommentedOptional.size()); - + } else if (*p == '@' && !strncmp(p+1, "required", strlen("required"))) { std::string CommentedRequired = "/* @required */"; SourceLocation OptionalLoc = LocStart.getFileLocWithOffset(p-startBuf); ReplaceText(OptionalLoc, strlen("@required"), CommentedRequired.c_str(), CommentedRequired.size()); - + } } } @@ -852,7 +851,7 @@ void RewriteObjC::RewriteForwardProtocolDecl(ObjCForwardProtocolDecl *PDecl) { ReplaceText(LocStart, 0, "// ", 3); } -void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, +void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, std::string &ResultStr) { //fprintf(stderr,"In RewriteObjCMethodDecl\n"); const FunctionType *FPRetType = 0; @@ -876,24 +875,24 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, } else ResultStr += OMD->getResultType().getAsString(); ResultStr += " "; - + // Unique method name std::string NameStr; - + if (OMD->isInstanceMethod()) NameStr += "_I_"; else NameStr += "_C_"; - + NameStr += OMD->getClassInterface()->getNameAsString(); NameStr += "_"; - - if (ObjCCategoryImplDecl *CID = + + if (ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext())) { NameStr += CID->getNameAsString(); NameStr += "_"; } - // Append selector names, replacing ':' with '_' + // Append selector names, replacing ':' with '_' { std::string selString = OMD->getSelector().getAsString(); int len = selString.size(); @@ -905,10 +904,10 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, // Remember this name for metadata emission MethodInternalNames[OMD] = NameStr; ResultStr += NameStr; - + // Rewrite arguments ResultStr += "("; - + // invisible arguments if (OMD->isInstanceMethod()) { QualType selfTy = Context->getObjCInterfaceType(OMD->getClassInterface()); @@ -923,11 +922,11 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, } else ResultStr += Context->getObjCClassType().getAsString(); - + ResultStr += " self, "; ResultStr += Context->getObjCSelType().getAsString(); ResultStr += " _cmd"; - + // Method arguments. for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(), E = OMD->param_end(); PI != E; ++PI) { @@ -951,10 +950,10 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, if (OMD->isVariadic()) ResultStr += ", ..."; ResultStr += ") "; - + if (FPRetType) { ResultStr += ")"; // close the precedence "scope" for "*". - + // Now, emit the argument types (if any). if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(FPRetType)) { ResultStr += "("; @@ -976,12 +975,12 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, void RewriteObjC::RewriteImplementationDecl(Decl *OID) { ObjCImplementationDecl *IMD = dyn_cast<ObjCImplementationDecl>(OID); ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OID); - + if (IMD) InsertText(IMD->getLocStart(), "// ", 3); else InsertText(CID->getLocStart(), "// ", 3); - + for (ObjCCategoryImplDecl::instmeth_iterator I = IMD ? IMD->instmeth_begin() : CID->instmeth_begin(), E = IMD ? IMD->instmeth_end() : CID->instmeth_end(); @@ -997,7 +996,7 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) { ReplaceText(LocStart, endBuf-startBuf, ResultStr.c_str(), ResultStr.size()); } - + for (ObjCCategoryImplDecl::classmeth_iterator I = IMD ? IMD->classmeth_begin() : CID->classmeth_begin(), E = IMD ? IMD->classmeth_end() : CID->classmeth_end(); @@ -1007,15 +1006,15 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) { RewriteObjCMethodDecl(OMD, ResultStr); SourceLocation LocStart = OMD->getLocStart(); SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart(); - + const char *startBuf = SM->getCharacterData(LocStart); const char *endBuf = SM->getCharacterData(LocEnd); ReplaceText(LocStart, endBuf-startBuf, - ResultStr.c_str(), ResultStr.size()); + ResultStr.c_str(), ResultStr.size()); } for (ObjCCategoryImplDecl::propimpl_iterator I = IMD ? IMD->propimpl_begin() : CID->propimpl_begin(), - E = IMD ? IMD->propimpl_end() : CID->propimpl_end(); + E = IMD ? IMD->propimpl_end() : CID->propimpl_end(); I != E; ++I) { RewritePropertyImplDecl(*I, IMD, CID); } @@ -1023,7 +1022,7 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) { if (IMD) InsertText(IMD->getLocEnd(), "// ", 3); else - InsertText(CID->getLocEnd(), "// ", 3); + InsertText(CID->getLocEnd(), "// ", 3); } void RewriteObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { @@ -1043,16 +1042,16 @@ void RewriteObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { ObjCForwardDecls.insert(ClassDecl); } SynthesizeObjCInternalStruct(ClassDecl, ResultStr); - - for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(), + + for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(), E = ClassDecl->prop_end(); I != E; ++I) RewriteProperty(*I); - for (ObjCInterfaceDecl::instmeth_iterator + for (ObjCInterfaceDecl::instmeth_iterator I = ClassDecl->instmeth_begin(), E = ClassDecl->instmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); - for (ObjCInterfaceDecl::classmeth_iterator - I = ClassDecl->classmeth_begin(), E = ClassDecl->classmeth_end(); + for (ObjCInterfaceDecl::classmeth_iterator + I = ClassDecl->classmeth_begin(), E = ClassDecl->classmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); @@ -1069,20 +1068,20 @@ Stmt *RewriteObjC::RewritePropertySetter(BinaryOperator *BinOp, Expr *newStmt, ObjCPropertyDecl *PDecl = PropRefExpr->getProperty(); llvm::SmallVector<Expr *, 1> ExprVec; ExprVec.push_back(newStmt); - + Stmt *Receiver = PropRefExpr->getBase(); ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(Receiver); if (PRE && PropGetters[PRE]) { // This allows us to handle chain/nested property getters. Receiver = PropGetters[PRE]; } - MsgExpr = new (Context) ObjCMessageExpr(dyn_cast<Expr>(Receiver), - PDecl->getSetterName(), PDecl->getType(), - PDecl->getSetterMethodDecl(), - SourceLocation(), SourceLocation(), + MsgExpr = new (Context) ObjCMessageExpr(dyn_cast<Expr>(Receiver), + PDecl->getSetterName(), PDecl->getType(), + PDecl->getSetterMethodDecl(), + SourceLocation(), SourceLocation(), &ExprVec[0], 1); Stmt *ReplacingStmt = SynthMessageExpr(MsgExpr); - + // Now do the actual rewrite. ReplaceStmtWithRange(BinOp, ReplacingStmt, SrcRange); //delete BinOp; @@ -1097,18 +1096,18 @@ Stmt *RewriteObjC::RewritePropertyGetter(ObjCPropertyRefExpr *PropRefExpr) { // This allows us to reuse all the fun and games in SynthMessageExpr(). ObjCMessageExpr *MsgExpr; ObjCPropertyDecl *PDecl = PropRefExpr->getProperty(); - + Stmt *Receiver = PropRefExpr->getBase(); - + ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(Receiver); if (PRE && PropGetters[PRE]) { // This allows us to handle chain/nested property getters. Receiver = PropGetters[PRE]; } - MsgExpr = new (Context) ObjCMessageExpr(dyn_cast<Expr>(Receiver), - PDecl->getGetterName(), PDecl->getType(), - PDecl->getGetterMethodDecl(), - SourceLocation(), SourceLocation(), + MsgExpr = new (Context) ObjCMessageExpr(dyn_cast<Expr>(Receiver), + PDecl->getGetterName(), PDecl->getType(), + PDecl->getGetterMethodDecl(), + SourceLocation(), SourceLocation(), 0, 0); Stmt *ReplacingStmt = SynthMessageExpr(MsgExpr); @@ -1127,7 +1126,7 @@ Stmt *RewriteObjC::RewritePropertyGetter(ObjCPropertyRefExpr *PropRefExpr) { return PropRefExpr; // return the original... } else { ReplaceStmt(PropRefExpr, ReplacingStmt); - // delete PropRefExpr; elsewhere... + // delete PropRefExpr; elsewhere... // NOTE: We don't want to call MsgExpr->Destroy(), as it holds references // to things that stay around. Context->Deallocate(MsgExpr); @@ -1135,7 +1134,7 @@ Stmt *RewriteObjC::RewritePropertyGetter(ObjCPropertyRefExpr *PropRefExpr) { } } -Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, +Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, SourceLocation OrigStart) { ObjCIvarDecl *D = IV->getDecl(); if (CurMethodDef) { @@ -1144,10 +1143,10 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, dyn_cast<ObjCInterfaceType>(pType->getPointeeType()); // lookup which class implements the instance variable. ObjCInterfaceDecl *clsDeclared = 0; - iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), + iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), clsDeclared); assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class"); - + // Synthesize an explicit cast to gain access to the ivar. std::string RecName = clsDeclared->getIdentifier()->getName(); RecName += "_IMPL"; @@ -1156,7 +1155,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, SourceLocation(), II); assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl"); QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); - CastExpr *castExpr = new (Context) CStyleCastExpr(castT, + CastExpr *castExpr = new (Context) CStyleCastExpr(castT, CastExpr::CK_Unknown, IV->getBase(), castT,SourceLocation(), @@ -1165,7 +1164,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, ParenExpr *PE = new (Context) ParenExpr(IV->getBase()->getLocStart(), IV->getBase()->getLocEnd(), castExpr); - if (IV->isFreeIvar() && + if (IV->isFreeIvar() && CurMethodDef->getClassInterface() == iFaceDecl->getDecl()) { MemberExpr *ME = new (Context) MemberExpr(PE, true, D, IV->getLocation(), @@ -1174,27 +1173,27 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, // delete IV; leak for now, see RewritePropertySetter() usage for more info. return ME; } - + ReplaceStmt(IV->getBase(), PE); // Cannot delete IV->getBase(), since PE points to it. // Replace the old base with the cast. This is important when doing // embedded rewrites. For example, [newInv->_container addObject:0]. - IV->setBase(PE); + IV->setBase(PE); return IV; } } else { // we are outside a method. assert(!IV->isFreeIvar() && "Cannot have a free standing ivar outside a method"); - + // Explicit ivar refs need to have a cast inserted. // FIXME: consider sharing some of this code with the code above. if (const PointerType *pType = IV->getBase()->getType()->getAs<PointerType>()) { ObjCInterfaceType *iFaceDecl = dyn_cast<ObjCInterfaceType>(pType->getPointeeType()); // lookup which class implements the instance variable. ObjCInterfaceDecl *clsDeclared = 0; - iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), + iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), clsDeclared); assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class"); - + // Synthesize an explicit cast to gain access to the ivar. std::string RecName = clsDeclared->getIdentifier()->getName(); RecName += "_IMPL"; @@ -1203,7 +1202,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, SourceLocation(), II); assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl"); QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); - CastExpr *castExpr = new (Context) CStyleCastExpr(castT, + CastExpr *castExpr = new (Context) CStyleCastExpr(castT, CastExpr::CK_Unknown, IV->getBase(), castT, SourceLocation(), @@ -1215,7 +1214,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, // Cannot delete IV->getBase(), since PE points to it. // Replace the old base with the cast. This is important when doing // embedded rewrites. For example, [newInv->_container addObject:0]. - IV->setBase(PE); + IV->setBase(PE); return IV; } } @@ -1225,10 +1224,10 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, /// SynthCountByEnumWithState - To print: /// ((unsigned int (*) /// (id, SEL, struct __objcFastEnumerationState *, id *, unsigned int)) -/// (void *)objc_msgSend)((id)l_collection, +/// (void *)objc_msgSend)((id)l_collection, /// sel_registerName( -/// "countByEnumeratingWithState:objects:count:"), -/// &enumState, +/// "countByEnumeratingWithState:objects:count:"), +/// &enumState, /// (id *)items, (unsigned int)16) /// void RewriteObjC::SynthCountByEnumWithState(std::string &buf) { @@ -1250,7 +1249,7 @@ Stmt *RewriteObjC::RewriteBreakStmt(BreakStmt *S) { return S; // replace break with goto __break_label std::string buf; - + SourceLocation startLoc = S->getLocStart(); buf = "goto __break_label_"; buf += utostr(ObjCBcLabelNo.back()); @@ -1267,39 +1266,39 @@ Stmt *RewriteObjC::RewriteContinueStmt(ContinueStmt *S) { return S; // replace continue with goto __continue_label std::string buf; - + SourceLocation startLoc = S->getLocStart(); buf = "goto __continue_label_"; buf += utostr(ObjCBcLabelNo.back()); ReplaceText(startLoc, strlen("continue"), buf.c_str(), buf.size()); - + return 0; } /// RewriteObjCForCollectionStmt - Rewriter for ObjC2's foreach statement. /// It rewrites: /// for ( type elem in collection) { stmts; } - + /// Into: /// { -/// type elem; +/// type elem; /// struct __objcFastEnumerationState enumState = { 0 }; /// id items[16]; /// id l_collection = (id)collection; -/// unsigned long limit = [l_collection countByEnumeratingWithState:&enumState +/// unsigned long limit = [l_collection countByEnumeratingWithState:&enumState /// objects:items count:16]; /// if (limit) { /// unsigned long startMutations = *enumState.mutationsPtr; /// do { /// unsigned long counter = 0; /// do { -/// if (startMutations != *enumState.mutationsPtr) |