summaryrefslogtreecommitdiff
path: root/src/ast-parser-lexer-shared.cc
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2017-04-24 15:18:57 -0700
committerGitHub <noreply@github.com>2017-04-24 15:18:57 -0700
commitf78f159d836ed6920f7a656a693220bbc9b5bbd6 (patch)
tree6b54d78ead821b7b524492bdde1ba8588d358bbb /src/ast-parser-lexer-shared.cc
parentbcdb11f2ab3d778a83bf53ddfbd174b70ebaf02a (diff)
downloadwabt-f78f159d836ed6920f7a656a693220bbc9b5bbd6.tar.gz
wabt-f78f159d836ed6920f7a656a693220bbc9b5bbd6.tar.bz2
wabt-f78f159d836ed6920f7a656a693220bbc9b5bbd6.zip
Change {Source,Binary}ErrorHandler to C++ (#403)
Added some new classes: * BinaryErrorHandler: abstract base class * BinaryErrorHandlerFile: writes errors to a FILE* * SourceErrorHandler: abstract base class * SourceErrorHandlerNop: eats all errors * SourceErrorHandlerFile: writes errors to a FILE* There are some specific ones as well: * BinaryErrorHandlerAssert: used in wasm-interp to handle writing out a custom header with assertion "failures"; i.e. places where the error handler should fire. * BinaryErrorHandlerModule: used when parsing a .wast, but there's an embedded binary file.
Diffstat (limited to 'src/ast-parser-lexer-shared.cc')
-rw-r--r--src/ast-parser-lexer-shared.cc12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/ast-parser-lexer-shared.cc b/src/ast-parser-lexer-shared.cc
index eab46b36..a6f8ba96 100644
--- a/src/ast-parser-lexer-shared.cc
+++ b/src/ast-parser-lexer-shared.cc
@@ -20,6 +20,8 @@
#include <stdio.h>
#include <string.h>
+#include <string>
+
namespace wabt {
void ast_parser_error(Location* loc,
@@ -52,7 +54,7 @@ void ast_format_error(SourceErrorHandler* error_handler,
char* source_line = nullptr;
size_t source_line_length = 0;
int source_line_column_offset = 0;
- size_t source_line_max_length = error_handler->source_line_max_length;
+ size_t source_line_max_length = error_handler->source_line_max_length();
if (loc && lexer) {
source_line = static_cast<char*>(alloca(source_line_max_length + 1));
Result result = ast_lexer_get_source_line(
@@ -65,11 +67,9 @@ void ast_format_error(SourceErrorHandler* error_handler,
}
}
- if (error_handler->on_error) {
- error_handler->on_error(loc, buffer, source_line, source_line_length,
- source_line_column_offset,
- error_handler->user_data);
- }
+ error_handler->OnError(loc, std::string(buffer),
+ std::string(source_line, source_line_length),
+ source_line_column_offset);
va_end(args_copy);
}