diff options
Diffstat (limited to 'src/wast-parser.cc')
-rw-r--r-- | src/wast-parser.cc | 73 |
1 files changed, 21 insertions, 52 deletions
diff --git a/src/wast-parser.cc b/src/wast-parser.cc index 20d5d44a..3b707848 100644 --- a/src/wast-parser.cc +++ b/src/wast-parser.cc @@ -19,7 +19,6 @@ #include "src/binary-reader-ir.h" #include "src/binary-reader.h" #include "src/cast.h" -#include "src/error-handler.h" #include "src/expr-visitor.h" #include "src/make-unique.h" #include "src/utf8.h" @@ -104,42 +103,6 @@ void RemoveEscapes(const TextVector& texts, OutputIter out) { RemoveEscapes(text, out); } -class BinaryErrorHandlerModule : public ErrorHandler { - public: - BinaryErrorHandlerModule(Location* loc, WastParser* parser); - bool OnError(ErrorLevel, - const Location&, - const std::string& error, - const std::string& source_line, - size_t source_line_column_offset) override; - - // Unused. - size_t source_line_max_length() const override { return 0; } - - private: - Location* loc_; - WastParser* parser_; -}; - -BinaryErrorHandlerModule::BinaryErrorHandlerModule(Location* loc, - WastParser* parser) - : ErrorHandler(Location::Type::Binary), loc_(loc), parser_(parser) {} - -bool BinaryErrorHandlerModule::OnError(ErrorLevel error_level, - const Location& binary_loc, - const std::string& error, - const std::string& source_line, - size_t source_line_column_offset) { - assert(error_level == ErrorLevel::Error); - if (binary_loc.offset == kInvalidOffset) { - parser_->Error(*loc_, "error in binary module: %s", error.c_str()); - } else { - parser_->Error(*loc_, "error in binary module: @0x%08" PRIzx ": %s", - binary_loc.offset, error.c_str()); - } - return true; -} - bool IsPlainInstr(TokenType token_type) { switch (token_type) { case TokenType::Unreachable: @@ -375,16 +338,13 @@ void AppendInlineExportFields(Module* module, } // End of anonymous namespace WastParser::WastParser(WastLexer* lexer, - ErrorHandler* error_handler, + Errors* errors, WastParseOptions* options) - : lexer_(lexer), error_handler_(error_handler), options_(options) {} + : lexer_(lexer), errors_(errors), options_(options) {} void WastParser::Error(Location loc, const char* format, ...) { - errors_++; - va_list args; - va_start(args, format); - error_handler_->OnError(ErrorLevel::Error, loc, format, args); - va_end(args); + WABT_SNPRINTF_ALLOCA(buffer, length, format); + errors_->emplace_back(ErrorLevel::Error, loc, buffer); } Token WastParser::GetToken() { @@ -747,7 +707,7 @@ Result WastParser::ParseModule(std::unique_ptr<Module>* out_module) { } EXPECT(Eof); - if (errors_ == 0) { + if (errors_->size() == 0) { *out_module = std::move(module); return Result::Ok; } else { @@ -776,7 +736,7 @@ Result WastParser::ParseScript(std::unique_ptr<Script>* out_script) { } EXPECT(Eof); - if (errors_ == 0) { + if (errors_->size() == 0) { *out_script = std::move(script); return Result::Ok; } else { @@ -2205,12 +2165,21 @@ Result WastParser::ParseModuleCommand(Script* script, CommandPtr* out_command) { case ScriptModuleType::Binary: { auto* bsm = cast<BinaryScriptModule>(script_module.get()); ReadBinaryOptions options; - BinaryErrorHandlerModule error_handler(&bsm->loc, this); + Errors errors; const char* filename = "<text>"; ReadBinaryIr(filename, bsm->data.data(), bsm->data.size(), options, - &error_handler, &module); + &errors, &module); module.name = bsm->name; module.loc = bsm->loc; + for (const auto& error: errors) { + assert(error.error_level == ErrorLevel::Error); + if (error.loc.offset == kInvalidOffset) { + Error(bsm->loc, "error in binary module: %s", error.message.c_str()); + } else { + Error(bsm->loc, "error in binary module: @0x%08" PRIzx ": %s", + error.loc.offset, error.message.c_str()); + } + } break; } @@ -2389,19 +2358,19 @@ void WastParser::CheckImportOrdering(Module* module) { Result ParseWatModule(WastLexer* lexer, std::unique_ptr<Module>* out_module, - ErrorHandler* error_handler, + Errors* errors, WastParseOptions* options) { assert(out_module != nullptr); - WastParser parser(lexer, error_handler, options); + WastParser parser(lexer, errors, options); return parser.ParseModule(out_module); } Result ParseWastScript(WastLexer* lexer, std::unique_ptr<Script>* out_script, - ErrorHandler* error_handler, + Errors* errors, WastParseOptions* options) { assert(out_script != nullptr); - WastParser parser(lexer, error_handler, options); + WastParser parser(lexer, errors, options); return parser.ParseScript(out_script); } |