Skip to content

Commit 15eb1ad

Browse files
committed
Preface visitor methods with visit()
1 parent 6ec98ee commit 15eb1ad

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

src/generic/stage2/json_iterator.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class json_iterator {
1111
dom_parser_implementation &dom_parser;
1212
uint32_t depth{0};
1313

14-
template<bool STREAMING, typename T>
15-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code walk_document(T &visitor) noexcept;
14+
template<bool STREAMING, typename V>
15+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code walk_document(V &visitor) noexcept;
1616

1717
// Start a structural
1818
simdjson_really_inline json_iterator(dom_parser_implementation &_dom_parser, size_t start_structural_index)
@@ -62,15 +62,15 @@ class json_iterator {
6262
}
6363
};
6464

65-
template<bool STREAMING, typename T>
66-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_document(T &visitor) noexcept {
65+
template<bool STREAMING, typename V>
66+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_document(V &visitor) noexcept {
6767
logger::log_start();
6868

6969
//
7070
// Start the document
7171
//
7272
if (at_end()) { return EMPTY; }
73-
SIMDJSON_TRY( visitor.start_document(*this) );
73+
SIMDJSON_TRY( visitor.visit_document_start(*this) );
7474

7575
//
7676
// Read first value
@@ -96,9 +96,9 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
9696
}
9797

9898
switch (*value) {
99-
case '{': if (peek_next_char() == '}') { advance(); SIMDJSON_TRY( visitor.empty_object(*this) ); break; } goto object_begin;
100-
case '[': if (peek_next_char() == ']') { advance(); SIMDJSON_TRY( visitor.empty_array(*this) ); break; } goto array_begin;
101-
default: SIMDJSON_TRY( visitor.root_primitive(*this, value) ); break;
99+
case '{': if (peek_next_char() == '}') { advance(); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
100+
case '[': if (peek_next_char() == ']') { advance(); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
101+
default: SIMDJSON_TRY( visitor.visit_root_primitive(*this, value) ); break;
102102
}
103103
}
104104
goto document_end;
@@ -109,23 +109,23 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
109109
object_begin:
110110
depth++;
111111
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
112-
SIMDJSON_TRY( visitor.start_object(*this) );
112+
SIMDJSON_TRY( visitor.visit_object_start(*this) );
113113

114114
{
115115
auto key = advance();
116116
if (*key != '"') { log_error("Object does not start with a key"); return TAPE_ERROR; }
117117
SIMDJSON_TRY( visitor.increment_count(*this) );
118-
SIMDJSON_TRY( visitor.key(*this, key) );
118+
SIMDJSON_TRY( visitor.visit_key(*this, key) );
119119
}
120120

121121
object_field:
122122
if (simdjson_unlikely( *advance() != ':' )) { log_error("Missing colon after key in object"); return TAPE_ERROR; }
123123
{
124124
auto value = advance();
125125
switch (*value) {
126-
case '{': if (peek_next_char() == '}') { advance(); SIMDJSON_TRY( visitor.empty_object(*this) ); break; } goto object_begin;
127-
case '[': if (peek_next_char() == ']') { advance(); SIMDJSON_TRY( visitor.empty_array(*this) ); break; } goto array_begin;
128-
default: SIMDJSON_TRY( visitor.primitive(*this, value) ); break;
126+
case '{': if (peek_next_char() == '}') { advance(); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
127+
case '[': if (peek_next_char() == ']') { advance(); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
128+
default: SIMDJSON_TRY( visitor.visit_primitive(*this, value) ); break;
129129
}
130130
}
131131

@@ -136,10 +136,10 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
136136
{
137137
auto key = advance();
138138
if (simdjson_unlikely( *key != '"' )) { log_error("Key string missing at beginning of field in object"); return TAPE_ERROR; }
139-
SIMDJSON_TRY( visitor.key(*this, key) );
139+
SIMDJSON_TRY( visitor.visit_key(*this, key) );
140140
}
141141
goto object_field;
142-
case '}': SIMDJSON_TRY( visitor.end_object(*this) ); goto scope_end;
142+
case '}': SIMDJSON_TRY( visitor.visit_object_end(*this) ); goto scope_end;
143143
default: log_error("No comma between object fields"); return TAPE_ERROR;
144144
}
145145

@@ -155,28 +155,28 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
155155
array_begin:
156156
depth++;
157157
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
158-
SIMDJSON_TRY( visitor.start_array(*this) );
158+
SIMDJSON_TRY( visitor.visit_array_start(*this) );
159159
SIMDJSON_TRY( visitor.increment_count(*this) );
160160

161161
array_value:
162162
{
163163
auto value = advance();
164164
switch (*value) {
165-
case '{': if (peek_next_char() == '}') { advance(); SIMDJSON_TRY( visitor.empty_object(*this) ); break; } goto object_begin;
166-
case '[': if (peek_next_char() == ']') { advance(); SIMDJSON_TRY( visitor.empty_array(*this) ); break; } goto array_begin;
167-
default: SIMDJSON_TRY( visitor.primitive(*this, value) ); break;
165+
case '{': if (peek_next_char() == '}') { advance(); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
166+
case '[': if (peek_next_char() == ']') { advance(); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
167+
default: SIMDJSON_TRY( visitor.visit_primitive(*this, value) ); break;
168168
}
169169
}
170170

171171
array_continue:
172172
switch (*advance()) {
173173
case ',': SIMDJSON_TRY( visitor.increment_count(*this) ); goto array_value;
174-
case ']': SIMDJSON_TRY( visitor.end_array(*this) ); goto scope_end;
174+
case ']': SIMDJSON_TRY( visitor.visit_array_end(*this) ); goto scope_end;
175175
default: log_error("Missing comma between array values"); return TAPE_ERROR;
176176
}
177177

178178
document_end:
179-
SIMDJSON_TRY( visitor.end_document(*this) );
179+
SIMDJSON_TRY( visitor.visit_document_end(*this) );
180180

181181
dom_parser.next_structural_index = uint32_t(next_structural - &dom_parser.structural_indexes[0]);
182182

src/generic/stage2/tape_builder.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,81 +17,81 @@ struct tape_builder {
1717
return iter.walk_document<STREAMING>(builder);
1818
}
1919

20-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code root_primitive(json_iterator &iter, const uint8_t *value) {
20+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_primitive(json_iterator &iter, const uint8_t *value) {
2121
switch (*value) {
22-
case '"': return parse_string(iter, value);
23-
case 't': return parse_root_true_atom(iter, value);
24-
case 'f': return parse_root_false_atom(iter, value);
25-
case 'n': return parse_root_null_atom(iter, value);
22+
case '"': return visit_string(iter, value);
23+
case 't': return visit_root_true_atom(iter, value);
24+
case 'f': return visit_root_false_atom(iter, value);
25+
case 'n': return visit_root_null_atom(iter, value);
2626
case '-':
2727
case '0': case '1': case '2': case '3': case '4':
2828
case '5': case '6': case '7': case '8': case '9':
29-
return parse_root_number(iter, value);
29+
return visit_root_number(iter, value);
3030
default:
3131
iter.log_error("Document starts with a non-value character");
3232
return TAPE_ERROR;
3333
}
3434
}
35-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code primitive(json_iterator &iter, const uint8_t *value) {
35+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_primitive(json_iterator &iter, const uint8_t *value) {
3636
switch (*value) {
37-
case '"': return parse_string(iter, value);
38-
case 't': return parse_true_atom(iter, value);
39-
case 'f': return parse_false_atom(iter, value);
40-
case 'n': return parse_null_atom(iter, value);
37+
case '"': return visit_string(iter, value);
38+
case 't': return visit_true_atom(iter, value);
39+
case 'f': return visit_false_atom(iter, value);
40+
case 'n': return visit_null_atom(iter, value);
4141
case '-':
4242
case '0': case '1': case '2': case '3': case '4':
4343
case '5': case '6': case '7': case '8': case '9':
44-
return parse_number(iter, value);
44+
return visit_number(iter, value);
4545
default:
4646
iter.log_error("Non-value found when value was expected!");
4747
return TAPE_ERROR;
4848
}
4949
}
50-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code empty_object(json_iterator &iter) {
50+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_empty_object(json_iterator &iter) {
5151
iter.log_value("empty object");
5252
return empty_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
5353
}
54-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code empty_array(json_iterator &iter) {
54+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_empty_array(json_iterator &iter) {
5555
iter.log_value("empty array");
5656
return empty_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
5757
}
5858

59-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code start_document(json_iterator &iter) {
59+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_document_start(json_iterator &iter) {
6060
iter.log_start_value("document");
6161
start_container(iter);
6262
iter.dom_parser.is_array[iter.depth] = false;
6363
return SUCCESS;
6464
}
65-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code start_object(json_iterator &iter) {
65+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_object_start(json_iterator &iter) {
6666
iter.log_start_value("object");
6767
start_container(iter);
6868
iter.dom_parser.is_array[iter.depth] = false;
6969
return SUCCESS;
7070
}
71-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code start_array(json_iterator &iter) {
71+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_array_start(json_iterator &iter) {
7272
iter.log_start_value("array");
7373
start_container(iter);
7474
iter.dom_parser.is_array[iter.depth] = true;
7575
return SUCCESS;
7676
}
7777

78-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code end_object(json_iterator &iter) {
78+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_object_end(json_iterator &iter) {
7979
iter.log_end_value("object");
8080
return end_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
8181
}
82-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code end_array(json_iterator &iter) {
82+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_array_end(json_iterator &iter) {
8383
iter.log_end_value("array");
8484
return end_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
8585
}
86-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code end_document(json_iterator &iter) {
86+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_document_end(json_iterator &iter) {
8787
iter.log_end_value("document");
8888
constexpr uint32_t start_tape_index = 0;
8989
tape.append(start_tape_index, internal::tape_type::ROOT);
9090
tape_writer::write(iter.dom_parser.doc->tape[start_tape_index], next_tape_index(iter), internal::tape_type::ROOT);
9191
return SUCCESS;
9292
}
93-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code key(json_iterator &iter, const uint8_t *key) {
94-
return parse_string(iter, key, true);
93+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_key(json_iterator &iter, const uint8_t *key) {
94+
return visit_string(iter, key, true);
9595
}
9696

9797
// increment_count increments the count of keys in an object or values in an array.
@@ -111,7 +111,7 @@ struct tape_builder {
111111

112112
simdjson_really_inline tape_builder(dom::document &doc) noexcept : tape{doc.tape.get()}, current_string_buf_loc{doc.string_buf.get()} {}
113113

114-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_string(json_iterator &iter, const uint8_t *value, bool key = false) {
114+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_string(json_iterator &iter, const uint8_t *value, bool key = false) {
115115
iter.log_value(key ? "key" : "string");
116116
uint8_t *dst = on_start_string(iter);
117117
dst = stringparsing::parse_string(value, dst);
@@ -123,13 +123,13 @@ struct tape_builder {
123123
return SUCCESS;
124124
}
125125

126-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_number(json_iterator &iter, const uint8_t *value) {
126+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_number(json_iterator &iter, const uint8_t *value) {
127127
iter.log_value("number");
128128
if (!numberparsing::parse_number(value, tape)) { iter.log_error("Invalid number"); return NUMBER_ERROR; }
129129
return SUCCESS;
130130
}
131131

132-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_root_number(json_iterator &iter, const uint8_t *value) {
132+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_number(json_iterator &iter, const uint8_t *value) {
133133
//
134134
// We need to make a copy to make sure that the string is space terminated.
135135
// This is not about padding the input, which should already padded up
@@ -149,47 +149,47 @@ struct tape_builder {
149149
}
150150
memcpy(copy, value, iter.remaining_len());
151151
memset(copy + iter.remaining_len(), ' ', SIMDJSON_PADDING);
152-
error_code error = parse_number(iter, copy);
152+
error_code error = visit_number(iter, copy);
153153
free(copy);
154154
return error;
155155
}
156156

157-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_true_atom(json_iterator &iter, const uint8_t *value) {
157+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_true_atom(json_iterator &iter, const uint8_t *value) {
158158
iter.log_value("true");
159159
if (!atomparsing::is_valid_true_atom(value)) { return T_ATOM_ERROR; }
160160
tape.append(0, internal::tape_type::TRUE_VALUE);
161161
return SUCCESS;
162162
}
163163

164-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_root_true_atom(json_iterator &iter, const uint8_t *value) {
164+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_true_atom(json_iterator &iter, const uint8_t *value) {
165165
iter.log_value("true");
166166
if (!atomparsing::is_valid_true_atom(value, iter.remaining_len())) { return T_ATOM_ERROR; }
167167
tape.append(0, internal::tape_type::TRUE_VALUE);
168168
return SUCCESS;
169169
}
170170

171-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_false_atom(json_iterator &iter, const uint8_t *value) {
171+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_false_atom(json_iterator &iter, const uint8_t *value) {
172172
iter.log_value("false");
173173
if (!atomparsing::is_valid_false_atom(value)) { return F_ATOM_ERROR; }
174174
tape.append(0, internal::tape_type::FALSE_VALUE);
175175
return SUCCESS;
176176
}
177177

178-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_root_false_atom(json_iterator &iter, const uint8_t *value) {
178+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_false_atom(json_iterator &iter, const uint8_t *value) {
179179
iter.log_value("false");
180180
if (!atomparsing::is_valid_false_atom(value, iter.remaining_len())) { return F_ATOM_ERROR; }
181181
tape.append(0, internal::tape_type::FALSE_VALUE);
182182
return SUCCESS;
183183
}
184184

185-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_null_atom(json_iterator &iter, const uint8_t *value) {
185+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_null_atom(json_iterator &iter, const uint8_t *value) {
186186
iter.log_value("null");
187187
if (!atomparsing::is_valid_null_atom(value)) { return N_ATOM_ERROR; }
188188
tape.append(0, internal::tape_type::NULL_VALUE);
189189
return SUCCESS;
190190
}
191191

192-
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_root_null_atom(json_iterator &iter, const uint8_t *value) {
192+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_null_atom(json_iterator &iter, const uint8_t *value) {
193193
iter.log_value("null");
194194
if (!atomparsing::is_valid_null_atom(value, iter.remaining_len())) { return N_ATOM_ERROR; }
195195
tape.append(0, internal::tape_type::NULL_VALUE);

0 commit comments

Comments
 (0)