[cfe-commits] r93094 - in /cfe/trunk: include/clang/Lex/DirectoryLookup.h include/clang/Lex/HeaderMap.h include/clang/Lex/HeaderSearch.h include/clang/Lex/Preprocessor.h lib/Lex/HeaderMap.cpp lib/Lex/HeaderSearch.cpp lib/Lex/PPDirectives.cpp lib/Lex/PPMacroExpansion.cpp lib/Lex/Pragma.cpp

Chris Lattner sabre at nondot.org
Sat Jan 9 17:35:13 PST 2010


Author: lattner
Date: Sat Jan  9 19:35:12 2010
New Revision: 93094

URL: http://llvm.org/viewvc/llvm-project?rev=93094&view=rev
Log:
stringref'ize a bunch of filename handling logic.  Much
nicer than passing around two const char*'s.

Modified:
    cfe/trunk/include/clang/Lex/DirectoryLookup.h
    cfe/trunk/include/clang/Lex/HeaderMap.h
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/HeaderMap.cpp
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
    cfe/trunk/lib/Lex/Pragma.cpp

Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=93094&r1=93093&r2=93094&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/DirectoryLookup.h (original)
+++ cfe/trunk/include/clang/Lex/DirectoryLookup.h Sat Jan  9 19:35:12 2010
@@ -16,6 +16,9 @@
 
 #include "clang/Basic/SourceManager.h"
 
