mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Re-order std/json if-else chain
This commit is contained in:
1 parent
48e7004636
commit
f6843719b5
2 files changed
+637
-627
No files matched your search
@@ -18704,93 +18704,79 @@ 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);
|
||||
goto exit;
|
||||
if (v_class == 1) {
|
||||
if (0 == (v_expect & 2)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
label_2_continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
goto label_2_continue;
|
||||
}
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
label_2_continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
goto label_2_continue;
|
||||
}
|
||||
if (wuffs_base__load_u8be(iop_a_src) != 92) {
|
||||
goto label_2_break;
|
||||
}
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
goto label_2_continue;
|
||||
}
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
if (wuffs_base__load_u8be(iop_a_src) != 92) {
|
||||
goto label_2_break;
|
||||
}
|
||||
label_2_break:;
|
||||
label_3_continue:;
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
goto label_2_continue;
|
||||
}
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
goto label_2_break;
|
||||
}
|
||||
label_2_break:;
|
||||
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);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
goto label_3_continue;
|
||||
}
|
||||
v_string_length = 0;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (v_string_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
}
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
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;
|
||||
}
|
||||
v_string_length = 0;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (v_string_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
}
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
v_c = wuffs_base__load_u8be(iop_a_src);
|
||||
if (v_c <= 34) {
|
||||
if (v_c == 34) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291456))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
goto label_3_continue;
|
||||
}
|
||||
v_c = wuffs_base__load_u8be(iop_a_src);
|
||||
if (v_c <= 34) {
|
||||
if (v_c == 34) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291456))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
goto label_3_break;
|
||||
} else if (v_c < 32) {
|
||||
if (v_string_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
}
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
} else if (v_c == 92) {
|
||||
goto label_3_break;
|
||||
} else if (v_c < 32) {
|
||||
if (v_string_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457))
|
||||
@@ -18798,183 +18784,133 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
goto label_3_continue;
|
||||
}
|
||||
}
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
v_string_length = 0;
|
||||
goto label_3_continue;
|
||||
}
|
||||
v_backslash =
|
||||
((uint8_t)((wuffs_base__load_u16le(iop_a_src) >> 8)));
|
||||
v_c = wuffs_json__backslashes[v_backslash];
|
||||
if (v_c > 0) {
|
||||
(iop_a_src += 2, wuffs_base__make_empty_struct());
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)((8388608 | ((uint64_t)((v_c & 127))))))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
goto label_3_continue;
|
||||
} else if (v_backslash == 117) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 6) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
v_string_length = 0;
|
||||
goto label_3_continue;
|
||||
}
|
||||
v_uni4_string = ((uint32_t)(
|
||||
(((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_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_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_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_uni4_ok &= v_c;
|
||||
v_uni4_value |= (((uint32_t)((v_c & 15))) << 0);
|
||||
if (v_uni4_ok != 0) {
|
||||
(iop_a_src += 6, wuffs_base__make_empty_struct());
|
||||
*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));
|
||||
goto label_3_continue;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
} else if (v_c == 92) {
|
||||
if (v_string_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(65535))
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
goto label_3_continue;
|
||||
}
|
||||
}
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
v_string_length = 0;
|
||||
goto label_3_continue;
|
||||
}
|
||||
v_string_length += 1;
|
||||
}
|
||||
}
|
||||
label_3_break:;
|
||||
label_4_continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label_4_continue;
|
||||
}
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
goto label_4_continue;
|
||||
v_backslash =
|
||||
((uint8_t)((wuffs_base__load_u16le(iop_a_src) >> 8)));
|
||||
v_c = wuffs_json__backslashes[v_backslash];
|
||||
if (v_c > 0) {
|
||||
(iop_a_src += 2, wuffs_base__make_empty_struct());
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)((8388608 | ((uint64_t)((v_c & 127))))))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
goto label_3_continue;
|
||||
} else if (v_backslash == 117) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 6) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
v_string_length = 0;
|
||||
goto label_3_continue;
|
||||
}
|
||||
v_uni4_string = ((uint32_t)(
|
||||
(((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_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_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_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_uni4_ok &= v_c;
|
||||
v_uni4_value |= (((uint32_t)((v_c & 15))) << 0);
|
||||
if (v_uni4_ok != 0) {
|
||||
(iop_a_src += 6, wuffs_base__make_empty_struct());
|
||||
*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));
|
||||
goto label_3_continue;
|
||||
}
|
||||
}
|
||||
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));
|
||||
goto label_4_break;
|
||||
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));
|
||||
v_string_length = 0;
|
||||
goto label_3_continue;
|
||||
}
|
||||
v_string_length += 1;
|
||||
}
|
||||
label_4_break:;
|
||||
if (0 == (v_expect & 1)) {
|
||||
v_expect = 8;
|
||||
goto label_0_continue;
|
||||
}
|
||||
label_3_break:;
|
||||
label_4_continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label_4_continue;
|
||||
}
|
||||
goto label_5_break;
|
||||
} else if (v_class == 2) {
|
||||
if (0 == (v_expect & 4)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
goto label_4_continue;
|
||||
}
|
||||
(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));
|
||||
if (0 == (v_expect & 16)) {
|
||||
v_expect = 2;
|
||||
} else {
|
||||
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);
|
||||
goto exit;
|
||||
}
|
||||
while (true) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_number_length = wuffs_json__decoder__decode_number(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
v_number_status = (v_number_length >> 8);
|
||||
v_token_value = 4194306;
|
||||
if ((v_number_length & 128) != 0) {
|
||||
v_token_value = 4194308;
|
||||
}
|
||||
v_number_length = (v_number_length & 127);
|
||||
if (v_number_status == 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(v_token_value))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_number_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
goto label_6_break;
|
||||
}
|
||||
while (v_number_length > 0) {
|
||||
v_number_length -= 1;
|
||||
if (iop_a_src > io1_a_src) {
|
||||
(iop_a_src--, wuffs_base__make_empty_struct());
|
||||
} else {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
if (v_number_status == 1) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
} else if (v_number_status == 2) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__unsupported_number_length);
|
||||
goto exit;
|
||||
} else {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12);
|
||||
}
|
||||
}
|
||||
}
|
||||
label_6_break:;
|
||||
goto label_5_break;
|
||||
goto label_4_break;
|
||||
}
|
||||
label_4_break:;
|
||||
if (0 == (v_expect & 1)) {
|
||||
v_expect = 8;
|
||||
goto label_0_continue;
|
||||
}
|
||||
goto label_5_break;
|
||||
} else if (v_class == 2) {
|
||||
if (0 == (v_expect & 4)) {
|
||||
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));
|
||||
if (0 == (v_expect & 16)) {
|
||||
v_expect = 2;
|
||||
} else {
|
||||
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);
|
||||
@@ -18986,6 +18922,115 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
(((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);
|
||||
goto exit;
|
||||
}
|
||||
while (true) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_number_length = wuffs_json__decoder__decode_number(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
v_number_status = (v_number_length >> 8);
|
||||
v_token_value = 4194306;
|
||||
if ((v_number_length & 128) != 0) {
|
||||
v_token_value = 4194308;
|
||||
}
|
||||
v_number_length = (v_number_length & 127);
|
||||
if (v_number_status == 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(v_token_value))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_number_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
goto label_6_break;
|
||||
}
|
||||
while (v_number_length > 0) {
|
||||
v_number_length -= 1;
|
||||
if (iop_a_src > io1_a_src) {
|
||||
(iop_a_src--, wuffs_base__make_empty_struct());
|
||||
} else {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
if (v_number_status == 1) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
} else if (v_number_status == 2) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__unsupported_number_length);
|
||||
goto exit;
|
||||
} else {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12);
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
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 (v_class == 7) {
|
||||
if (0 == (v_expect & 1)) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
@@ -19038,116 +19083,78 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
v_expect_after_value = 36;
|
||||
}
|
||||
goto label_0_continue;
|
||||
} else if (v_class == 5) {
|
||||
} else if (v_class == 9) {
|
||||
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) {
|
||||
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
|
||||
111546413966853);
|
||||
if (v_match == 0) {
|
||||
*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;
|
||||
(((uint64_t)(4194369)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(5)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 5) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
} else if (v_class == 9) {
|
||||
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
|
||||
111546413966853);
|
||||
if (v_match == 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4194369)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(5)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 5) {
|
||||
status = wuffs_base__make_status(
|
||||
wuffs_json__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
(iop_a_src += 5, wuffs_base__make_empty_struct());
|
||||
goto label_5_break;
|
||||
}
|
||||
} else if (v_class == 10) {
|
||||
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) |
|
||||
(((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;
|
||||
}
|
||||
}
|
||||
if (v_match == 1) {
|
||||
(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) {
|
||||
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) |
|
||||
(((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(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;
|
||||
}
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
|
||||
+296
-293
@@ -152,249 +152,199 @@ 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.
|
||||
return "#bad input"
|
||||
if class == 0x01 { // 0x01 is CLASS_STRING.
|
||||
// -------- BEGIN parse strings.
|
||||
if 0 == (expect & 0x02) { // 0x02 is EXPECT_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
|
||||
// The leading '"' is filler.
|
||||
args.dst.write_fast_token!(
|
||||
value: 0,
|
||||
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.
|
||||
while true {
|
||||
if args.src.available() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
|
||||
// The leading '"' is filler.
|
||||
args.dst.write_fast_token!(
|
||||
value: 0,
|
||||
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.
|
||||
while true {
|
||||
if args.src.available() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
if args.src.peek_u8() <> 0x5C { // 0x5C is '\\'.
|
||||
break
|
||||
}
|
||||
if args.dst.available() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue
|
||||
}
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0001,
|
||||
length: 0)
|
||||
if args.src.peek_u8() <> 0x5C { // 0x5C is '\\'.
|
||||
break
|
||||
}
|
||||
if args.dst.available() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue
|
||||
}
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0001,
|
||||
length: 0)
|
||||
break
|
||||
}
|
||||
|
||||
while.string_loop true {
|
||||
if args.dst.available() <= 0 {
|
||||
yield? base."$short write"
|
||||
while.string_loop true {
|
||||
if args.dst.available() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue.string_loop
|
||||
}
|
||||
|
||||
string_length = 0
|
||||
while true,
|
||||
pre args.dst.available() > 0,
|
||||
{
|
||||
if args.src.available() <= 0 {
|
||||
if string_length > 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0001,
|
||||
length: string_length as base.u64)
|
||||
string_length = 0
|
||||
}
|
||||
if args.src.is_closed() {
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
continue.string_loop
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
|
||||
string_length = 0
|
||||
while true,
|
||||
pre args.dst.available() > 0,
|
||||
{
|
||||
if args.src.available() <= 0 {
|
||||
if string_length > 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0001,
|
||||
length: string_length as base.u64)
|
||||
string_length = 0
|
||||
}
|
||||
if args.src.is_closed() {
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
if c <= 0x22 { // 0x22 is '"'.
|
||||
if c == 0x22 { // 0x22 is '"'.
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0000,
|
||||
length: string_length as base.u64)
|
||||
string_length = 0
|
||||
continue.string_loop
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
break.string_loop
|
||||
|
||||
if c <= 0x22 { // 0x22 is '"'.
|
||||
if c == 0x22 { // 0x22 is '"'.
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0000,
|
||||
length: string_length as base.u64)
|
||||
string_length = 0
|
||||
break.string_loop
|
||||
|
||||
} else if c < 0x20 { // 0x20 is ' '.
|
||||
if string_length > 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0001,
|
||||
length: string_length as base.u64)
|
||||
string_length = 0
|
||||
}
|
||||
return "#bad input"
|
||||
}
|
||||
|
||||
} else if c == 0x5C { // 0x5C is '\\'.
|
||||
} else if c < 0x20 { // 0x20 is ' '.
|
||||
if string_length > 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0001,
|
||||
length: string_length as base.u64)
|
||||
string_length = 0
|
||||
if args.dst.available() <= 0 {
|
||||
continue.string_loop
|
||||
}
|
||||
}
|
||||
assert args.dst.available() > 0
|
||||
|
||||
if args.src.available() < 2 {
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
continue.string_loop
|
||||
}
|
||||
backslash = (args.src.peek_u16le() >> 8) as base.u8
|
||||
c = backslashes[backslash]
|
||||
if c > 0 {
|
||||
args.src.skip32_fast!(actual: 2, worst_case: 2)
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x80_0000 | ((c & 0x7F) as base.u64),
|
||||
length: 2)
|
||||
continue.string_loop
|
||||
|
||||
} else if backslash == 0x75 { // 0x75 is 'u'.
|
||||
if args.src.available() < 6 {
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
continue.string_loop
|
||||
}
|
||||
uni4_string = (args.src.peek_u48le_as_u64() >> 16) as base.u32
|
||||
uni4_value = 0
|
||||
uni4_ok = 0x80
|
||||
c = hexadecimal_digits[0xFF & (uni4_string >> 0)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 12
|
||||
c = hexadecimal_digits[0xFF & (uni4_string >> 8)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 8
|
||||
c = hexadecimal_digits[0xFF & (uni4_string >> 16)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 4
|
||||
c = hexadecimal_digits[0xFF & (uni4_string >> 24)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 0
|
||||
if uni4_ok <> 0 {
|
||||
args.src.skip32_fast!(actual: 6, worst_case: 6)
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x80_0000 | (uni4_value as base.u64),
|
||||
length: 6)
|
||||
continue.string_loop
|
||||
}
|
||||
|
||||
}
|
||||
return "#bad input"
|
||||
}
|
||||
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
if string_length >= 0xFFFE {
|
||||
} else if c == 0x5C { // 0x5C is '\\'.
|
||||
if string_length > 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0001,
|
||||
length: 0xFFFF)
|
||||
length: string_length as base.u64)
|
||||
string_length = 0
|
||||
if args.dst.available() <= 0 {
|
||||
continue.string_loop
|
||||
}
|
||||
}
|
||||
assert args.dst.available() > 0
|
||||
|
||||
if args.src.available() < 2 {
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
continue.string_loop
|
||||
}
|
||||
string_length += 1
|
||||
}
|
||||
} // while.string_loop
|
||||
backslash = (args.src.peek_u16le() >> 8) as base.u8
|
||||
c = backslashes[backslash]
|
||||
if c > 0 {
|
||||
args.src.skip32_fast!(actual: 2, worst_case: 2)
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x80_0000 | ((c & 0x7F) as base.u64),
|
||||
length: 2)
|
||||
continue.string_loop
|
||||
|
||||
// The trailing '"' is filler.
|
||||
while true {
|
||||
if args.src.available() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
if args.dst.available() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue
|
||||
} else if backslash == 0x75 { // 0x75 is 'u'.
|
||||
if args.src.available() < 6 {
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
continue.string_loop
|
||||
}
|
||||
uni4_string = (args.src.peek_u48le_as_u64() >> 16) as base.u32
|
||||
uni4_value = 0
|
||||
uni4_ok = 0x80
|
||||
c = hexadecimal_digits[0xFF & (uni4_string >> 0)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 12
|
||||
c = hexadecimal_digits[0xFF & (uni4_string >> 8)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 8
|
||||
c = hexadecimal_digits[0xFF & (uni4_string >> 16)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 4
|
||||
c = hexadecimal_digits[0xFF & (uni4_string >> 24)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 0
|
||||
if uni4_ok <> 0 {
|
||||
args.src.skip32_fast!(actual: 6, worst_case: 6)
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x80_0000 | (uni4_value as base.u64),
|
||||
length: 6)
|
||||
continue.string_loop
|
||||
}
|
||||
|
||||
}
|
||||
return "#bad input"
|
||||
}
|
||||
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_fast_token!(
|
||||
value: 0,
|
||||
length: 1)
|
||||
break
|
||||
if string_length >= 0xFFFE {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x60_0001,
|
||||
length: 0xFFFF)
|
||||
string_length = 0
|
||||
continue.string_loop
|
||||
}
|
||||
string_length += 1
|
||||
}
|
||||
} // while.string_loop
|
||||
|
||||
// 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
|
||||
// The trailing '"' is filler.
|
||||
while true {
|
||||
if args.src.available() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
// -------- END parse strings.
|
||||
|
||||
} else if class == 0x02 { // 0x02 is CLASS_COMMA.
|
||||
if 0 == (expect & 0x04) { // 0x01 is EXPECT_COMMA.
|
||||
return "#bad input"
|
||||
if args.dst.available() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue
|
||||
}
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
// The ',' is filler.
|
||||
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.
|
||||
if 0 == (expect & 0x10) { // 0x10 is EXPECT_CLOSE_BRACKET
|
||||
expect = 0x02 // 0x02 is EXPECT_STRING_VALUE.
|
||||
} else {
|
||||
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.
|
||||
return "#bad input"
|
||||
}
|
||||
while true,
|
||||
pre args.dst.available() > 0,
|
||||
{
|
||||
number_length = this.decode_number!(src: args.src)
|
||||
number_status = number_length >> 8
|
||||
token_value = 0x40_0002
|
||||
if (number_length & 0x80) <> 0 {
|
||||
token_value = 0x40_0004
|
||||
}
|
||||
number_length = number_length & 0x7F
|
||||
if number_status == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: token_value,
|
||||
length: number_length as base.u64)
|
||||
break
|
||||
}
|
||||
|
||||
while number_length > 0 {
|
||||
number_length -= 1
|
||||
if args.src.can_undo_byte() {
|
||||
args.src.undo_byte!()
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
}
|
||||
|
||||
if number_status == 1 {
|
||||
return "#bad input"
|
||||
} else if number_status == 2 {
|
||||
return "#unsupported number length"
|
||||
} else {
|
||||
yield? base."$short read"
|
||||
while args.dst.available() <= 0,
|
||||
post args.dst.available() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
}
|
||||
}
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
// -------- END parse numbers.
|
||||
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 ':'.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
expect = 0x08 // 0x08 is EXPECT_COLON.
|
||||
continue.outer
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
// -------- END parse strings.
|
||||
|
||||
} else if class == 0x02 { // 0x02 is CLASS_COMMA.
|
||||
if 0 == (expect & 0x04) { // 0x01 is EXPECT_COMMA.
|
||||
return "#bad input"
|
||||
}
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
// The ',' is filler.
|
||||
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.
|
||||
if 0 == (expect & 0x10) { // 0x10 is EXPECT_CLOSE_BRACKET
|
||||
expect = 0x02 // 0x02 is EXPECT_STRING_VALUE.
|
||||
} else {
|
||||
expect = 0x03 // 0x03 is EXPECT_VALUE.
|
||||
}
|
||||
continue.outer
|
||||
|
||||
} else if class == 0x03 { // 0x03 is CLASS_COLON.
|
||||
if 0 == (expect & 0x08) { // 0x08 is EXPECT_COLON.
|
||||
return "#bad input"
|
||||
@@ -407,6 +357,104 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
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.
|
||||
return "#bad input"
|
||||
}
|
||||
while true,
|
||||
pre args.dst.available() > 0,
|
||||
{
|
||||
number_length = this.decode_number!(src: args.src)
|
||||
number_status = number_length >> 8
|
||||
token_value = 0x40_0002
|
||||
if (number_length & 0x80) <> 0 {
|
||||
token_value = 0x40_0004
|
||||
}
|
||||
number_length = number_length & 0x7F
|
||||
if number_status == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: token_value,
|
||||
length: number_length as base.u64)
|
||||
break
|
||||
}
|
||||
|
||||
while number_length > 0 {
|
||||
number_length -= 1
|
||||
if args.src.can_undo_byte() {
|
||||
args.src.undo_byte!()
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
}
|
||||
|
||||
if number_status == 1 {
|
||||
return "#bad input"
|
||||
} else if number_status == 2 {
|
||||
return "#unsupported number length"
|
||||
} else {
|
||||
yield? base."$short read"
|
||||
while args.dst.available() <= 0,
|
||||
post args.dst.available() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
}
|
||||
}
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
// -------- END parse numbers.
|
||||
|
||||
} 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 class == 0x07 { // 0x07 is CLASS_OPEN_SQUARE_BRACKET.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
@@ -458,104 +506,59 @@ 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.
|
||||
} else if class == 0x09 { // 0x09 is CLASS_FALSE.
|
||||
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 {
|
||||
match = args.src.match7(a: 0x6573_6C61_6605) // 5 bytes "false".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x20_0022,
|
||||
length: 1)
|
||||
break.outer
|
||||
value: 0x40_0041,
|
||||
length: 5)
|
||||
if args.src.available() < 5 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
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
|
||||
}
|
||||
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 {
|
||||
} else if class == 0x0A { // 0x0A is CLASS_TRUE.
|
||||
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
|
||||
match = args.src.match7(a: 0x65_7572_7404) // 4 bytes "true".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x40_0081,
|
||||
length: 4)
|
||||
if args.src.available() < 4 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
|
||||
} else if class == 0x09 { // 0x09 is CLASS_FALSE.
|
||||
match = args.src.match7(a: 0x6573_6C61_6605) // 5 bytes "false".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x40_0041,
|
||||
length: 5)
|
||||
if args.src.available() < 5 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
args.src.skip32_fast!(actual: 5, worst_case: 5)
|
||||
break.goto_parsed_a_leaf_value
|
||||
}
|
||||
|
||||
} else if class == 0x0A { // 0x0A is CLASS_TRUE.
|
||||
match = args.src.match7(a: 0x65_7572_7404) // 4 bytes "true".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0x40_0081,
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if match == 1 {
|
||||
} else if class == 0x0B { // 0x0B is CLASS_NULL.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
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