Move container logging into json_iterator
This commit is contained in:
parent
268b8845a9
commit
e180dc44bc
|
@ -110,6 +110,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
|
|||
// Start the document
|
||||
//
|
||||
if (at_eof()) { return EMPTY; }
|
||||
log_start_value("document");
|
||||
SIMDJSON_TRY( visitor.visit_document_start(*this) );
|
||||
|
||||
//
|
||||
|
@ -122,22 +123,14 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
|
|||
// could get into memory corruption. See https://github.com/simdjson/simdjson/issues/906
|
||||
if (!STREAMING) {
|
||||
switch (*value) {
|
||||
case '{':
|
||||
if (last_structural() != '}') {
|
||||
return TAPE_ERROR;
|
||||
}
|
||||
break;
|
||||
case '[':
|
||||
if (last_structural() != ']') {
|
||||
return TAPE_ERROR;
|
||||
}
|
||||
break;
|
||||
case '{': if (last_structural() != '}') { return TAPE_ERROR; }; break;
|
||||
case '[': if (last_structural() != ']') { return TAPE_ERROR; }; break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (*value) {
|
||||
case '{': if (*peek() == '}') { advance(); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
|
||||
case '[': if (*peek() == ']') { advance(); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
|
||||
case '{': if (*peek() == '}') { advance(); log_value("empty object"); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
|
||||
case '[': if (*peek() == ']') { advance(); log_value("empty array"); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
|
||||
default: SIMDJSON_TRY( visitor.visit_root_primitive(*this, value) ); break;
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +140,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
|
|||
// Object parser states
|
||||
//
|
||||
object_begin:
|
||||
log_start_value("object");
|
||||
depth++;
|
||||
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
|
||||
SIMDJSON_TRY( visitor.visit_object_start(*this) );
|
||||
|
@ -164,8 +158,8 @@ object_field:
|
|||
{
|
||||
auto value = advance();
|
||||
switch (*value) {
|
||||
case '{': if (*peek() == '}') { advance(); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
|
||||
case '[': if (*peek() == ']') { advance(); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
|
||||
case '{': if (*peek() == '}') { advance(); log_value("empty object"); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
|
||||
case '[': if (*peek() == ']') { advance(); log_value("empty array"); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
|
||||
default: SIMDJSON_TRY( visitor.visit_primitive(*this, value) ); break;
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +174,7 @@ object_continue:
|
|||
SIMDJSON_TRY( visitor.visit_key(*this, key) );
|
||||
}
|
||||
goto object_field;
|
||||
case '}': SIMDJSON_TRY( visitor.visit_object_end(*this) ); goto scope_end;
|
||||
case '}': log_end_value("object"); SIMDJSON_TRY( visitor.visit_object_end(*this) ); goto scope_end;
|
||||
default: log_error("No comma between object fields"); return TAPE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -194,6 +188,7 @@ scope_end:
|
|||
// Array parser states
|
||||
//
|
||||
array_begin:
|
||||
log_start_value("array");
|
||||
depth++;
|
||||
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
|
||||
SIMDJSON_TRY( visitor.visit_array_start(*this) );
|
||||
|
@ -204,8 +199,8 @@ array_value:
|
|||
{
|
||||
auto value = advance();
|
||||
switch (*value) {
|
||||
case '{': if (*peek() == '}') { advance(); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
|
||||
case '[': if (*peek() == ']') { advance(); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
|
||||
case '{': if (*peek() == '}') { advance(); log_value("empty object"); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
|
||||
case '[': if (*peek() == ']') { advance(); log_value("empty array"); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
|
||||
default: SIMDJSON_TRY( visitor.visit_primitive(*this, value) ); break;
|
||||
}
|
||||
}
|
||||
|
@ -213,11 +208,12 @@ array_value:
|
|||
array_continue:
|
||||
switch (*advance()) {
|
||||
case ',': SIMDJSON_TRY( visitor.increment_count(*this) ); goto array_value;
|
||||
case ']': SIMDJSON_TRY( visitor.visit_array_end(*this) ); goto scope_end;
|
||||
case ']': log_end_value("array"); SIMDJSON_TRY( visitor.visit_array_end(*this) ); goto scope_end;
|
||||
default: log_error("Missing comma between array values"); return TAPE_ERROR;
|
||||
}
|
||||
|
||||
document_end:
|
||||
log_end_value("document");
|
||||
SIMDJSON_TRY( visitor.visit_document_end(*this) );
|
||||
|
||||
dom_parser.next_structural_index = uint32_t(next_structural - &dom_parser.structural_indexes[0]);
|
||||
|
|
|
@ -122,40 +122,32 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_primi
|
|||
}
|
||||
}
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_empty_object(json_iterator &iter) noexcept {
|
||||
iter.log_value("empty object");
|
||||
return empty_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
|
||||
}
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_empty_array(json_iterator &iter) noexcept {
|
||||
iter.log_value("empty array");
|
||||
return empty_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
|
||||
}
|
||||
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_document_start(json_iterator &iter) noexcept {
|
||||
iter.log_start_value("document");
|
||||
start_container(iter);
|
||||
return SUCCESS;
|
||||
}
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_object_start(json_iterator &iter) noexcept {
|
||||
iter.log_start_value("object");
|
||||
start_container(iter);
|
||||
return SUCCESS;
|
||||
}
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_array_start(json_iterator &iter) noexcept {
|
||||
iter.log_start_value("array");
|
||||
start_container(iter);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_object_end(json_iterator &iter) noexcept {
|
||||
iter.log_end_value("object");
|
||||
return end_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
|
||||
}
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_array_end(json_iterator &iter) noexcept {
|
||||
iter.log_end_value("array");
|
||||
return end_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
|
||||
}
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_document_end(json_iterator &iter) noexcept {
|
||||
iter.log_end_value("document");
|
||||
constexpr uint32_t start_tape_index = 0;
|
||||
tape.append(start_tape_index, internal::tape_type::ROOT);
|
||||
tape_writer::write(iter.dom_parser.doc->tape[start_tape_index], next_tape_index(iter), internal::tape_type::ROOT);
|
||||
|
|
Loading…
Reference in New Issue