Remove global_arena (#814)

With this, only main.cpp instantiates an arena. Maybe we'll want to split that up more later (e.g., so that the runtime interpreter uses its own arena), but given the intent to have type-checking update the AST, I thought this was a reasonable approach for now in order to avoid ownership complexities.

Fixes #769
This commit is contained in:
Jon Meow authored and GitHub committed 2021-09-09 11:00:57 -07:00
1 parent 3610325c38
commit 90f04700e2
27 files changed
+568 -581

No files matched your search

+6 -9
View File
@@ -13,10 +13,7 @@
namespace Carbon {
// Returns an abstract representation of the program contained in the
// well-formed input file, or if the file was malformed, a description of the
// problem.
auto Parse(const std::string& input_file_name)
auto Parse(Ptr<Arena> arena, const std::string& input_file_name)
-> std::variant<AST, SyntaxErrorCode> {
FILE* input_file = fopen(input_file_name.c_str(), "r");
if (input_file == nullptr) {
@@ -30,11 +27,11 @@ auto Parse(const std::string& input_file_name)
yyset_in(input_file, scanner);
// Prepare other parser arguments.
std::optional<AST> parsed_input = std::nullopt;
ParseAndLexContext context(input_file_name);
std::optional<AST> ast = std::nullopt;
ParseAndLexContext context(arena->New<std::string>(input_file_name));
// Do the parse.
auto parser = Parser(parsed_input, scanner, context);
auto parser = Parser(arena, scanner, context, &ast);
if (tracing_output) {
parser.set_debug_level(1);
}
@@ -50,9 +47,9 @@ auto Parse(const std::string& input_file_name)
}
// Return parse results.
CHECK(parsed_input != std::nullopt)
CHECK(ast != std::nullopt)
<< "parser validated syntax yet didn't produce an AST.";
return *parsed_input;
return *ast;
}
} // namespace Carbon