mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
This shifts explorer's file_test to use ExplorerMain in order to be able to pass arguments similar to how the command line would. It also means that various output wrapping done by the command line is shared, no longer copied by file_test. In order to help make this work, I plugged vfs::FileSystem into explorer, similar to how we're doing this on the toolchain side (might try to share more code later). I was having trouble getting an overlay working, I think due to how paths are specified -- but due to the issues in fixing this, I'm just loading the prelude into the InMemoryFilesystem for now. Under this approach, I'm unifying more of the file versus string handling. I think we should shift towards an approach where, like toolchain code, anyone trying to use Explorer should use a vfs implementation to supply code. This should reduce the number of distinct code paths which we're maintaining/testing. Short-term, this allows the trace testdata to be merged into file_test with less special casing, using ARGS:. Long-term, it means that the file_test knows the ARGS to pass to generate checks to match against, which is the direction I'm planning for autoupdate.
32 lines
1.2 KiB
C++
32 lines
1.2 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "explorer/syntax/prelude.h"
|
|
|
|
#include "explorer/syntax/parse.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Adds the Carbon prelude to `declarations`.
|
|
void AddPrelude(llvm::vfs::FileSystem& fs, std::string_view prelude_file_name,
|
|
Nonnull<Arena*> arena,
|
|
std::vector<Nonnull<Declaration*>>* declarations,
|
|
int* num_prelude_declarations) {
|
|
ErrorOr<AST> parse_result =
|
|
Parse(fs, arena, prelude_file_name, FileKind::Prelude, false);
|
|
if (!parse_result.ok()) {
|
|
// Try again with tracing, to help diagnose the problem.
|
|
ErrorOr<AST> trace_parse_result =
|
|
Parse(fs, arena, prelude_file_name, FileKind::Prelude, true);
|
|
CARBON_FATAL() << "Failed to parse prelude:\n"
|
|
<< trace_parse_result.error();
|
|
}
|
|
const auto& prelude = *parse_result;
|
|
declarations->insert(declarations->begin(), prelude.declarations.begin(),
|
|
prelude.declarations.end());
|
|
*num_prelude_declarations = prelude.declarations.size();
|
|
}
|
|
|
|
} // namespace Carbon
|