void emitDiagnostic(Location loc, Twine message, DiagnosticSeverity kind);
protected:
- /// Get a memory buffer for the given file, or the main file of the source
- /// manager if one doesn't exist. If no file is available, nullptr is
- /// returned.
+ /// Get a memory buffer for the given file, or nullptr if no file is
+ /// available.
const llvm::MemoryBuffer *getBufferForFile(StringRef filename);
/// The source manager that we are wrapping.
return filenameToBuf[filename] = buf;
}
- // Otherwise, default to the main file buffer, if it exists.
+ // Otherwise, try to load the source file.
const llvm::MemoryBuffer *newBuf = nullptr;
- if (mgr.getNumBuffers() != 0)
- newBuf = mgr.getMemoryBuffer(mgr.getMainFileID());
+ std::string ignored;
+ if (auto newBufID = mgr.AddIncludeFile(filename, llvm::SMLoc(), ignored))
+ newBuf = mgr.getMemoryBuffer(newBufID);
return filenameToBuf[filename] = newBuf;
}