From 558fab2703cac636a181cc176d5ae63fd4c12296 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Thu, 8 Dec 2022 15:04:49 +0100 Subject: [PATCH] LibIDL: Use `Core::Stream` to read imports --- Userland/Libraries/LibIDL/IDLParser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibIDL/IDLParser.cpp b/Userland/Libraries/LibIDL/IDLParser.cpp index 5fb0a95c05..dba2a2d870 100644 --- a/Userland/Libraries/LibIDL/IDLParser.cpp +++ b/Userland/Libraries/LibIDL/IDLParser.cpp @@ -12,6 +12,7 @@ #include #include #include +#include [[noreturn]] static void report_parsing_error(StringView message, StringView filename, StringView input, size_t offset) { @@ -148,12 +149,14 @@ Optional Parser::resolve_import(auto path) report_parsing_error(DeprecatedString::formatted("Circular import detected: {}", include_path), filename, input, lexer.tell()); import_stack.set(real_path); - auto file_or_error = Core::File::open(real_path, Core::OpenMode::ReadOnly); + auto file_or_error = Core::Stream::File::open(real_path, Core::Stream::OpenMode::Read); if (file_or_error.is_error()) report_parsing_error(DeprecatedString::formatted("Failed to open {}: {}", real_path, file_or_error.error()), filename, input, lexer.tell()); - auto data = file_or_error.value()->read_all(); - auto& result = Parser(this, real_path, data, import_base_path).parse(); + auto data_or_error = file_or_error.value()->read_until_eof(); + if (data_or_error.is_error()) + report_parsing_error(DeprecatedString::formatted("Failed to read {}: {}", real_path, data_or_error.error()), filename, input, lexer.tell()); + auto& result = Parser(this, real_path, data_or_error.value(), import_base_path).parse(); import_stack.remove(real_path); top_level_resolved_imports().set(real_path, &result);