+namespace llvm {
+  class StringRef;
+}
 namespace clang {
 class HeaderMap;
 class DirectoryEntry;
@@ -118,12 +121,10 @@
 
   /// LookupFile - Lookup the specified file in this search path, returning it
   /// if it exists or returning null if not.
-  const FileEntry *LookupFile(const char *FilenameStart,
-                              const char *FilenameEnd, HeaderSearch &HS) const;
+  const FileEntry *LookupFile(llvm::StringRef Filename, HeaderSearch &HS) const;
 
 private:
-  const FileEntry *DoFrameworkLookup(const char *FilenameStart,
-                                     const char *FilenameEnd,
+  const FileEntry *DoFrameworkLookup(llvm::StringRef Filename,
                                      HeaderSearch &HS) const;
 
 };

Modified: cfe/trunk/include/clang/Lex/HeaderMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderMap.h?rev=93094&r1=93093&r2=93094&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderMap.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderMap.h Sat Jan  9 19:35:12 2010
@@ -16,6 +16,7 @@
 
 namespace llvm {
   class MemoryBuffer;
+  class StringRef;
 }
 namespace clang {
   class FileEntry;
@@ -46,8 +47,7 @@
 
   /// LookupFile - Check to see if the specified relative filename is located in
   /// this HeaderMap.  If so, open it and return its FileEntry.
-  const FileEntry *LookupFile(const char *FilenameStart,const char *FilenameEnd,
-                              FileManager &FM) const;
+  const FileEntry *LookupFile(llvm::StringRef Filename, FileManager &FM) const;
 
   /// getFileName - Return the filename of the headermap.
   const char *getFileName() const;

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=93094&r1=93093&r2=93094&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Sat Jan  9 19:35:12 2010
@@ -150,8 +150,7 @@
   /// search location.  This is used to implement #include_next.  CurFileEnt, if
   /// non-null, indicates where the #including file is, in case a relative
   /// search is needed.
-  const FileEntry *LookupFile(const char *FilenameStart,
-                              const char *FilenameEnd, bool isAngled,
+  const FileEntry *LookupFile(llvm::StringRef Filename, bool isAngled,
                               const DirectoryLookup *FromDir,
                               const DirectoryLookup *&CurDir,
                               const FileEntry *CurFileEnt);
@@ -161,16 +160,14 @@
   /// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox
   /// is a subframework within Carbon.framework.  If so, return the FileEntry
   /// for the designated file, otherwise return null.
-  const FileEntry *LookupSubframeworkHeader(const char *FilenameStart,
-                                            const char *FilenameEnd,
+  const FileEntry *LookupSubframeworkHeader(llvm::StringRef Filename,
                                             const FileEntry *RelativeFileEnt);
 
   /// LookupFrameworkCache - Look up the specified framework name in our
   /// framework cache, returning the DirectoryEntry it is in if we know,
   /// otherwise, return null.
-  const DirectoryEntry *&LookupFrameworkCache(const char *FWNameStart,
-                                              const char *FWNameEnd) {
-    return FrameworkMap.GetOrCreateValue(FWNameStart, FWNameEnd).getValue();
+  const DirectoryEntry *&LookupFrameworkCache(llvm::StringRef FWName) {
+    return FrameworkMap.GetOrCreateValue(FWName).getValue();
   }
 
   /// ShouldEnterIncludeFile - Mark the specified file as a target of of a

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=93094&r1=93093&r2=93094&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Jan  9 19:35:12 2010
@@ -691,13 +691,12 @@
   /// caller is expected to provide a buffer that is large enough to hold the
   /// spelling of the filename, but is also expected to handle the case when
   /// this method decides to use a different buffer.
-  bool GetIncludeFilenameSpelling(SourceLocation Loc,
-                                  const char *&BufStart, const char *&BufEnd);
+  bool GetIncludeFilenameSpelling(SourceLocation Loc,llvm::StringRef &Filename);
 
   /// LookupFile - Given a "foo" or <foo> reference, look up the indicated file,
   /// return null on failure.  isAngled indicates whether the file reference is
   /// for system #include's or not (i.e. using <> instead of "").
-  const FileEntry *LookupFile(const char *FilenameStart,const char *FilenameEnd,
+  const FileEntry *LookupFile(llvm::StringRef Filename,
                               SourceLocation FilenameTokLoc, bool isAngled,
                               const DirectoryLookup *FromDir,
                               const DirectoryLookup *&CurDir);

Modified: cfe/trunk/lib/Lex/HeaderMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp?rev=93094&r1=93093&r2=93094&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/HeaderMap.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderMap.cpp Sat Jan  9 19:35:12 2010
@@ -56,8 +56,9 @@
 /// HashHMapKey - This is the 'well known' hash function required by the file
 /// format, used to look up keys in the hash table.  The hash table uses simple
 /// linear probing based on this function.
-static inline unsigned HashHMapKey(const char *S, const char *End) {
+static inline unsigned HashHMapKey(llvm::StringRef Str) {
   unsigned Result = 0;
+  const char *S = Str.begin(), *End = Str.end();
 
   for (; S != End; S++)
     Result += tolower(*S) * 13;
@@ -209,8 +210,7 @@
 
 /// LookupFile - Check to see if the specified relative filename is located in
 /// this HeaderMap.  If so, open it and return its FileEntry.
-const FileEntry *HeaderMap::LookupFile(const char *FilenameStart,
-                                       const char *FilenameEnd,
+const FileEntry *HeaderMap::LookupFile(llvm::StringRef Filename,
                                        FileManager &FM) const {
   const HMapHeader &Hdr = getHeader();
   unsigned NumBuckets = getEndianAdjustedWord(Hdr.NumBuckets);
@@ -221,18 +221,18 @@
     return 0;
 
   // Linearly probe the hash table.
-  for (unsigned Bucket = HashHMapKey(FilenameStart, FilenameEnd);; ++Bucket) {
+  for (unsigned Bucket = HashHMapKey(Filename);; ++Bucket) {
     HMapBucket B = getBucket(Bucket & (NumBuckets-1));
     if (B.Key == HMAP_EmptyBucketKey) return 0; // Hash miss.
 
     // See if the key matches.  If not, probe on.
     const char *Key = getString(B.Key);
     unsigned BucketKeyLen = strlen(Key);
-    if (BucketKeyLen != unsigned(FilenameEnd-FilenameStart))
+    if (BucketKeyLen != unsigned(Filename.size()))
       continue;
 
     // See if the actual strings equal.
-    if (!StringsEqualWithoutCase(FilenameStart, Key, BucketKeyLen))
+    if (!StringsEqualWithoutCase(Filename.begin(), Key, BucketKeyLen))
       continue;
 
     // If so, we have a match in the hash table.  Construct the destination

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=93094&r1=93093&r2=93094&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Sat Jan  9 19:35:12 2010
@@ -109,8 +109,7 @@
 
 /// LookupFile - Lookup the specified file in this search path, returning it
 /// if it exists or returning null if not.
-const FileEntry *DirectoryLookup::LookupFile(const char *FilenameStart,
-                                             const char *FilenameEnd,
+const FileEntry *DirectoryLookup::LookupFile(llvm::StringRef Filename,
                                              HeaderSearch &HS) const {
   llvm::SmallString<1024> TmpDir;
   if (isNormalDir()) {
@@ -118,33 +117,32 @@
     // FIXME: Portability.  Filename concatenation should be in sys::Path.
     TmpDir += getDir()->getName();
     TmpDir.push_back('/');
-    TmpDir.append(FilenameStart, FilenameEnd);
+    TmpDir.append(Filename.begin(), Filename.end());
     return HS.getFileMgr().getFile(TmpDir.begin(), TmpDir.end());
   }
 
   if (isFramework())
-    return DoFrameworkLookup(FilenameStart, FilenameEnd, HS);
+    return DoFrameworkLookup(Filename, HS);
 
   assert(isHeaderMap() && "Unknown directory lookup");
-  return getHeaderMap()->LookupFile(FilenameStart, FilenameEnd,HS.getFileMgr());
+  return getHeaderMap()->LookupFile(Filename, HS.getFileMgr());
 }
 
 
 /// DoFrameworkLookup - Do a lookup of the specified file in the current
 /// DirectoryLookup, which is a framework directory.
-const FileEntry *DirectoryLookup::DoFrameworkLookup(const char *FilenameStart,
-                                                    const char *FilenameEnd,
+const FileEntry *DirectoryLookup::DoFrameworkLookup(llvm::StringRef Filename,
                                                     HeaderSearch &HS) const {
   FileManager &FileMgr = HS.getFileMgr();
 
   // Framework names must have a '/' in the filename.
-  const char *SlashPos = std::find(FilenameStart, FilenameEnd, '/');
-  if (SlashPos == FilenameEnd) return 0;
+  size_t SlashPos = Filename.find('/');
+  if (SlashPos == llvm::StringRef::npos) return 0;
 
   // Find out if this is the home for the specified framework, by checking
   // HeaderSearch.  Possible answer are yes/no and unknown.
   const DirectoryEntry *&FrameworkDirCache =
-    HS.LookupFrameworkCache(FilenameStart, SlashPos);
+    HS.LookupFrameworkCache(Filename.substr(0, SlashPos));
 
   // If it is known and in some other directory, fail.
   if (FrameworkDirCache && FrameworkDirCache != getFrameworkDir())
@@ -159,7 +157,7 @@
     FrameworkName.push_back('/');
 
   // FrameworkName = "/System/Library/Frameworks/Cocoa"
-  FrameworkName.append(FilenameStart, SlashPos);
+  FrameworkName.append(Filename.begin(), Filename.begin()+SlashPos);
 
   // FrameworkName = "/System/Library/Frameworks/Cocoa.framework/"
   FrameworkName += ".framework/";
@@ -184,7 +182,7 @@
   unsigned OrigSize = FrameworkName.size();
 
   FrameworkName += "Headers/";
-  FrameworkName.append(SlashPos+1, FilenameEnd);
+  FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end());
   if (const FileEntry *FE = FileMgr.getFile(FrameworkName.begin(),
                                             FrameworkName.end())) {
     return FE;
@@ -208,21 +206,20 @@
 /// for system #include's or not (i.e. using <> instead of "").  CurFileEnt, if
 /// non-null, indicates where the #including file is, in case a relative search
 /// is needed.
-const FileEntry *HeaderSearch::LookupFile(const char *FilenameStart,
-                                          const char *FilenameEnd,
+const FileEntry *HeaderSearch::LookupFile(llvm::StringRef Filename,
                                           bool isAngled,
                                           const DirectoryLookup *FromDir,
                                           const DirectoryLookup *&CurDir,
                                           const FileEntry *CurFileEnt) {
   // If 'Filename' is absolute, check to see if it exists and no searching.
-  if (llvm::sys::Path::isAbsolute(FilenameStart, FilenameEnd-FilenameStart)) {
+  if (llvm::sys::Path::isAbsolute(Filename.begin(), Filename.size())) {
     CurDir = 0;
 
     // If this was an #include_next "/absolute/file", fail.
     if (FromDir) return 0;
 
     // Otherwise, just return the file.
-    return FileMgr.getFile(FilenameStart, FilenameEnd);
+    return FileMgr.getFile(Filename);
   }
 
   // Step #0, unless disabled, check to see if the file is in the #includer's
@@ -236,8 +233,8 @@
     // FIXME: Portability.  Filename concatenation should be in sys::Path.
     TmpDir += CurFileEnt->getDir()->getName();
     TmpDir.push_back('/');
-    TmpDir.append(FilenameStart, FilenameEnd);
-    if (const FileEntry *FE = FileMgr.getFile(TmpDir.begin(), TmpDir.end())) {
+    TmpDir.append(Filename.begin(), Filename.end());
+    if (const FileEntry *FE = FileMgr.getFile(TmpDir.str())) {
       // Leave CurDir unset.
       // This file is a system header or C++ unfriendly if the old file is.
       //
@@ -265,7 +262,7 @@
   // being relex/pp'd, but they would still have to search through a
   // (potentially huge) series of SearchDirs to find it.
   std::pair<unsigned, unsigned> &CacheLookup =
-    LookupFileCache.GetOrCreateValue(FilenameStart, FilenameEnd).getValue();
+    LookupFileCache.GetOrCreateValue(Filename).getValue();
 
   // If the entry has been previously looked up, the first value will be
   // non-zero.  If the value is equal to i (the start point of our search), then
@@ -283,7 +280,7 @@
   // Check each directory in sequence to see if it contains this file.
   for (; i != SearchDirs.size(); ++i) {
     const FileEntry *FE =
-      SearchDirs[i].LookupFile(FilenameStart, FilenameEnd, *this);
+      SearchDirs[i].LookupFile(Filename, *this);
     if (!FE) continue;
 
     CurDir = &SearchDirs[i];
@@ -307,14 +304,13 @@
 /// is a subframework within Carbon.framework.  If so, return the FileEntry
 /// for the designated file, otherwise return null.
 const FileEntry *HeaderSearch::
-LookupSubframeworkHeader(const char *FilenameStart,
-                         const char *FilenameEnd,
+LookupSubframeworkHeader(llvm::StringRef Filename,
                          const FileEntry *ContextFileEnt) {
   assert(ContextFileEnt && "No context file?");
 
   // Framework names must have a '/' in the filename.  Find it.
-  const char *SlashPos = std::find(FilenameStart, FilenameEnd, '/');
-  if (SlashPos == FilenameEnd) return 0;
+  size_t SlashPos = Filename.find('/');
+  if (SlashPos == llvm::StringRef::npos) return 0;
 
   // Look up the base framework name of the ContextFileEnt.
   const char *ContextName = ContextFileEnt->getName();
@@ -329,11 +325,11 @@
 
   // Append Frameworks/HIToolbox.framework/
   FrameworkName += "Frameworks/";
-  FrameworkName.append(FilenameStart, SlashPos);
+  FrameworkName.append(Filename.begin(), Filename.begin()+SlashPos);
   FrameworkName += ".framework/";
 
   llvm::StringMapEntry<const DirectoryEntry *> &CacheLookup =
-    FrameworkMap.GetOrCreateValue(FilenameStart, SlashPos);
+    FrameworkMap.GetOrCreateValue(Filename.begin(), Filename.begin()+SlashPos);
 
   // Some other location?
   if (CacheLookup.getValue() &&
@@ -361,14 +357,14 @@
   // Check ".../Frameworks/HIToolbox.framework/Headers/HIToolbox.h"
   llvm::SmallString<1024> HeadersFilename(FrameworkName);
   HeadersFilename += "Headers/";
-  HeadersFilename.append(SlashPos+1, FilenameEnd);
+  HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
   if (!(FE = FileMgr.getFile(HeadersFilename.begin(),
                              HeadersFilename.end()))) {
 
     // Check ".../Frameworks/HIToolbox.framework/PrivateHeaders/HIToolbox.h"
     HeadersFilename = FrameworkName;
     HeadersFilename += "PrivateHeaders/";
-    HeadersFilename.append(SlashPos+1, FilenameEnd);
+    HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
     if (!(FE = FileMgr.getFile(HeadersFilename.begin(), HeadersFilename.end())))
       return 0;
   }

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=93094&r1=93093&r2=93094&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sat Jan  9 19:35:12 2010
@@ -404,8 +404,7 @@
 /// LookupFile - Given a "foo" or <foo> reference, look up the indicated file,
 /// return null on failure.  isAngled indicates whether the file reference is
 /// for system #include's or not (i.e. using <> instead of "").
-const FileEntry *Preprocessor::LookupFile(const char *FilenameStart,
-                                          const char *FilenameEnd,
+const FileEntry *Preprocessor::LookupFile(llvm::StringRef Filename,
                                           SourceLocation FilenameTokLoc,
                                           bool isAngled,
                                           const DirectoryLookup *FromDir,
@@ -432,8 +431,7 @@
   // Do a standard file entry lookup.
   CurDir = CurDirLookup;
   const FileEntry *FE =
-    HeaderInfo.LookupFile(FilenameStart, FilenameEnd,
-                          isAngled, FromDir, CurDir, CurFileEnt);
+    HeaderInfo.LookupFile(Filename, isAngled, FromDir, CurDir, CurFileEnt);
   if (FE) {
     // Warn about normal quoted #include from framework headers.  Since
     // framework headers are published (both public and private ones) they
@@ -450,8 +448,7 @@
   // headers on the #include stack and pass them to HeaderInfo.
   if (IsFileLexer()) {
     if ((CurFileEnt = SourceMgr.getFileEntryForID(CurPPLexer->getFileID())))
-      if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart, FilenameEnd,
-                                                    CurFileEnt)))
+      if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt)))
         return FE;
   }
 
@@ -460,8 +457,7 @@
     if (IsFileLexer(ISEntry)) {
       if ((CurFileEnt =
            SourceMgr.getFileEntryForID(ISEntry.ThePPLexer->getFileID())))
-        if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart,
-                                                      FilenameEnd, CurFileEnt)))
+        if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt)))
           return FE;
     }
   }
@@ -932,43 +928,41 @@
 /// spelling of the filename, but is also expected to handle the case when
 /// this method decides to use a different buffer.
 bool Preprocessor::GetIncludeFilenameSpelling(SourceLocation Loc,
-                                              const char *&BufStart,
-                                              const char *&BufEnd) {
+                                              llvm::StringRef &Buffer) {
   // Get the text form of the filename.
-  assert(BufStart != BufEnd && "Can't have tokens with empty spellings!");
+  assert(!Buffer.empty() && "Can't have tokens with empty spellings!");
 
   // Make sure the filename is <x> or "x".
   bool isAngled;
-  if (BufStart[0] == '<') {
-    if (BufEnd[-1] != '>') {
+  if (Buffer[0] == '<') {
+    if (Buffer.back() != '>') {
       Diag(Loc, diag::err_pp_expects_filename);
-      BufStart = 0;
+      Buffer = llvm::StringRef();
       return true;
     }
     isAngled = true;
-  } else if (BufStart[0] == '"') {
-    if (BufEnd[-1] != '"') {
+  } else if (Buffer[0] == '"') {
+    if (Buffer.back() != '"') {
       Diag(Loc, diag::err_pp_expects_filename);
-      BufStart = 0;
+      Buffer = llvm::StringRef();
       return true;
     }
     isAngled = false;
   } else {
     Diag(Loc, diag::err_pp_expects_filename);
-    BufStart = 0;
+    Buffer = llvm::StringRef();
     return true;
   }
 
   // Diagnose #include "" as invalid.
-  if (BufEnd-BufStart <= 2) {
+  if (Buffer.size() <= 2) {
     Diag(Loc, diag::err_pp_empty_filename);
-    BufStart = 0;
-    return "";
+    Buffer = llvm::StringRef();
+    return true;
   }
 
   // Skip the brackets.
-  ++BufStart;
-  --BufEnd;
+  Buffer = Buffer.substr(1, Buffer.size()-2);
   return isAngled;
 }
 
@@ -1034,8 +1028,8 @@
   CurPPLexer->LexIncludeFilename(FilenameTok);
 
   // Reserve a buffer to get the spelling.
-  llvm::SmallVector<char, 128> FilenameBuffer;
-  const char *FilenameStart, *FilenameEnd;
+  llvm::SmallString<128> FilenameBuffer;
+  llvm::StringRef Filename;
 
   switch (FilenameTok.getKind()) {
   case tok::eom:
@@ -1045,9 +1039,9 @@
   case tok::angle_string_literal:
   case tok::string_literal: {
     FilenameBuffer.resize(FilenameTok.getLength());
-    FilenameStart = &FilenameBuffer[0];
+    const char *FilenameStart = &FilenameBuffer[0];
     unsigned Len = getSpelling(FilenameTok, FilenameStart);
-    FilenameEnd = FilenameStart+Len;
+    Filename = llvm::StringRef(FilenameStart, Len);
     break;
   }
 
@@ -1057,8 +1051,7 @@
     FilenameBuffer.push_back('<');
     if (ConcatenateIncludeName(FilenameBuffer))
       return;   // Found <eom> but no ">"?  Diagnostic already emitted.
-    FilenameStart = FilenameBuffer.data();
-    FilenameEnd = FilenameStart + FilenameBuffer.size();
+    Filename = FilenameBuffer.str();
     break;
   default:
     Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
@@ -1066,11 +1059,11 @@
     return;
   }
 
-  bool isAngled = GetIncludeFilenameSpelling(FilenameTok.getLocation(),
-                                             FilenameStart, FilenameEnd);
+  bool isAngled = 
+    GetIncludeFilenameSpelling(FilenameTok.getLocation(), Filename);
   // If GetIncludeFilenameSpelling set the start ptr to null, there was an
   // error.
-  if (FilenameStart == 0) {
+  if (Filename.empty()) {
     DiscardUntilEndOfDirective();
     return;
   }
@@ -1089,12 +1082,10 @@
 
   // Search include directories.
   const DirectoryLookup *CurDir;
-  const FileEntry *File = LookupFile(FilenameStart, FilenameEnd,
-                                     FilenameTok.getLocation(),
+  const FileEntry *File = LookupFile(Filename, FilenameTok.getLocation(),
                                      isAngled, LookupFrom, CurDir);
   if (File == 0) {
-    Diag(FilenameTok, diag::err_pp_file_not_found)
-       << std::string(FilenameStart, FilenameEnd);
+    Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
     return;
   }
   
@@ -1114,8 +1105,7 @@
   FileID FID = SourceMgr.createFileID(File, FilenameTok.getLocation(),
                                       FileCharacter);
   if (FID.isInvalid()) {
-    Diag(FilenameTok, diag::err_pp_file_not_found)
-      << std::string(FilenameStart, FilenameEnd);
+    Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
     return;
   }
 

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=93094&r1=93093&r2=93094&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sat Jan  9 19:35:12 2010
@@ -519,8 +519,8 @@
   PP.getCurrentLexer()->LexIncludeFilename(Tok);
 
   // Reserve a buffer to get the spelling.
-  llvm::SmallVector<char, 128> FilenameBuffer;
-  const char *FilenameStart, *FilenameEnd;
+  llvm::SmallString<128> FilenameBuffer;
+  llvm::StringRef Filename;
 
   switch (Tok.getKind()) {
   case tok::eom:
@@ -530,9 +530,9 @@
   case tok::angle_string_literal:
   case tok::string_literal: {
     FilenameBuffer.resize(Tok.getLength());
-    FilenameStart = &FilenameBuffer[0];
+    const char *FilenameStart = &FilenameBuffer[0];
     unsigned Len = PP.getSpelling(Tok, FilenameStart);
-    FilenameEnd = FilenameStart+Len;
+    Filename = llvm::StringRef(FilenameStart, Len);
     break;
   }
 
@@ -542,25 +542,22 @@
     FilenameBuffer.push_back('<');
     if (PP.ConcatenateIncludeName(FilenameBuffer))
       return false;   // Found <eom> but no ">"?  Diagnostic already emitted.
-    FilenameStart = FilenameBuffer.data();
-    FilenameEnd = FilenameStart + FilenameBuffer.size();
+    Filename = FilenameBuffer.str();
     break;
   default:
     PP.Diag(Tok.getLocation(), diag::err_pp_expects_filename);
     return false;
   }
 
-  bool isAngled = PP.GetIncludeFilenameSpelling(Tok.getLocation(),
-                                             FilenameStart, FilenameEnd);
+  bool isAngled = PP.GetIncludeFilenameSpelling(Tok.getLocation(), Filename);
   // If GetIncludeFilenameSpelling set the start ptr to null, there was an
   // error.
-  if (FilenameStart == 0) {
+  if (Filename.empty())
     return false;
-  }
 
   // Search include directories.
   const DirectoryLookup *CurDir;
-  const FileEntry *File = PP.LookupFile(FilenameStart, FilenameEnd,
+  const FileEntry *File = PP.LookupFile(Filename,
                                         SourceLocation(),// produce no warnings.
                                         isAngled, LookupFrom, CurDir);
 

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=93094&r1=93093&r2=93094&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Sat Jan  9 19:35:12 2010
@@ -286,27 +286,25 @@
     return;
 
   // Reserve a buffer to get the spelling.
-  llvm::SmallVector<char, 128> FilenameBuffer;
+  llvm::SmallString<128> FilenameBuffer;
   FilenameBuffer.resize(FilenameTok.getLength());
 
   const char *FilenameStart = &FilenameBuffer[0];
   unsigned Len = getSpelling(FilenameTok, FilenameStart);
-  const char *FilenameEnd = FilenameStart+Len;
-  bool isAngled = GetIncludeFilenameSpelling(FilenameTok.getLocation(),
-                                             FilenameStart, FilenameEnd);
+  llvm::StringRef Filename(FilenameStart, Len);
+  bool isAngled =
+    GetIncludeFilenameSpelling(FilenameTok.getLocation(), Filename);
   // If GetIncludeFilenameSpelling set the start ptr to null, there was an
   // error.
-  if (FilenameStart == 0)
+  if (Filename.empty())
     return;
 
   // Search include directories for this file.
   const DirectoryLookup *CurDir;
-  const FileEntry *File = LookupFile(FilenameStart, FilenameEnd,
-                                     FilenameTok.getLocation(),
+  const FileEntry *File = LookupFile(Filename, FilenameTok.getLocation(),
                                      isAngled, 0, CurDir);
   if (File == 0) {
-    Diag(FilenameTok, diag::err_pp_file_not_found)
-      << std::string(FilenameStart, FilenameEnd);
+    Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
     return;
   }
 





More information about the cfe-commits mailing list