summaryrefslogtreecommitdiff
path: root/src/source-error-handler.cc
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2017-06-11 18:35:43 -0700
committerGitHub <noreply@github.com>2017-06-11 18:35:43 -0700
commit3377747c3fb159826c5bd6d4a70ee5e167c79552 (patch)
treece5f7989c14c017f24dc8c7b0233881b0fca78a8 /src/source-error-handler.cc
parent3b81354b2482930a311646c34863ef5a584e7b2c (diff)
downloadwabt-3377747c3fb159826c5bd6d4a70ee5e167c79552.tar.gz
wabt-3377747c3fb159826c5bd6d4a70ee5e167c79552.tar.bz2
wabt-3377747c3fb159826c5bd6d4a70ee5e167c79552.zip
Update testsuite; more lexer/parser changes (#484)
* Add support for quoted modules: `(module quote "...")` * Binary modules must be annotated: `(module binary "...")` * Multiple result blocks are no longer a parser error: `(func (result i32) (result i32) ...)` * Function types can specify unused bind variables: `(type (func (param $foo)))` * Rename `RawModule` -> `ScriptModule`. This encapsulates a module that may not be parsed yet, whether binary or "quoted". * Validate load/store offsets and alignment in the parser, not in the validator. The spec tests assume that you can catch these errors with `assert_malformed`. * Parse wast files in `wasm-interp` when checking malformed/invalid/etc. modules. This allows us to run all assertions at the same time, which is nice. `wasm-interp` should probably be renamed, though. * Two tests in `type.wast` fail because they use: `(assert_invalid (module quote "..."))`. I'd prefer that we don't support this, since it's unnecessary, and additional work. I'll fix in a follow-up CL if we decide this is worth keeping.
Diffstat (limited to 'src/source-error-handler.cc')
-rw-r--r--src/source-error-handler.cc22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/source-error-handler.cc b/src/source-error-handler.cc
index 87074ddc..96db1346 100644
--- a/src/source-error-handler.cc
+++ b/src/source-error-handler.cc
@@ -24,12 +24,17 @@ std::string SourceErrorHandler::DefaultErrorMessage(
const Location* loc,
const std::string& error,
const std::string& source_line,
- size_t source_line_column_offset) {
- std::string result = string_printf("%s:%d:%d: %s\n", loc->filename, loc->line,
- loc->first_column, error.c_str());
+ size_t source_line_column_offset,
+ int indent) {
+ std::string indent_str(indent, ' ');
+ std::string result =
+ string_printf("%s%s:%d:%d: %s\n", indent_str.c_str(), loc->filename,
+ loc->line, loc->first_column, error.c_str());
+ result += indent_str;
if (!source_line.empty()) {
result += source_line;
result += '\n';
+ result += indent_str;
size_t num_spaces = (loc->first_column - 1) - source_line_column_offset;
size_t num_carets = loc->last_column - loc->first_column;
@@ -56,8 +61,9 @@ bool SourceErrorHandlerFile::OnError(const Location* loc,
const std::string& source_line,
size_t source_line_column_offset) {
PrintErrorHeader();
- std::string message =
- DefaultErrorMessage(loc, error, source_line, source_line_column_offset);
+ int indent = header_.empty() ? 0 : 2;
+ std::string message = DefaultErrorMessage(loc, error, source_line,
+ source_line_column_offset, indent);
fwrite(message.data(), 1, message.size(), file_);
return true;
}
@@ -78,8 +84,6 @@ void SourceErrorHandlerFile::PrintErrorHeader() {
fprintf(file_, "%s:\n", header_.c_str());
break;
}
- // If there's a header, indent the following message.
- fprintf(file_, " ");
}
SourceErrorHandlerBuffer::SourceErrorHandlerBuffer(
@@ -90,8 +94,8 @@ bool SourceErrorHandlerBuffer::OnError(const Location* loc,
const std::string& error,
const std::string& source_line,
size_t source_line_column_offset) {
- buffer_ +=
- DefaultErrorMessage(loc, error, source_line, source_line_column_offset);
+ buffer_ += DefaultErrorMessage(loc, error, source_line,
+ source_line_column_offset, 0);
return true;
}