X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FSourceMgr.cpp;h=5460cb3824d5fbeba8920363c8abe73bec4dcf2d;hb=7ee5d5f97b3fa709038ff7fd640dc775efaadc26;hp=40a6f43f5e0f33c6f70500de541a8b440fc17a89;hpb=8070ea3f068980d08cc10381f4c9369d19a91353;p=oota-llvm.git diff --git a/lib/Support/SourceMgr.cpp b/lib/Support/SourceMgr.cpp index 40a6f43f5e0..5460cb3824d 100644 --- a/lib/Support/SourceMgr.cpp +++ b/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 {