[cfe-commits] r39090 - in /cfe/cfe/trunk: Lex/HeaderSearch.cpp Lex/Preprocessor.cpp include/clang/Lex/HeaderSearch.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:27:26 PDT 2007
Author: sabre
Date: Wed Jul 11 11:27:26 2007
New Revision: 39090
URL: http://llvm.org/viewvc/llvm-project?rev=39090&view=rev
Log:
Push strings out of the HeaderSearch interface, it now deals solely with
character ranges.
Modified:
cfe/cfe/trunk/Lex/HeaderSearch.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h
Modified: cfe/cfe/trunk/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/HeaderSearch.cpp?rev=39090&r1=39089&r2=39090&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/HeaderSearch.cpp (original)
+++ cfe/cfe/trunk/Lex/HeaderSearch.cpp Wed Jul 11 11:27:26 2007
@@ -56,13 +56,14 @@
//===----------------------------------------------------------------------===//
const FileEntry *HeaderSearch::DoFrameworkLookup(const DirectoryEntry *Dir,
- const std::string &Filename) {
+ const char *FilenameStart,
+ const char *FilenameEnd) {
// Framework names must have a '/' in the filename.
- std::string::size_type SlashPos = Filename.find('/');
- if (SlashPos == std::string::npos) return 0;
+ const char *SlashPos = std::find(FilenameStart, FilenameEnd, '/');
+ if (SlashPos == FilenameEnd) return 0;
const DirectoryEntry *&CacheLookup =
- FrameworkMap.GetOrCreateValue(&Filename[0], &Filename[0]+SlashPos);
+ FrameworkMap.GetOrCreateValue(FilenameStart, SlashPos);
// If it is some other directory, fail.
if (CacheLookup && CacheLookup != Dir)
@@ -75,7 +76,7 @@
FrameworkName.push_back('/');
// FrameworkName = "/System/Library/Frameworks/Cocoa"
- FrameworkName.append(Filename.begin(), Filename.begin()+SlashPos);
+ FrameworkName.append(FilenameStart, SlashPos);
// FrameworkName = "/System/Library/Frameworks/Cocoa.framework/"
FrameworkName += ".framework/";
@@ -97,7 +98,7 @@
unsigned OrigSize = FrameworkName.size();
FrameworkName += "Headers/";
- FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end());
+ FrameworkName.append(SlashPos+1, FilenameEnd);
if (const FileEntry *FE = FileMgr.getFile(FrameworkName.begin(),
FrameworkName.end())) {
return FE;
@@ -115,7 +116,8 @@
/// 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 std::string &Filename,
+const FileEntry *HeaderSearch::LookupFile(const char *FilenameStart,
+ const char *FilenameEnd,
bool isAngled,
const DirectoryLookup *FromDir,
const DirectoryLookup *&CurDir,
@@ -123,14 +125,14 @@
// If 'Filename' is absolute, check to see if it exists and no searching.
// FIXME: Portability. This should be a sys::Path interface, this doesn't
// handle things like C:\foo.txt right, nor win32 \\network\device\blah.
- if (Filename[0] == '/') {
+ if (FilenameStart[0] == '/') {
CurDir = 0;
// If this was an #include_next "/absolute/file", fail.
if (FromDir) return 0;
// Otherwise, just return the file.
- return FileMgr.getFile(Filename);
+ return FileMgr.getFile(FilenameStart, FilenameEnd);
}
SmallString<1024> TmpDir;
@@ -142,7 +144,7 @@
// FIXME: Portability. Filename concatenation should be in sys::Path.
TmpDir += CurFileEnt->getDir()->getName();
TmpDir.push_back('/');
- TmpDir.append(Filename.begin(), Filename.end());
+ TmpDir.append(FilenameStart, FilenameEnd);
if (const FileEntry *FE = FileMgr.getFile(TmpDir.begin(), TmpDir.end())) {
// Leave CurDir unset.
@@ -172,10 +174,10 @@
TmpDir.clear();
TmpDir += SearchDirs[i].getDir()->getName();
TmpDir.push_back('/');
- TmpDir.append(Filename.begin(), Filename.end());
+ TmpDir.append(FilenameStart, FilenameEnd);
FE = FileMgr.getFile(TmpDir.begin(), TmpDir.end());
} else {
- FE = DoFrameworkLookup(SearchDirs[i].getDir(), Filename);
+ FE = DoFrameworkLookup(SearchDirs[i].getDir(), FilenameStart,FilenameEnd);
}
if (FE) {
@@ -197,11 +199,12 @@
/// is a subframework within Carbon.framework. If so, return the FileEntry
/// for the designated file, otherwise return null.
const FileEntry *HeaderSearch::
-LookupSubframeworkHeader(const std::string &Filename,
+LookupSubframeworkHeader(const char *FilenameStart,
+ const char *FilenameEnd,
const FileEntry *ContextFileEnt) {
// Framework names must have a '/' in the filename. Find it.
- std::string::size_type SlashPos = Filename.find('/');
- if (SlashPos == std::string::npos) return 0;
+ const char *SlashPos = std::find(FilenameStart, FilenameEnd, '/');
+ if (SlashPos == FilenameEnd) return 0;
// Look up the base framework name of the ContextFileEnt.
const char *ContextName = ContextFileEnt->getName();
@@ -216,11 +219,11 @@
// Append Frameworks/HIToolbox.framework/
FrameworkName += "Frameworks/";
- FrameworkName.append(Filename.begin(), Filename.begin()+SlashPos);
+ FrameworkName.append(FilenameStart, SlashPos);
FrameworkName += ".framework/";
const DirectoryEntry *&CacheLookup =
- FrameworkMap.GetOrCreateValue(&Filename[0], &Filename[0]+SlashPos);
+ FrameworkMap.GetOrCreateValue(FilenameStart, SlashPos);
// Some other location?
if (CacheLookup && strcmp(CacheLookup->getName(), FrameworkName.c_str()) != 0)
@@ -245,14 +248,14 @@
// Check ".../Frameworks/HIToolbox.framework/Headers/HIToolbox.h"
SmallString<1024> HeadersFilename(FrameworkName);
HeadersFilename += "Headers/";
- HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
+ HeadersFilename.append(SlashPos+1, FilenameEnd);
if (!(FE = FileMgr.getFile(HeadersFilename.begin(),
HeadersFilename.end()))) {
// Check ".../Frameworks/HIToolbox.framework/PrivateHeaders/HIToolbox.h"
HeadersFilename = FrameworkName;
HeadersFilename += "PrivateHeaders/";
- HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
+ HeadersFilename.append(SlashPos+1, FilenameEnd);
if (!(FE = FileMgr.getFile(HeadersFilename.begin(), HeadersFilename.end())))
return 0;
}
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=39090&r1=39089&r2=39090&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:27:26 2007
@@ -263,10 +263,14 @@
CurFileEnt = SourceMgr.getFileEntryForFileID(TheFileID);
}
+ const char *FilenameStart = &Filename[0];
+ const char *FilenameEnd = FilenameStart+Filename.size();
+
// Do a standard file entry lookup.
CurDir = CurDirLookup;
const FileEntry *FE =
- HeaderInfo.LookupFile(Filename, isAngled, FromDir, CurDir, CurFileEnt);
+ HeaderInfo.LookupFile(FilenameStart, FilenameEnd,
+ isAngled, FromDir, CurDir, CurFileEnt);
if (FE) return FE;
// Otherwise, see if this is a subframework header. If so, this is relative
@@ -274,7 +278,8 @@
// headers on the #include stack and pass them to HeaderInfo.
if (CurLexer && !CurLexer->Is_PragmaLexer) {
CurFileEnt = SourceMgr.getFileEntryForFileID(CurLexer->getCurFileID());
- if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt)))
+ if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart, FilenameEnd,
+ CurFileEnt)))
return FE;
}
@@ -283,7 +288,8 @@
if (ISEntry.TheLexer && !ISEntry.TheLexer->Is_PragmaLexer) {
CurFileEnt =
SourceMgr.getFileEntryForFileID(ISEntry.TheLexer->getCurFileID());
- if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt)))
+ if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart, FilenameEnd,
+ CurFileEnt)))
return FE;
}
}
Modified: cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=39090&r1=39089&r2=39090&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Jul 11 11:27:26 2007
@@ -17,7 +17,6 @@
#include "clang/Lex/DirectoryLookup.h"
#include "llvm/ADT/CStringMap.h"
#include <vector>
-#include <string>
namespace llvm {
namespace clang {
@@ -98,7 +97,8 @@
/// 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 std::string &Filename, bool isAngled,
+ const FileEntry *LookupFile(const char *FilenameStart,
+ const char *FilenameEnd, bool isAngled,
const DirectoryLookup *FromDir,
const DirectoryLookup *&CurDir,
const FileEntry *CurFileEnt);
@@ -108,7 +108,8 @@
/// 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 std::string &Filename,
+ const FileEntry *LookupSubframeworkHeader(const char *FilenameStart,
+ const char *FilenameEnd,
const FileEntry *RelativeFileEnt);
/// ShouldEnterIncludeFile - Mark the specified file as a target of of a
@@ -146,7 +147,8 @@
void PrintStats();
private:
const FileEntry *DoFrameworkLookup(const DirectoryEntry *Dir,
- const std::string &Filename);
+ const char *FilenameStart,
+ const char *FilenameEnd);
/// getFileInfo - Return the PerFileInfo structure for the specified
/// FileEntry.
More information about the cfe-commits
mailing list