Add vfs support to toolchain. (#2888)

This adds vfs support to the toolchain, allowing Driver to take in-memory inputs in tests. As a consequence, I'm simplifying SourceBuffer: rather than allowing tests to pass in their own memory buffer, I'm using InMemoryFileSystem to push for greater consistency with production code. This does hit a quirk where I need to be careful about null terminator handling because fuzzer imports don't always have one, but that's probably more robust anyways.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2023-06-12 13:19:57 -07:00
committed by GitHub
co-authored by Richard Smith
parent 2c45cb3be8
commit a93e621488
17 changed files with 217 additions and 367 deletions
+6 -3
View File
@@ -21,18 +21,21 @@ using ::testing::ElementsAre;
class ParseTreeTest : public ::testing::Test {
protected:
auto GetSourceBuffer(llvm::Twine t) -> SourceBuffer& {
auto GetSourceBuffer(llvm::StringRef t) -> SourceBuffer& {
CARBON_CHECK(fs.addFile("test.carbon", /*ModificationTime=*/0,
llvm::MemoryBuffer::getMemBuffer(t)));
source_storage.push_front(
std::move(*SourceBuffer::CreateFromText(t.str())));
std::move(*SourceBuffer::CreateFromFile(fs, "test.carbon")));
return source_storage.front();
}
auto GetTokenizedBuffer(llvm::Twine t) -> TokenizedBuffer& {
auto GetTokenizedBuffer(llvm::StringRef t) -> TokenizedBuffer& {
token_storage.push_front(
TokenizedBuffer::Lex(GetSourceBuffer(t), consumer));
return token_storage.front();
}
llvm::vfs::InMemoryFileSystem fs;
std::forward_list<SourceBuffer> source_storage;
std::forward_list<TokenizedBuffer> token_storage;
DiagnosticConsumer& consumer = ConsoleDiagnosticConsumer();