diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2013-12-22 00:07:40 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2013-12-22 00:07:40 +0000 | 
| commit | bfef399519ca9b8a4b4c6b563253bad7e0eeffe0 (patch) | |
| tree | df8df0b0067b381eab470a3b8f28d14a552a6340 /lib/Rewrite/Frontend | |
| parent | 6a0372513edbc473b538d2f724efac50405d6fef (diff) | |
Diffstat (limited to 'lib/Rewrite/Frontend')
| -rw-r--r-- | lib/Rewrite/Frontend/FixItRewriter.cpp | 2 | ||||
| -rw-r--r-- | lib/Rewrite/Frontend/FrontendActions.cpp | 10 | ||||
| -rw-r--r-- | lib/Rewrite/Frontend/InclusionRewriter.cpp | 71 | ||||
| -rw-r--r-- | lib/Rewrite/Frontend/RewriteMacros.cpp | 2 | ||||
| -rw-r--r-- | lib/Rewrite/Frontend/RewriteModernObjC.cpp | 208 | ||||
| -rw-r--r-- | lib/Rewrite/Frontend/RewriteObjC.cpp | 66 | 
6 files changed, 212 insertions, 147 deletions
diff --git a/lib/Rewrite/Frontend/FixItRewriter.cpp b/lib/Rewrite/Frontend/FixItRewriter.cpp index 166c607d020e..8930c35d06c4 100644 --- a/lib/Rewrite/Frontend/FixItRewriter.cpp +++ b/lib/Rewrite/Frontend/FixItRewriter.cpp @@ -92,7 +92,7 @@ bool FixItRewriter::WriteFixedFiles(        OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true));      } else {        OS.reset(new llvm::raw_fd_ostream(Filename.c_str(), Err, -                                        llvm::raw_fd_ostream::F_Binary)); +                                        llvm::sys::fs::F_Binary));      }      if (!Err.empty()) {        Diags.Report(clang::diag::err_fe_unable_to_open_output) diff --git a/lib/Rewrite/Frontend/FrontendActions.cpp b/lib/Rewrite/Frontend/FrontendActions.cpp index 9935aeb63e58..e9ec38818265 100644 --- a/lib/Rewrite/Frontend/FrontendActions.cpp +++ b/lib/Rewrite/Frontend/FrontendActions.cpp @@ -76,12 +76,10 @@ class FixItRewriteToTemp : public FixItOptions {  public:    std::string RewriteFilename(const std::string &Filename, int &fd) {      SmallString<128> Path; -    Path = llvm::sys::path::filename(Filename); -    Path += "-%%%%%%%%"; -    Path += llvm::sys::path::extension(Filename); -    SmallString<128> NewPath; -    llvm::sys::fs::unique_file(Path.str(), fd, NewPath); -    return NewPath.str(); +    llvm::sys::fs::createTemporaryFile(llvm::sys::path::filename(Filename), +                                       llvm::sys::path::extension(Filename), fd, +                                       Path); +    return Path.str();    }  };  } // end anonymous namespace diff --git a/lib/Rewrite/Frontend/InclusionRewriter.cpp b/lib/Rewrite/Frontend/InclusionRewriter.cpp index 878be84224ae..71ceb5f0b6aa 100644 --- a/lib/Rewrite/Frontend/InclusionRewriter.cpp +++ b/lib/Rewrite/Frontend/InclusionRewriter.cpp @@ -16,6 +16,7 @@  #include "clang/Basic/SourceManager.h"  #include "clang/Frontend/PreprocessorOutputOptions.h"  #include "clang/Lex/HeaderSearch.h" +#include "clang/Lex/Pragma.h"  #include "clang/Lex/Preprocessor.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/Support/raw_ostream.h" @@ -39,6 +40,7 @@ class InclusionRewriter : public PPCallbacks {    Preprocessor &PP; ///< Used to find inclusion directives.    SourceManager &SM; ///< Used to read and manage source files.    raw_ostream &OS; ///< The destination stream for rewritten contents. +  const llvm::MemoryBuffer *PredefinesBuffer; ///< The preprocessor predefines.    bool ShowLineMarkers; ///< Show #line markers.    bool UseLineDirective; ///< Use of line directives or line markers.    typedef std::map<unsigned, FileChange> FileChangeMap; @@ -49,6 +51,9 @@ class InclusionRewriter : public PPCallbacks {  public:    InclusionRewriter(Preprocessor &PP, raw_ostream &OS, bool ShowLineMarkers);    bool Process(FileID FileId, SrcMgr::CharacteristicKind FileType); +  void setPredefinesBuffer(const llvm::MemoryBuffer *Buf) { +    PredefinesBuffer = Buf; +  }  private:    virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,                             SrcMgr::CharacteristicKind FileType, @@ -88,7 +93,7 @@ private:  /// Initializes an InclusionRewriter with a \p PP source and \p OS destination.  InclusionRewriter::InclusionRewriter(Preprocessor &PP, raw_ostream &OS,                                       bool ShowLineMarkers) -    : PP(PP), SM(PP.getSourceManager()), OS(OS), +    : PP(PP), SM(PP.getSourceManager()), OS(OS), PredefinesBuffer(0),      ShowLineMarkers(ShowLineMarkers),      LastInsertedFileChange(FileChanges.end()) {    // If we're in microsoft mode, use normal #line instead of line markers. @@ -105,11 +110,15 @@ void InclusionRewriter::WriteLineInfo(const char *Filename, int Line,    if (!ShowLineMarkers)      return;    if (UseLineDirective) { -    OS << "#line" << ' ' << Line << ' ' << '"' << Filename << '"'; +    OS << "#line" << ' ' << Line << ' ' << '"'; +    OS.write_escaped(Filename); +    OS << '"';    } else {      // Use GNU linemarkers as described here:      // http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html -    OS << '#' << ' ' << Line << ' ' << '"' << Filename << '"'; +    OS << '#' << ' ' << Line << ' ' << '"'; +    OS.write_escaped(Filename); +    OS << '"';      if (!Extra.empty())        OS << Extra;      if (FileType == SrcMgr::C_System) @@ -213,6 +222,11 @@ void InclusionRewriter::OutputContentUpTo(const MemoryBuffer &FromFile,                                            bool EnsureNewline) {    if (WriteTo <= WriteFrom)      return; +  if (&FromFile == PredefinesBuffer) { +    // Ignore the #defines of the predefines buffer. +    WriteFrom = WriteTo; +    return; +  }    OS.write(FromFile.getBufferStart() + WriteFrom, WriteTo - WriteFrom);    // count lines manually, it's faster than getPresumedLoc()    Line += std::count(FromFile.getBufferStart() + WriteFrom, @@ -328,7 +342,7 @@ bool InclusionRewriter::HandleHasInclude(    return true;  } -/// Use a raw lexer to analyze \p FileId, inccrementally copying parts of it +/// Use a raw lexer to analyze \p FileId, incrementally copying parts of it  /// and including content of included files recursively.  bool InclusionRewriter::Process(FileID FileId,                                  SrcMgr::CharacteristicKind FileType) @@ -353,6 +367,11 @@ bool InclusionRewriter::Process(FileID FileId,    unsigned NextToWrite = 0;    int Line = 1; // The current input file line number. +  // Ignore UTF-8 BOM, otherwise it'd end up somewhere else than the start +  // of the resulting file. +  if (FromFile.getBuffer().startswith("\xEF\xBB\xBF")) +    NextToWrite = 3; +    Token RawToken;    RawLex.LexFromRawLexer(RawToken); @@ -365,7 +384,7 @@ bool InclusionRewriter::Process(FileID FileId,        RawLex.LexFromRawLexer(RawToken);        if (RawToken.is(tok::raw_identifier))          PP.LookUpIdentifierInfo(RawToken); -      if (RawToken.is(tok::identifier) || RawToken.is(tok::kw_if)) { +      if (RawToken.getIdentifierInfo() != NULL) {          switch (RawToken.getIdentifierInfo()->getPPKeywordID()) {            case tok::pp_include:            case tok::pp_include_next: @@ -412,7 +431,9 @@ bool InclusionRewriter::Process(FileID FileId,              break;            }            case tok::pp_if: -          case tok::pp_elif: +          case tok::pp_elif: { +            bool elif = (RawToken.getIdentifierInfo()->getPPKeywordID() == +                         tok::pp_elif);              // Rewrite special builtin macros to avoid pulling in host details.              do {                // Walk over the directive. @@ -453,8 +474,33 @@ bool InclusionRewriter::Process(FileID FileId,                  OS << "*/";                }              } while (RawToken.isNot(tok::eod)); - +            if (elif) { +              OutputContentUpTo(FromFile, NextToWrite, +                                SM.getFileOffset(RawToken.getLocation()) + +                                    RawToken.getLength(), +                                EOL, Line, /*EnsureNewLine*/ true); +              WriteLineInfo(FileName, Line, FileType, EOL); +            }              break; +          } +          case tok::pp_endif: +          case tok::pp_else: { +            // We surround every #include by #if 0 to comment it out, but that +            // changes line numbers. These are fixed up right after that, but +            // the whole #include could be inside a preprocessor conditional +            // that is not processed. So it is necessary to fix the line +            // numbers one the next line after each #else/#endif as well. +            RawLex.SetKeepWhitespaceMode(true); +            do { +              RawLex.LexFromRawLexer(RawToken); +            } while (RawToken.isNot(tok::eod) && RawToken.isNot(tok::eof)); +            OutputContentUpTo( +                FromFile, NextToWrite, +                SM.getFileOffset(RawToken.getLocation()) + RawToken.getLength(), +                EOL, Line, /*EnsureNewLine*/ true); +            WriteLineInfo(FileName, Line, FileType, EOL); +            RawLex.SetKeepWhitespaceMode(false); +          }            default:              break;          } @@ -464,7 +510,7 @@ bool InclusionRewriter::Process(FileID FileId,      RawLex.LexFromRawLexer(RawToken);    }    OutputContentUpTo(FromFile, NextToWrite, -    SM.getFileOffset(SM.getLocForEndOfFile(FileId)) + 1, EOL, Line, +    SM.getFileOffset(SM.getLocForEndOfFile(FileId)), EOL, Line,      /*EnsureNewline*/true);    return true;  } @@ -476,6 +522,13 @@ void clang::RewriteIncludesInInput(Preprocessor &PP, raw_ostream *OS,    InclusionRewriter *Rewrite = new InclusionRewriter(PP, *OS,                                                       Opts.ShowLineMarkers);    PP.addPPCallbacks(Rewrite); +  // Ignore all pragmas, otherwise there will be warnings about unknown pragmas +  // (because there's nothing to handle them). +  PP.AddPragmaHandler(new EmptyPragmaHandler()); +  // Ignore also all pragma in all namespaces created +  // in Preprocessor::RegisterBuiltinPragmas(). +  PP.AddPragmaHandler("GCC", new EmptyPragmaHandler()); +  PP.AddPragmaHandler("clang", new EmptyPragmaHandler());    // First let the preprocessor process the entire file and call callbacks.    // Callbacks will record which #include's were actually performed. @@ -490,6 +543,8 @@ void clang::RewriteIncludesInInput(Preprocessor &PP, raw_ostream *OS,    do {      PP.Lex(Tok);    } while (Tok.isNot(tok::eof)); +  Rewrite->setPredefinesBuffer(SM.getBuffer(PP.getPredefinesFileID())); +  Rewrite->Process(PP.getPredefinesFileID(), SrcMgr::C_User);    Rewrite->Process(SM.getMainFileID(), SrcMgr::C_User);    OS->flush();  } diff --git a/lib/Rewrite/Frontend/RewriteMacros.cpp b/lib/Rewrite/Frontend/RewriteMacros.cpp index 3c1d2e11903d..4f6a93f7e0eb 100644 --- a/lib/Rewrite/Frontend/RewriteMacros.cpp +++ b/lib/Rewrite/Frontend/RewriteMacros.cpp @@ -115,7 +115,7 @@ void clang::RewriteMacrosInInput(Preprocessor &PP, raw_ostream *OS) {      SourceLocation PPLoc = SM.getExpansionLoc(PPTok.getLocation());      // If PPTok is from a different source file, ignore it. -    if (!SM.isFromMainFile(PPLoc)) { +    if (!SM.isWrittenInMainFile(PPLoc)) {        PP.Lex(PPTok);        continue;      } diff --git a/lib/Rewrite/Frontend/RewriteModernObjC.cpp b/lib/Rewrite/Frontend/RewriteModernObjC.cpp index 0e59b113c965..ae33ac816e3d 100644 --- a/lib/Rewrite/Frontend/RewriteModernObjC.cpp +++ b/lib/Rewrite/Frontend/RewriteModernObjC.cpp @@ -58,7 +58,6 @@ namespace {        BLOCK_IS_GLOBAL =         (1 << 28),        BLOCK_HAS_DESCRIPTOR =    (1 << 29)      }; -    static const int OBJC_ABI_VERSION = 7;      Rewriter Rewrite;      DiagnosticsEngine &Diags; @@ -103,7 +102,7 @@ namespace {      FunctionDecl *GetSuperClassFunctionDecl;      FunctionDecl *SelGetUidFunctionDecl;      FunctionDecl *CFStringFunctionDecl; -    FunctionDecl *SuperContructorFunctionDecl; +    FunctionDecl *SuperConstructorFunctionDecl;      FunctionDecl *CurFunctionDef;      /* Misc. containers needed for meta-data rewrite. */ @@ -222,6 +221,21 @@ namespace {        }        return true;      } +     +    virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) { +      for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { +        if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(*I)) { +          if (isTopLevelBlockPointerType(TD->getUnderlyingType())) +            RewriteBlockPointerDecl(TD); +          else if (TD->getUnderlyingType()->isFunctionPointerType()) +            CheckFunctionPointerDecl(TD->getUnderlyingType(), TD); +          else +            RewriteObjCQualifiedInterfaceTypes(TD); +        } +      } +      return; +    } +          void HandleTopLevelSingleDecl(Decl *D);      void HandleDeclInMainFile(Decl *D);      RewriteModernObjC(std::string inFile, raw_ostream *OS, @@ -307,7 +321,7 @@ namespace {      void ConvertSourceLocationToLineDirective(SourceLocation Loc,                                                std::string &LineString);      void RewriteForwardClassDecl(DeclGroupRef D); -    void RewriteForwardClassDecl(const SmallVector<Decl *, 8> &DG); +    void RewriteForwardClassDecl(const SmallVectorImpl<Decl *> &DG);      void RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl,                                        const std::string &typedefString);      void RewriteImplementations(); @@ -325,7 +339,7 @@ namespace {      void RewriteCategoryDecl(ObjCCategoryDecl *Dcl);      void RewriteProtocolDecl(ObjCProtocolDecl *Dcl);      void RewriteForwardProtocolDecl(DeclGroupRef D); -    void RewriteForwardProtocolDecl(const SmallVector<Decl *, 8> &DG); +    void RewriteForwardProtocolDecl(const SmallVectorImpl<Decl *> &DG);      void RewriteMethodDeclaration(ObjCMethodDecl *Method);      void RewriteProperty(ObjCPropertyDecl *prop);      void RewriteFunctionDecl(FunctionDecl *FD); @@ -411,7 +425,6 @@ namespace {                                             SourceLocation EndLoc=SourceLocation());      Expr *SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavor, -                                        QualType msgSendType,                                           QualType returnType,                                           SmallVectorImpl<QualType> &ArgTypes,                                          SmallVectorImpl<Expr*> &MsgExprs, @@ -431,7 +444,7 @@ namespace {      void SynthGetMetaClassFunctionDecl();      void SynthGetSuperClassFunctionDecl();      void SynthSelGetUidFunctionDecl(); -    void SynthSuperContructorFunctionDecl(); +    void SynthSuperConstructorFunctionDecl();      // Rewriting metadata      template<typename MethodIterator> @@ -478,7 +491,7 @@ namespace {                                   StringRef FunName);      FunctionDecl *SynthBlockInitFunctionDecl(StringRef name);      Stmt *SynthBlockInitExpr(BlockExpr *Exp, -            const SmallVector<DeclRefExpr *, 8> &InnerBlockDeclRefs); +                      const SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs);      // Misc. helper routines.      QualType getProtocolType(); @@ -490,8 +503,8 @@ namespace {      bool IsDeclStmtInForeachHeader(DeclStmt *DS);      void CollectBlockDeclRefInfo(BlockExpr *Exp);      void GetBlockDeclRefExprs(Stmt *S); -    void GetInnerBlockDeclRefExprs(Stmt *S,  -                SmallVector<DeclRefExpr *, 8> &InnerBlockDeclRefs, +    void GetInnerBlockDeclRefExprs(Stmt *S, +                SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs,                  llvm::SmallPtrSet<const DeclContext *, 8> &InnerContexts);      // We avoid calling Type::isBlockPointerType(), since it operates on the @@ -686,7 +699,7 @@ void RewriteModernObjC::InitializeCommon(ASTContext &context) {    ProtocolTypeDecl = 0;    ConstantStringDecl = 0;    BcLabelCount = 0; -  SuperContructorFunctionDecl = 0; +  SuperConstructorFunctionDecl = 0;    NumObjCStringLiterals = 0;    PropParentMap = 0;    CurrentBody = 0; @@ -791,7 +804,7 @@ void RewriteModernObjC::HandleTopLevelSingleDecl(Decl *D) {      }    }    // If we have a decl in the main file, see if we should rewrite it. -  if (SM->isFromMainFile(Loc)) +  if (SM->isWrittenInMainFile(Loc))      return HandleDeclInMainFile(D);  } @@ -1068,23 +1081,26 @@ void RewriteModernObjC::RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl  void RewriteModernObjC::RewriteForwardClassDecl(DeclGroupRef D) {    std::string typedefString;    for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { -    ObjCInterfaceDecl *ForwardDecl = cast<ObjCInterfaceDecl>(*I); -    if (I == D.begin()) { -      // 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. -      typedefString += "// @class "; -      typedefString += ForwardDecl->getNameAsString(); -      typedefString += ";"; +    if (ObjCInterfaceDecl *ForwardDecl = dyn_cast<ObjCInterfaceDecl>(*I)) { +      if (I == D.begin()) { +        // 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. +        typedefString += "// @class "; +        typedefString += ForwardDecl->getNameAsString(); +        typedefString += ";"; +      } +      RewriteOneForwardClassDecl(ForwardDecl, typedefString);      } -    RewriteOneForwardClassDecl(ForwardDecl, typedefString); +    else +      HandleTopLevelSingleDecl(*I);    }    DeclGroupRef::iterator I = D.begin();    RewriteForwardClassEpilogue(cast<ObjCInterfaceDecl>(*I), typedefString);  }  void RewriteModernObjC::RewriteForwardClassDecl( -                                const SmallVector<Decl *, 8> &D) { +                                const SmallVectorImpl<Decl *> &D) {    std::string typedefString;    for (unsigned i = 0; i < D.size(); i++) {      ObjCInterfaceDecl *ForwardDecl = cast<ObjCInterfaceDecl>(D[i]); @@ -1202,7 +1218,7 @@ void RewriteModernObjC::RewriteForwardProtocolDecl(DeclGroupRef D) {  }  void  -RewriteModernObjC::RewriteForwardProtocolDecl(const SmallVector<Decl *, 8> &DG) { +RewriteModernObjC::RewriteForwardProtocolDecl(const SmallVectorImpl<Decl *> &DG) {    SourceLocation LocStart = DG[0]->getLocStart();    if (LocStart.isInvalid())      llvm_unreachable("Invalid SourceLocation"); @@ -1618,23 +1634,23 @@ Stmt *RewriteModernObjC::RewritePropertyOrImplicitGetter(PseudoObjectExpr *Pseud  }  /// SynthCountByEnumWithState - To print: -/// ((unsigned int (*) -///  (id, SEL, struct __objcFastEnumerationState *, id *, unsigned int)) +/// ((NSUInteger (*) +///  (id, SEL, struct __objcFastEnumerationState *, id *, NSUInteger))  ///  (void *)objc_msgSend)((id)l_collection,  ///                        sel_registerName(  ///                          "countByEnumeratingWithState:objects:count:"),  ///                        &enumState, -///                        (id *)__rw_items, (unsigned int)16) +///                        (id *)__rw_items, (NSUInteger)16)  ///  void RewriteModernObjC::SynthCountByEnumWithState(std::string &buf) { -  buf += "((unsigned int (*) (id, SEL, struct __objcFastEnumerationState *, " -  "id *, unsigned int))(void *)objc_msgSend)"; +  buf += "((_WIN_NSUInteger (*) (id, SEL, struct __objcFastEnumerationState *, " +  "id *, _WIN_NSUInteger))(void *)objc_msgSend)";    buf += "\n\t\t";    buf += "((id)l_collection,\n\t\t";    buf += "sel_registerName(\"countByEnumeratingWithState:objects:count:\"),";    buf += "\n\t\t";    buf += "&enumState, " -         "(id *)__rw_items, (unsigned int)16)"; +         "(id *)__rw_items, (_WIN_NSUInteger)16)";  }  /// RewriteBreakStmt - Rewrite for a break-stmt inside an ObjC2's foreach @@ -1694,7 +1710,7 @@ Stmt *RewriteModernObjC::RewriteContinueStmt(ContinueStmt *S) {  ///   struct __objcFastEnumerationState enumState = { 0 };  ///   id __rw_items[16];  ///   id l_collection = (id)collection; -///   unsigned long limit = [l_collection countByEnumeratingWithState:&enumState +///   NSUInteger limit = [l_collection countByEnumeratingWithState:&enumState  ///                                       objects:__rw_items count:16];  /// if (limit) {  ///   unsigned long startMutations = *enumState.mutationsPtr; @@ -1707,8 +1723,8 @@ Stmt *RewriteModernObjC::RewriteContinueStmt(ContinueStmt *S) {  ///             stmts;  ///             __continue_label: ;  ///        } while (counter < limit); -///   } while (limit = [l_collection countByEnumeratingWithState:&enumState -///                                  objects:__rw_items count:16]); +///   } while ((limit = [l_collection countByEnumeratingWithState:&enumState +///                                  objects:__rw_items count:16]));  ///   elem = nil;  ///   __break_label: ;  ///  } @@ -1791,15 +1807,15 @@ Stmt *RewriteModernObjC::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,    // unsigned long limit = [l_collection countByEnumeratingWithState:&enumState    //                                   objects:__rw_items count:16];    // which is synthesized into: -  // unsigned int limit = -  // ((unsigned int (*) -  //  (id, SEL, struct __objcFastEnumerationState *, id *, unsigned int)) +  // NSUInteger limit = +  // ((NSUInteger (*) +  //  (id, SEL, struct __objcFastEnumerationState *, id *, NSUInteger))    //  (void *)objc_msgSend)((id)l_collection,    //                        sel_registerName(    //                          "countByEnumeratingWithState:objects:count:"),    //                        (struct __objcFastEnumerationState *)&state, -  //                        (id *)__rw_items, (unsigned int)16); -  buf += "unsigned long limit =\n\t\t"; +  //                        (id *)__rw_items, (NSUInteger)16); +  buf += "_WIN_NSUInteger limit =\n\t\t";    SynthCountByEnumWithState(buf);    buf += ";\n\t";    /// if (limit) { @@ -1826,8 +1842,8 @@ Stmt *RewriteModernObjC::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,    ///            __continue_label: ;    ///        } while (counter < limit); -  ///   } while (limit = [l_collection countByEnumeratingWithState:&enumState -  ///                                  objects:__rw_items count:16]); +  ///   } while ((limit = [l_collection countByEnumeratingWithState:&enumState +  ///                                  objects:__rw_items count:16]));    ///   elem = nil;    ///   __break_label: ;    ///  } @@ -1841,9 +1857,9 @@ Stmt *RewriteModernObjC::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,    buf += ": ;";    buf += "\n\t\t";    buf += "} while (counter < limit);\n\t"; -  buf += "} while (limit = "; +  buf += "} while ((limit = ";    SynthCountByEnumWithState(buf); -  buf += ");\n\t"; +  buf += "));\n\t";    buf += elementName;    buf += " = ((";    buf += elementTypeAsString; @@ -1906,7 +1922,7 @@ Stmt *RewriteModernObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S)    std::string buf;    SourceLocation SynchLoc = S->getAtSynchronizedLoc();    ConvertSourceLocationToLineDirective(SynchLoc, buf); -  buf += "{ id _rethrow = 0; id _sync_obj = "; +  buf += "{ id _rethrow = 0; id _sync_obj = (id)";    const char *lparenBuf = startBuf;    while (*lparenBuf != '(') lparenBuf++; @@ -2447,9 +2463,9 @@ void RewriteModernObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) {    InsertText(FunLocStart, FdStr);  } -// SynthSuperContructorFunctionDecl - id __rw_objc_super(id obj, id super); -void RewriteModernObjC::SynthSuperContructorFunctionDecl() { -  if (SuperContructorFunctionDecl) +// SynthSuperConstructorFunctionDecl - id __rw_objc_super(id obj, id super); +void RewriteModernObjC::SynthSuperConstructorFunctionDecl() { +  if (SuperConstructorFunctionDecl)      return;    IdentifierInfo *msgSendIdent = &Context->Idents.get("__rw_objc_super");    SmallVector<QualType, 16> ArgTys; @@ -2459,7 +2475,7 @@ void RewriteModernObjC::SynthSuperContructorFunctionDecl() {    ArgTys.push_back(argT);    QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),                                                 ArgTys); -  SuperContructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl, +  SuperConstructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl,                                                       SourceLocation(),                                                       SourceLocation(),                                                       msgSendIdent, msgSendType, @@ -3183,7 +3199,6 @@ void RewriteModernObjC::RewriteLineDirective(const Decl *D) {  /// starting with receiver.  /// Method - Method being rewritten.  Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavor, -                                                 QualType msgSendType,                                                    QualType returnType,                                                    SmallVectorImpl<QualType> &ArgTypes,                                                   SmallVectorImpl<Expr*> &MsgExprs, @@ -3199,6 +3214,7 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla    std::string name = "__Stret"; name += utostr(stretCount);    std::string str =       "extern \"C\" void * __cdecl memset(void *_Dst, int _Val, size_t _Size);\n"; +  str += "namespace {\n";    str += "struct "; str += name;    str += " {\n\t";    str += name; @@ -3217,9 +3233,27 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla    }    str += ") {\n"; -  str += "\t  if (receiver == 0)\n"; +  str += "\t  unsigned size = sizeof("; +  str += returnType.getAsString(Context->getPrintingPolicy()); str += ");\n"; +   +  str += "\t  if (size == 1 || size == 2 || size == 4 || size == 8)\n"; +   +  str += "\t    s = (("; str += castType.getAsString(Context->getPrintingPolicy()); +  str += ")(void *)objc_msgSend)(receiver, sel"; +  for (unsigned i = 2; i < ArgTypes.size(); i++) { +    str += ", arg"; str += utostr(i); +  } +  // could be vararg. +  for (unsigned i = ArgTypes.size(); i < MsgExprs.size(); i++) { +    str += ", arg"; str += utostr(i); +  } +  str+= ");\n"; +   +  str += "\t  else if (receiver == 0)\n";    str += "\t    memset((void*)&s, 0, sizeof(s));\n";    str += "\t  else\n"; +   +      str += "\t    s = (("; str += castType.getAsString(Context->getPrintingPolicy());    str += ")(void *)objc_msgSend_stret)(receiver, sel";    for (unsigned i = 2; i < ArgTypes.size(); i++) { @@ -3229,12 +3263,13 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla    for (unsigned i = ArgTypes.size(); i < MsgExprs.size(); i++) {      str += ", arg"; str += utostr(i);    } -      str += ");\n"; +   +      str += "\t}\n";    str += "\t"; str += returnType.getAsString(Context->getPrintingPolicy());    str += " s;\n"; -  str += "};\n\n"; +  str += "};\n};\n\n";    SourceLocation FunLocStart;    if (CurFunctionDef)      FunLocStart = getFunctionSourceLocation(*this, CurFunctionDef); @@ -3357,9 +3392,9 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp,      Expr *SuperRep;      if (LangOpts.MicrosoftExt) { -      SynthSuperContructorFunctionDecl(); -      // Simulate a contructor call... -      DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, +      SynthSuperConstructorFunctionDecl(); +      // Simulate a constructor call... +      DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperConstructorFunctionDecl,                                                     false, superType, VK_LValue,                                                     SourceLocation());        SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, @@ -3465,9 +3500,9 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp,      Expr *SuperRep;      if (LangOpts.MicrosoftExt) { -      SynthSuperContructorFunctionDecl(); -      // Simulate a contructor call... -      DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, +      SynthSuperConstructorFunctionDecl(); +      // Simulate a constructor call... +      DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperConstructorFunctionDecl,                                                     false, superType, VK_LValue,                                                     SourceLocation());        SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, @@ -3651,39 +3686,11 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp,      // expression which dictate which one to envoke depending on size of      // method's return type. -    Expr *STCE = SynthMsgSendStretCallExpr(MsgSendStretFlavor,  -                                           msgSendType, returnType,  +    Expr *STCE = SynthMsgSendStretCallExpr(MsgSendStretFlavor, +                                           returnType,                                             ArgTypes, MsgExprs,                                             Exp->getMethodDecl()); - -    // Build sizeof(returnType) -    UnaryExprOrTypeTraitExpr *sizeofExpr = -       new (Context) UnaryExprOrTypeTraitExpr(UETT_SizeOf, -                                 Context->getTrivialTypeSourceInfo(returnType), -                                 Context->getSizeType(), SourceLocation(), -                                 SourceLocation()); -    // (sizeof(returnType) <= 8 ? objc_msgSend(...) : objc_msgSend_stret(...)) -    // FIXME: Value of 8 is base on ppc32/x86 ABI for the most common cases. -    // For X86 it is more complicated and some kind of target specific routine -    // is needed to decide what to do. -    unsigned IntSize = -      static_cast<unsigned>(Context->getTypeSize(Context->IntTy)); -    IntegerLiteral *limit = IntegerLiteral::Create(*Context, -                                                   llvm::APInt(IntSize, 8), -                                                   Context->IntTy, -                                                   SourceLocation()); -    BinaryOperator *lessThanExpr =  -      new (Context) BinaryOperator(sizeofExpr, limit, BO_LE, Context->IntTy, -                                   VK_RValue, OK_Ordinary, SourceLocation(), -                                   false); -    // (sizeof(returnType) <= 8 ? objc_msgSend(...) : objc_msgSend_stret(...)) -    ConditionalOperator *CondExpr = -      new (Context) ConditionalOperator(lessThanExpr, -                                        SourceLocation(), CE, -                                        SourceLocation(), STCE, -                                        returnType, VK_RValue, OK_Ordinary); -    ReplacingStmt = new (Context) ParenExpr(SourceLocation(), SourceLocation(),  -                                            CondExpr); +    ReplacingStmt = STCE;    }    // delete Exp; leak for now, see RewritePropertyOrImplicitSetter() usage for more info.    return ReplacingStmt; @@ -4262,7 +4269,7 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,    // Create local declarations to avoid rewriting all closure decl ref exprs.    // First, emit a declaration for all "by ref" decls. -  for (SmallVector<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), +  for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin(),         E = BlockByRefDecls.end(); I != E; ++I) {      S += "  ";      std::string Name = (*I)->getNameAsString(); @@ -4273,7 +4280,7 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,      S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by ref\n";    }    // Next, emit a declaration for all "by copy" declarations. -  for (SmallVector<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(), +  for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin(),         E = BlockByCopyDecls.end(); I != E; ++I) {      S += "  ";      // Handle nested closure invocation. For example: @@ -4374,7 +4381,7 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta    if (BlockDeclRefs.size()) {      // Output all "by copy" declarations. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin(),           E = BlockByCopyDecls.end(); I != E; ++I) {        S += "  ";        std::string FieldName = (*I)->getNameAsString(); @@ -4403,7 +4410,7 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta        S += FieldName + ";\n";      }      // Output all "by ref" declarations. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin(),           E = BlockByRefDecls.end(); I != E; ++I) {        S += "  ";        std::string FieldName = (*I)->getNameAsString(); @@ -4422,7 +4429,7 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta      Constructor += ", int flags=0)";      // Initialize all "by copy" arguments.      bool firsTime = true; -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin(),           E = BlockByCopyDecls.end(); I != E; ++I) {        std::string Name = (*I)->getNameAsString();          if (firsTime) { @@ -4437,7 +4444,7 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta            Constructor += Name + "(_" + Name + ")";      }      // Initialize all "by ref" arguments. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin(),           E = BlockByRefDecls.end(); I != E; ++I) {        std::string Name = (*I)->getNameAsString();        if (firsTime) { @@ -4662,8 +4669,8 @@ void RewriteModernObjC::GetBlockDeclRefExprs(Stmt *S) {    return;  } -void RewriteModernObjC::GetInnerBlockDeclRefExprs(Stmt *S,  -                SmallVector<DeclRefExpr *, 8> &InnerBlockDeclRefs, +void RewriteModernObjC::GetInnerBlockDeclRefExprs(Stmt *S, +                SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs,                  llvm::SmallPtrSet<const DeclContext *, 8> &InnerContexts) {    for (Stmt::child_range CI = S->children(); CI; ++CI)      if (*CI) { @@ -5407,7 +5414,7 @@ FunctionDecl *RewriteModernObjC::SynthBlockInitFunctionDecl(StringRef name) {  }  Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, -          const SmallVector<DeclRefExpr *, 8> &InnerBlockDeclRefs) { +                     const SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs) {    const BlockDecl *block = Exp->getBlockDecl(); @@ -5474,7 +5481,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,    FunctionDecl *FD;    Expr *NewRep; -  // Simulate a contructor call... +  // Simulate a constructor call...    std::string Tag;    if (GlobalBlockExpr) @@ -5520,7 +5527,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,    if (BlockDeclRefs.size()) {      Expr *Exp;      // Output all "by copy" declarations. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin(),           E = BlockByCopyDecls.end(); I != E; ++I) {        if (isObjCType((*I)->getType())) {          // FIXME: Conform to ABI ([[obj retain] autorelease]). @@ -5554,7 +5561,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,        InitExprs.push_back(Exp);      }      // Output all "by ref" declarations. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin(),           E = BlockByRefDecls.end(); I != E; ++I) {        ValueDecl *ND = (*I);        std::string Name(ND->getNameAsString()); @@ -6166,6 +6173,11 @@ void RewriteModernObjC::Initialize(ASTContext &context) {    Preamble += "__OBJC_RW_DLLIMPORT int objc_sync_enter( struct objc_object *);\n";    Preamble += "__OBJC_RW_DLLIMPORT int objc_sync_exit( struct objc_object *);\n";    Preamble += "__OBJC_RW_DLLIMPORT Protocol *objc_getProtocol(const char *);\n"; +  Preamble += "#ifdef _WIN64\n"; +  Preamble += "typedef unsigned long long  _WIN_NSUInteger;\n"; +  Preamble += "#else\n"; +  Preamble += "typedef unsigned int _WIN_NSUInteger;\n"; +  Preamble += "#endif\n";    Preamble += "#ifndef __FASTENUMERATIONSTATE\n";    Preamble += "struct __objcFastEnumerationState {\n\t";    Preamble += "unsigned long state;\n\t"; diff --git a/lib/Rewrite/Frontend/RewriteObjC.cpp b/lib/Rewrite/Frontend/RewriteObjC.cpp index 2f5cd0f6c6c6..3dda2c56f5dc 100644 --- a/lib/Rewrite/Frontend/RewriteObjC.cpp +++ b/lib/Rewrite/Frontend/RewriteObjC.cpp @@ -100,7 +100,7 @@ namespace {      FunctionDecl *GetSuperClassFunctionDecl;      FunctionDecl *SelGetUidFunctionDecl;      FunctionDecl *CFStringFunctionDecl; -    FunctionDecl *SuperContructorFunctionDecl; +    FunctionDecl *SuperConstructorFunctionDecl;      FunctionDecl *CurFunctionDef;      FunctionDecl *CurFunctionDeclToDeclareForBlock; @@ -267,7 +267,7 @@ namespace {      void RewriteRecordBody(RecordDecl *RD);      void RewriteInclude();      void RewriteForwardClassDecl(DeclGroupRef D); -    void RewriteForwardClassDecl(const SmallVector<Decl *, 8> &DG); +    void RewriteForwardClassDecl(const SmallVectorImpl<Decl *> &DG);      void RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl,                                        const std::string &typedefString);      void RewriteImplementations(); @@ -285,7 +285,7 @@ namespace {      void RewriteCategoryDecl(ObjCCategoryDecl *Dcl);      void RewriteProtocolDecl(ObjCProtocolDecl *Dcl);      void RewriteForwardProtocolDecl(DeclGroupRef D); -    void RewriteForwardProtocolDecl(const SmallVector<Decl *, 8> &DG); +    void RewriteForwardProtocolDecl(const SmallVectorImpl<Decl *> &DG);      void RewriteMethodDeclaration(ObjCMethodDecl *Method);      void RewriteProperty(ObjCPropertyDecl *prop);      void RewriteFunctionDecl(FunctionDecl *FD); @@ -377,7 +377,7 @@ namespace {      void SynthGetMetaClassFunctionDecl();      void SynthGetSuperClassFunctionDecl();      void SynthSelGetUidFunctionDecl(); -    void SynthSuperContructorFunctionDecl(); +    void SynthSuperConstructorFunctionDecl();      std::string SynthesizeByrefCopyDestroyHelper(VarDecl *VD, int flag);      std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, @@ -395,7 +395,7 @@ namespace {                                   StringRef FunName);      FunctionDecl *SynthBlockInitFunctionDecl(StringRef name);      Stmt *SynthBlockInitExpr(BlockExpr *Exp, -            const SmallVector<DeclRefExpr *, 8> &InnerBlockDeclRefs); +            const SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs);      // Misc. helper routines.      QualType getProtocolType(); @@ -408,8 +408,8 @@ namespace {      bool IsDeclStmtInForeachHeader(DeclStmt *DS);      void CollectBlockDeclRefInfo(BlockExpr *Exp);      void GetBlockDeclRefExprs(Stmt *S); -    void GetInnerBlockDeclRefExprs(Stmt *S,  -                SmallVector<DeclRefExpr *, 8> &InnerBlockDeclRefs, +    void GetInnerBlockDeclRefExprs(Stmt *S, +                SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs,                  llvm::SmallPtrSet<const DeclContext *, 8> &InnerContexts);      // We avoid calling Type::isBlockPointerType(), since it operates on the @@ -623,7 +623,7 @@ void RewriteObjC::InitializeCommon(ASTContext &context) {    ProtocolTypeDecl = 0;    ConstantStringDecl = 0;    BcLabelCount = 0; -  SuperContructorFunctionDecl = 0; +  SuperConstructorFunctionDecl = 0;    NumObjCStringLiterals = 0;    PropParentMap = 0;    CurrentBody = 0; @@ -721,7 +721,7 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) {      }    }    // If we have a decl in the main file, see if we should rewrite it. -  if (SM->isFromMainFile(Loc)) +  if (SM->isWrittenInMainFile(Loc))      return HandleDeclInMainFile(D);  } @@ -926,7 +926,7 @@ void RewriteObjC::RewriteForwardClassDecl(DeclGroupRef D) {    RewriteForwardClassEpilogue(cast<ObjCInterfaceDecl>(*I), typedefString);  } -void RewriteObjC::RewriteForwardClassDecl(const SmallVector<Decl *, 8> &D) { +void RewriteObjC::RewriteForwardClassDecl(const SmallVectorImpl<Decl *> &D) {    std::string typedefString;    for (unsigned i = 0; i < D.size(); i++) {      ObjCInterfaceDecl *ForwardDecl = cast<ObjCInterfaceDecl>(D[i]); @@ -1038,7 +1038,7 @@ void RewriteObjC::RewriteForwardProtocolDecl(DeclGroupRef D) {  }  void  -RewriteObjC::RewriteForwardProtocolDecl(const SmallVector<Decl *, 8> &DG) { +RewriteObjC::RewriteForwardProtocolDecl(const SmallVectorImpl<Decl *> &DG) {    SourceLocation LocStart = DG[0]->getLocStart();    if (LocStart.isInvalid())      llvm_unreachable("Invalid SourceLocation"); @@ -2347,9 +2347,9 @@ void RewriteObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) {    CurFunctionDeclToDeclareForBlock = 0;  } -// SynthSuperContructorFunctionDecl - id objc_super(id obj, id super); -void RewriteObjC::SynthSuperContructorFunctionDecl() { -  if (SuperContructorFunctionDecl) +// SynthSuperConstructorFunctionDecl - id objc_super(id obj, id super); +void RewriteObjC::SynthSuperConstructorFunctionDecl() { +  if (SuperConstructorFunctionDecl)      return;    IdentifierInfo *msgSendIdent = &Context->Idents.get("__rw_objc_super");    SmallVector<QualType, 16> ArgTys; @@ -2359,7 +2359,7 @@ void RewriteObjC::SynthSuperContructorFunctionDecl() {    ArgTys.push_back(argT);    QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),                                                 ArgTys); -  SuperContructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl, +  SuperConstructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl,                                                       SourceLocation(),                                                       SourceLocation(),                                                       msgSendIdent, msgSendType, @@ -2746,9 +2746,9 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp,      Expr *SuperRep;      if (LangOpts.MicrosoftExt) { -      SynthSuperContructorFunctionDecl(); -      // Simulate a contructor call... -      DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, +      SynthSuperConstructorFunctionDecl(); +      // Simulate a constructor call... +      DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperConstructorFunctionDecl,                                                     false, superType, VK_LValue,                                                     SourceLocation());        SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, @@ -2854,9 +2854,9 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp,      Expr *SuperRep;      if (LangOpts.MicrosoftExt) { -      SynthSuperContructorFunctionDecl(); -      // Simulate a contructor call... -      DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, +      SynthSuperConstructorFunctionDecl(); +      // Simulate a constructor call... +      DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperConstructorFunctionDecl,                                                     false, superType, VK_LValue,                                                     SourceLocation());        SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, @@ -3366,7 +3366,7 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,    // Create local declarations to avoid rewriting all closure decl ref exprs.    // First, emit a declaration for all "by ref" decls. -  for (SmallVector<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), +  for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin(),         E = BlockByRefDecls.end(); I != E; ++I) {      S += "  ";      std::string Name = (*I)->getNameAsString(); @@ -3377,7 +3377,7 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,      S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by ref\n";    }    // Next, emit a declaration for all "by copy" declarations. -  for (SmallVector<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(), +  for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin(),         E = BlockByCopyDecls.end(); I != E; ++I) {      S += "  ";      // Handle nested closure invocation. For example: @@ -3478,7 +3478,7 @@ std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag,    if (BlockDeclRefs.size()) {      // Output all "by copy" declarations. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin(),           E = BlockByCopyDecls.end(); I != E; ++I) {        S += "  ";        std::string FieldName = (*I)->getNameAsString(); @@ -3507,7 +3507,7 @@ std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag,        S += FieldName + ";\n";      }      // Output all "by ref" declarations. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin(),           E = BlockByRefDecls.end(); I != E; ++I) {        S += "  ";        std::string FieldName = (*I)->getNameAsString(); @@ -3526,7 +3526,7 @@ std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag,      Constructor += ", int flags=0)";      // Initialize all "by copy" arguments.      bool firsTime = true; -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin(),           E = BlockByCopyDecls.end(); I != E; ++I) {        std::string Name = (*I)->getNameAsString();          if (firsTime) { @@ -3541,7 +3541,7 @@ std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag,            Constructor += Name + "(_" + Name + ")";      }      // Initialize all "by ref" arguments. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin(),           E = BlockByRefDecls.end(); I != E; ++I) {        std::string Name = (*I)->getNameAsString();        if (firsTime) { @@ -3743,8 +3743,8 @@ void RewriteObjC::GetBlockDeclRefExprs(Stmt *S) {    return;  } -void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S,  -                SmallVector<DeclRefExpr *, 8> &InnerBlockDeclRefs, +void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S, +                SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs,                  llvm::SmallPtrSet<const DeclContext *, 8> &InnerContexts) {    for (Stmt::child_range CI = S->children(); CI; ++CI)      if (*CI) { @@ -4452,7 +4452,7 @@ FunctionDecl *RewriteObjC::SynthBlockInitFunctionDecl(StringRef name) {  }  Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, -          const SmallVector<DeclRefExpr *, 8> &InnerBlockDeclRefs) { +                     const SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs) {    const BlockDecl *block = Exp->getBlockDecl();    Blocks.push_back(Exp); @@ -4510,7 +4510,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,    FunctionDecl *FD;    Expr *NewRep; -  // Simulate a contructor call... +  // Simulate a constructor call...    FD = SynthBlockInitFunctionDecl(Tag);    DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, FType, VK_RValue,                                                 SourceLocation()); @@ -4548,7 +4548,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,    if (BlockDeclRefs.size()) {      Expr *Exp;      // Output all "by copy" declarations. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin(),           E = BlockByCopyDecls.end(); I != E; ++I) {        if (isObjCType((*I)->getType())) {          // FIXME: Conform to ABI ([[obj retain] autorelease]). @@ -4582,7 +4582,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,        InitExprs.push_back(Exp);      }      // Output all "by ref" declarations. -    for (SmallVector<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), +    for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin(),           E = BlockByRefDecls.end(); I != E; ++I) {        ValueDecl *ND = (*I);        std::string Name(ND->getNameAsString());  | 
