mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 17:01:35 +01:00
Re-order std/json if-else chain
This commit is contained in:
1 parent
48e7004636
commit
f6843719b5
2 files changed
+207
-197
No files matched your search
@@ -18704,7 +18704,6 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
goto label_0_continue;
|
||||
}
|
||||
}
|
||||
if (v_c <= 57) {
|
||||
if (v_class == 1) {
|
||||
if (0 == (v_expect & 2)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
@@ -18726,8 +18725,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
goto label_2_break;
|
||||
}
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_write);
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
goto label_2_continue;
|
||||
}
|
||||
@@ -18740,8 +18739,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
label_3_continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_write);
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
goto label_3_continue;
|
||||
}
|
||||
@@ -18761,8 +18760,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_read);
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
v_string_length = 0;
|
||||
goto label_3_continue;
|
||||
@@ -18828,24 +18827,23 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
goto label_3_continue;
|
||||
}
|
||||
v_uni4_string = ((uint32_t)(
|
||||
(((uint64_t)(wuffs_base__load_u48le(iop_a_src))) >>
|
||||
16)));
|
||||
(((uint64_t)(wuffs_base__load_u48le(iop_a_src))) >> 16)));
|
||||
v_uni4_value = 0;
|
||||
v_uni4_ok = 128;
|
||||
v_c = wuffs_json__hexadecimal_digits[(
|
||||
255 & (v_uni4_string >> 0))];
|
||||
v_c = wuffs_json__hexadecimal_digits[(255 &
|
||||
(v_uni4_string >> 0))];
|
||||
v_uni4_ok &= v_c;
|
||||
v_uni4_value |= (((uint32_t)((v_c & 15))) << 12);
|
||||
v_c = wuffs_json__hexadecimal_digits[(
|
||||
255 & (v_uni4_string >> 8))];
|
||||
v_c = wuffs_json__hexadecimal_digits[(255 &
|
||||
(v_uni4_string >> 8))];
|
||||
v_uni4_ok &= v_c;
|
||||
v_uni4_value |= (((uint32_t)((v_c & 15))) << 8);
|
||||
v_c = wuffs_json__hexadecimal_digits[(
|
||||
255 & (v_uni4_string >> 16))];
|
||||
v_c = wuffs_json__hexadecimal_digits[(255 &
|
||||
(v_uni4_string >> 16))];
|
||||
v_uni4_ok &= v_c;
|
||||
v_uni4_value |= (((uint32_t)((v_c & 15))) << 4);
|
||||
v_c = wuffs_json__hexadecimal_digits[(
|
||||
255 & (v_uni4_string >> 24))];
|
||||
v_c = wuffs_json__hexadecimal_digits[(255 &
|
||||
(v_uni4_string >> 24))];
|
||||
v_uni4_ok &= v_c;
|
||||
v_uni4_value |= (((uint32_t)((v_c & 15))) << 0);
|
||||
if (v_uni4_ok != 0) {
|
||||
@@ -18853,22 +18851,18 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)((8388608 | ((uint64_t)(v_uni4_value)))))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(6))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
(((uint64_t)(6)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
goto label_3_continue;
|
||||
}
|
||||
}
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
if (v_string_length >= 65534) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(65535))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
(((uint64_t)(6291457)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(65535)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
goto label_3_continue;
|
||||
}
|
||||
@@ -18885,8 +18879,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
goto label_4_continue;
|
||||
}
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_write);
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
goto label_4_continue;
|
||||
}
|
||||
@@ -18917,6 +18911,17 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
v_expect = 3;
|
||||
}
|
||||
goto label_0_continue;
|
||||
} else if (v_class == 3) {
|
||||
if (0 == (v_expect & 8)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_expect = 3;
|
||||
goto label_0_continue;
|
||||
} else if (v_class == 4) {
|
||||
if (0 == (v_expect & 1)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
@@ -18974,17 +18979,57 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
}
|
||||
label_6_break:;
|
||||
goto label_5_break;
|
||||
} else if (v_class == 5) {
|
||||
if (0 == (v_expect & 1)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
} else if (v_class == 3) {
|
||||
if (0 == (v_expect & 8)) {
|
||||
if (v_depth >= 1024) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__unsupported_recursion_depth);
|
||||
goto exit;
|
||||
}
|
||||
v_stack_byte = (v_depth / 32);
|
||||
v_stack_bit = (v_depth & 31);
|
||||
self->private_data.f_stack[v_stack_byte] |=
|
||||
(((uint32_t)(1)) << v_stack_bit);
|
||||
v_depth += 1;
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2097185)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_expect = 34;
|
||||
v_expect_after_value = 36;
|
||||
goto label_0_continue;
|
||||
} else if (v_class == 6) {
|
||||
if (0 == (v_expect & 32)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
if (v_depth <= 1) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(2097186)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_expect = 3;
|
||||
goto label_0_break;
|
||||
}
|
||||
v_depth -= 1;
|
||||
v_stack_byte = ((v_depth - 1) / 32);
|
||||
v_stack_bit = ((v_depth - 1) & 31);
|
||||
if (0 == (self->private_data.f_stack[v_stack_byte] &
|
||||
(((uint32_t)(1)) << v_stack_bit))) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2101282)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_expect = 20;
|
||||
v_expect_after_value = 20;
|
||||
} else {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2105378)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_expect = 36;
|
||||
v_expect_after_value = 36;
|
||||
}
|
||||
goto label_0_continue;
|
||||
} else if (v_class == 7) {
|
||||
if (0 == (v_expect & 1)) {
|
||||
@@ -19038,80 +19083,11 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
v_expect_after_value = 36;
|
||||
}
|
||||
goto label_0_continue;
|
||||
} else if (v_class == 5) {
|
||||
if (0 == (v_expect & 1)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
if (v_depth >= 1024) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__unsupported_recursion_depth);
|
||||
goto exit;
|
||||
}
|
||||
v_stack_byte = (v_depth / 32);
|
||||
v_stack_bit = (v_depth & 31);
|
||||
self->private_data.f_stack[v_stack_byte] |=
|
||||
(((uint32_t)(1)) << v_stack_bit);
|
||||
v_depth += 1;
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2097185)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_expect = 34;
|
||||
v_expect_after_value = 36;
|
||||
goto label_0_continue;
|
||||
} else if (v_class == 6) {
|
||||
if (0 == (v_expect & 32)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
if (v_depth <= 1) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2097186)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
goto label_0_break;
|
||||
}
|
||||
v_depth -= 1;
|
||||
v_stack_byte = ((v_depth - 1) / 32);
|
||||
v_stack_bit = ((v_depth - 1) & 31);
|
||||
if (0 == (self->private_data.f_stack[v_stack_byte] &
|
||||
(((uint32_t)(1)) << v_stack_bit))) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2101282)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_expect = 20;
|
||||
v_expect_after_value = 20;
|
||||
} else {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2105378)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_expect = 36;
|
||||
v_expect_after_value = 36;
|
||||
}
|
||||
goto label_0_continue;
|
||||
} else {
|
||||
if (0 == (v_expect & 1)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
v_match = 2;
|
||||
if (v_class == 11) {
|
||||
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
|
||||
465676103172);
|
||||
if (v_match == 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4194337)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
(iop_a_src += 4, wuffs_base__make_empty_struct());
|
||||
goto label_5_break;
|
||||
}
|
||||
} else if (v_class == 9) {
|
||||
if (0 == (v_expect & 1)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
|
||||
111546413966853);
|
||||
if (v_match == 0) {
|
||||
@@ -19125,10 +19101,19 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
}
|
||||
(iop_a_src += 5, wuffs_base__make_empty_struct());
|
||||
goto label_5_break;
|
||||
} else if (v_match == 1) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(13);
|
||||
goto label_0_continue;
|
||||
}
|
||||
} else if (v_class == 10) {
|
||||
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
|
||||
435762131972);
|
||||
if (0 == (v_expect & 1)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
v_match =
|
||||
wuffs_base__io_reader__match7(iop_a_src, io2_a_src, 435762131972);
|
||||
if (v_match == 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4194433)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
@@ -19140,12 +19125,34 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
}
|
||||
(iop_a_src += 4, wuffs_base__make_empty_struct());
|
||||
goto label_5_break;
|
||||
}
|
||||
}
|
||||
if (v_match == 1) {
|
||||
} else if (v_match == 1) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(13);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(14);
|
||||
goto label_0_continue;
|
||||
}
|
||||
} else if (v_class == 11) {
|
||||
if (0 == (v_expect & 1)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
v_match =
|
||||
wuffs_base__io_reader__match7(iop_a_src, io2_a_src, 465676103172);
|
||||
if (v_match == 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4194337)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
(iop_a_src += 4, wuffs_base__make_empty_struct());
|
||||
goto label_5_break;
|
||||
} else if (v_match == 1) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(15);
|
||||
goto label_0_continue;
|
||||
}
|
||||
}
|
||||
|
||||
+90
-87
@@ -152,7 +152,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
assert args.dst.available() > 0
|
||||
assert args.src.available() > 0
|
||||
|
||||
if c <= 0x39 { // 0x39 is '9'.
|
||||
if class == 0x01 { // 0x01 is CLASS_STRING.
|
||||
// -------- BEGIN parse strings.
|
||||
if 0 == (expect & 0x02) { // 0x02 is EXPECT_STRING_VALUE.
|
||||
@@ -165,9 +164,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
length: 1)
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
|
||||
// If the string contents starts with an escape code, issue
|
||||
// a zero-length string token (one with value_base_category
|
||||
// 3) before issuing a token with value_base_category 4.
|
||||
// If the string contents starts with an escape code, issue a
|
||||
// zero-length string token (one with value_base_category 3)
|
||||
// before issuing a token with value_base_category 4.
|
||||
while true {
|
||||
if args.src.available() <= 0 {
|
||||
yield? base."$short read"
|
||||
@@ -318,10 +317,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
break
|
||||
}
|
||||
|
||||
// As above, expect must have contained
|
||||
// EXPECT_STRING_VALUE. If it didn't also contain
|
||||
// EXPECT_NON_STRING_VALUE then we were parsing an object
|
||||
// key and the next token should be ':'.
|
||||
// As above, expect must have contained EXPECT_STRING_VALUE. If
|
||||
// it didn't also contain EXPECT_NON_STRING_VALUE then we were
|
||||
// parsing an object key and the next token should be ':'.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
expect = 0x08 // 0x08 is EXPECT_COLON.
|
||||
continue.outer
|
||||
@@ -338,8 +336,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0,
|
||||
length: 1)
|
||||
// What's valid after a comma depends on whether or not
|
||||
// we're in an array or an object.
|
||||
// What's valid after a comma depends on whether or not we're
|
||||
// in an array or an object.
|
||||
if 0 == (expect & 0x10) { // 0x10 is EXPECT_CLOSE_BRACKET
|
||||
expect = 0x02 // 0x02 is EXPECT_STRING_VALUE.
|
||||
} else {
|
||||
@@ -347,6 +345,18 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
continue.outer
|
||||
|
||||
} else if class == 0x03 { // 0x03 is CLASS_COLON.
|
||||
if 0 == (expect & 0x08) { // 0x08 is EXPECT_COLON.
|
||||
return "#bad input"
|
||||
}
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
// The ':' is filler.
|
||||
args.dst.write_fast_token!(
|
||||
value: 0,
|
||||
length: 1)
|
||||
expect = 0x03 // 0x03 is EXPECT_VALUE.
|
||||
continue.outer
|
||||
|
||||
} else if class == 0x04 { // 0x04 is CLASS_NUMBER.
|
||||
// -------- BEGIN parse numbers.
|
||||
if 0 == (expect & 0x01) { // 0x02 is EXPECT_NON_STRING_VALUE.
|
||||
@@ -393,18 +403,56 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
// -------- END parse numbers.
|
||||
}
|
||||
|
||||
} else if class == 0x03 { // 0x03 is CLASS_COLON.
|
||||
if 0 == (expect & 0x08) { // 0x08 is EXPECT_COLON.
|
||||
} else if class == 0x05 { // 0x05 is CLASS_OPEN_CURLY_BRACE.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
if depth >= 1024 {
|
||||
return "#unsupported recursion depth"
|
||||
}
|
||||
stack_byte = depth / 32
|
||||
stack_bit = depth & 31
|
||||
this.stack[stack_byte] |= (1 as base.u32) << stack_bit
|
||||
depth += 1
|
||||
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x20_0021,
|
||||
length: 1)
|
||||
expect = 0x22 // 0x22 is (EXPECT_CLOSE_BRACE | EXPECT_STRING_VALUE).
|
||||
expect_after_value = 0x24 // 0x24 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA).
|
||||
continue.outer
|
||||
|
||||
} else if class == 0x06 { // 0x06 is CLASS_CLOSE_CURLY_BRACE.
|
||||
if 0 == (expect & 0x20) { // 0x20 is EXPECT_CLOSE_BRACE.
|
||||
return "#bad input"
|
||||
}
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
// The ':' is filler.
|
||||
if depth <= 1 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0,
|
||||
value: 0x20_0022,
|
||||
length: 1)
|
||||
expect = 0x03 // 0x03 is EXPECT_VALUE.
|
||||
break.outer
|
||||
}
|
||||
depth -= 1
|
||||
stack_byte = (depth - 1) / 32
|
||||
stack_bit = (depth - 1) & 31
|
||||
if 0 == (this.stack[stack_byte] & ((1 as base.u32) << stack_bit)) {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x20_1022,
|
||||
length: 1)
|
||||
// 0x14 is (EXPECT_CLOSE_BRACKET | EXPECT_COMMA).
|
||||
expect = 0x14
|
||||
expect_after_value = 0x14
|
||||
} else {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x20_2022,
|
||||
length: 1)
|
||||
// 0x24 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA).
|
||||
expect = 0x24
|
||||
expect_after_value = 0x24
|
||||
}
|
||||
continue.outer
|
||||
|
||||
} else if class == 0x07 { // 0x07 is CLASS_OPEN_SQUARE_BRACKET.
|
||||
@@ -458,76 +506,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
continue.outer
|
||||
|
||||
} else if class == 0x05 { // 0x05 is CLASS_OPEN_CURLY_BRACE.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
if depth >= 1024 {
|
||||
return "#unsupported recursion depth"
|
||||
}
|
||||
stack_byte = depth / 32
|
||||
stack_bit = depth & 31
|
||||
this.stack[stack_byte] |= (1 as base.u32) << stack_bit
|
||||
depth += 1
|
||||
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x20_0021,
|
||||
length: 1)
|
||||
expect = 0x22 // 0x22 is (EXPECT_CLOSE_BRACE | EXPECT_STRING_VALUE).
|
||||
expect_after_value = 0x24 // 0x24 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA).
|
||||
continue.outer
|
||||
|
||||
} else if class == 0x06 { // 0x06 is CLASS_CLOSE_CURLY_BRACE.
|
||||
if 0 == (expect & 0x20) { // 0x20 is EXPECT_CLOSE_BRACE.
|
||||
return "#bad input"
|
||||
}
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
if depth <= 1 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x20_0022,
|
||||
length: 1)
|
||||
break.outer
|
||||
}
|
||||
depth -= 1
|
||||
stack_byte = (depth - 1) / 32
|
||||
stack_bit = (depth - 1) & 31
|
||||
if 0 == (this.stack[stack_byte] & ((1 as base.u32) << stack_bit)) {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x20_1022,
|
||||
length: 1)
|
||||
// 0x14 is (EXPECT_CLOSE_BRACKET | EXPECT_COMMA).
|
||||
expect = 0x14
|
||||
expect_after_value = 0x14
|
||||
} else {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x20_2022,
|
||||
length: 1)
|
||||
// 0x24 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA).
|
||||
expect = 0x24
|
||||
expect_after_value = 0x24
|
||||
}
|
||||
continue.outer
|
||||
|
||||
} else {
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
match = 2
|
||||
if class == 0x0B { // 0x0B is CLASS_NULL.
|
||||
match = args.src.match7(a: 0x6C_6C75_6E04) // 4 bytes "null".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x40_0021,
|
||||
length: 4)
|
||||
if args.src.available() < 4 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
args.src.skip32_fast!(actual: 4, worst_case: 4)
|
||||
break.goto_parsed_a_leaf_value
|
||||
}
|
||||
|
||||
} else if class == 0x09 { // 0x09 is CLASS_FALSE.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
match = args.src.match7(a: 0x6573_6C61_6605) // 5 bytes "false".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
@@ -538,9 +520,15 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
args.src.skip32_fast!(actual: 5, worst_case: 5)
|
||||
break.goto_parsed_a_leaf_value
|
||||
} else if match == 1 {
|
||||
yield? base."$short read"
|
||||
continue.outer
|
||||
}
|
||||
|
||||
} else if class == 0x0A { // 0x0A is CLASS_TRUE.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
match = args.src.match7(a: 0x65_7572_7404) // 4 bytes "true".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
@@ -551,11 +539,26 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
args.src.skip32_fast!(actual: 4, worst_case: 4)
|
||||
break.goto_parsed_a_leaf_value
|
||||
} else if match == 1 {
|
||||
yield? base."$short read"
|
||||
continue.outer
|
||||
}
|
||||
|
||||
} else if class == 0x0B { // 0x0B is CLASS_NULL.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
|
||||
if match == 1 {
|
||||
match = args.src.match7(a: 0x6C_6C75_6E04) // 4 bytes "null".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x40_0021,
|
||||
length: 4)
|
||||
if args.src.available() < 4 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
args.src.skip32_fast!(actual: 4, worst_case: 4)
|
||||
break.goto_parsed_a_leaf_value
|
||||
} else if match == 1 {
|
||||
yield? base."$short read"
|
||||
continue.outer
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user