]> granicus.if.org Git - clang/commitdiff
Use StringRef for MemoryBuffer identifier API (NFC)
authorMehdi Amini <mehdi.amini@apple.com>
Sat, 1 Oct 2016 16:38:28 +0000 (16:38 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Sat, 1 Oct 2016 16:38:28 +0000 (16:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283043 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
include/clang/Basic/SourceManager.h
include/clang/Lex/DirectoryLookup.h
include/clang/Lex/HeaderMap.h
include/clang/Rewrite/Core/HTMLRewrite.h
lib/Basic/SourceManager.cpp
lib/CodeGen/CoverageMappingGen.cpp
lib/Frontend/InitHeaderSearch.cpp
lib/Frontend/Rewrite/HTMLPrint.cpp
lib/Frontend/Rewrite/InclusionRewriter.cpp
lib/Lex/HeaderMap.cpp
lib/Lex/HeaderSearch.cpp
lib/Lex/PPDirectives.cpp
lib/Rewrite/HTMLRewrite.cpp
lib/Serialization/ASTWriter.cpp

index 6610c56b15d53fa58f3f7d5f659aca4d3a2a1325..45187e58cb366ad45c67d4eca2e69b4626ffd8d9 100644 (file)
@@ -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
index ee0af292e6fccac6c6a221d229dfe3ad85576e3a..dcd58f434fa24af5df66ea577d4feaa7461faa45 100644 (file)
@@ -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.
   ///
index 8466f1a24d52d38dbe92e84136662af3516a4584..58bf79579a6a3990e5d7d48487c3e1cb92014741 100644 (file)
@@ -45,7 +45,7 @@ public:
                            SmallVectorImpl<char> &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;
index dafdf51ce63b590c1dc567d2a7e0ba46c2ed9c66..1fd7c7a3f84e243938316e7b8d790d7f9534c809 100644 (file)
@@ -62,8 +62,8 @@ namespace html {
 
   void AddLineNumbers(Rewriter& R, FileID FID);
 
-  void AddHeaderFooterInternalBuiltinCSS(RewriterR, 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.
index 605f990e41d144a8321cbefa74f69ee4081ee387..5dcb8811e27f952b1255e3c96e5324ee672dd2d2 100644 (file)
@@ -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 "<invalid loc>";
 
   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("<built-in>", LB) == 0;
-  bool RIsBuiltins = strcmp("<built-in>", RB) == 0;
+  StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier();
+  StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier();
+  bool LIsBuiltins = LB == "<built-in>";
+  bool RIsBuiltins = RB == "<built-in>";
   // 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("<inline asm>", LB) == 0;
-  bool RIsAsm = strcmp("<inline asm>", RB) == 0;
+  bool LIsAsm = LB == "<inline asm>";
+  bool RIsAsm = RB == "<inline asm>";
   // 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("<scratch space>", LB) == 0;
-  bool RIsScratch = strcmp("<scratch space>", RB) == 0;
+  bool LIsScratch = LB == "<scratch space>";
+  bool RIsScratch = RB == "<scratch space>";
   // Sort scratch after inline asm, but before the rest.
   if (LIsScratch || RIsScratch) {
     if (LIsScratch != RIsScratch)
index 0e51658e4b5f07172168edb55685067d04f8a08c..35d1b1d47f3fc8205d295aba84b142b373c6b6c3 100644 (file)
@@ -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)), "<built-in>") == 0;
+    return SM.getBufferName(SM.getSpellingLoc(Loc)) == "<built-in>";
   }
 
   /// \brief Check whether \c Loc is included or expanded from \c Parent.
index 24edb963f268f2d1b62c21b209868e017fa793df..c76ccea8ac3511877423f942352663ebf89f04de 100644 (file)
@@ -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 = "";
index 15af644b778eb057e9a4efa5aee7039180f25b97..11e431de0a31df75eeeaedd2163412f760e69f90 100644 (file)
@@ -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.
index b761c34fcbdebf3e8b361425f6ab26b8524ee9c7..d953da2e4fd2946916abc42c5905cb391eb40465 100644 (file)
@@ -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);
 
index 4cace5b002450eddc014172ffbf7fd28c13f5562..24a14b6cdb573c9acbfcb75ff9e43e5911dde137 100644 (file)
@@ -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();
 }
 
index bf266b30e50517353547f4e9a479980f3d0b22be..c2c909e361d6563dff30c19e8ae419bead97ffca 100644 (file)
@@ -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())
index 73036ac63223136f695a27c33fa2cf111fa95230..42e7de2f716b7cfb46d8702f10097659f5942cff 100644 (file)
@@ -284,7 +284,7 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
   if (ShadowFlag)
     *ShadowFlag = false;
   if (!SourceMgr.isInSystemHeader(MacroNameLoc) &&
-      (strcmp(SourceMgr.getBufferName(MacroNameLoc), "<built-in>") != 0)) {
+      (SourceMgr.getBufferName(MacroNameLoc) != "<built-in>")) {
     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), "<built-in>") != 0) {
+  if (SourceMgr.getBufferName(Loc) != "<built-in>") {
     Diag(IncludeMacrosTok.getLocation(),
          diag::pp_include_macros_out_of_predefines);
     DiscardUntilEndOfDirective();
index 553f695316ae187f34e814bdef8b8cae71d83b4b..78aad3940dfa289026a48d6ba71166062afc6a0e 100644 (file)
@@ -267,8 +267,8 @@ void html::AddLineNumbers(Rewriter& R, FileID FID) {
   RB.InsertTextAfter(FileEnd - FileBeg, "</table>");
 }
 
-void html::AddHeaderFooterInternalBuiltinCSS(RewriterR, 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 << "<!doctype html>\n" // Use HTML 5 doctype
         "<html>\n<head>\n";
 
-  if (title)
+  if (!title.empty())
     os << "<title>" << html::EscapeText(title) << "</title>\n";
 
   os << "<style type=\"text/css\">\n"
index 253fab2a36ab400f813d56a42706394cdc80f986..fff824e4373a3fbdc69e61384ac4f57a87251060 100644 (file)
@@ -2074,14 +2074,13 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
         // the reader side).
         const llvm::MemoryBuffer *Buffer
           = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager());
-        const char *Name = Buffer->getBufferIdentifier();
+        StringRef Name = Buffer->getBufferIdentifier();
         Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record,
-                                  StringRef(Name, strlen(Name) + 1));
+                                  StringRef(Name.data(), Name.size() + 1));
         EmitBlob = true;
 
-        if (strcmp(Name, "<built-in>") == 0) {
+        if (Name == "<built-in>")
           PreloadSLocs.push_back(SLocEntryOffsets.size());
-        }
       }
 
       if (EmitBlob) {