diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:11 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:11 +0000 |
commit | c7e70c433efc6953dc3888b9fbf9f3512d7da2b0 (patch) | |
tree | 27425930fc0c91650a7f3527fcac8e0f92907b90 /lib/Frontend | |
parent | 486754660bb926339aefcf012a3f848592babb8b (diff) | |
download | src-c7e70c433efc6953dc3888b9fbf9f3512d7da2b0.tar.gz src-c7e70c433efc6953dc3888b9fbf9f3512d7da2b0.zip |
Vendor import of clang trunk r338536:vendor/clang/clang-trunk-r338536
Notes
Notes:
svn path=/vendor/clang/dist/; revision=337139
svn path=/vendor/clang/clang-trunk-r338536/; revision=337140; tag=vendor/clang/clang-trunk-r338536
Diffstat (limited to 'lib/Frontend')
-rw-r--r-- | lib/Frontend/ASTConsumers.cpp | 2 | ||||
-rw-r--r-- | lib/Frontend/ASTMerge.cpp | 10 | ||||
-rw-r--r-- | lib/Frontend/ChainedIncludesSource.cpp | 6 | ||||
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 38 | ||||
-rw-r--r-- | lib/Frontend/DependencyFile.cpp | 2 | ||||
-rw-r--r-- | lib/Frontend/DependencyGraph.cpp | 20 | ||||
-rw-r--r-- | lib/Frontend/DiagnosticRenderer.cpp | 6 | ||||
-rw-r--r-- | lib/Frontend/FrontendAction.cpp | 8 | ||||
-rw-r--r-- | lib/Frontend/FrontendActions.cpp | 10 | ||||
-rw-r--r-- | lib/Frontend/LayoutOverrideSource.cpp | 58 | ||||
-rw-r--r-- | lib/Frontend/MultiplexConsumer.cpp | 6 | ||||
-rw-r--r-- | lib/Frontend/PrintPreprocessedOutput.cpp | 12 | ||||
-rw-r--r-- | lib/Frontend/Rewrite/FixItRewriter.cpp | 2 | ||||
-rw-r--r-- | lib/Frontend/Rewrite/FrontendActions.cpp | 4 | ||||
-rw-r--r-- | lib/Frontend/Rewrite/RewriteModernObjC.cpp | 964 | ||||
-rw-r--r-- | lib/Frontend/Rewrite/RewriteObjC.cpp | 388 | ||||
-rw-r--r-- | lib/Frontend/SerializedDiagnosticPrinter.cpp | 46 | ||||
-rw-r--r-- | lib/Frontend/TestModuleFileExtension.cpp | 2 | ||||
-rw-r--r-- | lib/Frontend/TextDiagnostic.cpp | 28 |
19 files changed, 806 insertions, 806 deletions
diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp index b67c019baed8..2a8bfef68eb9 100644 --- a/lib/Frontend/ASTConsumers.cpp +++ b/lib/Frontend/ASTConsumers.cpp @@ -181,7 +181,7 @@ namespace { void ASTViewer::HandleTopLevelSingleDecl(Decl *D) { if (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)) { D->print(llvm::errs()); - + if (Stmt *Body = D->getBody()) { llvm::errs() << '\n'; Body->viewAST(); diff --git a/lib/Frontend/ASTMerge.cpp b/lib/Frontend/ASTMerge.cpp index 6ec0e2a98c1b..2434113ab0db 100644 --- a/lib/Frontend/ASTMerge.cpp +++ b/lib/Frontend/ASTMerge.cpp @@ -51,9 +51,9 @@ void ASTMergeAction::ExecuteAction() { if (!Unit) continue; - ASTImporter Importer(CI.getASTContext(), + ASTImporter Importer(CI.getASTContext(), CI.getFileManager(), - Unit->getASTContext(), + Unit->getASTContext(), Unit->getFileManager(), /*MinimalImport=*/false); @@ -64,9 +64,9 @@ void ASTMergeAction::ExecuteAction() { if (IdentifierInfo *II = ND->getIdentifier()) if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list")) continue; - + Decl *ToD = Importer.Import(D); - + if (ToD) { DeclGroupRef DGR(ToD); CI.getASTConsumer().HandleTopLevelDecl(DGR); @@ -88,7 +88,7 @@ ASTMergeAction::ASTMergeAction(std::unique_ptr<FrontendAction> adaptedAction, assert(AdaptedAction && "ASTMergeAction needs an action to adapt"); } -ASTMergeAction::~ASTMergeAction() { +ASTMergeAction::~ASTMergeAction() { } bool ASTMergeAction::usesPreprocessorOnly() const { diff --git a/lib/Frontend/ChainedIncludesSource.cpp b/lib/Frontend/ChainedIncludesSource.cpp index 534c7587f48d..4e8eb32121dc 100644 --- a/lib/Frontend/ChainedIncludesSource.cpp +++ b/lib/Frontend/ChainedIncludesSource.cpp @@ -126,7 +126,7 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource( bool firstInclude = (i == 0); std::unique_ptr<CompilerInvocation> CInvok; CInvok.reset(new CompilerInvocation(CI.getInvocation())); - + CInvok->getPreprocessorOpts().ChainedIncludes.clear(); CInvok->getPreprocessorOpts().ImplicitPCHInclude.clear(); CInvok->getPreprocessorOpts().ImplicitPTHInclude.clear(); @@ -134,7 +134,7 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource( CInvok->getPreprocessorOpts().Includes.clear(); CInvok->getPreprocessorOpts().MacroIncludes.clear(); CInvok->getPreprocessorOpts().Macros.clear(); - + CInvok->getFrontendOpts().Inputs.clear(); FrontendInputFile InputFile(includes[i], IK); CInvok->getFrontendOpts().Inputs.push_back(InputFile); @@ -193,7 +193,7 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource( Clang->setModuleManager(Reader); Clang->getASTContext().setExternalSource(Reader); } - + if (!Clang->InitializeSourceManager(InputFile)) return nullptr; diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 155ead4ac8e8..ecb09da3c1ef 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -292,7 +292,7 @@ CompilerInstance::createDiagnostics(DiagnosticOptions *Opts, if (!Opts->DiagnosticSerializationFile.empty()) SetupSerializedDiagnostics(Opts, *Diags, Opts->DiagnosticSerializationFile); - + // Configure our handling of diagnostics. ProcessWarningOptions(*Diags, *Opts); @@ -935,7 +935,7 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { // Adjust target options based on codegen options. getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts()); - // rewriter project will change target built-in bool type from its default. + // rewriter project will change target built-in bool type from its default. if (getFrontendOpts().ProgramAction == frontend::RewriteObjC) getTarget().noSignedCharForObjCBool(); @@ -1026,7 +1026,7 @@ static InputKind::Language getLanguageFromOptions(const LangOptions &LangOpts) { return LangOpts.CPlusPlus ? InputKind::CXX : InputKind::C; } -/// Compile a module file for the given module, using the options +/// Compile a module file for the given module, using the options /// provided by the importing compiler instance. Returns true if the module /// was built without errors. static bool @@ -1042,7 +1042,7 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, std::make_shared<CompilerInvocation>(ImportingInstance.getInvocation()); PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts(); - + // For any options that aren't intended to affect how a module is built, // reset them to their default values. Invocation->getLangOpts()->resetNonModularOptions(); @@ -1092,11 +1092,11 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, // Don't free the remapped file buffers; they are owned by our caller. PPOpts.RetainRemappedFileBuffers = true; - + Invocation->getDiagnosticOpts().VerifyDiagnostics = 0; assert(ImportingInstance.getInvocation().getModuleHash() == Invocation->getModuleHash() && "Module hash mismatch!"); - + // Construct a compiler instance that will be used to actually create the // module. Since we're sharing a PCMCache, // CompilerInstance::CompilerInstance is responsible for finalizing the @@ -1172,7 +1172,7 @@ static const FileEntry *getPublicModuleMap(const FileEntry *File, return FileMgr.getFile(PublicFilename); } -/// Compile a module file for the given module, using the options +/// Compile a module file for the given module, using the options /// provided by the importing compiler instance. Returns true if the module /// was built without errors. static bool compileModuleImpl(CompilerInstance &ImportingInstance, @@ -1183,7 +1183,7 @@ static bool compileModuleImpl(CompilerInstance &ImportingInstance, InputKind::ModuleMap); // Get or create the module map that we'll use to build this module. - ModuleMap &ModMap + ModuleMap &ModMap = ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); bool Result; if (const FileEntry *ModuleMapFile = @@ -1327,7 +1327,7 @@ static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro, Module *Mod, SourceLocation ImportLoc) { IdentifierInfo *Id = PP.getIdentifierInfo(ConfigMacro); SourceManager &SourceMgr = PP.getSourceManager(); - + // If this identifier has never had a macro definition, then it could // not have changed. if (!Id->hadMacroDefinition()) @@ -1651,7 +1651,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, = KnownModules.find(Path[0].first); if (Known != KnownModules.end()) { // Retrieve the cached top-level module. - Module = Known->second; + Module = Known->second; } else if (ModuleName == getLangOpts().CurrentModule) { // This is the module we're building. Module = PP->getHeaderSearchInfo().lookupModule( @@ -1851,7 +1851,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // Cache the result of this top-level module lookup for later. Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first; } - + // If we never found the module, fail. if (!Module) return ModuleLoadResult(); @@ -1897,13 +1897,13 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, } } } - + if (!Sub) { // Attempt to perform typo correction to find a module name that works. SmallVector<StringRef, 2> Best; unsigned BestEditDistance = (std::numeric_limits<unsigned>::max)(); - - for (clang::Module::submodule_iterator J = Module->submodule_begin(), + + for (clang::Module::submodule_iterator J = Module->submodule_begin(), JEnd = Module->submodule_end(); J != JEnd; ++J) { unsigned ED = Name.edit_distance((*J)->Name, @@ -1914,20 +1914,20 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, Best.clear(); BestEditDistance = ED; } - + Best.push_back((*J)->Name); } } - + // If there was a clear winner, user it. if (Best.size() == 1) { - getDiagnostics().Report(Path[I].second, + getDiagnostics().Report(Path[I].second, diag::err_no_submodule_suggest) << Path[I].first << Module->getFullModuleName() << Best[0] << SourceRange(Path[0].second, Path[I-1].second) << FixItHint::CreateReplacement(SourceRange(Path[I].second), Best[0]); - + Sub = Module->findSubmodule(Best[0]); } } @@ -1940,7 +1940,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, << SourceRange(Path[0].second, Path[I-1].second); break; } - + Module = Sub; } } diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index f89722eeb9ed..e6e07190e1ff 100644 --- a/lib/Frontend/DependencyFile.cpp +++ b/lib/Frontend/DependencyFile.cpp @@ -318,7 +318,7 @@ void DFGImpl::InclusionDirective(SourceLocation HashLoc, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!File) { if (AddMissingHeaderDeps) diff --git a/lib/Frontend/DependencyGraph.cpp b/lib/Frontend/DependencyGraph.cpp index 660f664447ab..c6c9ac2ea2fa 100644 --- a/lib/Frontend/DependencyGraph.cpp +++ b/lib/Frontend/DependencyGraph.cpp @@ -33,9 +33,9 @@ class DependencyGraphCallback : public PPCallbacks { llvm::SetVector<const FileEntry *> AllFiles; typedef llvm::DenseMap<const FileEntry *, SmallVector<const FileEntry *, 2> > DependencyMap; - + DependencyMap Dependencies; - + private: raw_ostream &writeNodeReference(raw_ostream &OS, const FileEntry *Node); @@ -56,7 +56,7 @@ public: void EndOfMainFile() override { OutputGraphFile(); } - + }; } @@ -75,11 +75,11 @@ void DependencyGraphCallback::InclusionDirective( const FileEntry *File, StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!File) return; - + SourceManager &SM = PP->getSourceManager(); const FileEntry *FromFile = SM.getFileEntryForID(SM.getFileID(SM.getExpansionLoc(HashLoc))); @@ -87,7 +87,7 @@ void DependencyGraphCallback::InclusionDirective( return; Dependencies[FromFile].push_back(File); - + AllFiles.insert(File); AllFiles.insert(FromFile); } @@ -109,7 +109,7 @@ void DependencyGraphCallback::OutputGraphFile() { } OS << "digraph \"dependencies\" {\n"; - + // Write the nodes for (unsigned I = 0, N = AllFiles.size(); I != N; ++I) { // Write the node itself. @@ -119,15 +119,15 @@ void DependencyGraphCallback::OutputGraphFile() { StringRef FileName = AllFiles[I]->getName(); if (FileName.startswith(SysRoot)) FileName = FileName.substr(SysRoot.size()); - + OS << DOT::EscapeString(FileName) << "\"];\n"; } // Write the edges - for (DependencyMap::iterator F = Dependencies.begin(), + for (DependencyMap::iterator F = Dependencies.begin(), FEnd = Dependencies.end(); - F != FEnd; ++F) { + F != FEnd; ++F) { for (unsigned I = 0, N = F->second.size(); I != N; ++I) { OS.indent(2); writeNodeReference(OS, F->first); diff --git a/lib/Frontend/DiagnosticRenderer.cpp b/lib/Frontend/DiagnosticRenderer.cpp index fb0a92d1f8c6..757ceec7ec9d 100644 --- a/lib/Frontend/DiagnosticRenderer.cpp +++ b/lib/Frontend/DiagnosticRenderer.cpp @@ -172,9 +172,9 @@ void DiagnosticRenderer::emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc, // Skip redundant include stacks altogether. if (LastIncludeLoc == IncludeLoc) return; - + LastIncludeLoc = IncludeLoc; - + if (!DiagOpts->ShowNoteIncludeStack && Level == DiagnosticsEngine::Note) return; @@ -199,7 +199,7 @@ void DiagnosticRenderer::emitIncludeStackRecursively(FullSourceLoc Loc) { return; // If this source location was imported from a module, print the module - // import stack rather than the + // import stack rather than the // FIXME: We want submodule granularity here. std::pair<FullSourceLoc, StringRef> Imported = Loc.getModuleImportLoc(); if (!Imported.second.empty()) { diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index a5929424e52a..74550c410396 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -288,7 +288,7 @@ static void addHeaderInclude(StringRef HeaderName, Includes += "}\n"; } -/// Collect the set of header includes needed to construct the given +/// Collect the set of header includes needed to construct the given /// module and update the TopHeaders file set of the module. /// /// \param Module The module we're collecting includes from. @@ -345,7 +345,7 @@ static std::error_code collectModuleHeaderIncludes( vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); for (vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End; Dir != End && !EC; Dir.increment(EC)) { - // Check whether this entry has an extension typically associated with + // Check whether this entry has an extension typically associated with // headers. if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->getName())) .Cases(".h", ".H", ".hh", ".hpp", true) @@ -358,7 +358,7 @@ static std::error_code collectModuleHeaderIncludes( if (!Header) continue; - // If this header is marked 'unavailable' in this module, don't include + // If this header is marked 'unavailable' in this module, don't include // it. if (ModMap.isHeaderUnavailableInModule(Header, Module)) continue; @@ -431,7 +431,7 @@ static Module *prepareToBuildModule(CompilerInstance &CI, CI.getDiagnostics().Report(diag::err_missing_module_name); // FIXME: Eventually, we could consider asking whether there was just - // a single module described in the module map, and use that as a + // a single module described in the module map, and use that as a // default. Then it would be fairly trivial to just "compile" a module // map with a single module (the common case). return nullptr; diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 9344e673c7ac..8a8354c7d4c9 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -377,7 +377,7 @@ private: if (auto *NamedTemplate = dyn_cast_or_null<NamedDecl>(Inst.Entity)) { llvm::raw_string_ostream OS(Entry.Name); NamedTemplate->getNameForDiagnostic(OS, TheSema.getLangOpts(), true); - const PresumedLoc DefLoc = + const PresumedLoc DefLoc = TheSema.getSourceManager().getPresumedLoc(Inst.Entity->getLocation()); if(!DefLoc.isInvalid()) Entry.DefinitionLocation = std::string(DefLoc.getFilename()) + ":" + @@ -709,13 +709,13 @@ void PrintPreprocessedAction::ExecuteAction() { // the input format has inconsistent line endings. // // This should be a relatively fast operation since most files won't have - // all of their source code on a single line. However, that is still a + // all of their source code on a single line. However, that is still a // concern, so if we scan for too long, we'll just assume the file should // be opened in binary mode. bool BinaryMode = true; bool InvalidFile = false; const SourceManager& SM = CI.getSourceManager(); - const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(), + const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(), &InvalidFile); if (!InvalidFile) { const char *cur = Buffer->getBufferStart(); @@ -723,7 +723,7 @@ void PrintPreprocessedAction::ExecuteAction() { const char *next = (cur != end) ? cur + 1 : end; // Limit ourselves to only scanning 256 characters into the source - // file. This is mostly a sanity check in case the file has no + // file. This is mostly a sanity check in case the file has no // newlines whatsoever. if (end - cur > 256) end = cur + 256; @@ -774,7 +774,7 @@ void PrintPreambleAction::ExecuteAction() { case InputKind::CUDA: case InputKind::HIP: break; - + case InputKind::Unknown: case InputKind::Asm: case InputKind::LLVM_IR: diff --git a/lib/Frontend/LayoutOverrideSource.cpp b/lib/Frontend/LayoutOverrideSource.cpp index 93e07eb81f72..b31fbd087ba7 100644 --- a/lib/Frontend/LayoutOverrideSource.cpp +++ b/lib/Frontend/LayoutOverrideSource.cpp @@ -23,7 +23,7 @@ static std::string parseName(StringRef S) { unsigned Offset = 1; while (Offset < S.size() && isIdentifierBody(S[Offset])) ++Offset; - + return S.substr(0, Offset).str(); } @@ -31,33 +31,33 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) { std::ifstream Input(Filename.str().c_str()); if (!Input.is_open()) return; - + // Parse the output of -fdump-record-layouts. std::string CurrentType; Layout CurrentLayout; bool ExpectingType = false; - + while (Input.good()) { std::string Line; getline(Input, Line); - + StringRef LineStr(Line); - // Determine whether the following line will start a + // Determine whether the following line will start a if (LineStr.find("*** Dumping AST Record Layout") != StringRef::npos) { // Flush the last type/layout, if there is one. if (!CurrentType.empty()) Layouts[CurrentType] = CurrentLayout; CurrentLayout = Layout(); - + ExpectingType = true; continue; } - + // If we're expecting a type, grab it. if (ExpectingType) { ExpectingType = false; - + StringRef::size_type Pos; if ((Pos = LineStr.find("struct ")) != StringRef::npos) LineStr = LineStr.substr(Pos + strlen("struct ")); @@ -67,19 +67,19 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) { LineStr = LineStr.substr(Pos + strlen("union ")); else continue; - + // Find the name of the type. CurrentType = parseName(LineStr); CurrentLayout = Layout(); continue; } - + // Check for the size of the type. StringRef::size_type Pos = LineStr.find(" Size:"); if (Pos != StringRef::npos) { // Skip past the " Size:" prefix. LineStr = LineStr.substr(Pos + strlen(" Size:")); - + unsigned long long Size = 0; (void)LineStr.getAsInteger(10, Size); CurrentLayout.Size = Size; @@ -91,13 +91,13 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) { if (Pos != StringRef::npos) { // Skip past the "Alignment:" prefix. LineStr = LineStr.substr(Pos + strlen("Alignment:")); - + unsigned long long Alignment = 0; (void)LineStr.getAsInteger(10, Alignment); CurrentLayout.Align = Alignment; continue; } - + // Check for the size/alignment of the type. Pos = LineStr.find("sizeof="); if (Pos != StringRef::npos) { @@ -113,16 +113,16 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) { if (Pos != StringRef::npos) { /* Skip past the align= prefix. */ LineStr = LineStr.substr(Pos + strlen("align=")); - + // Parse alignment. unsigned long long Alignment = 0; (void)LineStr.getAsInteger(10, Alignment); CurrentLayout.Align = Alignment; } - + continue; } - + // Check for the field offsets of the type. Pos = LineStr.find("FieldOffsets: ["); if (Pos == StringRef::npos) @@ -134,55 +134,55 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) { unsigned Idx = 1; while (Idx < LineStr.size() && isDigit(LineStr[Idx])) ++Idx; - + unsigned long long Offset = 0; (void)LineStr.substr(0, Idx).getAsInteger(10, Offset); - + CurrentLayout.FieldOffsets.push_back(Offset); - + // Skip over this offset, the following comma, and any spaces. LineStr = LineStr.substr(Idx + 1); while (!LineStr.empty() && isWhitespace(LineStr[0])) LineStr = LineStr.substr(1); } } - + // Flush the last type/layout, if there is one. if (!CurrentType.empty()) Layouts[CurrentType] = CurrentLayout; } -bool +bool LayoutOverrideSource::layoutRecordType(const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, - llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) + llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) { // We can't override unnamed declarations. if (!Record->getIdentifier()) return false; - + // Check whether we have a layout for this record. llvm::StringMap<Layout>::iterator Known = Layouts.find(Record->getName()); if (Known == Layouts.end()) return false; - + // Provide field layouts. unsigned NumFields = 0; - for (RecordDecl::field_iterator F = Record->field_begin(), + for (RecordDecl::field_iterator F = Record->field_begin(), FEnd = Record->field_end(); F != FEnd; ++F, ++NumFields) { if (NumFields >= Known->second.FieldOffsets.size()) continue; - + FieldOffsets[*F] = Known->second.FieldOffsets[NumFields]; } - + // Wrong number of fields. if (NumFields != Known->second.FieldOffsets.size()) return false; - + Size = Known->second.Size; Alignment = Known->second.Align; return true; @@ -190,7 +190,7 @@ LayoutOverrideSource::layoutRecordType(const RecordDecl *Record, LLVM_DUMP_METHOD void LayoutOverrideSource::dump() { raw_ostream &OS = llvm::errs(); - for (llvm::StringMap<Layout>::iterator L = Layouts.begin(), + for (llvm::StringMap<Layout>::iterator L = Layouts.begin(), LEnd = Layouts.end(); L != LEnd; ++L) { OS << "Type: blah " << L->first() << '\n'; diff --git a/lib/Frontend/MultiplexConsumer.cpp b/lib/Frontend/MultiplexConsumer.cpp index df36c88ec38e..c6e18d9cae21 100644 --- a/lib/Frontend/MultiplexConsumer.cpp +++ b/lib/Frontend/MultiplexConsumer.cpp @@ -107,7 +107,7 @@ public: void DeclarationMarkedOpenMPDeclareTarget(const Decl *D, const Attr *Attr) override; void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override; - void AddedAttributeToRecord(const Attr *Attr, + void AddedAttributeToRecord(const Attr *Attr, const RecordDecl *Record) override; private: @@ -219,9 +219,9 @@ void MultiplexASTMutationListener::RedefinedHiddenDefinition(const NamedDecl *D, for (auto *L : Listeners) L->RedefinedHiddenDefinition(D, M); } - + void MultiplexASTMutationListener::AddedAttributeToRecord( - const Attr *Attr, + const Attr *Attr, const RecordDecl *Record) { for (auto *L : Listeners) L->AddedAttributeToRecord(Attr, Record); diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index 1b35b32656e7..69cd072ea57f 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -160,7 +160,7 @@ public: } bool MoveToLine(unsigned LineNo); - bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok, + bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok, const Token &Tok) { return ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok); } @@ -248,7 +248,7 @@ PrintPPOutputPPCallbacks::startNewLineIfNeeded(bool ShouldUpdateCurrentLine) { ++CurLine; return true; } - + return false; } @@ -262,11 +262,11 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, // Unless we are exiting a #include, make sure to skip ahead to the line the // #include directive was at. SourceManager &SourceMgr = SM; - + PresumedLoc UserLoc = SourceMgr.getPresumedLoc(Loc); if (UserLoc.isInvalid()) return; - + unsigned NewLine = UserLoc.getLine(); if (Reason == PPCallbacks::EnterFile) { @@ -281,7 +281,7 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, // off by one. We can do better by simply incrementing NewLine here. NewLine += 1; } - + CurLine = NewLine; CurFilename.clear(); @@ -292,7 +292,7 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false); return; } - + if (!Initialized) { WriteLineInfo(CurLine); Initialized = true; diff --git a/lib/Frontend/Rewrite/FixItRewriter.cpp b/lib/Frontend/Rewrite/FixItRewriter.cpp index 64785e301236..1c2efe63aa19 100644 --- a/lib/Frontend/Rewrite/FixItRewriter.cpp +++ b/lib/Frontend/Rewrite/FixItRewriter.cpp @@ -184,7 +184,7 @@ void FixItRewriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, } return; } - + if (!Editor.commit(commit)) { ++NumFailures; Diag(Info.getLocation(), diag::note_fixit_failed); diff --git a/lib/Frontend/Rewrite/FrontendActions.cpp b/lib/Frontend/Rewrite/FrontendActions.cpp index 4d587048f62d..fa17b3e7cb3f 100644 --- a/lib/Frontend/Rewrite/FrontendActions.cpp +++ b/lib/Frontend/Rewrite/FrontendActions.cpp @@ -131,9 +131,9 @@ bool FixItRecompile::BeginInvocation(CompilerInstance &CI) { FixItRewriter Rewriter(CI.getDiagnostics(), CI.getSourceManager(), CI.getLangOpts(), FixItOpts.get()); FixAction->Execute(); - + err = Rewriter.WriteFixedFiles(&RewrittenFiles); - + FixAction->EndSourceFile(); CI.setSourceManager(nullptr); CI.setFileManager(nullptr); diff --git a/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 52b979c85f15..36382e1438d5 100644 --- a/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -39,12 +39,12 @@ using llvm::utostr; namespace { class RewriteModernObjC : public ASTConsumer { protected: - + enum { BLOCK_FIELD_IS_OBJECT = 3, /* id, NSObject, __attribute__((NSObject)), block, ... */ BLOCK_FIELD_IS_BLOCK = 7, /* a block variable */ - BLOCK_FIELD_IS_BYREF = 8, /* the on stack structure holding the + BLOCK_FIELD_IS_BYREF = 8, /* the on stack structure holding the __block variable */ BLOCK_FIELD_IS_WEAK = 16, /* declared __weak, only used in byref copy helpers */ @@ -52,7 +52,7 @@ namespace { support routines */ BLOCK_BYREF_CURRENT_MAX = 256 }; - + enum { BLOCK_NEEDS_FREE = (1 << 24), BLOCK_HAS_COPY_DISPOSE = (1 << 25), @@ -61,7 +61,7 @@ namespace { BLOCK_IS_GLOBAL = (1 << 28), BLOCK_HAS_DESCRIPTOR = (1 << 29) }; - + Rewriter Rewrite; DiagnosticsEngine &Diags; const LangOptions &LangOpts; @@ -75,7 +75,7 @@ namespace { std::string InFileName; std::unique_ptr<raw_ostream> OutFile; std::string Preamble; - + TypeDecl *ProtocolTypeDecl; VarDecl *GlobalVarDecl; Expr *GlobalConstructionExp; @@ -88,13 +88,13 @@ namespace { // ObjC foreach break/continue generation support. int BcLabelCount; - + unsigned TryFinallyContainsReturnDiag; // Needed for super. ObjCMethodDecl *CurMethodDef; RecordDecl *SuperStructDecl; RecordDecl *ConstantStringDecl; - + FunctionDecl *MsgSendFunctionDecl; FunctionDecl *MsgSendSuperFunctionDecl; FunctionDecl *MsgSendStretFunctionDecl; @@ -118,22 +118,22 @@ namespace { SmallVector<ObjCInterfaceDecl*, 32> ObjCInterfacesSeen; /// DefinedNonLazyClasses - List of defined "non-lazy" classes. SmallVector<ObjCInterfaceDecl*, 8> DefinedNonLazyClasses; - + /// DefinedNonLazyCategories - List of defined "non-lazy" categories. SmallVector<ObjCCategoryDecl *, 8> DefinedNonLazyCategories; - + SmallVector<Stmt *, 32> Stmts; SmallVector<int, 8> ObjCBcLabelNo; // Remember all the @protocol(<expr>) expressions. llvm::SmallPtrSet<ObjCProtocolDecl *, 32> ProtocolExprDecls; - + llvm::DenseSet<uint64_t> CopyDestroyCache; // Block expressions. SmallVector<BlockExpr *, 32> Blocks; SmallVector<int, 32> InnerDeclRefsCount; SmallVector<DeclRefExpr *, 32> InnerDeclRefs; - + SmallVector<DeclRefExpr *, 32> BlockDeclRefs; // Block related declarations. @@ -144,11 +144,11 @@ namespace { llvm::DenseMap<ValueDecl *, unsigned> BlockByRefDeclNo; llvm::SmallPtrSet<ValueDecl *, 8> ImportedBlockDecls; llvm::SmallPtrSet<VarDecl *, 8> ImportedLocalExternalDecls; - + llvm::DenseMap<BlockExpr *, std::string> RewrittenBlockExprs; - llvm::DenseMap<ObjCInterfaceDecl *, + llvm::DenseMap<ObjCInterfaceDecl *, llvm::SmallSetVector<ObjCIvarDecl *, 8> > ReferencedIvars; - + // ivar bitfield grouping containers llvm::DenseSet<const ObjCInterfaceDecl *> ObjCInterefaceHasBitfieldGroups; llvm::DenseMap<const ObjCIvarDecl* , unsigned> IvarGroupNumber; @@ -156,7 +156,7 @@ namespace { // of the struct where the bitfield belongs. llvm::DenseMap<std::pair<const ObjCInterfaceDecl*, unsigned>, QualType> GroupRecordType; SmallVector<FunctionDecl*, 32> FunctionDefinitionsSeen; - + // 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. @@ -167,12 +167,12 @@ namespace { bool SilenceRewriteMacroWarning; bool GenerateLineInfo; bool objc_impl_method; - + bool DisableReplaceStmt; class DisableReplaceStmtScope { RewriteModernObjC &R; bool SavedValue; - + public: DisableReplaceStmtScope(RewriteModernObjC &R) : R(R), SavedValue(R.DisableReplaceStmt) { @@ -237,7 +237,7 @@ namespace { } } } - + void HandleTopLevelSingleDecl(Decl *D); void HandleDeclInMainFile(Decl *D); RewriteModernObjC(std::string inFile, std::unique_ptr<raw_ostream> OS, @@ -314,7 +314,7 @@ namespace { std::string &LineString); void RewriteForwardClassDecl(DeclGroupRef D); void RewriteForwardClassDecl(const SmallVectorImpl<Decl *> &DG); - void RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl, + void RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl, const std::string &typedefString); void RewriteImplementations(); void RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, @@ -341,9 +341,9 @@ namespace { void RewriteObjCQualifiedInterfaceTypes(Decl *Dcl); void RewriteTypeOfDecl(VarDecl *VD); void RewriteObjCQualifiedInterfaceTypes(Expr *E); - + std::string getIvarAccessString(ObjCIvarDecl *D); - + // Expression Rewriting. Stmt *RewriteFunctionBodyOrGlobalInitializer(Stmt *S); Stmt *RewriteAtEncode(ObjCEncodeExpr *Exp); @@ -367,7 +367,7 @@ namespace { Stmt *RewriteContinueStmt(ContinueStmt *S); void RewriteCastExpr(CStyleCastExpr *CE); void RewriteImplicitCastObjCExpr(CastExpr *IE); - + // Computes ivar bitfield group no. unsigned ObjCIvarBitfieldGroupNo(ObjCIvarDecl *IV); // Names field decl. for ivar bitfield group. @@ -381,28 +381,28 @@ namespace { QualType SynthesizeBitfieldGroupStructType( ObjCIvarDecl *IV, SmallVectorImpl<ObjCIvarDecl *> &IVars); - + // Block rewriting. void RewriteBlocksInFunctionProtoType(QualType funcType, NamedDecl *D); - + // Block specific rewrite rules. void RewriteBlockPointerDecl(NamedDecl *VD); void RewriteByRefVar(VarDecl *VD, bool firstDecl, bool lastDecl); Stmt *RewriteBlockDeclRefExpr(DeclRefExpr *VD); Stmt *RewriteLocalVariableExternalStorage(DeclRefExpr *DRE); void RewriteBlockPointerFunctionArgs(FunctionDecl *FD); - + void RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl, std::string &Result); - + void RewriteObjCFieldDecl(FieldDecl *fieldDecl, std::string &Result); bool IsTagDefinedInsideClass(ObjCContainerDecl *IDecl, TagDecl *Tag, bool &IsNamedDefinition); - void RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDecl, + void RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDecl, std::string &Result); - + bool RewriteObjCFieldDeclType(QualType &Type, std::string &Result); - + void RewriteIvarOffsetSymbols(ObjCInterfaceDecl *CDecl, std::string &Result); @@ -414,9 +414,9 @@ namespace { ArrayRef<Expr *> Args, SourceLocation StartLoc=SourceLocation(), SourceLocation EndLoc=SourceLocation()); - + Expr *SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavor, - QualType returnType, + QualType returnType, SmallVectorImpl<QualType> &ArgTypes, SmallVectorImpl<Expr*> &MsgExprs, ObjCMethodDecl *Method); @@ -424,7 +424,7 @@ namespace { Stmt *SynthMessageExpr(ObjCMessageExpr *Exp, SourceLocation StartLoc=SourceLocation(), SourceLocation EndLoc=SourceLocation()); - + void SynthCountByEnumWithState(std::string &buf); void SynthMsgSendFunctionDecl(); void SynthMsgSendSuperFunctionDecl(); @@ -436,7 +436,7 @@ namespace { void SynthGetSuperClassFunctionDecl(); void SynthSelGetUidFunctionDecl(); void SynthSuperConstructorFunctionDecl(); - + // Rewriting metadata template<typename MethodIterator> void RewriteObjCMethodsMetaData(MethodIterator MethodBegin, @@ -450,27 +450,27 @@ namespace { void RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, std::string &Result); void RewriteClassSetupInitHook(std::string &Result); - + void RewriteMetaDataIntoBuffer(std::string &Result); void WriteImageInfo(std::string &Result); void RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *CDecl, std::string &Result); void RewriteCategorySetupInitHook(std::string &Result); - + // Rewriting ivar void RewriteIvarOffsetComputation(ObjCIvarDecl *ivar, std::string &Result); Stmt *RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV); - + std::string SynthesizeByrefCopyDestroyHelper(VarDecl *VD, int flag); std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, StringRef funcName, std::string Tag); std::string SynthesizeBlockFunc(BlockExpr *CE, int i, StringRef funcName, std::string Tag); - std::string SynthesizeBlockImpl(BlockExpr *CE, + std::string SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, std::string Desc); - std::string SynthesizeBlockDescriptor(std::string DescTag, + std::string SynthesizeBlockDescriptor(std::string DescTag, std::string ImplTag, int i, StringRef funcName, unsigned hasCopy); @@ -512,18 +512,18 @@ namespace { } return false; } - + bool convertObjCTypeToCStyleType(QualType &T); - + bool needToScanForQualifiers(QualType T); QualType getSuperStructType(); QualType getConstantStringStructType(); QualType convertFunctionTypeOfBlocks(const FunctionType *FT); - + void convertToUnqualifiedObjCType(QualType &T) { if (T->isObjCQualifiedIdType()) { bool isConst = T.isConstQualified(); - T = isConst ? Context->getObjCIdType().withConst() + T = isConst ? Context->getObjCIdType().withConst() : Context->getObjCIdType(); } else if (T->isObjCQualifiedClassType()) @@ -538,7 +538,7 @@ namespace { } } } - + // FIXME: This predicate seems like it would be useful to add to ASTContext. bool isObjCType(QualType T) { if (!LangOpts.ObjC1 && !LangOpts.ObjC2) @@ -562,7 +562,7 @@ namespace { bool PointerTypeTakesAnyObjCQualifiedType(QualType QT); void GetExtentOfArgList(const char *Name, const char *&LParen, const char *&RParen); - + void QuoteDoublequotes(std::string &From, std::string &To) { for (unsigned i = 0; i < From.length(); i++) { if (From[i] == '"') @@ -589,7 +589,7 @@ namespace { return CStyleCastExpr::Create(*Ctx, Ty, VK_RValue, Kind, E, nullptr, TInfo, SourceLocation(), SourceLocation()); } - + bool ImplementationIsNonLazy(const ObjCImplDecl *OD) const { IdentifierInfo* II = &Context->Idents.get("load"); Selector LoadSel = Context->Selectors.getSelector(0, &II); @@ -653,7 +653,7 @@ RewriteModernObjC::RewriteModernObjC(std::string inFile, // may break including some headers. GlobalBlockRewriteFailedDiag = Diags.getCustomDiagID(DiagnosticsEngine::Warning, "rewriting block literal declared in global scope is not implemented"); - + TryFinallyContainsReturnDiag = Diags.getCustomDiagID( DiagnosticsEngine::Warning, "rewriter doesn't support user-specified control flow semantics " @@ -756,7 +756,7 @@ void RewriteModernObjC::HandleTopLevelSingleDecl(Decl *D) { DG.push_back(*DI); else break; - + ++DI; } while (DI != DIEnd); RewriteForwardClassDecl(DG); @@ -781,14 +781,14 @@ void RewriteModernObjC::HandleTopLevelSingleDecl(Decl *D) { DG.push_back(*DI); else break; - + ++DI; } while (DI != DIEnd); RewriteForwardProtocolDecl(DG); continue; } } - + HandleTopLevelSingleDecl(*DI); ++DI; } @@ -836,28 +836,28 @@ static void WriteInternalIvarName(const ObjCInterfaceDecl *IDecl, Result += IvarDecl->getName(); } -std::string +std::string RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) { const ObjCInterfaceDecl *ClassDecl = D->getContainingInterface(); - + // Build name of symbol holding ivar offset. std::string IvarOffsetName; if (D->isBitField()) ObjCIvarBitfieldGroupOffset(D, IvarOffsetName); else WriteInternalIvarName(ClassDecl, D, IvarOffsetName); - + std::string S = "(*("; QualType IvarT = D->getType(); if (D->isBitField()) IvarT = GetGroupRecordTypeForObjCIvarBitfield(D); - + if (!isa<TypedefType>(IvarT) && IvarT->isRecordType()) { RecordDecl *RD = IvarT->getAs<RecordType>()->getDecl(); RD = RD->getDefinition(); if (RD && !RD->getDeclName().getAsIdentifierInfo()) { // decltype(((Foo_IMPL*)0)->bar) * - ObjCContainerDecl *CDecl = + ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(D->getDeclContext()); // ivar in class extensions requires special treatment. if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) @@ -868,7 +868,7 @@ RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) { RecordDecl::Create(*Context, TTK_Struct, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(RecName)); QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD)); - unsigned UnsignedIntSize = + unsigned UnsignedIntSize = static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); Expr *Zero = IntegerLiteral::Create(*Context, llvm::APInt(UnsignedIntSize, 0), @@ -893,7 +893,7 @@ RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) { std::string TypeString(castT.getAsString(Context->getPrintingPolicy())); S += TypeString; S += ")"; - + // ((char *)self + IVAR_OFFSET_SYMBOL_NAME) S += "((char *)self + "; S += IvarOffsetName; @@ -913,7 +913,7 @@ static bool mustSynthesizeSetterGetterMethod(ObjCImplementationDecl *IMP, bool getter) { return getter ? !IMP->getInstanceMethod(PD->getGetterName()) : !IMP->getInstanceMethod(PD->getSetterName()); - + } void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, @@ -922,7 +922,7 @@ void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, static bool objcGetPropertyDefined = false; static bool objcSetPropertyDefined = false; SourceLocation startGetterSetterLoc; - + if (PID->getLocStart().isValid()) { SourceLocation startLoc = PID->getLocStart(); InsertText(startLoc, "// "); @@ -946,7 +946,7 @@ void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, unsigned Attributes = PD->getPropertyAttributes(); if (mustSynthesizeSetterGetterMethod(IMD, PD, true /*getter*/)) { bool GenGetProperty = !(Attributes & ObjCPropertyDecl::OBJC_PR_nonatomic) && - (Attributes & (ObjCPropertyDecl::OBJC_PR_retain | + (Attributes & (ObjCPropertyDecl::OBJC_PR_retain | ObjCPropertyDecl::OBJC_PR_copy)); std::string Getr; if (GenGetProperty && !objcGetPropertyDefined) { @@ -955,7 +955,7 @@ void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, Getr = "\nextern \"C\" __declspec(dllimport) " "id objc_getProperty(id, SEL, long, bool);\n"; } - RewriteObjCMethodDecl(OID->getContainingInterface(), + RewriteObjCMethodDecl(OID->getContainingInterface(), PD->getGetterMethodDecl(), Getr); Getr += "{ "; // Synthesize an explicit cast to gain access to the ivar. @@ -969,7 +969,7 @@ void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, Getr += " _TYPE"; if (FPRetType) { Getr += ")"; // close the precedence "scope" for "*". - + // Now, emit the argument types (if any). if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(FPRetType)){ Getr += "("; @@ -999,14 +999,14 @@ void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, Getr += "; }"; InsertText(startGetterSetterLoc, Getr); } - - if (PD->isReadOnly() || + + if (PD->isReadOnly() || !mustSynthesizeSetterGetterMethod(IMD, PD, false /*setter*/)) return; // Generate the 'setter' function. std::string Setr; - bool GenSetProperty = Attributes & (ObjCPropertyDecl::OBJC_PR_retain | + bool GenSetProperty = Attributes & (ObjCPropertyDecl::OBJC_PR_retain | ObjCPropertyDecl::OBJC_PR_copy); if (GenSetProperty && !objcSetPropertyDefined) { objcSetPropertyDefined = true; @@ -1015,7 +1015,7 @@ void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, "void objc_setProperty (id, SEL, long, id, bool, bool);\n"; } - RewriteObjCMethodDecl(OID->getContainingInterface(), + RewriteObjCMethodDecl(OID->getContainingInterface(), PD->getSetterMethodDecl(), Setr); Setr += "{ "; // Synthesize an explicit cast to initialize the ivar. @@ -1063,9 +1063,9 @@ void RewriteModernObjC::RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl const std::string &typedefString) { SourceLocation startLoc = ClassDecl->getLocStart(); const char *startBuf = SM->getCharacterData(startLoc); - const char *semiPtr = strchr(startBuf, ';'); + const char *semiPtr = strchr(startBuf, ';'); // Replace the @class with typedefs corresponding to the classes. - ReplaceText(startLoc, semiPtr-startBuf+1, typedefString); + ReplaceText(startLoc, semiPtr-startBuf+1, typedefString); } void RewriteModernObjC::RewriteForwardClassDecl(DeclGroupRef D) { @@ -1139,24 +1139,24 @@ void RewriteModernObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { else { ReplaceText(LocStart, 0, "// "); } - + for (auto *I : CatDecl->instance_properties()) RewriteProperty(I); - + for (auto *I : CatDecl->instance_methods()) RewriteMethodDeclaration(I); for (auto *I : CatDecl->class_methods()) RewriteMethodDeclaration(I); // Lastly, comment out the @end. - ReplaceText(CatDecl->getAtEndRange().getBegin(), + ReplaceText(CatDecl->getAtEndRange().getBegin(), strlen("@end"), "/* @end */\n"); } void RewriteModernObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { SourceLocation LocStart = PDecl->getLocStart(); assert(PDecl->isThisDeclarationADefinition()); - + // FIXME: handle protocol headers that are declared across multiple lines. ReplaceText(LocStart, 0, "// "); @@ -1166,7 +1166,7 @@ void RewriteModernObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { RewriteMethodDeclaration(I); for (auto *I : PDecl->instance_properties()) RewriteProperty(I); - + // Lastly, comment out the @end. SourceLocation LocEnd = PDecl->getAtEndRange().getBegin(); ReplaceText(LocEnd, strlen("@end"), "/* @end */\n"); @@ -1196,7 +1196,7 @@ void RewriteModernObjC::RewriteForwardProtocolDecl(DeclGroupRef D) { ReplaceText(LocStart, 0, "// "); } -void +void RewriteModernObjC::RewriteForwardProtocolDecl(const SmallVectorImpl<Decl *> &DG) { SourceLocation LocStart = DG[0]->getLocStart(); if (LocStart.isInvalid()) @@ -1390,11 +1390,11 @@ void RewriteModernObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { // we haven't seen a forward decl - generate a typedef. RewriteOneForwardClassDecl(ClassDecl, ResultStr); RewriteIvarOffsetSymbols(ClassDecl, ResultStr); - + RewriteObjCInternalStruct(ClassDecl, ResultStr); // Mark this typedef as having been written into its c++ equivalent. ObjCWrittenInterfaces.insert(ClassDecl->getCanonicalDecl()); - + for (auto *I : ClassDecl->instance_properties()) RewriteProperty(I); for (auto *I : ClassDecl->instance_methods()) @@ -1403,7 +1403,7 @@ void RewriteModernObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { RewriteMethodDeclaration(I); // Lastly, comment out the @end. - ReplaceText(ClassDecl->getAtEndRange().getBegin(), strlen("@end"), + ReplaceText(ClassDecl->getAtEndRange().getBegin(), strlen("@end"), "/* @end */\n"); } } @@ -1431,7 +1431,7 @@ Stmt *RewriteModernObjC::RewritePropertyOrImplicitSetter(PseudoObjectExpr *Pseud Base = cast<OpaqueValueExpr>(Base)->getSourceExpr(); Base = cast<Expr>(RewriteFunctionBodyOrGlobalInitializer(Base)); } - + unsigned numArgs = OldMsg->getNumArgs(); for (unsigned i = 0; i < numArgs; i++) { Expr *Arg = OldMsg->getArg(i); @@ -1869,11 +1869,11 @@ Stmt *RewriteModernObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) SourceLocation SynchLoc = S->getAtSynchronizedLoc(); ConvertSourceLocationToLineDirective(SynchLoc, buf); buf += "{ id _rethrow = 0; id _sync_obj = (id)"; - + const char *lparenBuf = startBuf; while (*lparenBuf != '(') lparenBuf++; ReplaceText(startLoc, lparenBuf-startBuf+1, buf); - + buf = "; objc_sync_enter(_sync_obj);\n"; buf += "try {\n\tstruct _SYNC_EXIT { _SYNC_EXIT(id arg) : sync_exit(arg) {}"; buf += "\n\t~_SYNC_EXIT() {objc_sync_exit(sync_exit);}"; @@ -1887,16 +1887,16 @@ Stmt *RewriteModernObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) const char *RParenExprLocBuf = SM->getCharacterData(RParenExprLoc); while (*RParenExprLocBuf != ')') RParenExprLocBuf--; RParenExprLoc = startLoc.getLocWithOffset(RParenExprLocBuf-startBuf); - + SourceLocation LBranceLoc = S->getSynchBody()->getLocStart(); const char *LBraceLocBuf = SM->getCharacterData(LBranceLoc); assert (*LBraceLocBuf == '{'); ReplaceText(RParenExprLoc, (LBraceLocBuf - SM->getCharacterData(RParenExprLoc) + 1), buf); - + SourceLocation startRBraceLoc = S->getSynchBody()->getLocEnd(); assert((*SM->getCharacterData(startRBraceLoc) == '}') && "bogus @synchronized block"); - + buf = "} catch (id e) {_rethrow = e;}\n"; Write_RethrowObject(buf); buf += "}\n"; @@ -1923,7 +1923,7 @@ void RewriteModernObjC::WarnAboutReturnGotoStmts(Stmt *S) Stmt *RewriteModernObjC::RewriteObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) { SourceLocation startLoc = S->getAtLoc(); ReplaceText(startLoc, strlen("@autoreleasepool"), "/* @autoreleasepool */"); - ReplaceText(S->getSubStmt()->getLocStart(), 1, + ReplaceText(S->getSubStmt()->getLocStart(), 1, "{ __AtAutoreleasePool __autoreleasepool; "); return nullptr; @@ -1935,7 +1935,7 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { std::string buf; SourceLocation TryLocation = S->getAtTryLoc(); ConvertSourceLocationToLineDirective(TryLocation, buf); - + if (finalStmt) { if (noCatch) buf += "{ id volatile _rethrow = 0;\n"; @@ -1953,11 +1953,11 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { else // @try -> try ReplaceText(startLoc, 1, ""); - + for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { ObjCAtCatchStmt *Catch = S->getCatchStmt(I); VarDecl *catchDecl = Catch->getCatchParamDecl(); - + startLoc = Catch->getLocStart(); bool AtRemoved = false; if (catchDecl) { @@ -1968,12 +1968,12 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { if (IDecl) { std::string Result; ConvertSourceLocationToLineDirective(Catch->getLocStart(), Result); - + startBuf = SM->getCharacterData(startLoc); assert((*startBuf == '@') && "bogus @catch location"); SourceLocation rParenLoc = Catch->getRParenLoc(); const char *rParenBuf = SM->getCharacterData(rParenLoc); - + // _objc_exc_Foo *_e as argument to catch. Result += "catch (_objc_exc_"; Result += IDecl->getNameAsString(); Result += " *_"; Result += catchDecl->getNameAsString(); @@ -1986,7 +1986,7 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { Result += " *"; Result += catchDecl->getNameAsString(); Result += " = ("; Result += IDecl->getNameAsString(); Result += "*)"; Result += "_"; Result += catchDecl->getNameAsString(); - + Result += "; "; SourceLocation lBraceLoc = Catch->getCatchBody()->getLocStart(); ReplaceText(lBraceLoc, 1, Result); @@ -1997,12 +1997,12 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { if (!AtRemoved) // @catch -> catch ReplaceText(startLoc, 1, ""); - + } if (finalStmt) { buf.clear(); SourceLocation FinallyLoc = finalStmt->getLocStart(); - + if (noCatch) { ConvertSourceLocationToLineDirective(FinallyLoc, buf); buf += "catch (id e) {_rethrow = e;}\n"; @@ -2012,7 +2012,7 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { ConvertSourceLocationToLineDirective(FinallyLoc, buf); buf += "catch (id e) {_rethrow = e;}\n"; } - + SourceLocation startFinalLoc = finalStmt->getLocStart(); ReplaceText(startFinalLoc, 8, buf); Stmt *body = finalStmt->getFinallyBody(); @@ -2020,7 +2020,7 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { buf.clear(); Write_RethrowObject(buf); ReplaceText(startFinalBodyLoc, 1, buf); - + SourceLocation endFinalBodyLoc = body->getLocEnd(); ReplaceText(endFinalBodyLoc, 1, "}\n}"); // Now check for any return/continue/go statements within the @try. @@ -2102,7 +2102,7 @@ RewriteModernObjC::SynthesizeCallToFunctionDecl(FunctionDecl *FD, // Now, we cast the reference to a pointer to the objc_msgSend type. QualType pToFunc = Context->getPointerType(msgSendType); - ImplicitCastExpr *ICE = + ImplicitCastExpr *ICE = ImplicitCastExpr::Create(*Context, pToFunc, CK_FunctionToPointerDecay, DRE, nullptr, VK_RValue); @@ -2525,7 +2525,7 @@ void RewriteModernObjC::SynthGetClassFunctionDecl() { // SynthGetSuperClassFunctionDecl - Class class_getSuperclass(Class cls); void RewriteModernObjC::SynthGetSuperClassFunctionDecl() { - IdentifierInfo *getSuperClassIdent = + IdentifierInfo *getSuperClassIdent = &Context->Idents.get("class_getSuperclass"); SmallVector<QualType, 16> ArgTys; ArgTys.push_back(Context->getObjCClassType()); @@ -2602,13 +2602,13 @@ Stmt *RewriteModernObjC::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) { Stmt *RewriteModernObjC::RewriteObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Exp) { unsigned IntSize = static_cast<unsigned>(Context->getTypeSize(Context->IntTy)); - - Expr *FlagExp = IntegerLiteral::Create(*Context, - llvm::APInt(IntSize, Exp->getValue()), + + Expr *FlagExp = IntegerLiteral::Create(*Context, + llvm::APInt(IntSize, Exp->getValue()), Context->IntTy, Exp->getLocation()); CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Context->ObjCBuiltinBoolTy, CK_BitCast, FlagExp); - ParenExpr *PE = new (Context) ParenExpr(Exp->getLocation(), Exp->getExprLoc(), + ParenExpr *PE = new (Context) ParenExpr(Exp->getLocation(), Exp->getExprLoc(), cast); ReplaceStmt(Exp, PE); return PE; @@ -2623,25 +2623,25 @@ Stmt *RewriteModernObjC::RewriteObjCBoxedExpr(ObjCBoxedExpr *Exp) { SynthMsgSendFunctionDecl(); if (!GetClassFunctionDecl) SynthGetClassFunctionDecl(); - + FunctionDecl *MsgSendFlavor = MsgSendFunctionDecl; SourceLocation StartLoc = Exp->getLocStart(); SourceLocation EndLoc = Exp->getLocEnd(); - + // Synthesize a call to objc_msgSend(). SmallVector<Expr*, 4> MsgExprs; SmallVector<Expr*, 4> ClsExprs; - + // Create a call to objc_getClass("<BoxingClass>"). It will be the 1st argument. ObjCMethodDecl *BoxingMethod = Exp->getBoxingMethod(); ObjCInterfaceDecl *BoxingClass = BoxingMethod->getClassInterface(); - + IdentifierInfo *clsName = BoxingClass->getIdentifier(); ClsExprs.push_back(getStringLiteral(clsName->getName())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl, ClsExprs, StartLoc, EndLoc); MsgExprs.push_back(Cls); - + // Create a call to sel_registerName("<BoxingMethod>:"), etc. // it will be the 2nd argument. SmallVector<Expr*, 4> SelExprs; @@ -2650,7 +2650,7 @@ Stmt *RewriteModernObjC::RewriteObjCBoxedExpr(ObjCBoxedExpr *Exp) { CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, SelExprs, StartLoc, EndLoc); MsgExprs.push_back(SelExp); - + // User provided sub-expression is the 3rd, and last, argument. Expr *subExpr = Exp->getSubExpr(); if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(subExpr)) { @@ -2662,35 +2662,35 @@ Stmt *RewriteModernObjC::RewriteObjCBoxedExpr(ObjCBoxedExpr *Exp) { subExpr = NoTypeInfoCStyleCastExpr(Context, type, CK, subExpr); } MsgExprs.push_back(subExpr); - + SmallVector<QualType, 4> ArgTypes; ArgTypes.push_back(Context->getObjCClassType()); ArgTypes.push_back(Context->getObjCSelType()); for (const auto PI : BoxingMethod->parameters()) ArgTypes.push_back(PI->getType()); - + QualType returnType = Exp->getType(); // Get the type, we will need to reference it in a couple spots. QualType msgSendType = MsgSendFlavor->getType(); - + // Create a reference to the objc_msgSend() declaration. DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); - + CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(Context->VoidTy), CK_BitCast, DRE); - + // Now do the "normal" pointer to function cast. QualType castType = getSimpleFunctionType(returnType, ArgTypes, BoxingMethod->isVariadic()); castType = Context->getPointerType(castType); cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast); - + // Don't forget the parens to enforce the proper binding. ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); - + const FunctionType *FT = msgSendType->getAs<FunctionType>(); CallExpr *CE = new (Context) CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); @@ -2707,24 +2707,24 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { SynthMsgSendFunctionDecl(); if (!GetClassFunctionDecl) SynthGetClassFunctionDecl(); - + FunctionDecl *MsgSendFlavor = MsgSendFunctionDecl; SourceLocation StartLoc = Exp->getLocStart(); SourceLocation EndLoc = Exp->getLocEnd(); - + // Build the expression: __NSContainer_literal(int, ...).arr QualType IntQT = Context->IntTy; QualType NSArrayFType = getSimpleFunctionType(Context->VoidTy, IntQT, true); std::string NSArrayFName("__NSContainer_literal"); FunctionDecl *NSArrayFD = SynthBlockInitFunctionDecl(NSArrayFName); - DeclRefExpr *NSArrayDRE = + DeclRefExpr *NSArrayDRE = new (Context) DeclRefExpr(NSArrayFD, false, NSArrayFType, VK_RValue, SourceLocation()); SmallVector<Expr*, 16> InitExprs; unsigned NumElements = Exp->getNumElements(); - unsigned UnsignedIntSize = + unsigned UnsignedIntSize = static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); Expr *count = IntegerLiteral::Create(*Context, llvm::APInt(UnsignedIntSize, NumElements), @@ -2732,7 +2732,7 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { InitExprs.push_back(count); for (unsigned i = 0; i < NumElements; i++) InitExprs.push_back(Exp->getElement(i)); - Expr *NSArrayCallExpr = + Expr *NSArrayCallExpr = new (Context) CallExpr(*Context, NSArrayDRE, InitExprs, NSArrayFType, VK_LValue, SourceLocation()); @@ -2746,27 +2746,27 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { MemberExpr(NSArrayCallExpr, false, SourceLocation(), ARRFD, SourceLocation(), ARRFD->getType(), VK_LValue, OK_Ordinary); QualType ConstIdT = Context->getObjCIdType().withConst(); - CStyleCastExpr * ArrayLiteralObjects = - NoTypeInfoCStyleCastExpr(Context, + CStyleCastExpr * ArrayLiteralObjects = + NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(ConstIdT), CK_BitCast, ArrayLiteralME); - + // Synthesize a call to objc_msgSend(). SmallVector<Expr*, 32> MsgExprs; SmallVector<Expr*, 4> ClsExprs; QualType expType = Exp->getType(); - + // Create a call to objc_getClass("NSArray"). It will be th 1st argument. - ObjCInterfaceDecl *Class = + ObjCInterfaceDecl *Class = expType->getPointeeType()->getAs<ObjCObjectType>()->getInterface(); - + IdentifierInfo *clsName = Class->getIdentifier(); ClsExprs.push_back(getStringLiteral(clsName->getName())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl, ClsExprs, StartLoc, EndLoc); MsgExprs.push_back(Cls); - + // Create a call to sel_registerName("arrayWithObjects:count:"). // it will be the 2nd argument. SmallVector<Expr*, 4> SelExprs; @@ -2776,44 +2776,44 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, SelExprs, StartLoc, EndLoc); MsgExprs.push_back(SelExp); - + // (const id [])objects MsgExprs.push_back(ArrayLiteralObjects); - + // (NSUInteger)cnt Expr *cnt = IntegerLiteral::Create(*Context, llvm::APInt(UnsignedIntSize, NumElements), Context->UnsignedIntTy, SourceLocation()); MsgExprs.push_back(cnt); - + SmallVector<QualType, 4> ArgTypes; ArgTypes.push_back(Context->getObjCClassType()); ArgTypes.push_back(Context->getObjCSelType()); for (const auto *PI : ArrayMethod->parameters()) ArgTypes.push_back(PI->getType()); - + QualType returnType = Exp->getType(); // Get the type, we will need to reference it in a couple spots. QualType msgSendType = MsgSendFlavor->getType(); - + // Create a reference to the objc_msgSend() declaration. DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); - + CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(Context->VoidTy), CK_BitCast, DRE); - + // Now do the "normal" pointer to function cast. QualType castType = getSimpleFunctionType(returnType, ArgTypes, ArrayMethod->isVariadic()); castType = Context->getPointerType(castType); cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast); - + // Don't forget the parens to enforce the proper binding. ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); - + const FunctionType *FT = msgSendType->getAs<FunctionType>(); CallExpr *CE = new (Context) CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); @@ -2830,26 +2830,26 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral SynthMsgSendFunctionDecl(); if (!GetClassFunctionDecl) SynthGetClassFunctionDecl(); - + FunctionDecl *MsgSendFlavor = MsgSendFunctionDecl; SourceLocation StartLoc = Exp->getLocStart(); SourceLocation EndLoc = Exp->getLocEnd(); - + // Build the expression: __NSContainer_literal(int, ...).arr QualType IntQT = Context->IntTy; QualType NSDictFType = getSimpleFunctionType(Context->VoidTy, IntQT, true); std::string NSDictFName("__NSContainer_literal"); FunctionDecl *NSDictFD = SynthBlockInitFunctionDecl(NSDictFName); - DeclRefExpr *NSDictDRE = + DeclRefExpr *NSDictDRE = new (Context) DeclRefExpr(NSDictFD, false, NSDictFType, VK_RValue, SourceLocation()); - + SmallVector<Expr*, 16> KeyExprs; SmallVector<Expr*, 16> ValueExprs; - + unsigned NumElements = Exp->getNumElements(); - unsigned UnsignedIntSize = + unsigned UnsignedIntSize = static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); Expr *count = IntegerLiteral::Create(*Context, llvm::APInt(UnsignedIntSize, NumElements), @@ -2861,9 +2861,9 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral KeyExprs.push_back(Element.Key); ValueExprs.push_back(Element.Value); } - + // (const id [])objects - Expr *NSValueCallExpr = + Expr *NSValueCallExpr = new (Context) CallExpr(*Context, NSDictDRE, ValueExprs, NSDictFType, VK_LValue, SourceLocation()); @@ -2877,13 +2877,13 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral MemberExpr(NSValueCallExpr, false, SourceLocation(), ARRFD, SourceLocation(), ARRFD->getType(), VK_LValue, OK_Ordinary); QualType ConstIdT = Context->getObjCIdType().withConst(); - CStyleCastExpr * DictValueObjects = - NoTypeInfoCStyleCastExpr(Context, + CStyleCastExpr * DictValueObjects = + NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(ConstIdT), CK_BitCast, DictLiteralValueME); // (const id <NSCopying> [])keys - Expr *NSKeyCallExpr = + Expr *NSKeyCallExpr = new (Context) CallExpr(*Context, NSDictDRE, KeyExprs, NSDictFType, VK_LValue, SourceLocation()); @@ -2891,27 +2891,27 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral MemberExpr(NSKeyCallExpr, false, SourceLocation(), ARRFD, SourceLocation(), ARRFD->getType(), VK_LValue, OK_Ordinary); - CStyleCastExpr * DictKeyObjects = - NoTypeInfoCStyleCastExpr(Context, + CStyleCastExpr * DictKeyObjects = + NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(ConstIdT), CK_BitCast, DictLiteralKeyME); - + // Synthesize a call to objc_msgSend(). SmallVector<Expr*, 32> MsgExprs; SmallVector<Expr*, 4> ClsExprs; QualType expType = Exp->getType(); - + // Create a call to objc_getClass("NSArray"). It will be th 1st argument. - ObjCInterfaceDecl *Class = + ObjCInterfaceDecl *Class = expType->getPointeeType()->getAs<ObjCObjectType>()->getInterface(); - + IdentifierInfo *clsName = Class->getIdentifier(); ClsExprs.push_back(getStringLiteral(clsName->getName())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl, ClsExprs, StartLoc, EndLoc); MsgExprs.push_back(Cls); - + // Create a call to sel_registerName("arrayWithObjects:count:"). // it will be the 2nd argument. SmallVector<Expr*, 4> SelExprs; @@ -2920,19 +2920,19 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, SelExprs, StartLoc, EndLoc); MsgExprs.push_back(SelExp); - + // (const id [])objects MsgExprs.push_back(DictValueObjects); - + // (const id <NSCopying> [])keys MsgExprs.push_back(DictKeyObjects); - + // (NSUInteger)cnt Expr *cnt = IntegerLiteral::Create(*Context, llvm::APInt(UnsignedIntSize, NumElements), Context->UnsignedIntTy, SourceLocation()); MsgExprs.push_back(cnt); - + SmallVector<QualType, 8> ArgTypes; ArgTypes.push_back(Context->getObjCClassType()); ArgTypes.push_back(Context->getObjCSelType()); @@ -2945,29 +2945,29 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral } ArgTypes.push_back(T); } - + QualType returnType = Exp->getType(); // Get the type, we will need to reference it in a couple spots. QualType msgSendType = MsgSendFlavor->getType(); - + // Create a reference to the objc_msgSend() declaration. DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); - + CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(Context->VoidTy), CK_BitCast, DRE); - + // Now do the "normal" pointer to function cast. QualType castType = getSimpleFunctionType(returnType, ArgTypes, DictMethod->isVariadic()); castType = Context->getPointerType(castType); cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast); - + // Don't forget the parens to enforce the proper binding. ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); - + const FunctionType *FT = msgSendType->getAs<FunctionType>(); CallExpr *CE = new (Context) CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); @@ -2975,8 +2975,8 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral return CE; } -// struct __rw_objc_super { -// struct objc_object *object; struct objc_object *superClass; +// struct __rw_objc_super { +// struct objc_object *object; struct objc_object *superClass; // }; QualType RewriteModernObjC::getSuperStructType() { if (!SuperStructDecl) { @@ -3057,9 +3057,9 @@ static SourceLocation getFunctionSourceLocation (RewriteModernObjC &R, } void RewriteModernObjC::RewriteLineDirective(const Decl *D) { - + SourceLocation Location = D->getLocation(); - + if (Location.isFileID() && GenerateLineInfo) { std::string LineString("\n#line "); PresumedLoc PLoc = SM->getPresumedLoc(Location); @@ -3069,7 +3069,7 @@ void RewriteModernObjC::RewriteLineDirective(const Decl *D) { if (isa<ObjCMethodDecl>(D)) LineString += "\""; else LineString += "\"\n"; - + Location = D->getLocStart(); if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { if (FD->isExternC() && !FD->isMain()) { @@ -3091,11 +3091,11 @@ void RewriteModernObjC::RewriteLineDirective(const Decl *D) { /// msgSendType - function type of objc_msgSend_stret(...) /// returnType - Result type of the method being synthesized. /// ArgTypes - type of the arguments passed to objc_msgSend_stret, starting with receiver type. -/// MsgExprs - list of argument expressions being passed to objc_msgSend_stret, +/// MsgExprs - list of argument expressions being passed to objc_msgSend_stret, /// starting with receiver. /// Method - Method being rewritten. Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavor, - QualType returnType, + QualType returnType, SmallVectorImpl<QualType> &ArgTypes, SmallVectorImpl<Expr*> &MsgExprs, ObjCMethodDecl *Method) { @@ -3104,11 +3104,11 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla Method ? Method->isVariadic() : false); castType = Context->getPointerType(castType); - + // build type for containing the objc_msgSend_stret object. static unsigned stretCount=0; std::string name = "__Stret"; name += utostr(stretCount); - std::string str = + std::string str = "extern \"C\" void * __cdecl memset(void *_Dst, int _Val, size_t _Size);\n"; str += "namespace {\n"; str += "struct "; str += name; @@ -3127,13 +3127,13 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla Context->getPrintingPolicy()); str += ", "; str += ArgName; } - + str += ") {\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++) { @@ -3144,11 +3144,11 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla 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++) { @@ -3159,7 +3159,7 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla str += ", arg"; str += utostr(i); } str += ");\n"; - + str += "\t}\n"; str += "\t"; str += returnType.getAsString(Context->getPrintingPolicy()); str += " s;\n"; @@ -3174,7 +3174,7 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla InsertText(FunLocStart, str); ++stretCount; - + // AST for __Stretn(receiver, args).s; IdentifierInfo *ID = &Context->Idents.get(name); FunctionDecl *FD = FunctionDecl::Create(*Context, TUDecl, SourceLocation(), @@ -3266,7 +3266,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ClsExprs.push_back(Cls); Cls = SynthesizeCallToFunctionDecl(GetSuperClassFunctionDecl, ClsExprs, StartLoc, EndLoc); - + // (id)class_getSuperclass((Class)objc_getClass("CurrentClass")) // To turn off a warning, type-cast to 'id' InitExprs.push_back( // set 'super class', using class_getSuperclass(). @@ -3350,7 +3350,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, Context->getObjCIdType(), VK_RValue, SourceLocation())) ); // set the 'receiver'. - + // (id)class_getSuperclass((Class)objc_getClass("CurrentClass")) SmallVector<Expr*, 8> ClsExprs; ClsExprs.push_back(getStringLiteral(ClassDecl->getIdentifier()->getName())); @@ -3361,7 +3361,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ClsExprs.push_back(Cls); Cls = SynthesizeCallToFunctionDecl(GetSuperClassFunctionDecl, ClsExprs, StartLoc, EndLoc); - + // (id)class_getSuperclass((Class)objc_getClass("CurrentClass")) // To turn off a warning, type-cast to 'id' InitExprs.push_back( @@ -3446,7 +3446,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, (void)convertBlockPointerToFunctionPointer(type); const Expr *SubExpr = ICE->IgnoreParenImpCasts(); CastKind CK; - if (SubExpr->getType()->isIntegralType(*Context) && + if (SubExpr->getType()->isIntegralType(*Context) && type->isBooleanType()) { CK = CK_IntegralToBoolean; } else if (type->isObjCObjectPointerType()) { @@ -3591,7 +3591,7 @@ QualType RewriteModernObjC::getProtocolType() { /// The forward references (and metadata) are generated in /// RewriteModernObjC::HandleTranslationUnit(). Stmt *RewriteModernObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) { - std::string Name = "_OBJC_PROTOCOL_REFERENCE_$_" + + std::string Name = "_OBJC_PROTOCOL_REFERENCE_$_" + Exp->getProtocol()->getNameAsString(); IdentifierInfo *ID = &Context->Idents.get(Name); VarDecl *VD = VarDecl::Create(*Context, TUDecl, SourceLocation(), @@ -3608,9 +3608,9 @@ Stmt *RewriteModernObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) { return castExpr; } -/// IsTagDefinedInsideClass - This routine checks that a named tagged type -/// is defined inside an objective-c class. If so, it returns true. -bool RewriteModernObjC::IsTagDefinedInsideClass(ObjCContainerDecl *IDecl, +/// IsTagDefinedInsideClass - This routine checks that a named tagged type +/// is defined inside an objective-c class. If so, it returns true. +bool RewriteModernObjC::IsTagDefinedInsideClass(ObjCContainerDecl *IDecl, TagDecl *Tag, bool &IsNamedDefinition) { if (!IDecl) @@ -3638,13 +3638,13 @@ bool RewriteModernObjC::IsTagDefinedInsideClass(ObjCContainerDecl *IDecl, /// RewriteObjCFieldDeclType - This routine rewrites a type into the buffer. /// It handles elaborated types, as well as enum types in the process. -bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, +bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, std::string &Result) { if (isa<TypedefType>(Type)) { Result += "\t"; return false; } - + if (Type->isArrayType()) { QualType ElemTy = Context->getBaseElementType(Type); return RewriteObjCFieldDeclType(ElemTy, Result); @@ -3658,7 +3658,7 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, Result += "\n\tunion "; else assert(false && "class not allowed as an ivar type"); - + Result += RD->getName(); if (GlobalDefinedTags.count(RD)) { // struct/union is defined globally, use it. @@ -3668,7 +3668,7 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, Result += " {\n"; for (auto *FD : RD->fields()) RewriteObjCFieldDecl(FD, Result); - Result += "\t} "; + Result += "\t} "; return true; } } @@ -3682,7 +3682,7 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, Result += " "; return true; } - + Result += " {\n"; for (const auto *EC : ED->enumerators()) { Result += "\t"; Result += EC->getName(); Result += " = "; @@ -3690,11 +3690,11 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, Result += Val.toString(10); Result += ",\n"; } - Result += "\t} "; + Result += "\t} "; return true; } } - + Result += "\t"; convertObjCTypeToCStyleType(Type); return false; @@ -3703,12 +3703,12 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, /// RewriteObjCFieldDecl - This routine rewrites a field into the buffer. /// It handles elaborated types, as well as enum types in the process. -void RewriteModernObjC::RewriteObjCFieldDecl(FieldDecl *fieldDecl, +void RewriteModernObjC::RewriteObjCFieldDecl(FieldDecl *fieldDecl, std::string &Result) { QualType Type = fieldDecl->getType(); std::string Name = fieldDecl->getNameAsString(); - - bool EleboratedType = RewriteObjCFieldDeclType(Type, Result); + + bool EleboratedType = RewriteObjCFieldDeclType(Type, Result); if (!EleboratedType) Type.getAsStringInternal(Name, Context->getPrintingPolicy()); Result += Name; @@ -3727,20 +3727,20 @@ void RewriteModernObjC::RewriteObjCFieldDecl(FieldDecl *fieldDecl, AT = Context->getAsArrayType(AT->getElementType()); } while (AT); } - + Result += ";\n"; } /// RewriteLocallyDefinedNamedAggregates - This routine rewrites locally defined /// named aggregate types into the input buffer. -void RewriteModernObjC::RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDecl, +void RewriteModernObjC::RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDecl, std::string &Result) { QualType Type = fieldDecl->getType(); if (isa<TypedefType>(Type)) return; if (Type->isArrayType()) Type = Context->getBaseElementType(Type); - ObjCContainerDecl *IDecl = + ObjCContainerDecl *IDecl = dyn_cast<ObjCContainerDecl>(fieldDecl->getDeclContext()); TagDecl *TD = nullptr; @@ -3750,11 +3750,11 @@ void RewriteModernObjC::RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDec else if (Type->isEnumeralType()) { TD = Type->getAs<EnumType>()->getDecl(); } - + if (TD) { if (GlobalDefinedTags.count(TD)) return; - + bool IsNamedDefinition = false; if (IsTagDefinedInsideClass(IDecl, TD, IsNamedDefinition)) { RewriteObjCFieldDeclType(Type, Result); @@ -3775,7 +3775,7 @@ unsigned RewriteModernObjC::ObjCIvarBitfieldGroupNo(ObjCIvarDecl *IV) { for (const ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); IVD; IVD = IVD->getNextIvar()) IVars.push_back(IVD); - + for (unsigned i = 0, e = IVars.size(); i < e; i++) if (IVars[i]->isBitField()) { IvarGroupNumber[IVars[i++]] = ++GroupNo; @@ -3816,7 +3816,7 @@ QualType RewriteModernObjC::GetGroupRecordTypeForObjCIvarBitfield(ObjCIvarDecl * std::pair<const ObjCInterfaceDecl*, unsigned> tuple = std::make_pair(CDecl, GroupNo); if (GroupRecordType.count(tuple)) return GroupRecordType[tuple]; - + SmallVector<ObjCIvarDecl *, 8> IVars; for (const ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); IVD; IVD = IVD->getNextIvar()) { @@ -3840,7 +3840,7 @@ QualType RewriteModernObjC::GetGroupRecordTypeForObjCIvarBitfield(ObjCIvarDecl * } QualType RetQT = GroupRecordType[tuple]; assert(!RetQT.isNull() && "GetGroupRecordTypeForObjCIvarBitfield struct type is NULL"); - + return RetQT; } @@ -3895,13 +3895,13 @@ void RewriteModernObjC::RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl, for (ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); IVD; IVD = IVD->getNextIvar()) IVars.push_back(IVD); - + SourceLocation LocStart = CDecl->getLocStart(); SourceLocation LocEnd = CDecl->getEndOfDefinitionLoc(); - + const char *startBuf = SM->getCharacterData(LocStart); const char *endBuf = SM->getCharacterData(LocEnd); - + // If no ivars and no root or if its root, directly or indirectly, // have no ivars (thus not synthesized) then no need to synthesize this class. if ((!CDecl->isThisDeclarationADefinition() || IVars.size() == 0) && @@ -3910,13 +3910,13 @@ void RewriteModernObjC::RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl, ReplaceText(LocStart, endBuf-startBuf, Result); return; } - + // Insert named struct/union definitions inside class to // outer scope. This follows semantics of locally defined // struct/unions in objective-c classes. for (unsigned i = 0, e = IVars.size(); i < e; i++) RewriteLocallyDefinedNamedAggregates(IVars[i], Result); - + // Insert named structs which are syntheized to group ivar bitfields // to outer scope as well. for (unsigned i = 0, e = IVars.size(); i < e; i++) @@ -3928,17 +3928,17 @@ void RewriteModernObjC::RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl, // skip over ivar bitfields in this group. SKIP_BITFIELDS(i , e, IVars); } - + Result += "\nstruct "; Result += CDecl->getNameAsString(); Result += "_IMPL {\n"; - + if (RCDecl && ObjCSynthesizedStructs.count(RCDecl)) { Result += "\tstruct "; Result += RCDecl->getNameAsString(); Result += "_IMPL "; Result += RCDecl->getNameAsString(); Result += "_IVARS;\n"; } - + for (unsigned i = 0, e = IVars.size(); i < e; i++) { if (IVars[i]->isBitField()) { ObjCIvarDecl *IV = IVars[i]; @@ -3984,7 +3984,7 @@ void RewriteModernObjC::RewriteIvarOffsetSymbols(ObjCInterfaceDecl *CDecl, if (LangOpts.MicrosoftExt) Result += "__declspec(allocate(\".objc_ivar$B\")) "; Result += "extern \"C\" "; - if (LangOpts.MicrosoftExt && + if (LangOpts.MicrosoftExt && IvarDecl->getAccessControl() != ObjCIvarDecl::Private && IvarDecl->getAccessControl() != ObjCIvarDecl::Package) Result += "__declspec(dllimport) "; @@ -4031,14 +4031,14 @@ void RewriteModernObjC::RewriteImplementations() { } } -void RewriteModernObjC::RewriteByRefString(std::string &ResultStr, +void RewriteModernObjC::RewriteByRefString(std::string &ResultStr, const std::string &Name, ValueDecl *VD, bool def) { - assert(BlockByRefDeclNo.count(VD) && + assert(BlockByRefDeclNo.count(VD) && "RewriteByRefString: ByRef decl missing"); if (def) ResultStr += "struct "; - ResultStr += "__Block_byref_" + Name + + ResultStr += "__Block_byref_" + Name + "_" + utostr(BlockByRefDeclNo[VD]) ; } @@ -4057,7 +4057,7 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, SourceLocation BlockLoc = CE->getExprLoc(); std::string S; ConvertSourceLocationToLineDirective(BlockLoc, S); - + S += "static " + RT.getAsString(Context->getPrintingPolicy()) + " __" + funcName.str() + "_block_func_" + utostr(i); @@ -4132,7 +4132,7 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, if (HasLocalVariableExternalStorage(*I)) QT = Context->getPointerType(QT); QT.getAsStringInternal(Name, Context->getPrintingPolicy()); - S += Name + " = __cself->" + + S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by copy\n"; } } @@ -4168,7 +4168,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, S += ", " + utostr(BLOCK_FIELD_IS_OBJECT) + "/*BLOCK_FIELD_IS_OBJECT*/);"; } S += "}\n"; - + S += "\nstatic void __"; S += funcName; S += "_block_dispose_" + utostr(i); @@ -4188,7 +4188,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, return S; } -std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, +std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, std::string Desc) { std::string S = "\nstruct " + Tag; std::string Constructor = " " + Tag; @@ -4277,7 +4277,7 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta Constructor += ", "; Constructor += Name + "(_" + Name + "->__forwarding)"; } - + Constructor += " {\n"; if (GlobalVarDecl) Constructor += " impl.isa = &_NSConcreteGlobalBlock;\n"; @@ -4303,19 +4303,19 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta return S; } -std::string RewriteModernObjC::SynthesizeBlockDescriptor(std::string DescTag, +std::string RewriteModernObjC::SynthesizeBlockDescriptor(std::string DescTag, std::string ImplTag, int i, StringRef FunName, unsigned hasCopy) { std::string S = "\nstatic struct " + DescTag; - + S += " {\n size_t reserved;\n"; S += " size_t Block_size;\n"; if (hasCopy) { S += " void (*copy)(struct "; S += ImplTag; S += "*, struct "; S += ImplTag; S += "*);\n"; - + S += " void (*dispose)(struct "; S += ImplTag; S += "*);\n"; } @@ -4343,7 +4343,7 @@ void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, SC += "() {}"; InsertText(FunLocStart, SC); } - + // Insert closures that were part of the function. for (unsigned i = 0, count=0; i < Blocks.size(); i++) { CollectBlockDeclRefInfo(Blocks[i]); @@ -4368,7 +4368,7 @@ void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, // imported objects in the inner blocks not used in the outer // blocks must be copied/disposed in the outer block as well. - if (VD->getType()->isObjCObjectPointerType() || + if (VD->getType()->isObjCObjectPointerType() || VD->getType()->isBlockPointerType()) ImportedBlockDecls.insert(VD); } @@ -4415,7 +4415,7 @@ void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, } if (GlobalConstructionExp) { // extra fancy dance for global literal expression. - + // Always the latest block expression on the block stack. std::string Tag = "__"; Tag += FunName; @@ -4424,7 +4424,7 @@ void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, std::string globalBuf = "static "; globalBuf += Tag; globalBuf += " "; std::string SStr; - + llvm::raw_string_ostream constructorExprBuf(SStr); GlobalConstructionExp->printPretty(constructorExprBuf, nullptr, PrintingPolicy(LangOpts)); @@ -4441,7 +4441,7 @@ void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, } void RewriteModernObjC::InsertBlockLiteralsWithinFunction(FunctionDecl *FD) { - SourceLocation FunLocStart = + SourceLocation FunLocStart = (!Blocks.empty()) ? getFunctionSourceLocation(*this, FD) : FD->getTypeSpecStartLoc(); StringRef FuncName = FD->getName(); @@ -4528,7 +4528,7 @@ bool RewriteModernObjC::convertObjCTypeToCStyleType(QualType &T) { } } } - + convertToUnqualifiedObjCType(T); return T != oldT; } @@ -4544,7 +4544,7 @@ QualType RewriteModernObjC::convertFunctionTypeOfBlocks(const FunctionType *FT) SmallVector<QualType, 8> ArgTypes; QualType Res = FT->getReturnType(); bool modified = convertObjCTypeToCStyleType(Res); - + if (FTP) { for (auto &I : FTP->param_types()) { QualType t = I; @@ -4569,13 +4569,13 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp CPT = DRE->getType()->getAs<BlockPointerType>(); } else if (const MemberExpr *MExpr = dyn_cast<MemberExpr>(BlockExp)) { CPT = MExpr->getType()->getAs<BlockPointerType>(); - } + } else if (const ParenExpr *PRE = dyn_cast<ParenExpr>(BlockExp)) { return SynthesizeBlockCall(Exp, PRE->getSubExpr()); } - else if (const ImplicitCastExpr *IEXPR = dyn_cast<ImplicitCastExpr>(BlockExp)) + else if (const ImplicitCastExpr *IEXPR = dyn_cast<ImplicitCastExpr>(BlockExp)) CPT = IEXPR->getType()->getAs<BlockPointerType>(); - else if (const ConditionalOperator *CEXPR = + else if (const ConditionalOperator *CEXPR = dyn_cast<ConditionalOperator>(BlockExp)) { Expr *LHSExp = CEXPR->getLHS(); Stmt *LHSStmt = SynthesizeBlockCall(Exp, LHSExp); @@ -4676,7 +4676,7 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp // }; //} Stmt *RewriteModernObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { - // Rewrite the byref variable into BYREFVAR->__forwarding->BYREFVAR + // Rewrite the byref variable into BYREFVAR->__forwarding->BYREFVAR // for each DeclRefExp where BYREFVAR is name of the variable. ValueDecl *VD = DeclRefExp->getDecl(); bool isArrow = DeclRefExp->refersToEnclosingVariableOrCapture() || @@ -4684,7 +4684,7 @@ Stmt *RewriteModernObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { FieldDecl *FD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), - &Context->Idents.get("__forwarding"), + &Context->Idents.get("__forwarding"), Context->VoidPtrTy, nullptr, /*BitWidth=*/nullptr, /*Mutable=*/true, ICIS_NoInit); @@ -4694,7 +4694,7 @@ Stmt *RewriteModernObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { StringRef Name = VD->getName(); FD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), - &Context->Idents.get(Name), + &Context->Idents.get(Name), Context->VoidPtrTy, nullptr, /*BitWidth=*/nullptr, /*Mutable=*/true, ICIS_NoInit); @@ -4703,14 +4703,14 @@ Stmt *RewriteModernObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { DeclRefExp->getType(), VK_LValue, OK_Ordinary); // Need parens to enforce precedence. - ParenExpr *PE = new (Context) ParenExpr(DeclRefExp->getExprLoc(), - DeclRefExp->getExprLoc(), + ParenExpr *PE = new (Context) ParenExpr(DeclRefExp->getExprLoc(), + DeclRefExp->getExprLoc(), ME); ReplaceStmt(DeclRefExp, PE); return PE; } -// Rewrites the imported local variable V with external storage +// Rewrites the imported local variable V with external storage // (static, extern, etc.) as *V // Stmt *RewriteModernObjC::RewriteLocalVariableExternalStorage(DeclRefExpr *DRE) { @@ -4722,7 +4722,7 @@ Stmt *RewriteModernObjC::RewriteLocalVariableExternalStorage(DeclRefExpr *DRE) { VK_LValue, OK_Ordinary, DRE->getLocation(), false); // Need parens to enforce precedence. - ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), + ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), Exp); ReplaceStmt(DRE, PE); return PE; @@ -4771,7 +4771,7 @@ void RewriteModernObjC::RewriteImplicitCastObjCExpr(CastExpr *IC) { if (CastKind != CK_BlockPointerToObjCPointerCast && CastKind != CK_AnyPointerToBlockPointerCast) return; - + QualType QT = IC->getType(); (void)convertBlockPointerToFunctionPointer(QT); std::string TypeString(QT.getAsString(Context->getPrintingPolicy())); @@ -4851,7 +4851,7 @@ bool RewriteModernObjC::PointerTypeTakesAnyObjCQualifiedType(QualType QT) { I->getPointeeType()->isObjCQualifiedInterfaceType()) return true; } - + } return false; } @@ -4917,7 +4917,7 @@ void RewriteModernObjC::RewriteBlockPointerDecl(NamedDecl *ND) { } buf += ')'; OrigLength++; - + if (PointerTypeTakesAnyBlockArguments(DeclT) || PointerTypeTakesAnyObjCQualifiedType(DeclT)) { // Replace the '^' with '*' for arguments. @@ -4930,7 +4930,7 @@ void RewriteModernObjC::RewriteBlockPointerDecl(NamedDecl *ND) { if (*argListBegin == '^') buf += '*'; else if (*argListBegin == '<') { - buf += "/*"; + buf += "/*"; buf += *argListBegin++; OrigLength++; while (*argListBegin != '>') { @@ -4954,19 +4954,19 @@ void RewriteModernObjC::RewriteBlockPointerDecl(NamedDecl *ND) { /// SynthesizeByrefCopyDestroyHelper - This routine synthesizes: /// void __Block_byref_id_object_copy(struct Block_byref_id_object *dst, /// struct Block_byref_id_object *src) { -/// _Block_object_assign (&_dest->object, _src->object, +/// _Block_object_assign (&_dest->object, _src->object, /// BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT /// [|BLOCK_FIELD_IS_WEAK]) // object -/// _Block_object_assign(&_dest->object, _src->object, +/// _Block_object_assign(&_dest->object, _src->object, /// BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK /// [|BLOCK_FIELD_IS_WEAK]) // block /// } /// And: /// void __Block_byref_id_object_dispose(struct Block_byref_id_object *_src) { -/// _Block_object_dispose(_src->object, +/// _Block_object_dispose(_src->object, /// BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT /// [|BLOCK_FIELD_IS_WEAK]) // object -/// _Block_object_dispose(_src->object, +/// _Block_object_dispose(_src->object, /// BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK /// [|BLOCK_FIELD_IS_WEAK]) // block /// } @@ -4980,14 +4980,14 @@ std::string RewriteModernObjC::SynthesizeByrefCopyDestroyHelper(VarDecl *VD, S = "static void __Block_byref_id_object_copy_"; S += utostr(flag); S += "(void *dst, void *src) {\n"; - + // offset into the object pointer is computed as: // void * + void* + int + int + void* + void * - unsigned IntSize = + unsigned IntSize = static_cast<unsigned>(Context->getTypeSize(Context->IntTy)); - unsigned VoidPtrSize = + unsigned VoidPtrSize = static_cast<unsigned>(Context->getTypeSize(Context->VoidPtrTy)); - + unsigned offset = (VoidPtrSize*4 + IntSize + IntSize)/Context->getCharWidth(); S += " _Block_object_assign((char*)dst + "; S += utostr(offset); @@ -4996,7 +4996,7 @@ std::string RewriteModernObjC::SynthesizeByrefCopyDestroyHelper(VarDecl *VD, S += "), "; S += utostr(flag); S += ");\n}\n"; - + S += "static void __Block_byref_id_object_dispose_"; S += utostr(flag); S += "(void *src) {\n"; @@ -5021,8 +5021,8 @@ std::string RewriteModernObjC::SynthesizeByrefCopyDestroyHelper(VarDecl *VD, /// }; /// /// It then replaces declaration of ND variable with: -/// struct __Block_byref_ND ND = {__isa=0B, __forwarding=&ND, __flags=some_flag, -/// __size=sizeof(struct __Block_byref_ND), +/// struct __Block_byref_ND ND = {__isa=0B, __forwarding=&ND, __flags=some_flag, +/// __size=sizeof(struct __Block_byref_ND), /// ND=initializer-if-any}; /// /// @@ -5048,7 +5048,7 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl, ByrefType += " *__forwarding;\n"; ByrefType += " int __flags;\n"; ByrefType += " int __size;\n"; - // Add void *__Block_byref_id_object_copy; + // Add void *__Block_byref_id_object_copy; // void *__Block_byref_id_object_dispose; if needed. QualType Ty = ND->getType(); bool HasCopyAndDispose = Context->BlockRequiresCopying(Ty, ND); @@ -5060,7 +5060,7 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl, QualType T = Ty; (void)convertBlockPointerToFunctionPointer(T); T.getAsStringInternal(Name, Context->getPrintingPolicy()); - + ByrefType += " " + Name + ";\n"; ByrefType += "};\n"; // Insert this type in global scope. It is needed by helper function. @@ -5072,7 +5072,7 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl, FunLocStart = CurMethodDef->getLocStart(); } InsertText(FunLocStart, ByrefType); - + if (Ty.isObjCGCWeak()) { flag |= BLOCK_FIELD_IS_WEAK; isa = 1; @@ -5089,9 +5089,9 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl, if (!HF.empty()) Preamble += HF; } - - // struct __Block_byref_ND ND = - // {0, &ND, some_flag, __size=sizeof(struct __Block_byref_ND), + + // struct __Block_byref_ND ND = + // {0, &ND, some_flag, __size=sizeof(struct __Block_byref_ND), // initializer-if-any}; bool hasInit = (ND->getInit() != nullptr); // FIXME. rewriter does not support __block c++ objects which @@ -5102,7 +5102,7 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl, if (CXXDecl && CXXDecl->isDefaultConstructor()) hasInit = false; } - + unsigned flags = 0; if (HasCopyAndDispose) flags |= BLOCK_HAS_COPY_DISPOSE; @@ -5125,7 +5125,7 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl, ByrefType += ", __Block_byref_id_object_dispose_"; ByrefType += utostr(flag); } - + if (!firstDecl) { // In multiple __block declarations, and for all but 1st declaration, // find location of the separating comma. This would be start location @@ -5139,7 +5139,7 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl, DeclLoc = DeclLoc.getLocWithOffset(commaBuf - startDeclBuf); startBuf = commaBuf; } - + if (!hasInit) { ByrefType += "};\n"; unsigned nameSize = Name.size(); @@ -5164,11 +5164,11 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl, const char separator = lastDecl ? ';' : ','; const char *startInitializerBuf = SM->getCharacterData(startLoc); const char *separatorBuf = strchr(startInitializerBuf, separator); - assert((*separatorBuf == separator) && + assert((*separatorBuf == separator) && "RewriteByRefVar: can't find ';' or ','"); SourceLocation separatorLoc = startLoc.getLocWithOffset(separatorBuf-startInitializerBuf); - + InsertText(separatorLoc, lastDecl ? "}" : "};\n"); } } @@ -5196,7 +5196,7 @@ void RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { // Find any imported blocks...they will need special attention. for (unsigned i = 0; i < BlockDeclRefs.size(); i++) if (BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>() || - BlockDeclRefs[i]->getType()->isObjCObjectPointerType() || + BlockDeclRefs[i]->getType()->isObjCObjectPointerType() || BlockDeclRefs[i]->getType()->isBlockPointerType()) ImportedBlockDecls.insert(BlockDeclRefs[i]->getDecl()); } @@ -5213,11 +5213,11 @@ FunctionDecl *RewriteModernObjC::SynthBlockInitFunctionDecl(StringRef name) { Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, const SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs) { const BlockDecl *block = Exp->getBlockDecl(); - + Blocks.push_back(Exp); CollectBlockDeclRefInfo(Exp); - + // Add inner imported variables now used in current block. int countOfInnerDecls = 0; if (!InnerBlockDeclRefs.empty()) { @@ -5243,12 +5243,12 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, // Find any imported blocks...they will need special attention. for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) if (InnerBlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>() || - InnerBlockDeclRefs[i]->getType()->isObjCObjectPointerType() || + InnerBlockDeclRefs[i]->getType()->isObjCObjectPointerType() || InnerBlockDeclRefs[i]->getType()->isBlockPointerType()) ImportedBlockDecls.insert(InnerBlockDeclRefs[i]->getDecl()); } InnerDeclRefsCount.push_back(countOfInnerDecls); - + std::string FuncName; if (CurFunctionDef) @@ -5258,14 +5258,14 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, else if (GlobalVarDecl) FuncName = std::string(GlobalVarDecl->getNameAsString()); - bool GlobalBlockExpr = + bool GlobalBlockExpr = block->getDeclContext()->getRedeclContext()->isFileContext(); - + if (GlobalBlockExpr && !GlobalVarDecl) { Diags.Report(block->getLocation(), GlobalBlockRewriteFailedDiag); GlobalBlockExpr = false; } - + std::string BlockNumber = utostr(Blocks.size()-1); std::string Func = "__" + FuncName + "_block_func_" + BlockNumber; @@ -5279,13 +5279,13 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, // Simulate a constructor call... std::string Tag; - + if (GlobalBlockExpr) Tag = "__global_"; else Tag = "__"; Tag += FuncName + "_block_impl_" + BlockNumber; - + FD = SynthBlockInitFunctionDecl(Tag); DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, FType, VK_RValue, SourceLocation()); @@ -5310,13 +5310,13 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, false, Context->VoidPtrTy, VK_LValue, - SourceLocation()), + SourceLocation()), UO_AddrOf, - Context->getPointerType(Context->VoidPtrTy), + Context->getPointerType(Context->VoidPtrTy), VK_RValue, OK_Ordinary, SourceLocation(), false); - InitExprs.push_back(DescRefExpr); - + InitExprs.push_back(DescRefExpr); + // Add initializers for any closure decl refs. if (BlockDeclRefs.size()) { Expr *Exp; @@ -5352,7 +5352,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, OK_Ordinary, SourceLocation(), false); } - + } InitExprs.push_back(Exp); } @@ -5363,14 +5363,14 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, std::string Name(ND->getNameAsString()); std::string RecName; RewriteByRefString(RecName, Name, ND, true); - IdentifierInfo *II = &Context->Idents.get(RecName.c_str() + IdentifierInfo *II = &Context->Idents.get(RecName.c_str() + sizeof("struct")); RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl, SourceLocation(), SourceLocation(), II); assert(RD && "SynthBlockInitExpr(): Can't find RecordDecl"); QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); - + FD = SynthBlockInitFunctionDecl((*I)->getName()); Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, SourceLocation()); @@ -5379,7 +5379,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, for (const auto &CI : block->captures()) { const VarDecl *variable = CI.getVariable(); if (variable == ND && CI.isNested()) { - assert (CI.isByRef() && + assert (CI.isByRef() && "SynthBlockInitExpr - captured block variable is not byref"); isNestedCapturedVar = true; break; @@ -5399,22 +5399,22 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, if (ImportedBlockDecls.size()) { // generate BLOCK_HAS_COPY_DISPOSE(have helper funcs) | BLOCK_HAS_DESCRIPTOR int flag = (BLOCK_HAS_COPY_DISPOSE | BLOCK_HAS_DESCRIPTOR); - unsigned IntSize = + unsigned IntSize = static_cast<unsigned>(Context->getTypeSize(Context->IntTy)); - Expr *FlagExp = IntegerLiteral::Create(*Context, llvm::APInt(IntSize, flag), + Expr *FlagExp = IntegerLiteral::Create(*Context, llvm::APInt(IntSize, flag), Context->IntTy, SourceLocation()); InitExprs.push_back(FlagExp); } NewRep = new (Context) CallExpr(*Context, DRE, InitExprs, FType, VK_LValue, SourceLocation()); - + if (GlobalBlockExpr) { assert (!GlobalConstructionExp && "SynthBlockInitExpr - GlobalConstructionExp must be null"); GlobalConstructionExp = NewRep; NewRep = DRE; } - + NewRep = new (Context) UnaryOperator(NewRep, UO_AddrOf, Context->getPointerType(NewRep->getType()), VK_RValue, OK_Ordinary, SourceLocation(), false); @@ -5423,7 +5423,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, // Put Paren around the call. NewRep = new (Context) ParenExpr(SourceLocation(), SourceLocation(), NewRep); - + BlockDeclRefs.clear(); BlockByRefDecls.clear(); BlockByRefDeclsPtrSet.clear(); @@ -5434,7 +5434,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, } bool RewriteModernObjC::IsDeclStmtInForeachHeader(DeclStmt *DS) { - if (const ObjCForCollectionStmt * CS = + if (const ObjCForCollectionStmt * CS = dyn_cast<ObjCForCollectionStmt>(Stmts.back())) return CS->getElement() == DS; return false; @@ -5506,7 +5506,7 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { RewrittenBlockExprs[BE] = Str; Stmt *blockTranscribed = SynthBlockInitExpr(BE, InnerBlockDeclRefs); - + //blockTranscribed->dump(); ReplaceStmt(S, blockTranscribed); return blockTranscribed; @@ -5520,17 +5520,17 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { if (ObjCStringLiteral *AtString = dyn_cast<ObjCStringLiteral>(S)) return RewriteObjCStringLiteral(AtString); - + if (ObjCBoolLiteralExpr *BoolLitExpr = dyn_cast<ObjCBoolLiteralExpr>(S)) return RewriteObjCBoolLiteralExpr(BoolLitExpr); - + if (ObjCBoxedExpr *BoxedExpr = dyn_cast<ObjCBoxedExpr>(S)) return RewriteObjCBoxedExpr(BoxedExpr); - + if (ObjCArrayLiteral *ArrayLitExpr = dyn_cast<ObjCArrayLiteral>(S)) return RewriteObjCArrayLiteralExpr(ArrayLitExpr); - - if (ObjCDictionaryLiteral *DictionaryLitExpr = + + if (ObjCDictionaryLiteral *DictionaryLitExpr = dyn_cast<ObjCDictionaryLiteral>(S)) return RewriteObjCDictionaryLiteralExpr(DictionaryLitExpr); @@ -5557,11 +5557,11 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { return RewriteMessageExpr(MessExpr); } - if (ObjCAutoreleasePoolStmt *StmtAutoRelease = + if (ObjCAutoreleasePoolStmt *StmtAutoRelease = dyn_cast<ObjCAutoreleasePoolStmt>(S)) { return RewriteObjCAutoreleasePoolStmt(StmtAutoRelease); } - + if (ObjCAtTryStmt *StmtTry = dyn_cast<ObjCAtTryStmt>(S)) return RewriteObjCTryStmt(StmtTry); @@ -5595,7 +5595,7 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { // the context of an ObjCForCollectionStmt. For example: // NSArray *someArray; // for (id <FooProtocol> index in someArray) ; - // This is because RewriteObjCForCollectionStmt() does textual rewriting + // This is because RewriteObjCForCollectionStmt() does textual rewriting // and it depends on the original text locations/positions. if (Stmts.empty() || !IsDeclStmtInForeachHeader(DS)) RewriteObjCQualifiedInterfaceTypes(*DS->decl_begin()); @@ -5617,7 +5617,7 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { BlockByRefDeclNo[ND] = uniqueByrefDeclCount++; RewriteByRefVar(VD, (DI == DS->decl_begin()), ((DI+1) == DE)); } - else + else RewriteTypeOfDecl(VD); } } @@ -5643,13 +5643,13 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { } // Handle blocks rewriting. if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(S)) { - ValueDecl *VD = DRE->getDecl(); + ValueDecl *VD = DRE->getDecl(); if (VD->hasAttr<BlocksAttr>()) return RewriteBlockDeclRefExpr(DRE); if (HasLocalVariableExternalStorage(VD)) return RewriteLocalVariableExternalStorage(DRE); } - + if (CallExpr *CE = dyn_cast<CallExpr>(S)) { if (CE->getCallee()->getType()->isBlockPointerType()) { Stmt *BlockCall = SynthesizeBlockCall(CE, CE->getCallee()); @@ -5812,7 +5812,7 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) { case Decl::CXXRecord: case Decl::Record: { RecordDecl *RD = cast<RecordDecl>(D); - if (RD->isCompleteDefinition()) + if (RD->isCompleteDefinition()) RewriteRecordBody(RD); break; } @@ -5825,7 +5825,7 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) { /// Write_ProtocolExprReferencedMetadata - This routine writer out the /// protocol reference symbols in the for of: /// struct _protocol_t *PROTOCOL_REF = &PROTOCOL_METADATA. -static void Write_ProtocolExprReferencedMetadata(ASTContext *Context, +static void Write_ProtocolExprReferencedMetadata(ASTContext *Context, ObjCProtocolDecl *PDecl, std::string &Result) { // Also output .objc_protorefs$B section and its meta-data. @@ -5861,10 +5861,10 @@ void RewriteModernObjC::HandleTranslationUnit(ASTContext &C) { } InsertText(SM->getLocForStartOfFile(MainFileID), Preamble, false); - + if (ClassImplementation.size() || CategoryImplementation.size()) RewriteImplementations(); - + for (unsigned i = 0, e = ObjCInterfacesSeen.size(); i < e; i++) { ObjCInterfaceDecl *CDecl = ObjCInterfacesSeen[i]; // Write struct declaration for the class matching its ivar declarations. @@ -5873,7 +5873,7 @@ void RewriteModernObjC::HandleTranslationUnit(ASTContext &C) { // private ivars. RewriteInterfaceDecl(CDecl); } - + // Get the buffer corresponding to MainFileID. If we haven't changed it, then // we are done. if (const RewriteBuffer *RewriteBuf = @@ -5903,7 +5903,7 @@ void RewriteModernObjC::HandleTranslationUnit(ASTContext &C) { void RewriteModernObjC::Initialize(ASTContext &context) { InitializeCommon(context); - + Preamble += "#ifndef __OBJC2__\n"; Preamble += "#define __OBJC2__\n"; Preamble += "#endif\n"; @@ -5919,7 +5919,7 @@ void RewriteModernObjC::Initialize(ASTContext &context) { Preamble += "\n\t__rw_objc_super(struct objc_object *o, struct objc_object *s) "; Preamble += ": object(o), superClass(s) {} "; Preamble += "\n};\n"; - + if (LangOpts.MicrosoftExt) { // Define all sections using syntax that makes sense. // These are currently generated. @@ -5933,13 +5933,13 @@ void RewriteModernObjC::Initialize(ASTContext &context) { Preamble += "#pragma section(\".inst_meth$B\", long, read, write)\n"; Preamble += "#pragma section(\".cls_meth$B\", long, read, write)\n"; Preamble += "#pragma section(\".objc_ivar$B\", long, read, write)\n"; - + // These need be generated for performance. Currently they are not, // using API calls instead. Preamble += "#pragma section(\".objc_selrefs$B\", long, read, write)\n"; Preamble += "#pragma section(\".objc_classrefs$B\", long, read, write)\n"; Preamble += "#pragma section(\".objc_superrefs$B\", long, read, write)\n"; - + } Preamble += "#ifndef _REWRITER_typedef_Protocol\n"; Preamble += "typedef struct objc_object Protocol;\n"; @@ -5948,10 +5948,10 @@ void RewriteModernObjC::Initialize(ASTContext &context) { if (LangOpts.MicrosoftExt) { Preamble += "#define __OBJC_RW_DLLIMPORT extern \"C\" __declspec(dllimport)\n"; Preamble += "#define __OBJC_RW_STATICIMPORT extern \"C\"\n"; - } + } else Preamble += "#define __OBJC_RW_DLLIMPORT extern\n"; - + Preamble += "__OBJC_RW_DLLIMPORT void objc_msgSend(void);\n"; Preamble += "__OBJC_RW_DLLIMPORT void objc_msgSendSuper(void);\n"; Preamble += "__OBJC_RW_DLLIMPORT void objc_msgSend_stret(void);\n"; @@ -6041,7 +6041,7 @@ void RewriteModernObjC::Initialize(ASTContext &context) { Preamble += "#define __block\n"; Preamble += "#define __weak\n"; } - + // Declarations required for modern objective-c array and dictionary literals. Preamble += "\n#include <stdarg.h>\n"; Preamble += "struct __NSContainer_literal {\n"; @@ -6058,7 +6058,7 @@ void RewriteModernObjC::Initialize(ASTContext &context) { Preamble += "\tdelete[] arr;\n"; Preamble += " }\n"; Preamble += "};\n"; - + // Declaration required for implementation of @autoreleasepool statement. Preamble += "extern \"C\" __declspec(dllimport) void * objc_autoreleasePoolPush(void);\n"; Preamble += "extern \"C\" __declspec(dllimport) void objc_autoreleasePoolPop(void *);\n\n"; @@ -6067,7 +6067,7 @@ void RewriteModernObjC::Initialize(ASTContext &context) { Preamble += " ~__AtAutoreleasePool() {objc_autoreleasePoolPop(atautoreleasepoolobj);}\n"; Preamble += " void * atautoreleasepoolobj;\n"; Preamble += "};\n"; - + // NOTE! Windows uses LLP64 for 64bit mode. So, cast pointer to long long // as this avoids warning in any 64bit/32bit compilation model. Preamble += "\n#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)\n"; @@ -6195,20 +6195,20 @@ static void WriteModernMetadataDeclarations(ASTContext *Context, std::string &Re static bool meta_data_declared = false; if (meta_data_declared) return; - + Result += "\nstruct _prop_t {\n"; Result += "\tconst char *name;\n"; Result += "\tconst char *attributes;\n"; Result += "};\n"; - + Result += "\nstruct _protocol_t;\n"; - + Result += "\nstruct _objc_method {\n"; Result += "\tstruct objc_selector * _cmd;\n"; Result += "\tconst char *method_type;\n"; Result += "\tvoid *_imp;\n"; Result += "};\n"; - + Result += "\nstruct _protocol_t {\n"; Result += "\tvoid * isa; // NULL\n"; Result += "\tconst char *protocol_name;\n"; @@ -6222,7 +6222,7 @@ static void WriteModernMetadataDeclarations(ASTContext *Context, std::string &Re Result += "\tconst unsigned int flags; // = 0\n"; Result += "\tconst char ** extendedMethodTypes;\n"; Result += "};\n"; - + Result += "\nstruct _ivar_t {\n"; Result += "\tunsigned long int *offset; // pointer to ivar offset location\n"; Result += "\tconst char *name;\n"; @@ -6230,7 +6230,7 @@ static void WriteModernMetadataDeclarations(ASTContext *Context, std::string &Re Result += "\tunsigned int alignment;\n"; Result += "\tunsigned int size;\n"; Result += "};\n"; - + Result += "\nstruct _class_ro_t {\n"; Result += "\tunsigned int flags;\n"; Result += "\tunsigned int instanceStart;\n"; @@ -6246,7 +6246,7 @@ static void WriteModernMetadataDeclarations(ASTContext *Context, std::string &Re Result += "\tconst unsigned char *weakIvarLayout;\n"; Result += "\tconst struct _prop_list_t *properties;\n"; Result += "};\n"; - + Result += "\nstruct _class_t {\n"; Result += "\tstruct _class_t *isa;\n"; Result += "\tstruct _class_t *superclass;\n"; @@ -6254,7 +6254,7 @@ static void WriteModernMetadataDeclarations(ASTContext *Context, std::string &Re Result += "\tvoid *vtable;\n"; Result += "\tstruct _class_ro_t *ro;\n"; Result += "};\n"; - + Result += "\nstruct _category_t {\n"; Result += "\tconst char *name;\n"; Result += "\tstruct _class_t *cls;\n"; @@ -6263,7 +6263,7 @@ static void WriteModernMetadataDeclarations(ASTContext *Context, std::string &Re Result += "\tconst struct _protocol_list_t *protocols;\n"; Result += "\tconst struct _prop_list_t *properties;\n"; Result += "};\n"; - + Result += "extern \"C\" __declspec(dllimport) struct objc_cache _objc_empty_cache;\n"; Result += "#pragma warning(disable:4273)\n"; meta_data_declared = true; @@ -6316,12 +6316,12 @@ static void Write_protocol_list_initializer(ASTContext *Context, std::string &Re Result += "\nstatic "; Write_protocol_list_t_TypeDecl(Result, SuperProtocols.size()); Result += " "; Result += VarName; - Result += ProtocolName; + Result += ProtocolName; Result += " __attribute__ ((used, section (\"__DATA,__objc_const\"))) = {\n"; Result += "\t"; Result += utostr(SuperProtocols.size()); Result += ",\n"; for (unsigned i = 0, e = SuperProtocols.size(); i < e; i++) { ObjCProtocolDecl *SuperPD = SuperProtocols[i]; - Result += "\t&"; Result += "_OBJC_PROTOCOL_"; + Result += "\t&"; Result += "_OBJC_PROTOCOL_"; Result += SuperPD->getNameAsString(); if (i == e-1) Result += "\n};\n"; @@ -6341,7 +6341,7 @@ static void Write_method_list_t_initializer(RewriteModernObjC &RewriteObj, Result += "\nstatic "; Write_method_list_t_TypeDecl(Result, Methods.size()); Result += " "; Result += VarName; - Result += TopLevelDeclName; + Result += TopLevelDeclName; Result += " __attribute__ ((used, section (\"__DATA,__objc_const\"))) = {\n"; Result += "\t"; Result += "sizeof(_objc_method)"; Result += ",\n"; Result += "\t"; Result += utostr(Methods.size()); Result += ",\n"; @@ -6381,7 +6381,7 @@ static void Write_prop_list_t_initializer(RewriteModernObjC &RewriteObj, Result += "\nstatic "; Write__prop_list_t_TypeDecl(Result, Properties.size()); Result += " "; Result += VarName; - Result += ProtocolName; + Result += ProtocolName; Result += " __attribute__ ((used, section (\"__DATA,__objc_const\"))) = {\n"; Result += "\t"; Result += "sizeof(_prop_t)"; Result += ",\n"; Result += "\t"; Result += utostr(Properties.size()); Result += ",\n"; @@ -6413,16 +6413,16 @@ enum MetaDataDlags { CLS_ROOT = 0x2, OBJC2_CLS_HIDDEN = 0x10, CLS_EXCEPTION = 0x20, - + /// (Obsolete) ARC-specific: this class has a .release_ivars method CLS_HAS_IVAR_RELEASER = 0x40, /// class was compiled with -fobjc-arr CLS_COMPILED_BY_ARC = 0x80 // (1<<7) }; -static void Write__class_ro_t_initializer(ASTContext *Context, std::string &Result, - unsigned int flags, - const std::string &InstanceStart, +static void Write__class_ro_t_initializer(ASTContext *Context, std::string &Result, + unsigned int flags, + const std::string &InstanceStart, const std::string &InstanceSize, ArrayRef<ObjCMethodDecl *>baseMethods, ArrayRef<ObjCProtocolDecl *>baseProtocols, @@ -6433,8 +6433,8 @@ static void Write__class_ro_t_initializer(ASTContext *Context, std::string &Resu Result += "\nstatic struct _class_ro_t "; Result += VarName; Result += ClassName; Result += " __attribute__ ((used, section (\"__DATA,__objc_const\"))) = {\n"; - Result += "\t"; - Result += llvm::utostr(flags); Result += ", "; + Result += "\t"; + Result += llvm::utostr(flags); Result += ", "; Result += InstanceStart; Result += ", "; Result += InstanceSize; Result += ", \n"; Result += "\t"; @@ -6492,7 +6492,7 @@ static void Write_class_t(ASTContext *Context, std::string &Result, const ObjCInterfaceDecl *CDecl, bool metaclass) { bool rootClass = (!CDecl->getSuperClass()); const ObjCInterfaceDecl *RootClass = CDecl; - + if (!rootClass) { // Find the Root class RootClass = CDecl->getSuperClass(); @@ -6509,7 +6509,7 @@ static void Write_class_t(ASTContext *Context, std::string &Result, Result += "__declspec(dllexport) "; else Result += "__declspec(dllimport) "; - + Result += "struct _class_t OBJC_CLASS_$_"; Result += CDecl->getNameAsString(); Result += ";\n"; @@ -6524,11 +6524,11 @@ static void Write_class_t(ASTContext *Context, std::string &Result, else Result += "__declspec(dllimport) "; - Result += "struct _class_t "; + Result += "struct _class_t "; Result += VarName; Result += SuperClass->getNameAsString(); Result += ";\n"; - + if (metaclass && RootClass != SuperClass) { Result += "extern \"C\" "; if (RootClass->getImplementation()) @@ -6536,14 +6536,14 @@ static void Write_class_t(ASTContext *Context, std::string &Result, else Result += "__declspec(dllimport) "; - Result += "struct _class_t "; + Result += "struct _class_t "; Result += VarName; Result += RootClass->getNameAsString(); Result += ";\n"; } } - - Result += "\nextern \"C\" __declspec(dllexport) struct _class_t "; + + Result += "\nextern \"C\" __declspec(dllexport) struct _class_t "; Result += VarName; Result += CDecl->getNameAsString(); Result += " __attribute__ ((used, section (\"__DATA,__objc_data\"))) = {\n"; Result += "\t"; @@ -6557,7 +6557,7 @@ static void Write_class_t(ASTContext *Context, std::string &Result, Result += ",\n\t"; } else { - Result += "0, // &"; Result += VarName; + Result += "0, // &"; Result += VarName; Result += CDecl->getNameAsString(); Result += ",\n\t"; Result += "0, // &OBJC_CLASS_$_"; Result += CDecl->getNameAsString(); @@ -6565,7 +6565,7 @@ static void Write_class_t(ASTContext *Context, std::string &Result, } } else { - Result += "0, // &OBJC_METACLASS_$_"; + Result += "0, // &OBJC_METACLASS_$_"; Result += CDecl->getNameAsString(); Result += ",\n\t"; if (!rootClass) { @@ -6573,7 +6573,7 @@ static void Write_class_t(ASTContext *Context, std::string &Result, Result += CDecl->getSuperClass()->getNameAsString(); Result += ",\n\t"; } - else + else Result += "0,\n\t"; } Result += "0, // (void *)&_objc_empty_cache,\n\t"; @@ -6584,22 +6584,22 @@ static void Write_class_t(ASTContext *Context, std::string &Result, Result += "&_OBJC_CLASS_RO_$_"; Result += CDecl->getNameAsString(); Result += ",\n};\n"; - + // Add static function to initialize some of the meta-data fields. // avoid doing it twice. if (metaclass) return; - - const ObjCInterfaceDecl *SuperClass = + + const ObjCInterfaceDecl *SuperClass = rootClass ? CDecl : CDecl->getSuperClass(); - + Result += "static void OBJC_CLASS_SETUP_$_"; Result += CDecl->getNameAsString(); Result += "(void ) {\n"; Result += "\tOBJC_METACLASS_$_"; Result += CDecl->getNameAsString(); Result += ".isa = "; Result += "&OBJC_METACLASS_$_"; Result += RootClass->getNameAsString(); Result += ";\n"; - + Result += "\tOBJC_METACLASS_$_"; Result += CDecl->getNameAsString(); Result += ".superclass = "; if (rootClass) @@ -6608,26 +6608,26 @@ static void Write_class_t(ASTContext *Context, std::string &Result, Result += "&OBJC_METACLASS_$_"; Result += SuperClass->getNameAsString(); Result += ";\n"; - + Result += "\tOBJC_METACLASS_$_"; Result += CDecl->getNameAsString(); Result += ".cache = "; Result += "&_objc_empty_cache"; Result += ";\n"; - + Result += "\tOBJC_CLASS_$_"; Result += CDecl->getNameAsString(); Result += ".isa = "; Result += "&OBJC_METACLASS_$_"; Result += CDecl->getNameAsString(); Result += ";\n"; - + if (!rootClass) { Result += "\tOBJC_CLASS_$_"; Result += CDecl->getNameAsString(); Result += ".superclass = "; Result += "&OBJC_CLASS_$_"; Result += SuperClass->getNameAsString(); Result += ";\n"; } - + Result += "\tOBJC_CLASS_$_"; Result += CDecl->getNameAsString(); Result += ".cache = "; Result += "&_objc_empty_cache"; Result += ";\n"; Result += "}\n"; } -static void Write_category_t(RewriteModernObjC &RewriteObj, ASTContext *Context, +static void Write_category_t(RewriteModernObjC &RewriteObj, ASTContext *Context, std::string &Result, ObjCCategoryDecl *CatDecl, ObjCInterfaceDecl *ClassDecl, @@ -6637,7 +6637,7 @@ static void Write_category_t(RewriteModernObjC &RewriteObj, ASTContext *Context, ArrayRef<ObjCPropertyDecl *> ClassProperties) { StringRef CatName = CatDecl->getName(); StringRef ClassName = ClassDecl->getName(); - // must declare an extern class object in case this class is not implemented + // must declare an extern class object in case this class is not implemented // in this TU. Result += "\n"; Result += "extern \"C\" "; @@ -6645,11 +6645,11 @@ static void Write_category_t(RewriteModernObjC &RewriteObj, ASTContext *Context, Result += "__declspec(dllexport) "; else Result += "__declspec(dllimport) "; - + Result += "struct _class_t "; Result += "OBJC_CLASS_$_"; Result += ClassName; Result += ";\n"; - + Result += "\nstatic struct _category_t "; Result += "_OBJC_$_CATEGORY_"; Result += ClassName; Result += "_$_"; Result += CatName; @@ -6659,32 +6659,32 @@ static void Write_category_t(RewriteModernObjC &RewriteObj, ASTContext *Context, Result += "\t0, // &"; Result += "OBJC_CLASS_$_"; Result += ClassName; Result += ",\n"; if (InstanceMethods.size() > 0) { - Result += "\t(const struct _method_list_t *)&"; + Result += "\t(const struct _method_list_t *)&"; Result += "_OBJC_$_CATEGORY_INSTANCE_METHODS_"; Result += ClassName; Result += "_$_"; Result += CatName; Result += ",\n"; } else Result += "\t0,\n"; - + if (ClassMethods.size() > 0) { - Result += "\t(const struct _method_list_t *)&"; + Result += "\t(const struct _method_list_t *)&"; Result += "_OBJC_$_CATEGORY_CLASS_METHODS_"; Result += ClassName; Result += "_$_"; Result += CatName; Result += ",\n"; } else Result += "\t0,\n"; - + if (RefedProtocols.size() > 0) { - Result += "\t(const struct _protocol_list_t *)&"; + Result += "\t(const struct _protocol_list_t *)&"; Result += "_OBJC_CATEGORY_PROTOCOLS_$_"; Result += ClassName; Result += "_$_"; Result += CatName; Result += ",\n"; } else Result += "\t0,\n"; - + if (ClassProperties.size() > 0) { Result += "\t(const struct _prop_list_t *)&"; Result += "_OBJC_$_PROP_LIST_"; Result += ClassName; Result += "_$_"; Result += CatName; @@ -6692,16 +6692,16 @@ static void Write_category_t(RewriteModernObjC &RewriteObj, ASTContext *Context, } else Result += "\t0,\n"; - + Result += "};\n"; - + // Add static function to initialize the class pointer in the category structure. Result += "static void OBJC_CATEGORY_SETUP_$_"; Result += ClassDecl->getNameAsString(); Result += "_$_"; Result += CatName; Result += "(void ) {\n"; - Result += "\t_OBJC_$_CATEGORY_"; + Result += "\t_OBJC_$_CATEGORY_"; Result += ClassDecl->getNameAsString(); Result += "_$_"; Result += CatName; @@ -6716,7 +6716,7 @@ static void Write__extendedMethodTypes_initializer(RewriteModernObjC &RewriteObj StringRef ProtocolName) { if (Methods.size() == 0) return; - + Result += "\nstatic const char *"; Result += VarName; Result += ProtocolName; Result += " [] __attribute__ ((used, section (\"__DATA,__objc_const\"))) = \n"; @@ -6738,8 +6738,8 @@ static void Write__extendedMethodTypes_initializer(RewriteModernObjC &RewriteObj static void Write_IvarOffsetVar(RewriteModernObjC &RewriteObj, ASTContext *Context, - std::string &Result, - ArrayRef<ObjCIvarDecl *> Ivars, + std::string &Result, + ArrayRef<ObjCIvarDecl *> Ivars, ObjCInterfaceDecl *CDecl) { // FIXME. visibilty of offset symbols may have to be set; for Darwin // this is what happens: @@ -6751,17 +6751,17 @@ static void Write_IvarOffsetVar(RewriteModernObjC &RewriteObj, else Visibility should be: DefaultVisibility; */ - + Result += "\n"; for (unsigned i =0, e = Ivars.size(); i < e; i++) { ObjCIvarDecl *IvarDecl = Ivars[i]; if (Context->getLangOpts().MicrosoftExt) Result += "__declspec(allocate(\".objc_ivar$B\")) "; - + if (!Context->getLangOpts().MicrosoftExt || IvarDecl->getAccessControl() == ObjCIvarDecl::Private || IvarDecl->getAccessControl() == ObjCIvarDecl::Package) - Result += "extern \"C\" unsigned long int "; + Result += "extern \"C\" unsigned long int "; else Result += "extern \"C\" __declspec(dllexport) unsigned long int "; if (Ivars[i]->isBitField()) @@ -6799,7 +6799,7 @@ static void Write__ivar_list_t_initializer(RewriteModernObjC &RewriteObj, else Ivars.push_back(OriginalIvars[i]); } - + Result += "\nstatic "; Write__ivar_list_t_TypeDecl(Result, Ivars.size()); Result += " "; Result += VarName; @@ -6819,24 +6819,24 @@ static void Write__ivar_list_t_initializer(RewriteModernObjC &RewriteObj, else WriteInternalIvarName(CDecl, IvarDecl, Result); Result += ", "; - + Result += "\""; if (Ivars[i]->isBitField()) RewriteObj.ObjCIvarBitfieldGroupDecl(Ivars[i], Result); else Result += IvarDecl->getName(); Result += "\", "; - + QualType IVQT = IvarDecl->getType(); if (IvarDecl->isBitField()) IVQT = RewriteObj.GetGroupRecordTypeForObjCIvarBitfield(IvarDecl); - + std::string IvarTypeString, QuoteIvarTypeString; Context->getObjCEncodingForType(IVQT, IvarTypeString, IvarDecl); RewriteObj.QuoteDoublequotes(IvarTypeString, QuoteIvarTypeString); Result += "\""; Result += QuoteIvarTypeString; Result += "\", "; - + // FIXME. this alignment represents the host alignment and need be changed to // represent the target alignment. unsigned Align = Context->getTypeAlign(IVQT)/8; @@ -6854,21 +6854,21 @@ static void Write__ivar_list_t_initializer(RewriteModernObjC &RewriteObj, } /// RewriteObjCProtocolMetaData - Rewrite protocols meta-data. -void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, +void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, std::string &Result) { - + // Do not synthesize the protocol more than once. if (ObjCSynthesizedProtocols.count(PDecl->getCanonicalDecl())) return; WriteModernMetadataDeclarations(Context, Result); - + if (ObjCProtocolDecl *Def = PDecl->getDefinition()) PDecl = Def; // Must write out all protocol definitions in current qualifier list, // and in their nested qualifiers before writing out current definition. for (auto *I : PDecl->protocols()) RewriteObjCProtocolMetaData(I, Result); - + // Construct method lists. std::vector<ObjCMethodDecl *> InstanceMethods, ClassMethods; std::vector<ObjCMethodDecl *> OptInstanceMethods, OptClassMethods; @@ -6879,7 +6879,7 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, InstanceMethods.push_back(MD); } } - + for (auto *MD : PDecl->class_methods()) { if (MD->getImplementationControl() == ObjCMethodDecl::Optional) { OptClassMethods.push_back(MD); @@ -6902,27 +6902,27 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, "_OBJC_PROTOCOL_METHOD_TYPES_", PDecl->getNameAsString()); // Protocol's super protocol list - SmallVector<ObjCProtocolDecl *, 8> SuperProtocols(PDecl->protocols()); + SmallVector<ObjCProtocolDecl *, 8> SuperProtocols(PDecl->protocols()); Write_protocol_list_initializer(Context, Result, SuperProtocols, "_OBJC_PROTOCOL_REFS_", PDecl->getNameAsString()); - - Write_method_list_t_initializer(*this, Context, Result, InstanceMethods, + + Write_method_list_t_initializer(*this, Context, Result, InstanceMethods, "_OBJC_PROTOCOL_INSTANCE_METHODS_", PDecl->getNameAsString(), false); - - Write_method_list_t_initializer(*this, Context, Result, ClassMethods, + + Write_method_list_t_initializer(*this, Context, Result, ClassMethods, "_OBJC_PROTOCOL_CLASS_METHODS_", PDecl->getNameAsString(), false); - Write_method_list_t_initializer(*this, Context, Result, OptInstanceMethods, + Write_method_list_t_initializer(*this, Context, Result, OptInstanceMethods, "_OBJC_PROTOCOL_OPT_INSTANCE_METHODS_", PDecl->getNameAsString(), false); - - Write_method_list_t_initializer(*this, Context, Result, OptClassMethods, + + Write_method_list_t_initializer(*this, Context, Result, OptClassMethods, "_OBJC_PROTOCOL_OPT_CLASS_METHODS_", PDecl->getNameAsString(), false); - + // Protocol's property metadata. SmallVector<ObjCPropertyDecl *, 8> ProtocolProperties( PDecl->instance_properties()); @@ -6947,43 +6947,43 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, else Result += "\t0,\n"; if (InstanceMethods.size() > 0) { - Result += "\t(const struct method_list_t *)&_OBJC_PROTOCOL_INSTANCE_METHODS_"; + Result += "\t(const struct method_list_t *)&_OBJC_PROTOCOL_INSTANCE_METHODS_"; Result += PDecl->getNameAsString(); Result += ",\n"; } else Result += "\t0,\n"; if (ClassMethods.size() > 0) { - Result += "\t(const struct method_list_t *)&_OBJC_PROTOCOL_CLASS_METHODS_"; + Result += "\t(const struct method_list_t *)&_OBJC_PROTOCOL_CLASS_METHODS_"; Result += PDecl->getNameAsString(); Result += ",\n"; } else Result += "\t0,\n"; - + if (OptInstanceMethods.size() > 0) { - Result += "\t(const struct method_list_t *)&_OBJC_PROTOCOL_OPT_INSTANCE_METHODS_"; + Result += "\t(const struct method_list_t *)&_OBJC_PROTOCOL_OPT_INSTANCE_METHODS_"; Result += PDecl->getNameAsString(); Result += ",\n"; } else Result += "\t0,\n"; - + if (OptClassMethods.size() > 0) { - Result += "\t(const struct method_list_t *)&_OBJC_PROTOCOL_OPT_CLASS_METHODS_"; + Result += "\t(const struct method_list_t *)&_OBJC_PROTOCOL_OPT_CLASS_METHODS_"; Result += PDecl->getNameAsString(); Result += ",\n"; } else Result += "\t0,\n"; - + if (ProtocolProperties.size() > 0) { - Result += "\t(const struct _prop_list_t *)&_OBJC_PROTOCOL_PROPERTIES_"; + Result += "\t(const struct _prop_list_t *)&_OBJC_PROTOCOL_PROPERTIES_"; Result += PDecl->getNameAsString(); Result += ",\n"; } else Result += "\t0,\n"; - + Result += "\t"; Result += "sizeof(_protocol_t)"; Result += ",\n"; Result += "\t0,\n"; - + if (AllMethods.size() > 0) { Result += "\t(const char **)&"; Result += "_OBJC_PROTOCOL_METHOD_TYPES_"; Result += PDecl->getNameAsString(); @@ -6991,14 +6991,14 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, } else Result += "\t0\n};\n"; - + if (LangOpts.MicrosoftExt) Result += "static "; Result += "struct _protocol_t *"; Result += "_OBJC_LABEL_PROTOCOL_$_"; Result += PDecl->getNameAsString(); Result += " = &_OBJC_PROTOCOL_"; Result += PDecl->getNameAsString(); Result += ";\n"; - + // Mark this protocol as having been generated. if (!ObjCSynthesizedProtocols.insert(PDecl->getCanonicalDecl()).second) llvm_unreachable("protocol already synthesized"); @@ -7019,15 +7019,15 @@ static bool hasObjCExceptionAttribute(ASTContext &Context, void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, std::string &Result) { ObjCInterfaceDecl *CDecl = IDecl->getClassInterface(); - + // Explicitly declared @interface's are already synthesized. if (CDecl->isImplicitInterfaceDecl()) - assert(false && + assert(false && "Legacy implicit interface rewriting not supported in moder abi"); - + WriteModernMetadataDeclarations(Context, Result); SmallVector<ObjCIvarDecl *, 8> IVars; - + for (ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); IVD; IVD = IVD->getNextIvar()) { // Ignore unnamed bit-fields. @@ -7035,14 +7035,14 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, continue; IVars.push_back(IVD); } - - Write__ivar_list_t_initializer(*this, Context, Result, IVars, + + Write__ivar_list_t_initializer(*this, Context, Result, IVars, "_OBJC_$_INSTANCE_VARIABLES_", CDecl); - + // Build _objc_method_list for class's instance methods if needed SmallVector<ObjCMethodDecl *, 32> InstanceMethods(IDecl->instance_methods()); - + // If any of our property implementations have associated getters or // setters, produce metadata for them as well. for (const auto *Prop : IDecl->property_impls()) { @@ -7062,17 +7062,17 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, if (mustSynthesizeSetterGetterMethod(IDecl, PD, false /*setter*/)) InstanceMethods.push_back(Setter); } - + Write_method_list_t_initializer(*this, Context, Result, InstanceMethods, "_OBJC_$_INSTANCE_METHODS_", IDecl->getNameAsString(), true); - + SmallVector<ObjCMethodDecl *, 32> ClassMethods(IDecl->class_methods()); - + Write_method_list_t_initializer(*this, Context, Result, ClassMethods, "_OBJC_$_CLASS_METHODS_", IDecl->getNameAsString(), true); - + // Protocols referenced in class declaration? // Protocol's super protocol list std::vector<ObjCProtocolDecl *> RefedProtocols; @@ -7085,12 +7085,12 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, // and in their nested qualifiers before writing out current definition. RewriteObjCProtocolMetaData(*I, Result); } - - Write_protocol_list_initializer(Context, Result, + + Write_protocol_list_initializer(Context, Result, RefedProtocols, "_OBJC_CLASS_PROTOCOLS_$_", IDecl->getNameAsString()); - + // Protocol's property metadata. SmallVector<ObjCPropertyDecl *, 8> ClassProperties( CDecl->instance_properties()); @@ -7098,22 +7098,22 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, /* Container */IDecl, "_OBJC_$_PROP_LIST_", CDecl->getNameAsString()); - + // Data for initializing _class_ro_t metaclass meta-data uint32_t flags = CLS_META; std::string InstanceSize; std::string InstanceStart; - + bool classIsHidden = CDecl->getVisibility() == HiddenVisibility; if (classIsHidden) flags |= OBJC2_CLS_HIDDEN; - + if (!CDecl->getSuperClass()) // class is root flags |= CLS_ROOT; InstanceSize = "sizeof(struct _class_t)"; InstanceStart = InstanceSize; - Write__class_ro_t_initializer(Context, Result, flags, + Write__class_ro_t_initializer(Context, Result, flags, InstanceStart, InstanceSize, ClassMethods, nullptr, @@ -7126,14 +7126,14 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, flags = CLS; if (classIsHidden) flags |= OBJC2_CLS_HIDDEN; - + if (hasObjCExceptionAttribute(*Context, CDecl)) flags |= CLS_EXCEPTION; if (!CDecl->getSuperClass()) // class is root flags |= CLS_ROOT; - + InstanceSize.clear(); InstanceStart.clear(); if (!ObjCSynthesizedStructs.count(CDecl)) { @@ -7144,15 +7144,15 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, InstanceSize = "sizeof(struct "; InstanceSize += CDecl->getNameAsString(); InstanceSize += "_IMPL)"; - + ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); if (IVD) { RewriteIvarOffsetComputation(IVD, InstanceStart); } - else + else InstanceStart = InstanceSize; } - Write__class_ro_t_initializer(Context, Result, flags, + Write__class_ro_t_initializer(Context, Result, flags, InstanceStart, InstanceSize, InstanceMethods, RefedProtocols, @@ -7160,15 +7160,15 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, ClassProperties, "_OBJC_CLASS_RO_$_", CDecl->getNameAsString()); - + Write_class_t(Context, Result, "OBJC_METACLASS_$_", CDecl, /*metaclass*/true); - + Write_class_t(Context, Result, "OBJC_CLASS_$_", CDecl, /*metaclass*/false); - + if (ImplementationIsNonLazy(IDecl)) DefinedNonLazyClasses.push_back(CDecl); } @@ -7192,25 +7192,25 @@ void RewriteModernObjC::RewriteClassSetupInitHook(std::string &Result) { void RewriteModernObjC::RewriteMetaDataIntoBuffer(std::string &Result) { int ClsDefCount = ClassImplementation.size(); int CatDefCount = CategoryImplementation.size(); - + // For each implemented class, write out all its meta data. for (int i = 0; i < ClsDefCount; i++) RewriteObjCClassMetaData(ClassImplementation[i], Result); - + RewriteClassSetupInitHook(Result); - + // For each implemented category, write out all its meta data. for (int i = 0; i < CatDefCount; i++) RewriteObjCCategoryImplDecl(CategoryImplementation[i], Result); - + RewriteCategorySetupInitHook(Result); - + if (ClsDefCount > 0) { if (LangOpts.MicrosoftExt) Result += "__declspec(allocate(\".objc_classlist$B\")) "; Result += "static struct _class_t *L_OBJC_LABEL_CLASS_$ ["; Result += llvm::utostr(ClsDefCount); Result += "]"; - Result += + Result += " __attribute__((used, section (\"__DATA, __objc_classlist," "regular,no_dead_strip\")))= {\n"; for (int i = 0; i < ClsDefCount; i++) { @@ -7219,7 +7219,7 @@ void RewriteModernObjC::RewriteMetaDataIntoBuffer(std::string &Result) { Result += ",\n"; } Result += "};\n"; - + if (!DefinedNonLazyClasses.empty()) { if (LangOpts.MicrosoftExt) Result += "__declspec(allocate(\".objc_nlclslist$B\")) \n"; @@ -7231,34 +7231,34 @@ void RewriteModernObjC::RewriteMetaDataIntoBuffer(std::string &Result) { Result += "};\n"; } } - + if (CatDefCount > 0) { if (LangOpts.MicrosoftExt) Result += "__declspec(allocate(\".objc_catlist$B\")) "; Result += "static struct _category_t *L_OBJC_LABEL_CATEGORY_$ ["; Result += llvm::utostr(CatDefCount); Result += "]"; - Result += + Result += " __attribute__((used, section (\"__DATA, __objc_catlist," "regular,no_dead_strip\")))= {\n"; for (int i = 0; i < CatDefCount; i++) { Result += "\t&_OBJC_$_CATEGORY_"; - Result += - CategoryImplementation[i]->getClassInterface()->getNameAsString(); + Result += + CategoryImplementation[i]->getClassInterface()->getNameAsString(); Result += "_$_"; Result += CategoryImplementation[i]->getNameAsString(); Result += ",\n"; } Result += "};\n"; } - + if (!DefinedNonLazyCategories.empty()) { if (LangOpts.MicrosoftExt) Result += "__declspec(allocate(\".objc_nlcatlist$B\")) \n"; Result += "static struct _category_t *_OBJC_LABEL_NONLAZY_CATEGORY_$[] = {\n\t"; for (unsigned i = 0, e = DefinedNonLazyCategories.size(); i < e; i++) { Result += "\t&_OBJC_$_CATEGORY_"; - Result += - DefinedNonLazyCategories[i]->getClassInterface()->getNameAsString(); + Result += + DefinedNonLazyCategories[i]->getClassInterface()->getNameAsString(); Result += "_$_"; Result += DefinedNonLazyCategories[i]->getNameAsString(); Result += ",\n"; @@ -7270,7 +7270,7 @@ void RewriteModernObjC::RewriteMetaDataIntoBuffer(std::string &Result) { void RewriteModernObjC::WriteImageInfo(std::string &Result) { if (LangOpts.MicrosoftExt) Result += "__declspec(allocate(\".objc_imageinfo$B\")) \n"; - + Result += "static struct IMAGE_INFO { unsigned version; unsigned flag; } "; // version 0, ObjCABI is 2 Result += "_OBJC_IMAGE_INFO = { 0, 2 };\n"; @@ -7285,14 +7285,14 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, // Find category declaration for this implementation. ObjCCategoryDecl *CDecl = ClassDecl->FindCategoryDeclaration(IDecl->getIdentifier()); - + std::string FullCategoryName = ClassDecl->getNameAsString(); FullCategoryName += "_$_"; FullCategoryName += CDecl->getNameAsString(); - + // Build _objc_method_list for class's instance methods if needed SmallVector<ObjCMethodDecl *, 32> InstanceMethods(IDecl->instance_methods()); - + // If any of our property implementations have associated getters or // setters, produce metadata for them as well. for (const auto *Prop : IDecl->property_impls()) { @@ -7310,17 +7310,17 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, if (ObjCMethodDecl *Setter = PD->getSetterMethodDecl()) InstanceMethods.push_back(Setter); } - + Write_method_list_t_initializer(*this, Context, Result, InstanceMethods, "_OBJC_$_CATEGORY_INSTANCE_METHODS_", FullCategoryName, true); - + SmallVector<ObjCMethodDecl *, 32> ClassMethods(IDecl->class_methods()); - + Write_method_list_t_initializer(*this, Context, Result, ClassMethods, "_OBJC_$_CATEGORY_CLASS_METHODS_", FullCategoryName, true); - + // Protocols referenced in class declaration? // Protocol's super protocol list SmallVector<ObjCProtocolDecl *, 8> RefedProtocols(CDecl->protocols()); @@ -7328,12 +7328,12 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, // Must write out all protocol definitions in current qualifier list, // and in their nested qualifiers before writing out current definition. RewriteObjCProtocolMetaData(I, Result); - - Write_protocol_list_initializer(Context, Result, + + Write_protocol_list_initializer(Context, Result, RefedProtocols, "_OBJC_CATEGORY_PROTOCOLS_$_", FullCategoryName); - + // Protocol's property metadata. SmallVector<ObjCPropertyDecl *, 8> ClassProperties( CDecl->instance_properties()); @@ -7341,7 +7341,7 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, /* Container */IDecl, "_OBJC_$_PROP_LIST_", FullCategoryName); - + Write_category_t(*this, Context, Result, CDecl, ClassDecl, @@ -7349,7 +7349,7 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, ClassMethods, RefedProtocols, ClassProperties); - + // Determine if this category is also "non-lazy". if (ImplementationIsNonLazy(IDecl)) DefinedNonLazyCategories.push_back(CDecl); @@ -7385,7 +7385,7 @@ void RewriteModernObjC::RewriteObjCMethodsMetaData(MethodIterator MethodBegin, StringRef ClassName, std::string &Result) { if (MethodBegin == MethodEnd) return; - + if (!objc_impl_method) { /* struct _objc_method { SEL _cmd; @@ -7398,12 +7398,12 @@ void RewriteModernObjC::RewriteObjCMethodsMetaData(MethodIterator MethodBegin, Result += "\tchar *method_types;\n"; Result += "\tvoid *_imp;\n"; Result += "};\n"; - + objc_impl_method = true; } - + // Build _objc_method_list for class's methods if needed - + /* struct { struct _objc_method_list *next_method; int method_count; @@ -7432,7 +7432,7 @@ void RewriteModernObjC::RewriteObjCMethodsMetaData(MethodIterator MethodBegin, Result += IsInstanceMethod ? "inst" : "cls"; Result += "_meth\")))= "; Result += "{\n\t0, " + utostr(NumMethods) + "\n"; - + Result += "\t,{{(SEL)\""; Result += (*MethodBegin)->getSelector().getAsString().c_str(); std::string MethodTypeString; @@ -7459,18 +7459,18 @@ void RewriteModernObjC::RewriteObjCMethodsMetaData(MethodIterator MethodBegin, Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { SourceRange OldRange = IV->getSourceRange(); Expr *BaseExpr = IV->getBase(); - + // Rewrite the base, but without actually doing replaces. { DisableReplaceStmtScope S(*this); BaseExpr = cast<Expr>(RewriteFunctionBodyOrGlobalInitializer(BaseExpr)); IV->setBase(BaseExpr); } - + ObjCIvarDecl *D = IV->getDecl(); - + Expr *Replacement = IV; - + if (BaseExpr->getType()->isObjCObjectPointerType()) { const ObjCInterfaceType *iFaceDecl = dyn_cast<ObjCInterfaceType>(BaseExpr->getType()->getPointeeType()); @@ -7480,18 +7480,18 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), clsDeclared); assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class"); - + // Build name of symbol holding ivar offset. std::string IvarOffsetName; if (D->isBitField()) ObjCIvarBitfieldGroupOffset(D, IvarOffsetName); else WriteInternalIvarName(clsDeclared, D, IvarOffsetName); - + ReferencedIvars[clsDeclared].insert(D); - + // cast offset to "char *". - CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, + CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(Context->CharTy), CK_BitCast, BaseExpr); @@ -7502,8 +7502,8 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, false, Context->UnsignedLongTy, VK_LValue, SourceLocation()); - BinaryOperator *addExpr = - new (Context) BinaryOperator(castExpr, DRE, BO_Add, + BinaryOperator *addExpr = + new (Context) BinaryOperator(castExpr, DRE, BO_Add, Context->getPointerType(Context->CharTy), VK_RValue, OK_Ordinary, SourceLocation(), FPOptions()); // Don't forget the parens to enforce the proper binding. @@ -7519,7 +7519,7 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { RD = RD->getDefinition(); if (RD && !RD->getDeclName().getAsIdentifierInfo()) { // decltype(((Foo_IMPL*)0)->bar) * - ObjCContainerDecl *CDecl = + ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(D->getDeclContext()); // ivar in class extensions requires special treatment. if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) @@ -7530,7 +7530,7 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { *Context, TTK_Struct, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(RecName)); QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD)); - unsigned UnsignedIntSize = + unsigned UnsignedIntSize = static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); Expr *Zero = IntegerLiteral::Create(*Context, llvm::APInt(UnsignedIntSize, 0), @@ -7552,20 +7552,20 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { } convertObjCTypeToCStyleType(IvarT); QualType castT = Context->getPointerType(IvarT); - - castExpr = NoTypeInfoCStyleCastExpr(Context, + + castExpr = NoTypeInfoCStyleCastExpr(Context, castT, CK_BitCast, PE); - - + + Expr *Exp = new (Context) UnaryOperator(castExpr, UO_Deref, IvarT, VK_LValue, OK_Ordinary, SourceLocation(), false); PE = new (Context) ParenExpr(OldRange.getBegin(), OldRange.getEnd(), Exp); - + if (D->isBitField()) { FieldDecl *FD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), @@ -7582,9 +7582,9 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { else Replacement = PE; } - + ReplaceStmtWithRange(IV, Replacement, OldRange); - return Replacement; + return Replacement; } #endif // CLANG_ENABLE_OBJC_REWRITER diff --git a/lib/Frontend/Rewrite/RewriteObjC.cpp b/lib/Frontend/Rewrite/RewriteObjC.cpp index 9938f89eb869..6229351e8f54 100644 --- a/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -42,7 +42,7 @@ namespace { BLOCK_FIELD_IS_OBJECT = 3, /* id, NSObject, __attribute__((NSObject)), block, ... */ BLOCK_FIELD_IS_BLOCK = 7, /* a block variable */ - BLOCK_FIELD_IS_BYREF = 8, /* the on stack structure holding the + BLOCK_FIELD_IS_BYREF = 8, /* the on stack structure holding the __block variable */ BLOCK_FIELD_IS_WEAK = 16, /* declared __weak, only used in byref copy helpers */ @@ -50,7 +50,7 @@ namespace { support routines */ BLOCK_BYREF_CURRENT_MAX = 256 }; - + enum { BLOCK_NEEDS_FREE = (1 << 24), BLOCK_HAS_COPY_DISPOSE = (1 << 25), @@ -60,7 +60,7 @@ namespace { BLOCK_HAS_DESCRIPTOR = (1 << 29) }; static const int OBJC_ABI_VERSION = 7; - + Rewriter Rewrite; DiagnosticsEngine &Diags; const LangOptions &LangOpts; @@ -74,7 +74,7 @@ namespace { std::string InFileName; std::unique_ptr<raw_ostream> OutFile; std::string Preamble; - + TypeDecl *ProtocolTypeDecl; VarDecl *GlobalVarDecl; unsigned RewriteFailedDiag; @@ -85,13 +85,13 @@ namespace { // ObjC foreach break/continue generation support. int BcLabelCount; - + unsigned TryFinallyContainsReturnDiag; // Needed for super. ObjCMethodDecl *CurMethodDef; RecordDecl *SuperStructDecl; RecordDecl *ConstantStringDecl; - + FunctionDecl *MsgSendFunctionDecl; FunctionDecl *MsgSendSuperFunctionDecl; FunctionDecl *MsgSendStretFunctionDecl; @@ -117,14 +117,14 @@ namespace { SmallVector<int, 8> ObjCBcLabelNo; // Remember all the @protocol(<expr>) expressions. llvm::SmallPtrSet<ObjCProtocolDecl *, 32> ProtocolExprDecls; - + llvm::DenseSet<uint64_t> CopyDestroyCache; // Block expressions. SmallVector<BlockExpr *, 32> Blocks; SmallVector<int, 32> InnerDeclRefsCount; SmallVector<DeclRefExpr *, 32> InnerDeclRefs; - + SmallVector<DeclRefExpr *, 32> BlockDeclRefs; // Block related declarations. @@ -135,7 +135,7 @@ namespace { llvm::DenseMap<ValueDecl *, unsigned> BlockByRefDeclNo; llvm::SmallPtrSet<ValueDecl *, 8> ImportedBlockDecls; llvm::SmallPtrSet<VarDecl *, 8> ImportedLocalExternalDecls; - + llvm::DenseMap<BlockExpr *, std::string> RewrittenBlockExprs; // This maps an original source AST to it's rewritten form. This allows @@ -147,12 +147,12 @@ namespace { bool IsHeader; bool SilenceRewriteMacroWarning; bool objc_impl_method; - + bool DisableReplaceStmt; class DisableReplaceStmtScope { RewriteObjC &R; bool SavedValue; - + public: DisableReplaceStmtScope(RewriteObjC &R) : R(R), SavedValue(R.DisableReplaceStmt) { @@ -262,7 +262,7 @@ namespace { void RewriteInclude(); void RewriteForwardClassDecl(DeclGroupRef D); void RewriteForwardClassDecl(const SmallVectorImpl<Decl *> &DG); - void RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl, + void RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl, const std::string &typedefString); void RewriteImplementations(); void RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, @@ -289,7 +289,7 @@ namespace { void RewriteObjCQualifiedInterfaceTypes(Decl *Dcl); void RewriteTypeOfDecl(VarDecl *VD); void RewriteObjCQualifiedInterfaceTypes(Expr *E); - + // Expression Rewriting. Stmt *RewriteFunctionBodyOrGlobalInitializer(Stmt *S); Stmt *RewriteAtEncode(ObjCEncodeExpr *Exp); @@ -309,17 +309,17 @@ namespace { Stmt *RewriteBreakStmt(BreakStmt *S); Stmt *RewriteContinueStmt(ContinueStmt *S); void RewriteCastExpr(CStyleCastExpr *CE); - + // Block rewriting. void RewriteBlocksInFunctionProtoType(QualType funcType, NamedDecl *D); - + // Block specific rewrite rules. void RewriteBlockPointerDecl(NamedDecl *VD); void RewriteByRefVar(VarDecl *VD); Stmt *RewriteBlockDeclRefExpr(DeclRefExpr *VD); Stmt *RewriteLocalVariableExternalStorage(DeclRefExpr *DRE); void RewriteBlockPointerFunctionArgs(FunctionDecl *FD); - + void RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl, std::string &Result); @@ -339,12 +339,12 @@ namespace { std::string &Result) = 0; virtual void RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, std::string &Result) = 0; - + // Rewriting ivar access virtual Stmt *RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) = 0; virtual void RewriteIvarOffsetComputation(ObjCIvarDecl *ivar, std::string &Result) = 0; - + // Misc. AST transformation routines. Sometimes they end up calling // rewriting routines on the new ASTs. CallExpr *SynthesizeCallToFunctionDecl(FunctionDecl *FD, @@ -352,15 +352,15 @@ namespace { SourceLocation StartLoc=SourceLocation(), SourceLocation EndLoc=SourceLocation()); CallExpr *SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavor, - QualType msgSendType, - QualType returnType, + QualType msgSendType, + QualType returnType, SmallVectorImpl<QualType> &ArgTypes, SmallVectorImpl<Expr*> &MsgExprs, ObjCMethodDecl *Method); Stmt *SynthMessageExpr(ObjCMessageExpr *Exp, SourceLocation StartLoc=SourceLocation(), SourceLocation EndLoc=SourceLocation()); - + void SynthCountByEnumWithState(std::string &buf); void SynthMsgSendFunctionDecl(); void SynthMsgSendSuperFunctionDecl(); @@ -372,15 +372,15 @@ namespace { void SynthGetSuperClassFunctionDecl(); void SynthSelGetUidFunctionDecl(); void SynthSuperConstructorFunctionDecl(); - + std::string SynthesizeByrefCopyDestroyHelper(VarDecl *VD, int flag); std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, StringRef funcName, std::string Tag); std::string SynthesizeBlockFunc(BlockExpr *CE, int i, StringRef funcName, std::string Tag); - std::string SynthesizeBlockImpl(BlockExpr *CE, + std::string SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, std::string Desc); - std::string SynthesizeBlockDescriptor(std::string DescTag, + std::string SynthesizeBlockDescriptor(std::string DescTag, std::string ImplTag, int i, StringRef funcName, unsigned hasCopy); @@ -423,13 +423,13 @@ namespace { } return false; } - + bool needToScanForQualifiers(QualType T); QualType getSuperStructType(); QualType getConstantStringStructType(); QualType convertFunctionTypeOfBlocks(const FunctionType *FT); bool BufferContainsPPDirectives(const char *startBuf, const char *endBuf); - + void convertToUnqualifiedObjCType(QualType &T) { if (T->isObjCQualifiedIdType()) T = Context->getObjCIdType(); @@ -445,7 +445,7 @@ namespace { } } } - + // FIXME: This predicate seems like it would be useful to add to ASTContext. bool isObjCType(QualType T) { if (!LangOpts.ObjC1 && !LangOpts.ObjC2) @@ -468,7 +468,7 @@ namespace { bool PointerTypeTakesAnyObjCQualifiedType(QualType QT); void GetExtentOfArgList(const char *Name, const char *&LParen, const char *&RParen); - + void QuoteDoublequotes(std::string &From, std::string &To) { for (unsigned i = 0; i < From.length(); i++) { if (From[i] == '"') @@ -504,7 +504,7 @@ namespace { /*Pascal=*/false, StrType, SourceLocation()); } }; - + class RewriteObjCFragileABI : public RewriteObjC { public: RewriteObjCFragileABI(std::string inFile, std::unique_ptr<raw_ostream> OS, @@ -688,7 +688,7 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) { DG.push_back(*DI); else break; - + ++DI; } while (DI != DIEnd); RewriteForwardClassDecl(DG); @@ -707,14 +707,14 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) { DG.push_back(*DI); else break; - + ++DI; } while (DI != DIEnd); RewriteForwardProtocolDecl(DG); continue; } } - + HandleTopLevelSingleDecl(*DI); ++DI; } @@ -790,7 +790,7 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, unsigned Attributes = PD->getPropertyAttributes(); if (!PD->getGetterMethodDecl()->isDefined()) { bool GenGetProperty = !(Attributes & ObjCPropertyDecl::OBJC_PR_nonatomic) && - (Attributes & (ObjCPropertyDecl::OBJC_PR_retain | + (Attributes & (ObjCPropertyDecl::OBJC_PR_retain | ObjCPropertyDecl::OBJC_PR_copy)); std::string Getr; if (GenGetProperty && !objcGetPropertyDefined) { @@ -799,7 +799,7 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, Getr = "\nextern \"C\" __declspec(dllimport) " "id objc_getProperty(id, SEL, long, bool);\n"; } - RewriteObjCMethodDecl(OID->getContainingInterface(), + RewriteObjCMethodDecl(OID->getContainingInterface(), PD->getGetterMethodDecl(), Getr); Getr += "{ "; // Synthesize an explicit cast to gain access to the ivar. @@ -813,7 +813,7 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, Getr += " _TYPE"; if (FPRetType) { Getr += ")"; // close the precedence "scope" for "*". - + // Now, emit the argument types (if any). if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(FPRetType)){ Getr += "("; @@ -843,13 +843,13 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, Getr += "; }"; InsertText(onePastSemiLoc, Getr); } - + if (PD->isReadOnly() || PD->getSetterMethodDecl()->isDefined()) return; // Generate the 'setter' function. std::string Setr; - bool GenSetProperty = Attributes & (ObjCPropertyDecl::OBJC_PR_retain | + bool GenSetProperty = Attributes & (ObjCPropertyDecl::OBJC_PR_retain | ObjCPropertyDecl::OBJC_PR_copy); if (GenSetProperty && !objcSetPropertyDefined) { objcSetPropertyDefined = true; @@ -857,8 +857,8 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, Setr = "\nextern \"C\" __declspec(dllimport) " "void objc_setProperty (id, SEL, long, id, bool, bool);\n"; } - - RewriteObjCMethodDecl(OID->getContainingInterface(), + + RewriteObjCMethodDecl(OID->getContainingInterface(), PD->getSetterMethodDecl(), Setr); Setr += "{ "; // Synthesize an explicit cast to initialize the ivar. @@ -903,9 +903,9 @@ void RewriteObjC::RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl, const std::string &typedefString) { SourceLocation startLoc = ClassDecl->getLocStart(); const char *startBuf = SM->getCharacterData(startLoc); - const char *semiPtr = strchr(startBuf, ';'); + const char *semiPtr = strchr(startBuf, ';'); // Replace the @class with typedefs corresponding to the classes. - ReplaceText(startLoc, semiPtr-startBuf+1, typedefString); + ReplaceText(startLoc, semiPtr-startBuf+1, typedefString); } void RewriteObjC::RewriteForwardClassDecl(DeclGroupRef D) { @@ -971,21 +971,21 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { ReplaceText(LocStart, 0, "// "); for (auto *I : CatDecl->instance_properties()) - RewriteProperty(I); + RewriteProperty(I); for (auto *I : CatDecl->instance_methods()) RewriteMethodDeclaration(I); for (auto *I : CatDecl->class_methods()) RewriteMethodDeclaration(I); // Lastly, comment out the @end. - ReplaceText(CatDecl->getAtEndRange().getBegin(), + ReplaceText(CatDecl->getAtEndRange().getBegin(), strlen("@end"), "/* @end */"); } void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { SourceLocation LocStart = PDecl->getLocStart(); assert(PDecl->isThisDeclarationADefinition()); - + // FIXME: handle protocol headers that are declared across multiple lines. ReplaceText(LocStart, 0, "// "); @@ -995,7 +995,7 @@ void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { RewriteMethodDeclaration(I); for (auto *I : PDecl->instance_properties()) RewriteProperty(I); - + // Lastly, comment out the @end. SourceLocation LocEnd = PDecl->getAtEndRange().getBegin(); ReplaceText(LocEnd, strlen("@end"), "/* @end */"); @@ -1025,7 +1025,7 @@ void RewriteObjC::RewriteForwardProtocolDecl(DeclGroupRef D) { ReplaceText(LocStart, 0, "// "); } -void +void RewriteObjC::RewriteForwardProtocolDecl(const SmallVectorImpl<Decl *> &DG) { SourceLocation LocStart = DG[0]->getLocStart(); if (LocStart.isInvalid()) @@ -1220,7 +1220,7 @@ void RewriteObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { RewriteMethodDeclaration(I); // Lastly, comment out the @end. - ReplaceText(ClassDecl->getAtEndRange().getBegin(), strlen("@end"), + ReplaceText(ClassDecl->getAtEndRange().getBegin(), strlen("@end"), "/* @end */"); } @@ -1677,7 +1677,7 @@ Stmt *RewriteObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) { buf += "}\n"; buf += "{ /* implicit finally clause */\n"; buf += " if (!_rethrow) objc_exception_try_exit(&_stack);\n"; - + std::string syncBuf; syncBuf += " objc_sync_exit("; @@ -1695,7 +1695,7 @@ Stmt *RewriteObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) { syncExpr->printPretty(syncExprBuf, nullptr, PrintingPolicy(LangOpts)); syncBuf += syncExprBuf.str(); syncBuf += ");"; - + buf += syncBuf; buf += "\n if (_rethrow) objc_exception_throw(_rethrow);\n"; buf += "}\n"; @@ -1724,8 +1724,8 @@ void RewriteObjC::WarnAboutReturnGotoStmts(Stmt *S) } } -void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns) -{ +void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns) +{ // Perform a bottom up traversal of all children. for (Stmt *SubStmt : S->children()) if (SubStmt) @@ -1750,7 +1750,7 @@ void RewriteObjC::RewriteTryReturnStmts(Stmt *S) { std::string buf; buf = "{ objc_exception_try_exit(&_stack); return"; - + ReplaceText(startLoc, 6, buf); InsertText(onePastSemiLoc, "}"); } @@ -1774,7 +1774,7 @@ void RewriteObjC::RewriteSyncReturnStmts(Stmt *S, std::string syncExitBuf) { buf = "{ objc_exception_try_exit(&_stack);"; buf += syncExitBuf; buf += " return"; - + ReplaceText(startLoc, 6, buf); InsertText(onePastSemiLoc, "}"); } @@ -1930,7 +1930,7 @@ Stmt *RewriteObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { buf += " if (_rethrow) objc_exception_throw(_rethrow);\n"; buf += "}"; ReplaceText(lastCurlyLoc, 1, buf); - + // Now check for any return/continue/go statements within the @try. // The implicit finally clause won't called if the @try contains any // jump statements. @@ -2446,7 +2446,7 @@ void RewriteObjC::SynthGetClassFunctionDecl() { // SynthGetSuperClassFunctionDecl - Class class_getSuperclass(Class cls); void RewriteObjC::SynthGetSuperClassFunctionDecl() { - IdentifierInfo *getSuperClassIdent = + IdentifierInfo *getSuperClassIdent = &Context->Idents.get("class_getSuperclass"); SmallVector<QualType, 16> ArgTys; ArgTys.push_back(Context->getObjCClassType()); @@ -2583,8 +2583,8 @@ QualType RewriteObjC::getConstantStringStructType() { } CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavor, - QualType msgSendType, - QualType returnType, + QualType msgSendType, + QualType returnType, SmallVectorImpl<QualType> &ArgTypes, SmallVectorImpl<Expr*> &MsgExprs, ObjCMethodDecl *Method) { @@ -2603,10 +2603,10 @@ CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavo castType = Context->getPointerType(castType); cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast); - + // Don't forget the parens to enforce the proper binding. ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), cast); - + const FunctionType *FT = msgSendType->getAs<FunctionType>(); CallExpr *STCE = new (Context) CallExpr( *Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, SourceLocation()); @@ -2764,7 +2764,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, Context->getObjCIdType(), VK_RValue, SourceLocation())) ); // set the 'receiver'. - + // (id)class_getSuperclass((Class)objc_getClass("CurrentClass")) SmallVector<Expr*, 8> ClsExprs; ClsExprs.push_back(getStringLiteral(ClassDecl->getIdentifier()->getName())); @@ -2778,7 +2778,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ClsExprs.push_back(ArgExpr); Cls = SynthesizeCallToFunctionDecl(GetSuperClassFunctionDecl, ClsExprs, StartLoc, EndLoc); - + // (id)class_getSuperclass((Class)objc_getClass("CurrentClass")) // To turn off a warning, type-cast to 'id' InitExprs.push_back( @@ -2863,7 +2863,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, (void)convertBlockPointerToFunctionPointer(type); const Expr *SubExpr = ICE->IgnoreParenImpCasts(); CastKind CK; - if (SubExpr->getType()->isIntegralType(*Context) && + if (SubExpr->getType()->isIntegralType(*Context) && type->isBooleanType()) { CK = CK_IntegralToBoolean; } else if (type->isObjCObjectPointerType()) { @@ -2968,9 +2968,9 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, // call to objc_msgSend_stret and hang both varieties on a conditional // expression which dictate which one to envoke depending on size of // method's return type. - - CallExpr *STCE = SynthMsgSendStretCallExpr(MsgSendStretFlavor, - msgSendType, returnType, + + CallExpr *STCE = SynthMsgSendStretCallExpr(MsgSendStretFlavor, + msgSendType, returnType, ArgTypes, MsgExprs, Exp->getMethodDecl()); @@ -2990,7 +2990,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, llvm::APInt(IntSize, 8), Context->IntTy, SourceLocation()); - BinaryOperator *lessThanExpr = + BinaryOperator *lessThanExpr = new (Context) BinaryOperator(sizeofExpr, limit, BO_LE, Context->IntTy, VK_RValue, OK_Ordinary, SourceLocation(), FPOptions()); @@ -3000,7 +3000,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, SourceLocation(), CE, SourceLocation(), STCE, returnType, VK_RValue, OK_Ordinary); - ReplacingStmt = new (Context) ParenExpr(SourceLocation(), SourceLocation(), + ReplacingStmt = new (Context) ParenExpr(SourceLocation(), SourceLocation(), CondExpr); } // delete Exp; leak for now, see RewritePropertyOrImplicitSetter() usage for more info. @@ -3232,14 +3232,14 @@ void RewriteObjC::RewriteImplementations() { RewriteImplementationDecl(CategoryImplementation[i]); } -void RewriteObjC::RewriteByRefString(std::string &ResultStr, +void RewriteObjC::RewriteByRefString(std::string &ResultStr, const std::string &Name, ValueDecl *VD, bool def) { - assert(BlockByRefDeclNo.count(VD) && + assert(BlockByRefDeclNo.count(VD) && "RewriteByRefString: ByRef decl missing"); if (def) ResultStr += "struct "; - ResultStr += "__Block_byref_" + Name + + ResultStr += "__Block_byref_" + Name + "_" + utostr(BlockByRefDeclNo[VD]) ; } @@ -3329,7 +3329,7 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, if (HasLocalVariableExternalStorage(*I)) QT = Context->getPointerType(QT); QT.getAsStringInternal(Name, Context->getPrintingPolicy()); - S += Name + " = __cself->" + + S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by copy\n"; } } @@ -3365,7 +3365,7 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, S += ", " + utostr(BLOCK_FIELD_IS_OBJECT) + "/*BLOCK_FIELD_IS_OBJECT*/);"; } S += "}\n"; - + S += "\nstatic void __"; S += funcName; S += "_block_dispose_" + utostr(i); @@ -3385,7 +3385,7 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, return S; } -std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, +std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, std::string Desc) { std::string S = "\nstruct " + Tag; std::string Constructor = " " + Tag; @@ -3474,7 +3474,7 @@ std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, Constructor += ", "; Constructor += Name + "(_" + Name + "->__forwarding)"; } - + Constructor += " {\n"; if (GlobalVarDecl) Constructor += " impl.isa = &_NSConcreteGlobalBlock;\n"; @@ -3500,19 +3500,19 @@ std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, return S; } -std::string RewriteObjC::SynthesizeBlockDescriptor(std::string DescTag, +std::string RewriteObjC::SynthesizeBlockDescriptor(std::string DescTag, std::string ImplTag, int i, StringRef FunName, unsigned hasCopy) { std::string S = "\nstatic struct " + DescTag; - + S += " {\n unsigned long reserved;\n"; S += " unsigned long Block_size;\n"; if (hasCopy) { S += " void (*copy)(struct "; S += ImplTag; S += "*, struct "; S += ImplTag; S += "*);\n"; - + S += " void (*dispose)(struct "; S += ImplTag; S += "*);\n"; } @@ -3543,7 +3543,7 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, SC += "() {}"; InsertText(FunLocStart, SC); } - + // Insert closures that were part of the function. for (unsigned i = 0, count=0; i < Blocks.size(); i++) { CollectBlockDeclRefInfo(Blocks[i]); @@ -3564,7 +3564,7 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, // imported objects in the inner blocks not used in the outer // blocks must be copied/disposed in the outer block as well. if (VD->hasAttr<BlocksAttr>() || - VD->getType()->isObjCObjectPointerType() || + VD->getType()->isObjCObjectPointerType() || VD->getType()->isBlockPointerType()) ImportedBlockDecls.insert(VD); } @@ -3609,7 +3609,7 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, SC += "restrict "; InsertText(FunLocStart, SC); } - + Blocks.clear(); InnerDeclRefsCount.clear(); InnerDeclRefs.clear(); @@ -3697,7 +3697,7 @@ QualType RewriteObjC::convertFunctionTypeOfBlocks(const FunctionType *FT) { SmallVector<QualType, 8> ArgTypes; QualType Res = FT->getReturnType(); bool HasBlockType = convertBlockPointerToFunctionPointer(Res); - + if (FTP) { for (auto &I : FTP->param_types()) { QualType t = I; @@ -3724,13 +3724,13 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { CPT = DRE->getType()->getAs<BlockPointerType>(); } else if (const MemberExpr *MExpr = dyn_cast<MemberExpr>(BlockExp)) { CPT = MExpr->getType()->getAs<BlockPointerType>(); - } + } else if (const ParenExpr *PRE = dyn_cast<ParenExpr>(BlockExp)) { return SynthesizeBlockCall(Exp, PRE->getSubExpr()); } - else if (const ImplicitCastExpr *IEXPR = dyn_cast<ImplicitCastExpr>(BlockExp)) + else if (const ImplicitCastExpr *IEXPR = dyn_cast<ImplicitCastExpr>(BlockExp)) CPT = IEXPR->getType()->getAs<BlockPointerType>(); - else if (const ConditionalOperator *CEXPR = + else if (const ConditionalOperator *CEXPR = dyn_cast<ConditionalOperator>(BlockExp)) { Expr *LHSExp = CEXPR->getLHS(); Stmt *LHSStmt = SynthesizeBlockCall(Exp, LHSExp); @@ -3831,7 +3831,7 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { // }; //} Stmt *RewriteObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { - // Rewrite the byref variable into BYREFVAR->__forwarding->BYREFVAR + // Rewrite the byref variable into BYREFVAR->__forwarding->BYREFVAR // for each DeclRefExp where BYREFVAR is name of the variable. ValueDecl *VD = DeclRefExp->getDecl(); bool isArrow = DeclRefExp->refersToEnclosingVariableOrCapture() || @@ -3839,7 +3839,7 @@ Stmt *RewriteObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { FieldDecl *FD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), - &Context->Idents.get("__forwarding"), + &Context->Idents.get("__forwarding"), Context->VoidPtrTy, nullptr, /*BitWidth=*/nullptr, /*Mutable=*/true, ICIS_NoInit); @@ -3849,7 +3849,7 @@ Stmt *RewriteObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { StringRef Name = VD->getName(); FD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), - &Context->Idents.get(Name), + &Context->Idents.get(Name), Context->VoidPtrTy, nullptr, /*BitWidth=*/nullptr, /*Mutable=*/true, ICIS_NoInit); @@ -3858,14 +3858,14 @@ Stmt *RewriteObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { DeclRefExp->getType(), VK_LValue, OK_Ordinary); // Need parens to enforce precedence. - ParenExpr *PE = new (Context) ParenExpr(DeclRefExp->getExprLoc(), - DeclRefExp->getExprLoc(), + ParenExpr *PE = new (Context) ParenExpr(DeclRefExp->getExprLoc(), + DeclRefExp->getExprLoc(), ME); ReplaceStmt(DeclRefExp, PE); return PE; } -// Rewrites the imported local variable V with external storage +// Rewrites the imported local variable V with external storage // (static, extern, etc.) as *V // Stmt *RewriteObjC::RewriteLocalVariableExternalStorage(DeclRefExpr *DRE) { @@ -3877,7 +3877,7 @@ Stmt *RewriteObjC::RewriteLocalVariableExternalStorage(DeclRefExpr *DRE) { VK_LValue, OK_Ordinary, DRE->getLocation(), false); // Need parens to enforce precedence. - ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), + ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), Exp); ReplaceStmt(DRE, PE); return PE; @@ -3991,7 +3991,7 @@ bool RewriteObjC::PointerTypeTakesAnyObjCQualifiedType(QualType QT) { I->getPointeeType()->isObjCQualifiedInterfaceType()) return true; } - + } return false; } @@ -4057,7 +4057,7 @@ void RewriteObjC::RewriteBlockPointerDecl(NamedDecl *ND) { } buf += ')'; OrigLength++; - + if (PointerTypeTakesAnyBlockArguments(DeclT) || PointerTypeTakesAnyObjCQualifiedType(DeclT)) { // Replace the '^' with '*' for arguments. @@ -4070,7 +4070,7 @@ void RewriteObjC::RewriteBlockPointerDecl(NamedDecl *ND) { if (*argListBegin == '^') buf += '*'; else if (*argListBegin == '<') { - buf += "/*"; + buf += "/*"; buf += *argListBegin++; OrigLength++; while (*argListBegin != '>') { @@ -4094,19 +4094,19 @@ void RewriteObjC::RewriteBlockPointerDecl(NamedDecl *ND) { /// SynthesizeByrefCopyDestroyHelper - This routine synthesizes: /// void __Block_byref_id_object_copy(struct Block_byref_id_object *dst, /// struct Block_byref_id_object *src) { -/// _Block_object_assign (&_dest->object, _src->object, +/// _Block_object_assign (&_dest->object, _src->object, /// BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT /// [|BLOCK_FIELD_IS_WEAK]) // object -/// _Block_object_assign(&_dest->object, _src->object, +/// _Block_object_assign(&_dest->object, _src->object, /// BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK /// [|BLOCK_FIELD_IS_WEAK]) // block /// } /// And: /// void __Block_byref_id_object_dispose(struct Block_byref_id_object *_src) { -/// _Block_object_dispose(_src->object, +/// _Block_object_dispose(_src->object, /// BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT /// [|BLOCK_FIELD_IS_WEAK]) // object -/// _Block_object_dispose(_src->object, +/// _Block_object_dispose(_src->object, /// BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK /// [|BLOCK_FIELD_IS_WEAK]) // block /// } @@ -4120,14 +4120,14 @@ std::string RewriteObjC::SynthesizeByrefCopyDestroyHelper(VarDecl *VD, S = "static void __Block_byref_id_object_copy_"; S += utostr(flag); S += "(void *dst, void *src) {\n"; - + // offset into the object pointer is computed as: // void * + void* + int + int + void* + void * - unsigned IntSize = + unsigned IntSize = static_cast<unsigned>(Context->getTypeSize(Context->IntTy)); - unsigned VoidPtrSize = + unsigned VoidPtrSize = static_cast<unsigned>(Context->getTypeSize(Context->VoidPtrTy)); - + unsigned offset = (VoidPtrSize*4 + IntSize + IntSize)/Context->getCharWidth(); S += " _Block_object_assign((char*)dst + "; S += utostr(offset); @@ -4136,7 +4136,7 @@ std::string RewriteObjC::SynthesizeByrefCopyDestroyHelper(VarDecl *VD, S += "), "; S += utostr(flag); S += ");\n}\n"; - + S += "static void __Block_byref_id_object_dispose_"; S += utostr(flag); S += "(void *src) {\n"; @@ -4161,8 +4161,8 @@ std::string RewriteObjC::SynthesizeByrefCopyDestroyHelper(VarDecl *VD, /// }; /// /// It then replaces declaration of ND variable with: -/// struct __Block_byref_ND ND = {__isa=0B, __forwarding=&ND, __flags=some_flag, -/// __size=sizeof(struct __Block_byref_ND), +/// struct __Block_byref_ND ND = {__isa=0B, __forwarding=&ND, __flags=some_flag, +/// __size=sizeof(struct __Block_byref_ND), /// ND=initializer-if-any}; /// /// @@ -4191,7 +4191,7 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { ByrefType += " *__forwarding;\n"; ByrefType += " int __flags;\n"; ByrefType += " int __size;\n"; - // Add void *__Block_byref_id_object_copy; + // Add void *__Block_byref_id_object_copy; // void *__Block_byref_id_object_dispose; if needed. QualType Ty = ND->getType(); bool HasCopyAndDispose = Context->BlockRequiresCopying(Ty, ND); @@ -4203,7 +4203,7 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { QualType T = Ty; (void)convertBlockPointerToFunctionPointer(T); T.getAsStringInternal(Name, Context->getPrintingPolicy()); - + ByrefType += " " + Name + ";\n"; ByrefType += "};\n"; // Insert this type in global scope. It is needed by helper function. @@ -4219,7 +4219,7 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { flag |= BLOCK_FIELD_IS_WEAK; isa = 1; } - + if (HasCopyAndDispose) { flag = BLOCK_BYREF_CALLER; QualType Ty = ND->getType(); @@ -4232,9 +4232,9 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { if (!HF.empty()) InsertText(FunLocStart, HF); } - - // struct __Block_byref_ND ND = - // {0, &ND, some_flag, __size=sizeof(struct __Block_byref_ND), + + // struct __Block_byref_ND ND = + // {0, &ND, some_flag, __size=sizeof(struct __Block_byref_ND), // initializer-if-any}; bool hasInit = (ND->getInit() != nullptr); unsigned flags = 0; @@ -4294,13 +4294,13 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { ByrefType += ", "; } ReplaceText(DeclLoc, endBuf-startBuf, ByrefType); - + // Complete the newly synthesized compound expression by inserting a right // curly brace before the end of the declaration. // FIXME: This approach avoids rewriting the initializer expression. It // also assumes there is only one declarator. For example, the following // isn't currently supported by this routine (in general): - // + // // double __block BYREFVAR = 1.34, BYREFVAR2 = 1.37; // const char *startInitializerBuf = SM->getCharacterData(startLoc); @@ -4336,7 +4336,7 @@ void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { // Find any imported blocks...they will need special attention. for (unsigned i = 0; i < BlockDeclRefs.size(); i++) if (BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>() || - BlockDeclRefs[i]->getType()->isObjCObjectPointerType() || + BlockDeclRefs[i]->getType()->isObjCObjectPointerType() || BlockDeclRefs[i]->getType()->isBlockPointerType()) ImportedBlockDecls.insert(BlockDeclRefs[i]->getDecl()); } @@ -4356,7 +4356,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, Blocks.push_back(Exp); CollectBlockDeclRefInfo(Exp); - + // Add inner imported variables now used in current block. int countOfInnerDecls = 0; if (!InnerBlockDeclRefs.empty()) { @@ -4382,12 +4382,12 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, // Find any imported blocks...they will need special attention. for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) if (InnerBlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>() || - InnerBlockDeclRefs[i]->getType()->isObjCObjectPointerType() || + InnerBlockDeclRefs[i]->getType()->isObjCObjectPointerType() || InnerBlockDeclRefs[i]->getType()->isBlockPointerType()) ImportedBlockDecls.insert(InnerBlockDeclRefs[i]->getDecl()); } InnerDeclRefsCount.push_back(countOfInnerDecls); - + std::string FuncName; if (CurFunctionDef) @@ -4434,13 +4434,13 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, false, Context->VoidPtrTy, VK_LValue, - SourceLocation()), + SourceLocation()), UO_AddrOf, - Context->getPointerType(Context->VoidPtrTy), + Context->getPointerType(Context->VoidPtrTy), VK_RValue, OK_Ordinary, SourceLocation(), false); - InitExprs.push_back(DescRefExpr); - + InitExprs.push_back(DescRefExpr); + // Add initializers for any closure decl refs. if (BlockDeclRefs.size()) { Expr *Exp; @@ -4486,14 +4486,14 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, std::string Name(ND->getNameAsString()); std::string RecName; RewriteByRefString(RecName, Name, ND, true); - IdentifierInfo *II = &Context->Idents.get(RecName.c_str() + IdentifierInfo *II = &Context->Idents.get(RecName.c_str() + sizeof("struct")); RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl, SourceLocation(), SourceLocation(), II); assert(RD && "SynthBlockInitExpr(): Can't find RecordDecl"); QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); - + FD = SynthBlockInitFunctionDecl((*I)->getName()); Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, SourceLocation()); @@ -4502,7 +4502,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, for (const auto &CI : block->captures()) { const VarDecl *variable = CI.getVariable(); if (variable == ND && CI.isNested()) { - assert (CI.isByRef() && + assert (CI.isByRef() && "SynthBlockInitExpr - captured block variable is not byref"); isNestedCapturedVar = true; break; @@ -4521,9 +4521,9 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, if (ImportedBlockDecls.size()) { // generate BLOCK_HAS_COPY_DISPOSE(have helper funcs) | BLOCK_HAS_DESCRIPTOR int flag = (BLOCK_HAS_COPY_DISPOSE | BLOCK_HAS_DESCRIPTOR); - unsigned IntSize = + unsigned IntSize = static_cast<unsigned>(Context->getTypeSize(Context->IntTy)); - Expr *FlagExp = IntegerLiteral::Create(*Context, llvm::APInt(IntSize, flag), + Expr *FlagExp = IntegerLiteral::Create(*Context, llvm::APInt(IntSize, flag), Context->IntTy, SourceLocation()); InitExprs.push_back(FlagExp); } @@ -4544,7 +4544,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, } bool RewriteObjC::IsDeclStmtInForeachHeader(DeclStmt *DS) { - if (const ObjCForCollectionStmt * CS = + if (const ObjCForCollectionStmt * CS = dyn_cast<ObjCForCollectionStmt>(Stmts.back())) return CS->getElement() == DS; return false; @@ -4614,7 +4614,7 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { RewrittenBlockExprs[BE] = Str; Stmt *blockTranscribed = SynthBlockInitExpr(BE, InnerBlockDeclRefs); - + //blockTranscribed->dump(); ReplaceStmt(S, blockTranscribed); return blockTranscribed; @@ -4685,7 +4685,7 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { // the context of an ObjCForCollectionStmt. For example: // NSArray *someArray; // for (id <FooProtocol> index in someArray) ; - // This is because RewriteObjCForCollectionStmt() does textual rewriting + // This is because RewriteObjCForCollectionStmt() does textual rewriting // and it depends on the original text locations/positions. if (Stmts.empty() || !IsDeclStmtInForeachHeader(DS)) RewriteObjCQualifiedInterfaceTypes(*DS->decl_begin()); @@ -4705,7 +4705,7 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { BlockByRefDeclNo[ND] = uniqueByrefDeclCount++; RewriteByRefVar(VD); } - else + else RewriteTypeOfDecl(VD); } } @@ -4731,13 +4731,13 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { } // Handle blocks rewriting. if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(S)) { - ValueDecl *VD = DRE->getDecl(); + ValueDecl *VD = DRE->getDecl(); if (VD->hasAttr<BlocksAttr>()) return RewriteBlockDeclRefExpr(DRE); if (HasLocalVariableExternalStorage(VD)) return RewriteLocalVariableExternalStorage(DRE); } - + if (CallExpr *CE = dyn_cast<CallExpr>(S)) { if (CE->getCallee()->getType()->isBlockPointerType()) { Stmt *BlockCall = SynthesizeBlockCall(CE, CE->getCallee()); @@ -4894,7 +4894,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) { case Decl::CXXRecord: case Decl::Record: { RecordDecl *RD = cast<RecordDecl>(D); - if (RD->isCompleteDefinition()) + if (RD->isCompleteDefinition()) RewriteRecordBody(RD); break; } @@ -4942,7 +4942,7 @@ void RewriteObjC::HandleTranslationUnit(ASTContext &C) { void RewriteObjCFragileABI::Initialize(ASTContext &context) { InitializeCommon(context); - + // declaring objc_selector outside the parameter list removes a silly // scope related warning... if (IsHeader) @@ -5079,7 +5079,7 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData( ObjCProtocolDecl *PDecl, StringRef prefix, StringRef ClassName, std::string &Result) { static bool objc_protocol_methods = false; - + // Output struct protocol_methods holder of method selector and type. if (!objc_protocol_methods && PDecl->hasDefinition()) { /* struct protocol_methods { @@ -5091,16 +5091,16 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData( Result += "\tstruct objc_selector *_cmd;\n"; Result += "\tchar *method_types;\n"; Result += "};\n"; - + objc_protocol_methods = true; } // Do not synthesize the protocol more than once. if (ObjCSynthesizedProtocols.count(PDecl->getCanonicalDecl())) return; - + if (ObjCProtocolDecl *Def = PDecl->getDefinition()) PDecl = Def; - + if (PDecl->instmeth_begin() != PDecl->instmeth_end()) { unsigned NumMethods = std::distance(PDecl->instmeth_begin(), PDecl->instmeth_end()); @@ -5117,7 +5117,7 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData( Result += PDecl->getNameAsString(); Result += " __attribute__ ((used, section (\"__OBJC, __cat_inst_meth\")))= " "{\n\t" + utostr(NumMethods) + "\n"; - + // Output instance methods declared in this protocol. for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), E = PDecl->instmeth_end(); @@ -5134,7 +5134,7 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData( } Result += "\t }\n};\n"; } - + // Output class methods declared in this protocol. unsigned NumMethods = std::distance(PDecl->classmeth_begin(), PDecl->classmeth_end()); @@ -5154,7 +5154,7 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData( "{\n\t"; Result += utostr(NumMethods); Result += "\n"; - + // Output instance methods declared in this protocol. for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); @@ -5171,7 +5171,7 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData( } Result += "\t }\n};\n"; } - + // Output: /* struct _objc_protocol { // Objective-C 1.0 extensions @@ -5191,10 +5191,10 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData( Result += "\tstruct _objc_protocol_method_list *instance_methods;\n"; Result += "\tstruct _objc_protocol_method_list *class_methods;\n"; Result += "};\n"; - + objc_protocol = true; } - + Result += "\nstatic struct _objc_protocol _OBJC_PROTOCOL_"; Result += PDecl->getNameAsString(); Result += " __attribute__ ((used, section (\"__OBJC, __protocol\")))= " @@ -5216,7 +5216,7 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData( else Result += "0\n"; Result += "};\n"; - + // Mark this protocol as having been generated. if (!ObjCSynthesizedProtocols.insert(PDecl->getCanonicalDecl()).second) llvm_unreachable("protocol already synthesized"); @@ -5227,10 +5227,10 @@ void RewriteObjCFragileABI::RewriteObjCProtocolListMetaData( StringRef prefix, StringRef ClassName, std::string &Result) { if (Protocols.empty()) return; - + for (unsigned i = 0; i != Protocols.size(); i++) RewriteObjCProtocolMetaData(Protocols[i], prefix, ClassName, Result); - + // Output the top lovel protocol meta-data for the class. /* struct _objc_protocol_list { struct _objc_protocol_list *next; @@ -5251,11 +5251,11 @@ void RewriteObjCFragileABI::RewriteObjCProtocolListMetaData( "{\n\t0, "; Result += utostr(Protocols.size()); Result += "\n"; - + Result += "\t,{&_OBJC_PROTOCOL_"; Result += Protocols[0]->getNameAsString(); Result += " \n"; - + for (unsigned i = 1; i != Protocols.size(); i++) { Result += "\t ,&_OBJC_PROTOCOL_"; Result += Protocols[i]->getNameAsString(); @@ -5267,14 +5267,14 @@ void RewriteObjCFragileABI::RewriteObjCProtocolListMetaData( void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, std::string &Result) { ObjCInterfaceDecl *CDecl = IDecl->getClassInterface(); - + // Explicitly declared @interface's are already synthesized. if (CDecl->isImplicitInterfaceDecl()) { // FIXME: Implementation of a class with no @interface (legacy) does not // produce correct synthesis as yet. RewriteObjCInternalStruct(CDecl, Result); } - + // Build _objc_ivar_list metadata for classes ivars if needed unsigned NumIvars = !IDecl->ivar_empty() ? IDecl->ivar_size() @@ -5293,10 +5293,10 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe Result += "\tchar *ivar_type;\n"; Result += "\tint ivar_offset;\n"; Result += "};\n"; - + objc_ivar = true; } - + /* struct { int ivar_count; struct _objc_ivar ivar_list[nIvars]; @@ -5312,7 +5312,7 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe "{\n\t"; Result += utostr(NumIvars); Result += "\n"; - + ObjCInterfaceDecl::ivar_iterator IVI, IVE; SmallVector<ObjCIvarDecl *, 8> IVars; if (!IDecl->ivar_empty()) { @@ -5346,13 +5346,13 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe RewriteIvarOffsetComputation(*IVI, Result); Result += "}\n"; } - + Result += "\t }\n};\n"; } - + // Build _objc_method_list for class's instance methods if needed SmallVector<ObjCMethodDecl *, 32> InstanceMethods(IDecl->instance_methods()); - + // If any of our property implementations have associated getters or // setters, produce metadata for them as well. for (const auto *Prop : IDecl->property_impls()) { @@ -5374,15 +5374,15 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe } RewriteObjCMethodsMetaData(InstanceMethods.begin(), InstanceMethods.end(), true, "", IDecl->getName(), Result); - + // Build _objc_method_list for class's class methods if needed RewriteObjCMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(), false, "", IDecl->getName(), Result); - + // Protocols referenced in class declaration? RewriteObjCProtocolListMetaData(CDecl->getReferencedProtocols(), "CLASS", CDecl->getName(), Result); - + // Declaration of class/meta-class metadata /* struct _objc_class { struct _objc_class *isa; // or const char *root_class_name when metadata @@ -5417,7 +5417,7 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe Result += "};\n"; objc_class = true; } - + // Meta-class metadata generation. ObjCInterfaceDecl *RootClass = nullptr; ObjCInterfaceDecl *SuperClass = CDecl->getSuperClass(); @@ -5426,14 +5426,14 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe SuperClass = SuperClass->getSuperClass(); } SuperClass = CDecl->getSuperClass(); - + Result += "\nstatic struct _objc_class _OBJC_METACLASS_"; Result += CDecl->getNameAsString(); Result += " __attribute__ ((used, section (\"__OBJC, __meta_class\")))= " "{\n\t(struct _objc_class *)\""; Result += (RootClass ? RootClass->getNameAsString() : CDecl->getNameAsString()); Result += "\""; - + if (SuperClass) { Result += ", \""; Result += SuperClass->getNameAsString(); @@ -5464,7 +5464,7 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe else Result += "\t,0,0,0,0\n"; Result += "};\n"; - + // class metadata generation. Result += "\nstatic struct _objc_class _OBJC_CLASS_"; Result += CDecl->getNameAsString(); @@ -5522,15 +5522,15 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe void RewriteObjCFragileABI::RewriteMetaDataIntoBuffer(std::string &Result) { int ClsDefCount = ClassImplementation.size(); int CatDefCount = CategoryImplementation.size(); - + // For each implemented class, write out all its meta data. for (int i = 0; i < ClsDefCount; i++) RewriteObjCClassMetaData(ClassImplementation[i], Result); - + // For each implemented category, write out all its meta data. for (int i = 0; i < CatDefCount; i++) RewriteObjCCategoryImplDecl(CategoryImplementation[i], Result); - + // Write objc_symtab metadata /* struct _objc_symtab @@ -5542,7 +5542,7 @@ void RewriteObjCFragileABI::RewriteMetaDataIntoBuffer(std::string &Result) { void *defs[cls_def_cnt + cat_def_cnt]; }; */ - + Result += "\nstruct _objc_symtab {\n"; Result += "\tlong sel_ref_cnt;\n"; Result += "\tSEL *refs;\n"; @@ -5550,7 +5550,7 @@ void RewriteObjCFragileABI::RewriteMetaDataIntoBuffer(std::string &Result) { Result += "\tshort cat_def_cnt;\n"; Result += "\tvoid *defs[" + utostr(ClsDefCount + CatDefCount)+ "];\n"; Result += "};\n\n"; - + Result += "static struct _objc_symtab " "_OBJC_SYMBOLS __attribute__((used, section (\"__OBJC, __symbols\")))= {\n"; Result += "\t0, 0, " + utostr(ClsDefCount) @@ -5560,7 +5560,7 @@ void RewriteObjCFragileABI::RewriteMetaDataIntoBuffer(std::string &Result) { Result += ClassImplementation[i]->getNameAsString(); Result += "\n"; } - + for (int i = 0; i < CatDefCount; i++) { Result += "\t,&_OBJC_CATEGORY_"; Result += CategoryImplementation[i]->getClassInterface()->getNameAsString(); @@ -5568,11 +5568,11 @@ void RewriteObjCFragileABI::RewriteMetaDataIntoBuffer(std::string &Result) { Result += CategoryImplementation[i]->getNameAsString(); Result += "\n"; } - + Result += "};\n\n"; - + // Write objc_module metadata - + /* struct _objc_module { long version; @@ -5581,7 +5581,7 @@ void RewriteObjCFragileABI::RewriteMetaDataIntoBuffer(std::string &Result) { struct _objc_symtab *symtab; } */ - + Result += "\nstruct _objc_module {\n"; Result += "\tlong version;\n"; Result += "\tlong size;\n"; @@ -5593,7 +5593,7 @@ void RewriteObjCFragileABI::RewriteMetaDataIntoBuffer(std::string &Result) { Result += "\t" + utostr(OBJC_ABI_VERSION) + ", sizeof(struct _objc_module), \"\", &_OBJC_SYMBOLS\n"; Result += "};\n\n"; - + if (LangOpts.MicrosoftExt) { if (ProtocolExprDecls.size()) { Result += "#pragma section(\".objc_protocol$B\",long,read,write)\n"; @@ -5623,14 +5623,14 @@ void RewriteObjCFragileABI::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *ID // Find category declaration for this implementation. ObjCCategoryDecl *CDecl = ClassDecl->FindCategoryDeclaration(IDecl->getIdentifier()); - + std::string FullCategoryName = ClassDecl->getNameAsString(); FullCategoryName += '_'; FullCategoryName += IDecl->getNameAsString(); - + // Build _objc_method_list for class's instance methods if needed SmallVector<ObjCMethodDecl *, 32> InstanceMethods(IDecl->instance_methods()); - + // If any of our property implementations have associated getters or // setters, produce metadata for them as well. for (const auto *Prop : IDecl->property_impls()) { @@ -5672,7 +5672,7 @@ void RewriteObjCFragileABI::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *ID // @property decl. }; */ - + static bool objc_category = false; if (!objc_category) { Result += "\nstruct _objc_category {\n"; @@ -5693,7 +5693,7 @@ void RewriteObjCFragileABI::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *ID Result += "\"\n\t, \""; Result += ClassDecl->getNameAsString(); Result += "\"\n"; - + if (IDecl->instmeth_begin() != IDecl->instmeth_end()) { Result += "\t, (struct _objc_method_list *)" "&_OBJC_CATEGORY_INSTANCE_METHODS_"; @@ -5710,7 +5710,7 @@ void RewriteObjCFragileABI::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *ID } else Result += "\t, 0\n"; - + if (CDecl && CDecl->protocol_begin() != CDecl->protocol_end()) { Result += "\t, (struct _objc_protocol_list *)&_OBJC_CATEGORY_PROTOCOLS_"; Result += FullCategoryName; @@ -5731,7 +5731,7 @@ void RewriteObjCFragileABI::RewriteObjCMethodsMetaData(MethodIterator MethodBegi StringRef ClassName, std::string &Result) { if (MethodBegin == MethodEnd) return; - + if (!objc_impl_method) { /* struct _objc_method { SEL _cmd; @@ -5744,12 +5744,12 @@ void RewriteObjCFragileABI::RewriteObjCMethodsMetaData(MethodIterator MethodBegi Result += "\tchar *method_types;\n"; Result += "\tvoid *_imp;\n"; Result += "};\n"; - + objc_impl_method = true; } - + // Build _objc_method_list for class's methods if needed - + /* struct { struct _objc_method_list *next_method; int method_count; @@ -5771,7 +5771,7 @@ void RewriteObjCFragileABI::RewriteObjCMethodsMetaData(MethodIterator MethodBegi Result += IsInstanceMethod ? "inst" : "cls"; Result += "_meth\")))= "; Result += "{\n\t0, " + utostr(NumMethods) + "\n"; - + Result += "\t,{{(SEL)\""; Result += (*MethodBegin)->getSelector().getAsString(); std::string MethodTypeString = @@ -5798,16 +5798,16 @@ void RewriteObjCFragileABI::RewriteObjCMethodsMetaData(MethodIterator MethodBegi Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { SourceRange OldRange = IV->getSourceRange(); Expr *BaseExpr = IV->getBase(); - + // Rewrite the base, but without actually doing replaces. { DisableReplaceStmtScope S(*this); BaseExpr = cast<Expr>(RewriteFunctionBodyOrGlobalInitializer(BaseExpr)); IV->setBase(BaseExpr); } - + ObjCIvarDecl *D = IV->getDecl(); - + Expr *Replacement = IV; if (CurMethodDef) { if (BaseExpr->getType()->isObjCObjectPointerType()) { @@ -5819,7 +5819,7 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { 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"; @@ -5848,7 +5848,7 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *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 (BaseExpr->getType()->isObjCObjectPointerType()) { @@ -5859,7 +5859,7 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { 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"; @@ -5881,9 +5881,9 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { IV->setBase(PE); } } - + ReplaceStmtWithRange(IV, Replacement, OldRange); - return Replacement; + return Replacement; } #endif // CLANG_ENABLE_OBJC_REWRITER diff --git a/lib/Frontend/SerializedDiagnosticPrinter.cpp b/lib/Frontend/SerializedDiagnosticPrinter.cpp index ca60c4812f72..22546ce4c097 100644 --- a/lib/Frontend/SerializedDiagnosticPrinter.cpp +++ b/lib/Frontend/SerializedDiagnosticPrinter.cpp @@ -28,31 +28,31 @@ using namespace clang; using namespace clang::serialized_diags; namespace { - + class AbbreviationMap { llvm::DenseMap<unsigned, unsigned> Abbrevs; public: AbbreviationMap() {} - + void set(unsigned recordID, unsigned abbrevID) { - assert(Abbrevs.find(recordID) == Abbrevs.end() + assert(Abbrevs.find(recordID) == Abbrevs.end() && "Abbreviation already set."); Abbrevs[recordID] = abbrevID; } - + unsigned get(unsigned recordID) { assert(Abbrevs.find(recordID) != Abbrevs.end() && "Abbreviation not set."); return Abbrevs[recordID]; } }; - + typedef SmallVector<uint64_t, 64> RecordData; typedef SmallVectorImpl<uint64_t> RecordDataImpl; typedef ArrayRef<uint64_t> RecordDataRef; class SDiagsWriter; - + class SDiagsRenderer : public DiagnosticNoteRenderer { SDiagsWriter &Writer; public: @@ -172,7 +172,7 @@ private: /// Emit the preamble for the serialized diagnostics. void EmitPreamble(); - + /// Emit the BLOCKINFO block. void EmitBlockInfoBlock(); @@ -197,10 +197,10 @@ private: /// Emit a record for a CharSourceRange. void EmitCharSourceRange(CharSourceRange R, const SourceManager &SM); - + /// Emit the string information for the category. unsigned getEmitCategory(unsigned category = 0); - + /// Emit the string information for diagnostic flags. unsigned getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel, unsigned DiagID = 0); @@ -312,7 +312,7 @@ static void EmitBlockID(unsigned ID, const char *Name, Record.clear(); Record.push_back(ID); Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); - + // Emit the block name if present. if (!Name || Name[0] == 0) return; @@ -370,11 +370,11 @@ void SDiagsWriter::AddCharSourceRangeToRecord(CharSourceRange Range, unsigned SDiagsWriter::getEmitFile(const char *FileName){ if (!FileName) return 0; - + unsigned &entry = State->Files[FileName]; if (entry) return entry; - + // Lazily generate the record for the file. entry = State->Files.size(); StringRef Name(FileName); @@ -417,7 +417,7 @@ static void AddSourceLocationAbbrev(llvm::BitCodeAbbrev &Abbrev) { static void AddRangeLocationAbbrev(llvm::BitCodeAbbrev &Abbrev) { AddSourceLocationAbbrev(Abbrev); - AddSourceLocationAbbrev(Abbrev); + AddSourceLocationAbbrev(Abbrev); } void SDiagsWriter::EmitBlockInfoBlock() { @@ -456,12 +456,12 @@ void SDiagsWriter::EmitBlockInfoBlock() { Abbrev->Add(BitCodeAbbrevOp(RECORD_DIAG)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Diag level. AddSourceLocationAbbrev(*Abbrev); - Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Category. + Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Category. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped Diag ID. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // Text size. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Diagnostc text. Abbrevs.set(RECORD_DIAG, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); - + // Emit abbreviation for RECORD_CATEGORY. Abbrev = std::make_shared<BitCodeAbbrev>(); Abbrev->Add(BitCodeAbbrevOp(RECORD_CATEGORY)); @@ -476,7 +476,7 @@ void SDiagsWriter::EmitBlockInfoBlock() { AddRangeLocationAbbrev(*Abbrev); Abbrevs.set(RECORD_SOURCE_RANGE, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); - + // Emit the abbreviation for RECORD_DIAG_FLAG. Abbrev = std::make_shared<BitCodeAbbrev>(); Abbrev->Add(BitCodeAbbrevOp(RECORD_DIAG_FLAG)); @@ -485,18 +485,18 @@ void SDiagsWriter::EmitBlockInfoBlock() { Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Flag name text. Abbrevs.set(RECORD_DIAG_FLAG, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); - + // Emit the abbreviation for RECORD_FILENAME. Abbrev = std::make_shared<BitCodeAbbrev>(); Abbrev->Add(BitCodeAbbrevOp(RECORD_FILENAME)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped file ID. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Size. - Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Modification time. + Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Modification time. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name text. Abbrevs.set(RECORD_FILENAME, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); - + // Emit the abbreviation for RECORD_FIXIT. Abbrev = std::make_shared<BitCodeAbbrev>(); Abbrev->Add(BitCodeAbbrevOp(RECORD_FIXIT)); @@ -529,7 +529,7 @@ unsigned SDiagsWriter::getEmitCategory(unsigned int category) { RecordData::value_type Record[] = {RECORD_CATEGORY, category, catName.size()}; State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_CATEGORY), Record, catName); - + return category; } @@ -537,7 +537,7 @@ unsigned SDiagsWriter::getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel, unsigned DiagID) { if (DiagLevel == DiagnosticsEngine::Note) return 0; // No flag for notes. - + StringRef FlagName = DiagnosticIDs::getWarningOptionForDiag(DiagID); return getEmitDiagnosticFlag(FlagName); } @@ -553,7 +553,7 @@ unsigned SDiagsWriter::getEmitDiagnosticFlag(StringRef FlagName) { if (entry.first == 0) { entry.first = State->DiagFlags.size(); entry.second = FlagName; - + // Lazily emit the string in a separate record. RecordData::value_type Record[] = {RECORD_DIAG_FLAG, entry.first, FlagName.size()}; @@ -630,7 +630,7 @@ void SDiagsWriter::EmitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, llvm::BitstreamWriter &Stream = State->Stream; RecordData &Record = State->Record; AbbreviationMap &Abbrevs = State->Abbrevs; - + // Emit the RECORD_DIAG record. Record.clear(); Record.push_back(RECORD_DIAG); diff --git a/lib/Frontend/TestModuleFileExtension.cpp b/lib/Frontend/TestModuleFileExtension.cpp index 294f7e44cee5..087bdc543548 100644 --- a/lib/Frontend/TestModuleFileExtension.cpp +++ b/lib/Frontend/TestModuleFileExtension.cpp @@ -91,7 +91,7 @@ llvm::hash_code TestModuleFileExtension::hashExtension( Code = llvm::hash_combine(Code, MinorVersion); Code = llvm::hash_combine(Code, UserInfo); } - + return Code; } diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp index 85cd019005da..35b99b10f94a 100644 --- a/lib/Frontend/TextDiagnostic.cpp +++ b/lib/Frontend/TextDiagnostic.cpp @@ -100,7 +100,7 @@ printableTextForNextCharacter(StringRef SourceLine, size_t *i, unsigned TabStop) { assert(i && "i must not be null"); assert(*i<SourceLine.size() && "must point to a valid index"); - + if (SourceLine[*i]=='\t') { assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop && "Invalid -ftabstop value"); @@ -118,7 +118,7 @@ printableTextForNextCharacter(StringRef SourceLine, size_t *i, unsigned char const *begin, *end; begin = reinterpret_cast<unsigned char const *>(&*(SourceLine.begin() + *i)); end = begin + (SourceLine.size() - *i); - + if (llvm::isLegalUTF8Sequence(begin, end)) { llvm::UTF32 c; llvm::UTF32 *cptr = &c; @@ -203,7 +203,7 @@ static void byteToColumn(StringRef SourceLine, unsigned TabStop, out.resize(1u,0); return; } - + out.resize(SourceLine.size()+1, -1); int columns = 0; @@ -255,10 +255,10 @@ namespace { struct SourceColumnMap { SourceColumnMap(StringRef SourceLine, unsigned TabStop) : m_SourceLine(SourceLine) { - + ::byteToColumn(SourceLine, TabStop, m_byteToColumn); ::columnToByte(SourceLine, TabStop, m_columnToByte); - + assert(m_byteToColumn.size()==SourceLine.size()+1); assert(0 < m_byteToColumn.size() && 0 < m_columnToByte.size()); assert(m_byteToColumn.size() @@ -309,7 +309,7 @@ struct SourceColumnMap { StringRef getSourceLine() const { return m_SourceLine; } - + private: const std::string m_SourceLine; SmallVector<int,200> m_byteToColumn; @@ -684,7 +684,7 @@ void TextDiagnostic::emitDiagnosticMessage( if (DiagOpts->ShowColors) OS.resetColor(); - + printDiagnosticLevel(OS, Level, DiagOpts->ShowColors, DiagOpts->CLFallbackMode); printDiagnosticMessage(OS, @@ -891,7 +891,7 @@ void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) { OS << "In file included from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n"; else - OS << "In included file:\n"; + OS << "In included file:\n"; } void TextDiagnostic::emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, @@ -1269,15 +1269,15 @@ void TextDiagnostic::emitSnippet(StringRef line) { return; size_t i = 0; - + std::string to_print; bool print_reversed = false; - + while (i<line.size()) { std::pair<SmallString<16>,bool> res = printableTextForNextCharacter(line, &i, DiagOpts->TabStop); bool was_printable = res.second; - + if (DiagOpts->ShowColors && was_printable == print_reversed) { if (print_reversed) OS.reverseColor(); @@ -1286,17 +1286,17 @@ void TextDiagnostic::emitSnippet(StringRef line) { if (DiagOpts->ShowColors) OS.resetColor(); } - + print_reversed = !was_printable; to_print += res.first.str(); } - + if (print_reversed && DiagOpts->ShowColors) OS.reverseColor(); OS << to_print; if (print_reversed && DiagOpts->ShowColors) OS.resetColor(); - + OS << '\n'; } |