diff options
Diffstat (limited to 'lib/Frontend')
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 44 | ||||
-rw-r--r-- | lib/Frontend/FrontendActions.cpp | 7 | ||||
-rw-r--r-- | lib/Frontend/InitHeaderSearch.cpp | 65 | ||||
-rw-r--r-- | lib/Frontend/InitPreprocessor.cpp | 8 | ||||
-rw-r--r-- | lib/Frontend/MultiplexConsumer.cpp | 9 | ||||
-rw-r--r-- | lib/Frontend/Rewrite/InclusionRewriter.cpp | 92 | ||||
-rw-r--r-- | lib/Frontend/Rewrite/RewriteModernObjC.cpp | 32 | ||||
-rw-r--r-- | lib/Frontend/Rewrite/RewriteObjC.cpp | 50 |
8 files changed, 144 insertions, 163 deletions
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 8546763..dd664ca 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1521,6 +1521,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Args.hasArg(OPT_fmodules_decluse) || Opts.ModulesStrictDeclUse; Opts.ModulesLocalVisibility = Args.hasArg(OPT_fmodules_local_submodule_visibility); + Opts.ModulesHideInternalLinkage = + !Args.hasArg(OPT_fno_modules_hide_internal_linkage); Opts.ModulesSearchAll = Opts.Modules && !Args.hasArg(OPT_fno_modules_search_all) && Args.hasArg(OPT_fmodules_search_all); @@ -1586,6 +1588,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.ImplementationOfModule = Args.getLastArgValue(OPT_fmodule_implementation_of); Opts.ModuleFeatures = Args.getAllArgValues(OPT_fmodule_feature); + std::sort(Opts.ModuleFeatures.begin(), Opts.ModuleFeatures.end()); Opts.NativeHalfType |= Args.hasArg(OPT_fnative_half_type); Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns); Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm); @@ -1847,37 +1850,37 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, std::unique_ptr<OptTable> Opts(createDriverOptTable()); const unsigned IncludedFlagsBitmask = options::CC1Option; unsigned MissingArgIndex, MissingArgCount; - std::unique_ptr<InputArgList> Args( - Opts->ParseArgs(ArgBegin, ArgEnd, MissingArgIndex, MissingArgCount, - IncludedFlagsBitmask)); + InputArgList Args = + Opts->ParseArgs(llvm::makeArrayRef(ArgBegin, ArgEnd), MissingArgIndex, + MissingArgCount, IncludedFlagsBitmask); // Check for missing argument error. if (MissingArgCount) { Diags.Report(diag::err_drv_missing_argument) - << Args->getArgString(MissingArgIndex) << MissingArgCount; + << Args.getArgString(MissingArgIndex) << MissingArgCount; Success = false; } // Issue errors on unknown arguments. - for (const Arg *A : Args->filtered(OPT_UNKNOWN)) { - Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(*Args); + for (const Arg *A : Args.filtered(OPT_UNKNOWN)) { + Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args); Success = false; } - Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), *Args, Diags); - Success &= ParseMigratorArgs(Res.getMigratorOpts(), *Args); - ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args); - Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, &Diags); - ParseCommentArgs(Res.getLangOpts()->CommentOpts, *Args); - ParseFileSystemArgs(Res.getFileSystemOpts(), *Args); + Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags); + Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args); + ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args); + Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags); + ParseCommentArgs(Res.getLangOpts()->CommentOpts, Args); + ParseFileSystemArgs(Res.getFileSystemOpts(), Args); // FIXME: We shouldn't have to pass the DashX option around here - InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags); - ParseTargetArgs(Res.getTargetOpts(), *Args); - Success &= ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags, + InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags); + ParseTargetArgs(Res.getTargetOpts(), Args); + Success &= ParseCodeGenArgs(Res.getCodeGenOpts(), Args, DashX, Diags, Res.getTargetOpts()); - ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args); + ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args); if (DashX != IK_AST && DashX != IK_LLVM_IR) { - ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags); + ParseLangArgs(*Res.getLangOpts(), Args, DashX, Diags); if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC) Res.getLangOpts()->ObjCExceptions = 1; } @@ -1886,8 +1889,8 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, // ParsePreprocessorArgs and remove the FileManager // parameters from the function and the "FileManager.h" #include. FileManager FileMgr(Res.getFileSystemOpts()); - ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, FileMgr, Diags); - ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args, + ParsePreprocessorArgs(Res.getPreprocessorOpts(), Args, FileMgr, Diags); + ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), Args, Res.getFrontendOpts().ProgramAction); return Success; } @@ -1965,6 +1968,9 @@ std::string CompilerInvocation::getModuleHash() const { #define BENIGN_LANGOPT(Name, Bits, Default, Description) #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) #include "clang/Basic/LangOptions.def" + + for (StringRef Feature : LangOpts->ModuleFeatures) + code = hash_combine(code, Feature); // Extend the signature with the target options. code = hash_combine(code, TargetOpts->Triple, TargetOpts->CPU, diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 6f202a1..4997764 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -470,6 +470,13 @@ namespace { #define BENIGN_LANGOPT(Name, Bits, Default, Description) #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) #include "clang/Basic/LangOptions.def" + + if (!LangOpts.ModuleFeatures.empty()) { + Out.indent(4) << "Module features:\n"; + for (StringRef Feature : LangOpts.ModuleFeatures) + Out.indent(6) << Feature << "\n"; + } + return false; } diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp index bf8470e..e3a17c9 100644 --- a/lib/Frontend/InitHeaderSearch.cpp +++ b/lib/Frontend/InitHeaderSearch.cpp @@ -82,11 +82,6 @@ public: StringRef Arch, StringRef Version); - /// AddMinGW64CXXPaths - Add the necessary paths to support - /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64. - void AddMinGW64CXXPaths(StringRef Base, - StringRef Version); - // AddDefaultCIncludePaths - Add paths that should always be searched. void AddDefaultCIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts); @@ -208,19 +203,6 @@ void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base, CXXSystem, false); } -void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base, - StringRef Version) { - // Assumes Base is HeaderSearchOpts' ResourceDir - AddPath(Base + "/../../../include/c++/" + Version, - CXXSystem, false); - AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32", - CXXSystem, false); - AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32", - CXXSystem, false); - AddPath(Base + "/../../../include/c++/" + Version + "/backward", - CXXSystem, false); -} - void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { llvm::Triple::OSType os = triple.getOS(); @@ -234,6 +216,9 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, case llvm::Triple::Bitrig: case llvm::Triple::NaCl: break; + case llvm::Triple::Win32: + if (triple.getEnvironment() != llvm::Triple::Cygnus) + break; default: // FIXME: temporary hack: hard-coded paths. AddPath("/usr/local/include", System, false); @@ -323,26 +308,6 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, AddPath("/usr/include/w32api", System, false); break; case llvm::Triple::GNU: - // mingw-w64 crt include paths - // <sysroot>/i686-w64-mingw32/include - SmallString<128> P = StringRef(HSOpts.ResourceDir); - llvm::sys::path::append(P, "../../../i686-w64-mingw32/include"); - AddPath(P, System, false); - - // <sysroot>/x86_64-w64-mingw32/include - P.resize(HSOpts.ResourceDir.size()); - llvm::sys::path::append(P, "../../../x86_64-w64-mingw32/include"); - AddPath(P, System, false); - - // mingw.org crt include paths - // <sysroot>/include - P.resize(HSOpts.ResourceDir.size()); - llvm::sys::path::append(P, "../../../include"); - AddPath(P, System, false); - AddPath("/mingw/include", System, false); -#if defined(LLVM_ON_WIN32) - AddPath("c:/mingw/include", System, false); -#endif break; } break; @@ -419,27 +384,8 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOp // g++-4 / Cygwin-1.5 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); break; - case llvm::Triple::GNU: - // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32) - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.1"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.2"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.3"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.8.0"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.8.1"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.8.2"); - // mingw.org C++ include paths -#if defined(LLVM_ON_WIN32) - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.0"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.1"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.2"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.3"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.0"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.1"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.2"); -#endif - break; } + break; case llvm::Triple::DragonFly: if (llvm::sys::fs::exists("/usr/lib/gcc47")) AddPath("/usr/include/c++/4.7", CXXSystem, false); @@ -482,8 +428,7 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang, return; case llvm::Triple::Win32: - if (triple.getEnvironment() == llvm::Triple::MSVC || - triple.getEnvironment() == llvm::Triple::Itanium || + if (triple.getEnvironment() != llvm::Triple::Cygnus || triple.isOSBinFormatMachO()) return; break; diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 2417146..025c8b9 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -868,6 +868,14 @@ static void InitializePredefinedMacros(const TargetInfo &TI, "__attribute__((objc_ownership(none)))"); } + // On Darwin, there are __double_underscored variants of the type + // nullability qualifiers. + if (TI.getTriple().isOSDarwin()) { + Builder.defineMacro("__nonnull", "_Nonnull"); + Builder.defineMacro("__null_unspecified", "_Null_unspecified"); + Builder.defineMacro("__nullable", "_Nullable"); + } + // OpenMP definition if (LangOpts.OpenMP) { // OpenMP 2.2: diff --git a/lib/Frontend/MultiplexConsumer.cpp b/lib/Frontend/MultiplexConsumer.cpp index a53f4d2..91ee100 100644 --- a/lib/Frontend/MultiplexConsumer.cpp +++ b/lib/Frontend/MultiplexConsumer.cpp @@ -128,6 +128,8 @@ public: void DeclarationMarkedUsed(const Decl *D) override; void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override; void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override; + void AddedAttributeToRecord(const Attr *Attr, + const RecordDecl *Record) override; private: std::vector<ASTMutationListener*> Listeners; @@ -226,6 +228,13 @@ void MultiplexASTMutationListener::RedefinedHiddenDefinition(const NamedDecl *D, for (auto *L : Listeners) L->RedefinedHiddenDefinition(D, M); } + +void MultiplexASTMutationListener::AddedAttributeToRecord( + const Attr *Attr, + const RecordDecl *Record) { + for (auto *L : Listeners) + L->AddedAttributeToRecord(Attr, Record); +} } // end namespace clang diff --git a/lib/Frontend/Rewrite/InclusionRewriter.cpp b/lib/Frontend/Rewrite/InclusionRewriter.cpp index b9ea051..08d6cf1 100644 --- a/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -29,13 +29,11 @@ namespace { class InclusionRewriter : public PPCallbacks { /// Information about which #includes were actually performed, /// created by preprocessor callbacks. - struct FileChange { - const Module *Mod; - SourceLocation From; + struct IncludedFile { FileID Id; SrcMgr::CharacteristicKind FileType; - FileChange(SourceLocation From, const Module *Mod) : Mod(Mod), From(From) { - } + IncludedFile(FileID Id, SrcMgr::CharacteristicKind FileType) + : Id(Id), FileType(FileType) {} }; Preprocessor &PP; ///< Used to find inclusion directives. SourceManager &SM; ///< Used to read and manage source files. @@ -44,11 +42,13 @@ class InclusionRewriter : public PPCallbacks { const llvm::MemoryBuffer *PredefinesBuffer; ///< The preprocessor predefines. bool ShowLineMarkers; ///< Show #line markers. bool UseLineDirectives; ///< Use of line directives or line markers. - typedef std::map<unsigned, FileChange> FileChangeMap; - FileChangeMap FileChanges; ///< Tracks which files were included where. - /// Used transitively for building up the FileChanges mapping over the + /// Tracks where inclusions that change the file are found. + std::map<unsigned, IncludedFile> FileIncludes; + /// Tracks where inclusions that import modules are found. + std::map<unsigned, const Module *> ModuleIncludes; + /// Used transitively for building up the FileIncludes mapping over the /// various \c PPCallbacks callbacks. - FileChangeMap::iterator LastInsertedFileChange; + SourceLocation LastInclusionLocation; public: InclusionRewriter(Preprocessor &PP, raw_ostream &OS, bool ShowLineMarkers, bool UseLineDirectives); @@ -82,7 +82,8 @@ private: bool HandleHasInclude(FileID FileId, Lexer &RawLex, const DirectoryLookup *Lookup, Token &Tok, bool &FileExists); - const FileChange *FindFileChangeLocation(SourceLocation Loc) const; + const IncludedFile *FindIncludeAtLocation(SourceLocation Loc) const; + const Module *FindModuleAtLocation(SourceLocation Loc) const; StringRef NextIdentifierName(Lexer &RawLex, Token &RawToken); }; @@ -95,7 +96,7 @@ InclusionRewriter::InclusionRewriter(Preprocessor &PP, raw_ostream &OS, : PP(PP), SM(PP.getSourceManager()), OS(OS), MainEOL("\n"), PredefinesBuffer(nullptr), ShowLineMarkers(ShowLineMarkers), UseLineDirectives(UseLineDirectives), - LastInsertedFileChange(FileChanges.end()) {} + LastInclusionLocation(SourceLocation()) {} /// Write appropriate line information as either #line directives or GNU line /// markers depending on what mode we're in, including the \p Filename and @@ -143,12 +144,15 @@ void InclusionRewriter::FileChanged(SourceLocation Loc, FileID) { if (Reason != EnterFile) return; - if (LastInsertedFileChange == FileChanges.end()) + if (LastInclusionLocation.isInvalid()) // we didn't reach this file (eg: the main file) via an inclusion directive return; - LastInsertedFileChange->second.Id = FullSourceLoc(Loc, SM).getFileID(); - LastInsertedFileChange->second.FileType = NewFileType; - LastInsertedFileChange = FileChanges.end(); + FileID Id = FullSourceLoc(Loc, SM).getFileID(); + auto P = FileIncludes.insert(std::make_pair( + LastInclusionLocation.getRawEncoding(), IncludedFile(Id, NewFileType))); + (void)P; + assert(P.second && "Unexpected revisitation of the same include directive"); + LastInclusionLocation = SourceLocation(); } /// Called whenever an inclusion is skipped due to canonical header protection @@ -156,10 +160,9 @@ void InclusionRewriter::FileChanged(SourceLocation Loc, void InclusionRewriter::FileSkipped(const FileEntry &/*SkippedFile*/, const Token &/*FilenameTok*/, SrcMgr::CharacteristicKind /*FileType*/) { - assert(LastInsertedFileChange != FileChanges.end() && "A file, that wasn't " - "found via an inclusion directive, was skipped"); - FileChanges.erase(LastInsertedFileChange); - LastInsertedFileChange = FileChanges.end(); + assert(!LastInclusionLocation.isInvalid() && + "A file, that wasn't found via an inclusion directive, was skipped"); + LastInclusionLocation = SourceLocation(); } /// This should be called whenever the preprocessor encounters include @@ -176,25 +179,38 @@ void InclusionRewriter::InclusionDirective(SourceLocation HashLoc, StringRef /*SearchPath*/, StringRef /*RelativePath*/, const Module *Imported) { - assert(LastInsertedFileChange == FileChanges.end() && "Another inclusion " - "directive was found before the previous one was processed"); - std::pair<FileChangeMap::iterator, bool> p = FileChanges.insert( - std::make_pair(HashLoc.getRawEncoding(), FileChange(HashLoc, Imported))); - assert(p.second && "Unexpected revisitation of the same include directive"); - if (!Imported) - LastInsertedFileChange = p.first; + assert(LastInclusionLocation.isInvalid() && + "Another inclusion directive was found before the previous one " + "was processed"); + if (Imported) { + auto P = ModuleIncludes.insert( + std::make_pair(HashLoc.getRawEncoding(), Imported)); + (void)P; + assert(P.second && "Unexpected revisitation of the same include directive"); + } else + LastInclusionLocation = HashLoc; } /// Simple lookup for a SourceLocation (specifically one denoting the hash in /// an inclusion directive) in the map of inclusion information, FileChanges. -const InclusionRewriter::FileChange * -InclusionRewriter::FindFileChangeLocation(SourceLocation Loc) const { - FileChangeMap::const_iterator I = FileChanges.find(Loc.getRawEncoding()); - if (I != FileChanges.end()) +const InclusionRewriter::IncludedFile * +InclusionRewriter::FindIncludeAtLocation(SourceLocation Loc) const { + const auto I = FileIncludes.find(Loc.getRawEncoding()); + if (I != FileIncludes.end()) return &I->second; return nullptr; } +/// Simple lookup for a SourceLocation (specifically one denoting the hash in +/// an inclusion directive) in the map of module inclusion information. +const Module * +InclusionRewriter::FindModuleAtLocation(SourceLocation Loc) const { + const auto I = ModuleIncludes.find(Loc.getRawEncoding()); + if (I != ModuleIncludes.end()) + return I->second; + return nullptr; +} + /// Detect the likely line ending style of \p FromFile by examining the first /// newline found within it. static StringRef DetectEOL(const MemoryBuffer &FromFile) { @@ -388,8 +404,7 @@ bool InclusionRewriter::Process(FileID FileId, { bool Invalid; const MemoryBuffer &FromFile = *SM.getBuffer(FileId, &Invalid); - if (Invalid) // invalid inclusion - return false; + assert(!Invalid && "Attempting to process invalid inclusion"); const char *FileName = FromFile.getBufferIdentifier(); Lexer RawLex(FileId, &FromFile, PP.getSourceManager(), PP.getLangOpts()); RawLex.SetCommentRetentionState(false); @@ -433,13 +448,12 @@ bool InclusionRewriter::Process(FileID FileId, if (FileId != PP.getPredefinesFileID()) WriteLineInfo(FileName, Line - 1, FileType, ""); StringRef LineInfoExtra; - if (const FileChange *Change = FindFileChangeLocation( - HashToken.getLocation())) { - if (Change->Mod) { - WriteImplicitModuleImport(Change->Mod); - - // else now include and recursively process the file - } else if (Process(Change->Id, Change->FileType)) { + SourceLocation Loc = HashToken.getLocation(); + if (const Module *Mod = FindModuleAtLocation(Loc)) + WriteImplicitModuleImport(Mod); + else if (const IncludedFile *Inc = FindIncludeAtLocation(Loc)) { + // include and recursively process the file + if (Process(Inc->Id, Inc->FileType)) { // and set lineinfo back to this file, if the nested one was // actually included // `2' indicates returning to a file (after having included diff --git a/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/lib/Frontend/Rewrite/RewriteModernObjC.cpp index e13cdb3..2902ba7 100644 --- a/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -1932,9 +1932,9 @@ Stmt *RewriteModernObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) void RewriteModernObjC::WarnAboutReturnGotoStmts(Stmt *S) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) - WarnAboutReturnGotoStmts(*CI); + for (Stmt *SubStmt : S->children()) + if (SubStmt) + WarnAboutReturnGotoStmts(SubStmt); if (isa<ReturnStmt>(S) || isa<GotoStmt>(S)) { Diags.Report(Context->getFullLoc(S->getLocStart()), @@ -4549,12 +4549,12 @@ void RewriteModernObjC::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) { } void RewriteModernObjC::GetBlockDeclRefExprs(Stmt *S) { - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - if (BlockExpr *CBE = dyn_cast<BlockExpr>(*CI)) + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + if (BlockExpr *CBE = dyn_cast<BlockExpr>(SubStmt)) GetBlockDeclRefExprs(CBE->getBody()); else - GetBlockDeclRefExprs(*CI); + GetBlockDeclRefExprs(SubStmt); } // Handle specific things. if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(S)) @@ -4569,19 +4569,16 @@ void RewriteModernObjC::GetBlockDeclRefExprs(Stmt *S) { void RewriteModernObjC::GetInnerBlockDeclRefExprs(Stmt *S, SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs, llvm::SmallPtrSetImpl<const DeclContext *> &InnerContexts) { - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - if (BlockExpr *CBE = dyn_cast<BlockExpr>(*CI)) { + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + if (BlockExpr *CBE = dyn_cast<BlockExpr>(SubStmt)) { InnerContexts.insert(cast<DeclContext>(CBE->getBlockDecl())); GetInnerBlockDeclRefExprs(CBE->getBody(), InnerBlockDeclRefs, InnerContexts); } else - GetInnerBlockDeclRefExprs(*CI, - InnerBlockDeclRefs, - InnerContexts); - + GetInnerBlockDeclRefExprs(SubStmt, InnerBlockDeclRefs, InnerContexts); } // Handle specific things. if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(S)) { @@ -5564,12 +5561,11 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { SourceRange OrigStmtRange = S->getSourceRange(); // Perform a bottom up rewrite of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - Stmt *childStmt = (*CI); + for (Stmt *&childStmt : S->children()) + if (childStmt) { Stmt *newStmt = RewriteFunctionBodyOrGlobalInitializer(childStmt); if (newStmt) { - *CI = newStmt; + childStmt = newStmt; } } diff --git a/lib/Frontend/Rewrite/RewriteObjC.cpp b/lib/Frontend/Rewrite/RewriteObjC.cpp index b2a45b4..204820b 100644 --- a/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -1712,9 +1712,9 @@ Stmt *RewriteObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) { void RewriteObjC::WarnAboutReturnGotoStmts(Stmt *S) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) - WarnAboutReturnGotoStmts(*CI); + for (Stmt *SubStmt : S->children()) + if (SubStmt) + WarnAboutReturnGotoStmts(SubStmt); if (isa<ReturnStmt>(S) || isa<GotoStmt>(S)) { Diags.Report(Context->getFullLoc(S->getLocStart()), @@ -1726,9 +1726,9 @@ void RewriteObjC::WarnAboutReturnGotoStmts(Stmt *S) void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) - HasReturnStmts(*CI, hasReturns); + for (Stmt *SubStmt : S->children()) + if (SubStmt) + HasReturnStmts(SubStmt, hasReturns); if (isa<ReturnStmt>(S)) hasReturns = true; @@ -1737,9 +1737,9 @@ void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns) void RewriteObjC::RewriteTryReturnStmts(Stmt *S) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - RewriteTryReturnStmts(*CI); + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + RewriteTryReturnStmts(SubStmt); } if (isa<ReturnStmt>(S)) { SourceLocation startLoc = S->getLocStart(); @@ -1760,9 +1760,9 @@ void RewriteObjC::RewriteTryReturnStmts(Stmt *S) { void RewriteObjC::RewriteSyncReturnStmts(Stmt *S, std::string syncExitBuf) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - RewriteSyncReturnStmts(*CI, syncExitBuf); + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + RewriteSyncReturnStmts(SubStmt, syncExitBuf); } if (isa<ReturnStmt>(S)) { SourceLocation startLoc = S->getLocStart(); @@ -3663,12 +3663,12 @@ void RewriteObjC::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) { } void RewriteObjC::GetBlockDeclRefExprs(Stmt *S) { - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - if (BlockExpr *CBE = dyn_cast<BlockExpr>(*CI)) + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + if (BlockExpr *CBE = dyn_cast<BlockExpr>(SubStmt)) GetBlockDeclRefExprs(CBE->getBody()); else - GetBlockDeclRefExprs(*CI); + GetBlockDeclRefExprs(SubStmt); } // Handle specific things. if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(S)) @@ -3683,19 +3683,16 @@ void RewriteObjC::GetBlockDeclRefExprs(Stmt *S) { void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S, SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs, llvm::SmallPtrSetImpl<const DeclContext *> &InnerContexts) { - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - if (BlockExpr *CBE = dyn_cast<BlockExpr>(*CI)) { + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + if (BlockExpr *CBE = dyn_cast<BlockExpr>(SubStmt)) { InnerContexts.insert(cast<DeclContext>(CBE->getBlockDecl())); GetInnerBlockDeclRefExprs(CBE->getBody(), InnerBlockDeclRefs, InnerContexts); } else - GetInnerBlockDeclRefExprs(*CI, - InnerBlockDeclRefs, - InnerContexts); - + GetInnerBlockDeclRefExprs(SubStmt, InnerBlockDeclRefs, InnerContexts); } // Handle specific things. if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(S)) { @@ -4611,12 +4608,11 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { SourceRange OrigStmtRange = S->getSourceRange(); // Perform a bottom up rewrite of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - Stmt *childStmt = (*CI); + for (Stmt *&childStmt : S->children()) + if (childStmt) { Stmt *newStmt = RewriteFunctionBodyOrGlobalInitializer(childStmt); if (newStmt) { - *CI = newStmt; + childStmt = newStmt; } } |