summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/SourceMgr.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-06-21 05:06:04 +0000
committerChris Lattner <sabre@nondot.org>2009-06-21 05:06:04 +0000
commit976af622a91af85673136465194435ea853517e4 (patch)
tree7a52c515cbfdd179ca84ef4930ece7e506c50cdd /llvm/lib/Support/SourceMgr.cpp
parentfd255754afcd352c8907ae0eb778b82de063a8fd (diff)
downloadbcm5719-llvm-976af622a91af85673136465194435ea853517e4.tar.gz
bcm5719-llvm-976af622a91af85673136465194435ea853517e4.zip
move include searching logic from TGLexer to SourceMgr.
llvm-svn: 73845
Diffstat (limited to 'llvm/lib/Support/SourceMgr.cpp')
-rw-r--r--llvm/lib/Support/SourceMgr.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp
index 40a6f43f5e0..5460cb3824d 100644
--- a/llvm/lib/Support/SourceMgr.cpp
+++ b/llvm/lib/Support/SourceMgr.cpp
@@ -25,6 +25,26 @@ SourceMgr::~SourceMgr() {
}
}
+/// AddIncludeFile - Search for a file with the specified name in the current
+/// directory or in one of the IncludeDirs. If no file is found, this returns
+/// ~0, otherwise it returns the buffer ID of the stacked file.
+unsigned SourceMgr::AddIncludeFile(const std::string &Filename,
+ SMLoc IncludeLoc) {
+
+ MemoryBuffer *NewBuf = MemoryBuffer::getFile(Filename.c_str());
+
+ // If the file didn't exist directly, see if it's in an include path.
+ for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBuf; ++i) {
+ std::string IncFile = IncludeDirectories[i] + "/" + Filename;
+ NewBuf = MemoryBuffer::getFile(IncFile.c_str());
+ }
+
+ if (NewBuf == 0) return ~0U;
+
+ return AddNewSourceBuffer(NewBuf, IncludeLoc);
+}
+
+
/// FindBufferContainingLoc - Return the ID of the buffer containing the
/// specified location, returning -1 if not found.
int SourceMgr::FindBufferContainingLoc(SMLoc Loc) const {
OpenPOWER on IntegriCloud