From 99d1b295031ea4e74630914c14f94d919aa8e8dc Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Sat, 1 Oct 2016 16:38:28 +0000 Subject: [PATCH] Use StringRef for MemoryBuffer identifier API (NFC) llvm-svn: 283043 --- clang/include/clang/Basic/SourceManager.h | 2 +- clang/include/clang/Lex/DirectoryLookup.h | 2 +- clang/include/clang/Lex/HeaderMap.h | 2 +- .../include/clang/Rewrite/Core/HTMLRewrite.h | 4 ++-- clang/lib/Basic/SourceManager.cpp | 24 +++++++++---------- clang/lib/CodeGen/CoverageMappingGen.cpp | 2 +- clang/lib/Frontend/InitHeaderSearch.cpp | 2 +- clang/lib/Frontend/Rewrite/HTMLPrint.cpp | 2 +- .../Frontend/Rewrite/InclusionRewriter.cpp | 6 ++--- clang/lib/Lex/HeaderMap.cpp | 2 +- clang/lib/Lex/HeaderSearch.cpp | 2 +- clang/lib/Lex/PPDirectives.cpp | 4 ++-- clang/lib/Rewrite/HTMLRewrite.cpp | 6 ++--- clang/lib/Serialization/ASTWriter.cpp | 7 +++--- .../llvm/ExecutionEngine/ObjectMemoryBuffer.h | 2 +- llvm/include/llvm/Support/MemoryBuffer.h | 4 +--- llvm/lib/Support/MemoryBuffer.cpp | 10 ++++---- llvm/lib/Support/SourceMgr.cpp | 2 +- llvm/utils/TableGen/CTagsEmitter.cpp | 2 +- 19 files changed, 42 insertions(+), 45 deletions(-) diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 6610c56b15d5..45187e58cb36 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1291,7 +1291,7 @@ public: /// /// Note that this name does not respect \#line directives. Use /// getPresumedLoc for normal clients. - const char *getBufferName(SourceLocation Loc, bool *Invalid = nullptr) const; + StringRef getBufferName(SourceLocation Loc, bool *Invalid = nullptr) const; /// \brief Return the file characteristic of the specified source /// location, indicating whether this is a normal file, a system diff --git a/clang/include/clang/Lex/DirectoryLookup.h b/clang/include/clang/Lex/DirectoryLookup.h index ee0af292e6fc..dcd58f434fa2 100644 --- a/clang/include/clang/Lex/DirectoryLookup.h +++ b/clang/include/clang/Lex/DirectoryLookup.h @@ -88,7 +88,7 @@ public: /// getName - Return the directory or filename corresponding to this lookup /// object. - const char *getName() const; + StringRef getName() const; /// getDir - Return the directory that this entry refers to. /// diff --git a/clang/include/clang/Lex/HeaderMap.h b/clang/include/clang/Lex/HeaderMap.h index 8466f1a24d52..58bf79579a6a 100644 --- a/clang/include/clang/Lex/HeaderMap.h +++ b/clang/include/clang/Lex/HeaderMap.h @@ -45,7 +45,7 @@ public: SmallVectorImpl &DestPath) const; /// Return the filename of the headermap. - const char *getFileName() const; + StringRef getFileName() const; /// Print the contents of this headermap to stderr. void dump() const; diff --git a/clang/include/clang/Rewrite/Core/HTMLRewrite.h b/clang/include/clang/Rewrite/Core/HTMLRewrite.h index dafdf51ce63b..1fd7c7a3f84e 100644 --- a/clang/include/clang/Rewrite/Core/HTMLRewrite.h +++ b/clang/include/clang/Rewrite/Core/HTMLRewrite.h @@ -62,8 +62,8 @@ namespace html { void AddLineNumbers(Rewriter& R, FileID FID); - void AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID, - const char *title = nullptr); + void AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID, + StringRef title); /// SyntaxHighlight - Relex the specified FileID and annotate the HTML with /// information about keywords, comments, etc. diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 605f990e41d1..5dcb8811e27f 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -1437,8 +1437,8 @@ SourceManager::getFileCharacteristic(SourceLocation Loc) const { /// Return the filename or buffer identifier of the buffer the location is in. /// Note that this name does not respect \#line directives. Use getPresumedLoc /// for normal clients. -const char *SourceManager::getBufferName(SourceLocation Loc, - bool *Invalid) const { +StringRef SourceManager::getBufferName(SourceLocation Loc, + bool *Invalid) const { if (isInvalid(Loc, Invalid)) return ""; return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier(); @@ -1470,7 +1470,7 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc, // To get the source name, first consult the FileEntry (if one exists) // before the MemBuffer as this will avoid unnecessarily paging in the // MemBuffer. - const char *Filename; + StringRef Filename; if (C->OrigEntry) Filename = C->OrigEntry->getName(); else @@ -1513,7 +1513,7 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc, } } - return PresumedLoc(Filename, LineNo, ColNo, IncludeLoc); + return PresumedLoc(Filename.data(), LineNo, ColNo, IncludeLoc); } /// \brief Returns whether the PresumedLoc for a given SourceLocation is @@ -2095,10 +2095,10 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, // Clear the lookup cache, it depends on a common location. IsBeforeInTUCache.clear(); - const char *LB = getBuffer(LOffs.first)->getBufferIdentifier(); - const char *RB = getBuffer(ROffs.first)->getBufferIdentifier(); - bool LIsBuiltins = strcmp("", LB) == 0; - bool RIsBuiltins = strcmp("", RB) == 0; + StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier(); + StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier(); + bool LIsBuiltins = LB == ""; + bool RIsBuiltins = RB == ""; // Sort built-in before non-built-in. if (LIsBuiltins || RIsBuiltins) { if (LIsBuiltins != RIsBuiltins) @@ -2107,8 +2107,8 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, // lower IDs come first. return LOffs.first < ROffs.first; } - bool LIsAsm = strcmp("", LB) == 0; - bool RIsAsm = strcmp("", RB) == 0; + bool LIsAsm = LB == ""; + bool RIsAsm = RB == ""; // Sort assembler after built-ins, but before the rest. if (LIsAsm || RIsAsm) { if (LIsAsm != RIsAsm) @@ -2116,8 +2116,8 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, assert(LOffs.first == ROffs.first); return false; } - bool LIsScratch = strcmp("", LB) == 0; - bool RIsScratch = strcmp("", RB) == 0; + bool LIsScratch = LB == ""; + bool RIsScratch = RB == ""; // Sort scratch after inline asm, but before the rest. if (LIsScratch || RIsScratch) { if (LIsScratch != RIsScratch) diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 0e51658e4b5f..35d1b1d47f3f 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -136,7 +136,7 @@ public: /// \brief Return true if \c Loc is a location in a built-in macro. bool isInBuiltin(SourceLocation Loc) { - return strcmp(SM.getBufferName(SM.getSpellingLoc(Loc)), "") == 0; + return SM.getBufferName(SM.getSpellingLoc(Loc)) == ""; } /// \brief Check whether \c Loc is included or expanded from \c Parent. diff --git a/clang/lib/Frontend/InitHeaderSearch.cpp b/clang/lib/Frontend/InitHeaderSearch.cpp index 24edb963f268..c76ccea8ac35 100644 --- a/clang/lib/Frontend/InitHeaderSearch.cpp +++ b/clang/lib/Frontend/InitHeaderSearch.cpp @@ -625,7 +625,7 @@ void InitHeaderSearch::Realize(const LangOptions &Lang) { for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { if (i == NumQuoted) llvm::errs() << "#include <...> search starts here:\n"; - const char *Name = SearchList[i].getName(); + StringRef Name = SearchList[i].getName(); const char *Suffix; if (SearchList[i].isNormalDir()) Suffix = ""; diff --git a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp index 15af644b778e..11e431de0a31 100644 --- a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp +++ b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp @@ -64,7 +64,7 @@ void HTMLPrinter::HandleTranslationUnit(ASTContext &Ctx) { // Format the file. FileID FID = R.getSourceMgr().getMainFileID(); const FileEntry* Entry = R.getSourceMgr().getFileEntryForID(FID); - const char* Name; + StringRef Name; // In some cases, in particular the case where the input is from stdin, // there is no entry. Fall back to the memory buffer for a name in those // cases. diff --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp index b761c34fcbde..d953da2e4fd2 100644 --- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -68,7 +68,7 @@ private: CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported) override; - void WriteLineInfo(const char *Filename, int Line, + void WriteLineInfo(StringRef Filename, int Line, SrcMgr::CharacteristicKind FileType, StringRef Extra = StringRef()); void WriteImplicitModuleImport(const Module *Mod); @@ -102,7 +102,7 @@ InclusionRewriter::InclusionRewriter(Preprocessor &PP, raw_ostream &OS, /// markers depending on what mode we're in, including the \p Filename and /// \p Line we are located at, using the specified \p EOL line separator, and /// any \p Extra context specifiers in GNU line directives. -void InclusionRewriter::WriteLineInfo(const char *Filename, int Line, +void InclusionRewriter::WriteLineInfo(StringRef Filename, int Line, SrcMgr::CharacteristicKind FileType, StringRef Extra) { if (!ShowLineMarkers) @@ -406,7 +406,7 @@ bool InclusionRewriter::Process(FileID FileId, bool Invalid; const MemoryBuffer &FromFile = *SM.getBuffer(FileId, &Invalid); assert(!Invalid && "Attempting to process invalid inclusion"); - const char *FileName = FromFile.getBufferIdentifier(); + StringRef FileName = FromFile.getBufferIdentifier(); Lexer RawLex(FileId, &FromFile, PP.getSourceManager(), PP.getLangOpts()); RawLex.SetCommentRetentionState(false); diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 4cace5b00245..24a14b6cdb57 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -106,7 +106,7 @@ bool HeaderMapImpl::checkHeader(const llvm::MemoryBuffer &File, /// getFileName - Return the filename of the headermap. -const char *HeaderMapImpl::getFileName() const { +StringRef HeaderMapImpl::getFileName() const { return FileBuffer->getBufferIdentifier(); } diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index bf266b30e505..c2c909e361d6 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -257,7 +257,7 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch) { /// getName - Return the directory or filename corresponding to this lookup /// object. -const char *DirectoryLookup::getName() const { +StringRef DirectoryLookup::getName() const { if (isNormalDir()) return getDir()->getName(); if (isFramework()) diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 73036ac63223..42e7de2f716b 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -284,7 +284,7 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef, if (ShadowFlag) *ShadowFlag = false; if (!SourceMgr.isInSystemHeader(MacroNameLoc) && - (strcmp(SourceMgr.getBufferName(MacroNameLoc), "") != 0)) { + (SourceMgr.getBufferName(MacroNameLoc) != "")) { MacroDiag D = MD_NoWarn; if (isDefineUndef == MU_Define) { D = shouldWarnOnMacroDef(*this, II); @@ -2114,7 +2114,7 @@ void Preprocessor::HandleIncludeMacrosDirective(SourceLocation HashLoc, // This directive should only occur in the predefines buffer. If not, emit an // error and reject it. SourceLocation Loc = IncludeMacrosTok.getLocation(); - if (strcmp(SourceMgr.getBufferName(Loc), "") != 0) { + if (SourceMgr.getBufferName(Loc) != "") { Diag(IncludeMacrosTok.getLocation(), diag::pp_include_macros_out_of_predefines); DiscardUntilEndOfDirective(); diff --git a/clang/lib/Rewrite/HTMLRewrite.cpp b/clang/lib/Rewrite/HTMLRewrite.cpp index 553f695316ae..78aad3940dfa 100644 --- a/clang/lib/Rewrite/HTMLRewrite.cpp +++ b/clang/lib/Rewrite/HTMLRewrite.cpp @@ -267,8 +267,8 @@ void html::AddLineNumbers(Rewriter& R, FileID FID) { RB.InsertTextAfter(FileEnd - FileBeg, ""); } -void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID, - const char *title) { +void html::AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID, + StringRef title) { const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID); const char* FileStart = Buf->getBufferStart(); @@ -282,7 +282,7 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID, os << "\n" // Use HTML 5 doctype "\n\n"; - if (title) + if (!title.empty()) os << "" << html::EscapeText(title) << "\n"; os << "