From a67e83e24ea178fbd82a21a46e200d9712e52164 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 6 Aug 2020 12:45:13 -0700 Subject: [PATCH] Remove parse_* from visitor method names --- src/generic/stage2/structural_parser.h | 25 ++++++++-------- src/generic/stage2/tape_builder.h | 41 +++++++++++++------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/generic/stage2/structural_parser.h b/src/generic/stage2/structural_parser.h index 72dd1cf8..0d36bf83 100644 --- a/src/generic/stage2/structural_parser.h +++ b/src/generic/stage2/structural_parser.h @@ -101,11 +101,10 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code structural_parser::walk_d } switch (*value) { - case '{': if (!empty_object(visitor)) { goto object_begin; }; break; - case '[': if (!empty_array(visitor)) { goto array_begin; }; break; - default: SIMDJSON_TRY( visitor.parse_root_primitive(*this, value) ); + case '{': if (!empty_object(visitor)) { goto object_begin; }; goto document_end; + case '[': if (!empty_array(visitor)) { goto array_begin; }; goto document_end; + default: SIMDJSON_TRY( visitor.root_primitive(*this, value) ); goto document_end; } - goto document_end; // // Object parser states @@ -118,15 +117,15 @@ object_begin: value = advance(); if (*value != '"') { log_error("Object does not start with a key"); return TAPE_ERROR; } visitor.increment_count(*this); - SIMDJSON_TRY( visitor.parse_key(*this, value) ); + SIMDJSON_TRY( visitor.key(*this, value) ); goto object_field; object_field: if (simdjson_unlikely( advance_char() != ':' )) { log_error("Missing colon after key in object"); return TAPE_ERROR; } switch (*(value = advance())) { - case '{': if (!empty_object(visitor)) { goto object_begin; }; break; - case '[': if (!empty_array(visitor)) { goto array_begin; }; break; - default: SIMDJSON_TRY( visitor.parse_primitive(*this, value) ); + case '{': if (!empty_object(visitor)) { goto object_begin; }; goto object_continue; + case '[': if (!empty_array(visitor)) { goto array_begin; }; goto object_continue; + default: SIMDJSON_TRY( visitor.primitive(*this, value) ); } object_continue: @@ -135,7 +134,7 @@ object_continue: visitor.increment_count(*this); value = advance(); if (simdjson_unlikely( *value != '"' )) { log_error("Key string missing at beginning of field in object"); return TAPE_ERROR; } - SIMDJSON_TRY( visitor.parse_key(*this, value) ); + SIMDJSON_TRY( visitor.key(*this, value) ); goto object_field; } case '}': @@ -163,9 +162,9 @@ array_begin: array_value: switch (*(value = advance())) { - case '{': if (!empty_object(visitor)) { goto object_begin; }; break; - case '[': if (!empty_array(visitor)) { goto array_begin; }; break; - default: SIMDJSON_TRY( visitor.parse_primitive(*this, value) ); + case '{': if (!empty_object(visitor)) { goto object_begin; }; goto array_continue; + case '[': if (!empty_array(visitor)) { goto array_begin; }; goto array_continue; + default: SIMDJSON_TRY( visitor.primitive(*this, value) ); } array_continue: @@ -193,7 +192,7 @@ document_end: return SUCCESS; -} // parse_structurals() +} // walk_document() } // namespace stage2 } // namespace SIMDJSON_IMPLEMENTATION diff --git a/src/generic/stage2/tape_builder.h b/src/generic/stage2/tape_builder.h index 3310fc58..d795863e 100644 --- a/src/generic/stage2/tape_builder.h +++ b/src/generic/stage2/tape_builder.h @@ -7,11 +7,6 @@ namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { struct tape_builder { - /** Next location to write to tape */ - tape_writer tape; - /** Next write location in the string buf for stage 2 parsing */ - uint8_t *current_string_buf_loc; - template SIMDJSON_WARN_UNUSED static simdjson_really_inline error_code parse_document( dom_parser_implementation &dom_parser, @@ -22,12 +17,7 @@ struct tape_builder { return iter.walk_document(builder); } -private: - friend struct structural_parser; - - simdjson_really_inline tape_builder(dom::document &doc) noexcept : tape{doc.tape.get()}, current_string_buf_loc{doc.string_buf.get()} {} - - simdjson_really_inline error_code parse_root_primitive(structural_parser &iter, const uint8_t *value) { + simdjson_really_inline error_code root_primitive(structural_parser &iter, const uint8_t *value) { switch (*value) { case '"': return parse_string(iter, value); case 't': return parse_root_true_atom(iter, value); @@ -42,7 +32,7 @@ private: return TAPE_ERROR; } } - simdjson_really_inline error_code parse_primitive(structural_parser &iter, const uint8_t *value) { + simdjson_really_inline error_code primitive(structural_parser &iter, const uint8_t *value) { switch (*value) { case '"': return parse_string(iter, value); case 't': return parse_true_atom(iter, value); @@ -96,10 +86,26 @@ private: 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); } - - SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_key(structural_parser &iter, const uint8_t *value) { - return parse_string(iter, value, true); + SIMDJSON_WARN_UNUSED simdjson_really_inline error_code key(structural_parser &iter, const uint8_t *key) { + return parse_string(iter, key, true); } + + // increment_count increments the count of keys in an object or values in an array. + simdjson_really_inline void increment_count(structural_parser &iter) { + iter.dom_parser.open_containers[iter.depth].count++; // we have a key value pair in the object at parser.dom_parser.depth - 1 + } + simdjson_really_inline bool in_array(structural_parser &iter) noexcept { + return iter.dom_parser.is_array[iter.depth]; + } + +private: + /** Next location to write to tape */ + tape_writer tape; + /** Next write location in the string buf for stage 2 parsing */ + uint8_t *current_string_buf_loc; + + simdjson_really_inline tape_builder(dom::document &doc) noexcept : tape{doc.tape.get()}, current_string_buf_loc{doc.string_buf.get()} {} + SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_string(structural_parser &iter, const uint8_t *value, bool key = false) { iter.log_value(key ? "key" : "string"); uint8_t *dst = on_start_string(iter); @@ -185,11 +191,6 @@ private: return SUCCESS; } - // increment_count increments the count of keys in an object or values in an array. - simdjson_really_inline void increment_count(structural_parser &iter) { - iter.dom_parser.open_containers[iter.depth].count++; // we have a key value pair in the object at parser.dom_parser.depth - 1 - } - // private: simdjson_really_inline uint32_t next_tape_index(structural_parser &iter) {