diff options
author | Ben Smith <binjimin@gmail.com> | 2017-06-02 13:35:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-02 13:35:24 -0700 |
commit | 3c6c7a83c5bcf4f6654d4646652ace2c1468f0fb (patch) | |
tree | e595fdac4cfb86796b50db01f0a807a451b1cfcb /src/wast-parser-lexer-shared.cc | |
parent | c37a2d912e83f9298c64c61e1e92aff8042566e1 (diff) | |
download | wabt-3c6c7a83c5bcf4f6654d4646652ace2c1468f0fb.tar.gz wabt-3c6c7a83c5bcf4f6654d4646652ace2c1468f0fb.tar.bz2 wabt-3c6c7a83c5bcf4f6654d4646652ace2c1468f0fb.zip |
Cleanup Lexer (#466)
* Add class LexerSource: it encapsulates reading data from a source,
either buffer or file.
* Add class LexerSourceLineFinder: it uses a LexerSource to read a line
from the source for displaying in errors. It lazily caches line
numbers -> file offsets, so no work is done unless an error occurs.
* Make WastLexer a class instead of a struct.
Diffstat (limited to 'src/wast-parser-lexer-shared.cc')
-rw-r--r-- | src/wast-parser-lexer-shared.cc | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/wast-parser-lexer-shared.cc b/src/wast-parser-lexer-shared.cc index e073a369..fe785fe8 100644 --- a/src/wast-parser-lexer-shared.cc +++ b/src/wast-parser-lexer-shared.cc @@ -50,25 +50,20 @@ void wast_format_error(SourceErrorHandler* error_handler, len = wabt_vsnprintf(buffer, len + 1, format, args_copy); } - 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(); + LexerSourceLineFinder::SourceLine source_line; if (loc && lexer) { - source_line = static_cast<char*>(alloca(source_line_max_length + 1)); - Result result = wast_lexer_get_source_line( - lexer, loc, source_line_max_length, source_line, &source_line_length, - &source_line_column_offset); + size_t source_line_max_length = error_handler->source_line_max_length(); + Result result = lexer->line_finder().GetSourceLine( + *loc, source_line_max_length, &source_line); if (WABT_FAILED(result)) { - /* if this fails, it means that we've probably screwed up the lexer. blow - * up. */ + // If this fails, it means that we've probably screwed up the lexer. Blow + // up. WABT_FATAL("error getting the source line.\n"); } } - error_handler->OnError(loc, std::string(buffer), - std::string(source_line, source_line_length), - source_line_column_offset); + error_handler->OnError(loc, std::string(buffer), source_line.line, + source_line.column_offset); va_end(args_copy); } |