"parser.parser" -> "parser.dom_parser"
This commit is contained in:
parent
3a56e13b78
commit
6ef9395419
|
@ -6,13 +6,13 @@ class structural_iterator {
|
|||
public:
|
||||
const uint8_t* const buf;
|
||||
uint32_t *next_structural;
|
||||
dom_parser_implementation &parser;
|
||||
dom_parser_implementation &dom_parser;
|
||||
|
||||
// Start a structural
|
||||
really_inline structural_iterator(dom_parser_implementation &_parser, size_t start_structural_index)
|
||||
: buf{_parser.buf},
|
||||
next_structural{&_parser.structural_indexes[start_structural_index]},
|
||||
parser{_parser} {
|
||||
really_inline structural_iterator(dom_parser_implementation &_dom_parser, size_t start_structural_index)
|
||||
: buf{_dom_parser.buf},
|
||||
next_structural{&_dom_parser.structural_indexes[start_structural_index]},
|
||||
dom_parser{_dom_parser} {
|
||||
}
|
||||
// Get the buffer position of the current structural character
|
||||
really_inline const uint8_t* current() {
|
||||
|
@ -36,14 +36,14 @@ public:
|
|||
return buf[*(next_structural++)];
|
||||
}
|
||||
really_inline size_t remaining_len() {
|
||||
return parser.len - *(next_structural-1);
|
||||
return dom_parser.len - *(next_structural-1);
|
||||
}
|
||||
|
||||
really_inline bool at_end() {
|
||||
return next_structural == &parser.structural_indexes[parser.n_structural_indexes];
|
||||
return next_structural == &dom_parser.structural_indexes[dom_parser.n_structural_indexes];
|
||||
}
|
||||
really_inline bool at_beginning() {
|
||||
return next_structural == parser.structural_indexes.get();
|
||||
return next_structural == dom_parser.structural_indexes.get();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,28 +25,28 @@ struct structural_parser : structural_iterator {
|
|||
}
|
||||
|
||||
// For non-streaming, to pass an explicit 0 as next_structural, which enables optimizations
|
||||
really_inline structural_parser(dom_parser_implementation &_parser, uint32_t start_structural_index)
|
||||
: structural_iterator(_parser, start_structural_index) {
|
||||
really_inline structural_parser(dom_parser_implementation &_dom_parser, uint32_t start_structural_index)
|
||||
: structural_iterator(_dom_parser, start_structural_index) {
|
||||
}
|
||||
|
||||
WARN_UNUSED really_inline error_code start_document() {
|
||||
parser.is_array[depth] = false;
|
||||
dom_parser.is_array[depth] = false;
|
||||
return SUCCESS;
|
||||
}
|
||||
template<typename T>
|
||||
WARN_UNUSED really_inline error_code start_object(T &builder) {
|
||||
depth++;
|
||||
if (depth >= parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
|
||||
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
|
||||
builder.start_object(*this);
|
||||
parser.is_array[depth] = false;
|
||||
dom_parser.is_array[depth] = false;
|
||||
return SUCCESS;
|
||||
}
|
||||
template<typename T>
|
||||
WARN_UNUSED really_inline error_code start_array(T &builder) {
|
||||
depth++;
|
||||
if (depth >= parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
|
||||
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
|
||||
builder.start_array(*this);
|
||||
parser.is_array[depth] = true;
|
||||
dom_parser.is_array[depth] = true;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ struct structural_parser : structural_iterator {
|
|||
|
||||
template<bool STREAMING>
|
||||
WARN_UNUSED really_inline error_code finish() {
|
||||
parser.next_structural_index = uint32_t(next_structural - &parser.structural_indexes[0]);
|
||||
dom_parser.next_structural_index = uint32_t(next_structural - &dom_parser.structural_indexes[0]);
|
||||
|
||||
if (depth != 0) {
|
||||
log_error("Unclosed objects or arrays!");
|
||||
|
@ -79,7 +79,7 @@ struct structural_parser : structural_iterator {
|
|||
}
|
||||
|
||||
// If we didn't make it to the end, it's an error
|
||||
if ( !STREAMING && parser.next_structural_index != parser.n_structural_indexes ) {
|
||||
if ( !STREAMING && dom_parser.next_structural_index != dom_parser.n_structural_indexes ) {
|
||||
logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
|
||||
return TAPE_ERROR;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ WARN_UNUSED really_inline error_code structural_parser::parse(T &builder) noexce
|
|||
// Make sure the outer array is closed before continuing; otherwise, there are ways we could get
|
||||
// into memory corruption. See https://github.com/simdjson/simdjson/issues/906
|
||||
if (!STREAMING) {
|
||||
if (buf[parser.structural_indexes[parser.n_structural_indexes - 1]] != ']') {
|
||||
if (buf[dom_parser.structural_indexes[dom_parser.n_structural_indexes - 1]] != ']') {
|
||||
return TAPE_ERROR;
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ object_continue: {
|
|||
|
||||
scope_end: {
|
||||
if (depth == 0) { goto document_end; }
|
||||
if (parser.is_array[depth]) { goto array_continue; }
|
||||
if (dom_parser.is_array[depth]) { goto array_continue; }
|
||||
goto object_continue;
|
||||
} // scope_end:
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ private:
|
|||
parser.log_end_value("document");
|
||||
constexpr uint32_t start_tape_index = 0;
|
||||
tape.append(start_tape_index, internal::tape_type::ROOT);
|
||||
tape_writer::write(parser.parser.doc->tape[start_tape_index], next_tape_index(parser), internal::tape_type::ROOT);
|
||||
tape_writer::write(parser.dom_parser.doc->tape[start_tape_index], next_tape_index(parser), internal::tape_type::ROOT);
|
||||
}
|
||||
|
||||
WARN_UNUSED really_inline error_code parse_key(structural_parser &parser, const uint8_t *value) {
|
||||
|
@ -143,13 +143,13 @@ private:
|
|||
|
||||
// increment_count increments the count of keys in an object or values in an array.
|
||||
really_inline void increment_count(structural_parser &parser) {
|
||||
parser.parser.containing_scope[parser.depth].count++; // we have a key value pair in the object at parser.parser.depth - 1
|
||||
parser.dom_parser.containing_scope[parser.depth].count++; // we have a key value pair in the object at parser.dom_parser.depth - 1
|
||||
}
|
||||
|
||||
// private:
|
||||
|
||||
really_inline uint32_t next_tape_index(structural_parser &parser) {
|
||||
return uint32_t(tape.next_tape_loc - parser.parser.doc->tape.get());
|
||||
return uint32_t(tape.next_tape_loc - parser.dom_parser.doc->tape.get());
|
||||
}
|
||||
|
||||
really_inline void empty_container(structural_parser &parser, internal::tape_type start, internal::tape_type end) {
|
||||
|
@ -159,26 +159,26 @@ private:
|
|||
}
|
||||
|
||||
really_inline void start_container(structural_parser &parser) {
|
||||
parser.parser.containing_scope[parser.depth].tape_index = next_tape_index(parser);
|
||||
parser.parser.containing_scope[parser.depth].count = 0;
|
||||
parser.dom_parser.containing_scope[parser.depth].tape_index = next_tape_index(parser);
|
||||
parser.dom_parser.containing_scope[parser.depth].count = 0;
|
||||
tape.skip(); // We don't actually *write* the start element until the end.
|
||||
}
|
||||
|
||||
really_inline void end_container(structural_parser &parser, internal::tape_type start, internal::tape_type end) noexcept {
|
||||
// Write the ending tape element, pointing at the start location
|
||||
const uint32_t start_tape_index = parser.parser.containing_scope[parser.depth].tape_index;
|
||||
const uint32_t start_tape_index = parser.dom_parser.containing_scope[parser.depth].tape_index;
|
||||
tape.append(start_tape_index, end);
|
||||
// Write the start tape element, pointing at the end location (and including count)
|
||||
// count can overflow if it exceeds 24 bits... so we saturate
|
||||
// the convention being that a cnt of 0xffffff or more is undetermined in value (>= 0xffffff).
|
||||
const uint32_t count = parser.parser.containing_scope[parser.depth].count;
|
||||
const uint32_t count = parser.dom_parser.containing_scope[parser.depth].count;
|
||||
const uint32_t cntsat = count > 0xFFFFFF ? 0xFFFFFF : count;
|
||||
tape_writer::write(parser.parser.doc->tape[start_tape_index], next_tape_index(parser) | (uint64_t(cntsat) << 32), start);
|
||||
tape_writer::write(parser.dom_parser.doc->tape[start_tape_index], next_tape_index(parser) | (uint64_t(cntsat) << 32), start);
|
||||
}
|
||||
|
||||
really_inline uint8_t *on_start_string(structural_parser &parser) noexcept {
|
||||
// we advance the point, accounting for the fact that we have a NULL termination
|
||||
tape.append(current_string_buf_loc - parser.parser.doc->string_buf.get(), internal::tape_type::STRING);
|
||||
tape.append(current_string_buf_loc - parser.dom_parser.doc->string_buf.get(), internal::tape_type::STRING);
|
||||
return current_string_buf_loc + sizeof(uint32_t);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue