1
- #include " generic/stage2/structural_parser .h"
1
+ #include " generic/stage2/json_iterator .h"
2
2
#include " generic/stage2/tape_writer.h"
3
3
#include " generic/stage2/atomparsing.h"
4
4
@@ -12,12 +12,12 @@ struct tape_builder {
12
12
dom_parser_implementation &dom_parser,
13
13
dom::document &doc) noexcept {
14
14
dom_parser.doc = &doc;
15
- structural_parser iter (dom_parser, STREAMING ? dom_parser.next_structural_index : 0 );
15
+ json_iterator iter (dom_parser, STREAMING ? dom_parser.next_structural_index : 0 );
16
16
tape_builder builder (doc);
17
17
return iter.walk_document <STREAMING>(builder);
18
18
}
19
19
20
- really_inline error_code root_primitive (structural_parser &iter, const uint8_t *value) {
20
+ really_inline error_code root_primitive (json_iterator &iter, const uint8_t *value) {
21
21
switch (*value) {
22
22
case ' "' : return parse_string (iter, value);
23
23
case ' t' : return parse_root_true_atom (iter, value);
@@ -32,7 +32,7 @@ struct tape_builder {
32
32
return TAPE_ERROR;
33
33
}
34
34
}
35
- really_inline error_code primitive (structural_parser &iter, const uint8_t *value) {
35
+ really_inline error_code primitive (json_iterator &iter, const uint8_t *value) {
36
36
switch (*value) {
37
37
case ' "' : return parse_string (iter, value);
38
38
case ' t' : return parse_true_atom (iter, value);
@@ -47,29 +47,29 @@ struct tape_builder {
47
47
return TAPE_ERROR;
48
48
}
49
49
}
50
- really_inline void empty_object (structural_parser &iter) {
50
+ really_inline void empty_object (json_iterator &iter) {
51
51
iter.log_value (" empty object" );
52
52
empty_container (iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
53
53
}
54
- really_inline void empty_array (structural_parser &iter) {
54
+ really_inline void empty_array (json_iterator &iter) {
55
55
iter.log_value (" empty array" );
56
56
empty_container (iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
57
57
}
58
58
59
- really_inline void start_document (structural_parser &iter) {
59
+ really_inline void start_document (json_iterator &iter) {
60
60
iter.log_start_value (" document" );
61
61
start_container (iter);
62
62
iter.dom_parser .is_array [depth] = false ;
63
63
}
64
- WARN_UNUSED really_inline error_code start_object (structural_parser &iter) {
64
+ WARN_UNUSED really_inline error_code start_object (json_iterator &iter) {
65
65
iter.log_start_value (" object" );
66
66
depth++;
67
67
if (depth >= iter.dom_parser .max_depth ()) { iter.log_error (" Exceeded max depth!" ); return DEPTH_ERROR; }
68
68
start_container (iter);
69
69
iter.dom_parser .is_array [depth] = false ;
70
70
return SUCCESS;
71
71
}
72
- WARN_UNUSED really_inline error_code start_array (structural_parser &iter) {
72
+ WARN_UNUSED really_inline error_code start_array (json_iterator &iter) {
73
73
iter.log_start_value (" array" );
74
74
depth++;
75
75
if (depth >= iter.dom_parser .max_depth ()) { iter.log_error (" Exceeded max depth!" ); return DEPTH_ERROR; }
@@ -78,15 +78,15 @@ struct tape_builder {
78
78
return SUCCESS;
79
79
}
80
80
81
- really_inline void end_object (structural_parser &iter) {
81
+ really_inline void end_object (json_iterator &iter) {
82
82
iter.log_end_value (" object" );
83
83
end_container (iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
84
84
}
85
- really_inline void end_array (structural_parser &iter) {
85
+ really_inline void end_array (json_iterator &iter) {
86
86
iter.log_end_value (" array" );
87
87
end_container (iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
88
88
}
89
- WARN_UNUSED really_inline error_code end_document (structural_parser &iter) {
89
+ WARN_UNUSED really_inline error_code end_document (json_iterator &iter) {
90
90
iter.log_end_value (" document" );
91
91
constexpr uint32_t start_tape_index = 0 ;
92
92
tape.append (start_tape_index, internal::tape_type::ROOT);
@@ -98,7 +98,7 @@ struct tape_builder {
98
98
}
99
99
return SUCCESS;
100
100
}
101
- WARN_UNUSED really_inline error_code key (structural_parser &iter, const uint8_t *value) {
101
+ WARN_UNUSED really_inline error_code key (json_iterator &iter, const uint8_t *value) {
102
102
return parse_string (iter, value, true );
103
103
}
104
104
@@ -108,21 +108,21 @@ struct tape_builder {
108
108
// The object returned from end_container() should support the in_container(),
109
109
// in_array() and in_object() methods, allowing the iterator to branch to the
110
110
// correct place.
111
- really_inline tape_builder &end_container (structural_parser &) {
111
+ really_inline tape_builder &end_container (json_iterator &) {
112
112
depth--;
113
113
return *this ;
114
114
}
115
115
// increment_count increments the count of keys in an object or values in an array.
116
- really_inline void increment_count (structural_parser &iter) {
116
+ really_inline void i
10000
ncrement_count (json_iterator &iter) {
117
117
iter.dom_parser .open_containers [depth].count ++; // we have a key value pair in the object at parser.dom_parser.depth - 1
118
118
}
119
- really_inline bool in_container (structural_parser &) {
119
+ really_inline bool in_container (json_iterator &) {
120
120
return depth != 0 ;
121
121
}
122
- really_inline bool in_array (structural_parser &iter) {
122
+ really_inline bool in_array (json_iterator &iter) {
123
123
return iter.dom_parser .is_array [depth];
124
124
}
125
- really_inline bool in_object (structural_parser &iter) {
125
+ really_inline bool in_object (json_iterator &iter) {
126
126
return !iter.dom_parser .is_array [depth];
127
127
}
128
128
@@ -136,7 +136,7 @@ struct tape_builder {
136
136
137
137
really_inline tape_builder (dom::document &doc) noexcept : tape{doc.tape .get ()}, current_string_buf_loc{doc.string_buf .get ()} {}
138
138
139
- WARN_UNUSED really_inline error_code parse_string (structural_parser &iter, const uint8_t *value, bool key = false ) {
139
+ WARN_UNUSED really_inline error_code parse_string (json_iterator &iter, const uint8_t *value, bool key = false ) {
140
140
iter.log_value (key ? " key" : " string" );
141
141
uint8_t *dst = on_start_string (iter);
142
142
dst = stringparsing::parse_string (value, dst);
@@ -148,13 +148,13 @@ struct tape_builder {
148
148
return SUCCESS;
149
149
}
150
150
151
- WARN_UNUSED really_inline error_code parse_number (structural_parser &iter, const uint8_t *value) {
151
+ WARN_UNUSED really_inline error_code parse_number (json_iterator &iter, const uint8_t *value) {
152
152
iter.log_value (" number" );
153
153
if (!numberparsing::parse_number (value, tape)) { iter.log_error (" Invalid number" ); return NUMBER_ERROR; }
154
154
return SUCCESS;
155
155
}
156
156
157
- really_inline error_code parse_root_number (structural_parser &iter, const uint8_t *value) {
157
+ really_inline error_code parse_root_number (json_iterator &iter, const uint8_t *value) {
158
158
//
159
159
// We need to make a copy to make sure that the string is space terminated.
160
160
// This is not about padding the input, which should already padded up
@@ -179,42 +179,42 @@ struct tape_builder {
179
179
return error;
180
180
}
181
181
182
- WARN_UNUSED really_inline error_code parse_true_atom (structural_parser &iter, const uint8_t *value) {
182
+ WARN_UNUSED really_inline error_code parse_true_atom (json_iterator &iter, const uint8_t *value) {
183
183
iter.log_value (" true" );
184
184
if (!atomparsing::is_valid_true_atom (value)) { return T_ATOM_ERROR; }
185
185
tape.append (0 , internal::tape_type::TRUE_VALUE);
186
186
return SUCCESS;
187
187
}
188
188
189
- WARN_UNUSED really_inline error_code parse_root_true_atom (structural_parser &iter, const uint8_t *value) {
189
+ WARN_UNUSED really_inline error_code parse_root_true_atom (json_iterator &iter, const uint8_t *value) {
190
190
iter.log_value (" true" );
191
191
if (!atomparsing::is_valid_true_atom (value, iter.remaining_len ())) { return T_ATOM_ERROR; }
192
192
tape.append (0 , internal::tape_type::TRUE_VALUE);
193
193
return SUCCESS;
194
194
}
195
195
196
- WARN_UNUSED really_inline error_code parse_false_atom (structural_parser &iter, const uint8_t *value) {
196
+ WARN_UNUSED really_inline error_code parse_false_atom (json_iterator &iter, const uint8_t *value) {
197
197
iter.log_value (" false" );
198
198
if (!atomparsing::is_valid_false_atom (value)) { return F_ATOM_ERROR; }
199
199
tape.append (0 , internal::tape_type::FALSE_VALUE);
200
200
return SUCCESS;
201
201
}
202
202
203
- WARN_UNUSED really_inline error_code parse_root_false_atom (structural_parser &iter, const uint8_t *value) {
203
+ WARN_UNUSED really_inline error_code parse_root_false_atom (json_iterator &iter, const uint8_t *value) {
204
204
iter.log_value (" false" );
205
205
if (!atomparsing::is_valid_false_atom (value, iter.remaining_len ())) { return F_ATOM_ERROR; }
206
206
tape.append (0 , internal::tape_type::FALSE_VALUE);
207
207
return SUCCESS;
208
208
}
209
209
210
- WARN_UNUSED really_inline error_code parse_null_atom (structural_parser &iter, const uint8_t *value) {
210
+ WARN_UNUSED really_inline error_code parse_null_atom (json_iterator &iter, const uint8_t *value) {
211
211
iter.log_value (" null" );
212
212
if (!atomparsing::is_valid_null_atom (value)) { return N_ATOM_ERROR; }
213
213
tape.append (0 , internal::tape_type::NULL_VALUE);
214
214
return SUCCESS;
215
215
}
216
216
217
- WARN_UNUSED really_inline error_code parse_root_null_atom (structural_parser &iter, const uint8_t *value) {
217
+ WARN_UNUSED really_inline error_code parse_root_null_atom (json_iterator &iter, const uint8_t *value) {
218
218
iter.log_value (" null" );
219
219
if (!atomparsing::is_valid_null_atom (value, iter.remaining_len ())) { return N_ATOM_ERROR; }
220
220
tape.append (0 , internal::tape_type::NULL_VALUE);
@@ -223,23 +223,23 @@ struct tape_builder {
223
223
224
224
// private:
225
225
226
- really_inline uint32_t next_tape_index (structural_parser &iter) {
226
+ really_inline uint32_t next_tape_index (json_iterator &iter) {
227
227
return uint32_t (tape.next_tape_loc - iter.dom_parser .doc ->tape .get ());
228
228
}
229
229
230
- really_inline void empty_container (structural_parser &iter, internal::tape_type start, internal::tape_type end) {
230
+ really_inline void empty_container (json_iterator &iter, internal::tape_type start, internal::tape_type end) {
231
231
auto start_index = next_tape_index (iter);
232
232
tape.append (start_index+2 , start);
233
233
tape.append (start_index, end);
234
234
}
235
235
236
- really_inline void start_container (structural_parser &iter) {
236
+ really_inline void start_container (json_iterator &iter) {
237
237
iter.dom_parser .open_containers [depth].tape_index = next_tape_index (iter);
238
238
iter.dom_parser .open_containers [depth].count = 0 ;
239
239
tape.skip (); // We don't actually *write* the start element until the end.
240
240
}
241
241
242
- really_inline void end_container (structural_parser &iter, internal::tape_type start, internal::tape_type end) noexcept {
242
+ really_inline void end_container (json_iterator &iter, internal::tape_type start, internal::tape_type end) noexcept {
243
243
// Write the ending tape element, pointing at the start location
244
244
const uint32_t start_tape_index = iter.dom_parser .open_containers [depth].tape_index ;
245
245
tape.append (start_tape_index, end);
@@ -251,7 +251,7 @@ struct tape_builder {
251
251
tape_writer::write (iter.dom_parser .doc ->tape [start_tape_index], next_tape_index (iter) | (uint64_t (cntsat) << 32 ), start);
252
252
}
253
253
254
- really_inline uint8_t *on_start_string (structural_parser &iter) noexcept {
254
+ really_inline uint8_t *on_start_string (json_iterator &iter) noexcept {
255
255
// we advance the point, accounting for the fact that we have a NULL termination
256
256
tape.append (current_string_buf_loc - iter.dom_parser .doc ->string_buf .get (), internal::tape_type::STRING);
257
257
return current_string_buf_loc + sizeof (uint32_t );
0 commit comments