Factor out CHECK_AT macro

This commit is contained in:
David Tolnay 2022-07-22 18:47:09 -07:00
parent d9917668b4
commit 2e94cd3bdb
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
3 changed files with 56 additions and 134 deletions

View file

@ -1511,16 +1511,8 @@ unsafe fn yaml_emitter_analyze_scalar(
(*emitter).scalar_data.block_allowed = 0_i32; (*emitter).scalar_data.block_allowed = 0_i32;
return 1_i32; return 1_i32;
} }
if *string.pointer as libc::c_int == '-' as i32 as yaml_char_t as libc::c_int if CHECK_AT!(string, '-', 0) && CHECK_AT!(string, '-', 1) && CHECK_AT!(string, '-', 2)
&& *string.pointer.wrapping_offset(1_isize) as libc::c_int || CHECK_AT!(string, '.', 0) && CHECK_AT!(string, '.', 1) && CHECK_AT!(string, '.', 2)
== '-' as i32 as yaml_char_t as libc::c_int
&& *string.pointer.wrapping_offset(2_isize) as libc::c_int
== '-' as i32 as yaml_char_t as libc::c_int
|| *string.pointer as libc::c_int == '.' as i32 as yaml_char_t as libc::c_int
&& *string.pointer.wrapping_offset(1_isize) as libc::c_int
== '.' as i32 as yaml_char_t as libc::c_int
&& *string.pointer.wrapping_offset(2_isize) as libc::c_int
== '.' as i32 as yaml_char_t as libc::c_int
{ {
block_indicators = 1_i32; block_indicators = 1_i32;
flow_indicators = 1_i32; flow_indicators = 1_i32;

View file

@ -122,7 +122,9 @@ macro_rules! JOIN {
} }
macro_rules! CHECK_AT { macro_rules! CHECK_AT {
() => {}; // TODO ($string:expr, $octet:expr, $offset:expr) => {
*$string.pointer.offset($offset as isize) == $octet as yaml_char_t
};
} }
macro_rules! CHECK { macro_rules! CHECK {
@ -228,8 +230,7 @@ macro_rules! IS_PRINTABLE {
macro_rules! IS_Z_AT { macro_rules! IS_Z_AT {
($string:expr, $offset:expr) => { ($string:expr, $offset:expr) => {
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int CHECK_AT!($string, '\0', $offset)
== '\0' as i32 as yaml_char_t as libc::c_int
}; };
} }
@ -241,18 +242,15 @@ macro_rules! IS_Z {
macro_rules! IS_BOM { macro_rules! IS_BOM {
($string:expr) => { ($string:expr) => {
*$string.pointer as libc::c_int == -17i32 as yaml_char_t as libc::c_int CHECK_AT!($string, b'\xEF', 0)
&& *$string.pointer.wrapping_offset(1) as libc::c_int && CHECK_AT!($string, b'\xBB', 1)
== -69i32 as yaml_char_t as libc::c_int && CHECK_AT!($string, b'\xBF', 2)
&& *$string.pointer.wrapping_offset(2) as libc::c_int
== -65i32 as yaml_char_t as libc::c_int
}; };
} }
macro_rules! IS_SPACE_AT { macro_rules! IS_SPACE_AT {
($string:expr, $offset:expr) => { ($string:expr, $offset:expr) => {
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int CHECK_AT!($string, ' ', $offset)
== ' ' as i32 as yaml_char_t as libc::c_int
}; };
} }
@ -264,8 +262,7 @@ macro_rules! IS_SPACE {
macro_rules! IS_TAB_AT { macro_rules! IS_TAB_AT {
($string:expr, $offset:expr) => { ($string:expr, $offset:expr) => {
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int CHECK_AT!($string, '\t', $offset)
== '\t' as i32 as yaml_char_t as libc::c_int
}; };
} }
@ -289,26 +286,15 @@ macro_rules! IS_BLANK {
macro_rules! IS_BREAK_AT { macro_rules! IS_BREAK_AT {
($string:expr, $offset:expr) => { ($string:expr, $offset:expr) => {
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int CHECK_AT!($string, '\r', $offset)
== '\r' as i32 as yaml_char_t as libc::c_int || CHECK_AT!($string, '\n', $offset)
|| *$string.pointer.wrapping_offset($offset as isize) as libc::c_int || CHECK_AT!($string, b'\xC2', $offset) && CHECK_AT!($string, b'\x85', $offset + 1)
== '\n' as i32 as yaml_char_t as libc::c_int || CHECK_AT!($string, b'\xE2', $offset)
|| *$string.pointer.wrapping_offset($offset as isize) as libc::c_int && CHECK_AT!($string, b'\x80', $offset + 1)
== -62i32 as yaml_char_t as libc::c_int && CHECK_AT!($string, b'\xA8', $offset + 2)
&& *$string.pointer.wrapping_offset($offset as isize + 1) as libc::c_int || CHECK_AT!($string, b'\xE2', $offset)
== -123i32 as yaml_char_t as libc::c_int && CHECK_AT!($string, b'\x80', $offset + 1)
|| *$string.pointer.wrapping_offset($offset as isize) as libc::c_int && CHECK_AT!($string, b'\xA9', $offset + 2)
== -30i32 as yaml_char_t as libc::c_int
&& *$string.pointer.wrapping_offset($offset as isize + 1) as libc::c_int
== -128i32 as yaml_char_t as libc::c_int
&& *$string.pointer.wrapping_offset($offset as isize + 2) as libc::c_int
== -88i32 as yaml_char_t as libc::c_int
|| *$string.pointer.wrapping_offset($offset as isize) as libc::c_int
== -30i32 as yaml_char_t as libc::c_int
&& *$string.pointer.wrapping_offset($offset as isize + 1) as libc::c_int
== -128i32 as yaml_char_t as libc::c_int
&& *$string.pointer.wrapping_offset($offset as isize + 2) as libc::c_int
== -87i32 as yaml_char_t as libc::c_int
}; };
} }
@ -320,9 +306,7 @@ macro_rules! IS_BREAK {
macro_rules! IS_CRLF { macro_rules! IS_CRLF {
($string:expr) => { ($string:expr) => {
*$string.pointer as libc::c_int == '\r' as i32 as yaml_char_t as libc::c_int CHECK_AT!($string, '\r', 0) && CHECK_AT!($string, '\n', 1)
&& *$string.pointer.offset(1) as libc::c_int
== '\n' as i32 as yaml_char_t as libc::c_int
}; };
} }

View file

@ -89,11 +89,7 @@ macro_rules! READ {
macro_rules! READ_LINE { macro_rules! READ_LINE {
($parser:expr, $string:expr) => { ($parser:expr, $string:expr) => {
if STRING_EXTEND!($parser, $string) != 0 { if STRING_EXTEND!($parser, $string) != 0 {
if *((*$parser).buffer.pointer) as libc::c_int if CHECK_AT!((*$parser).buffer, '\r', 0) && CHECK_AT!((*$parser).buffer, '\n', 1) {
== '\r' as i32 as yaml_char_t as libc::c_int
&& *((*$parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int
== '\n' as i32 as yaml_char_t as libc::c_int
{
let fresh484 = addr_of_mut!($string.pointer); let fresh484 = addr_of_mut!($string.pointer);
let fresh485 = *fresh484; let fresh485 = *fresh484;
*fresh484 = (*fresh484).wrapping_offset(1); *fresh484 = (*fresh484).wrapping_offset(1);
@ -107,10 +103,7 @@ macro_rules! READ_LINE {
*fresh488 = (*fresh488).wrapping_add(1); *fresh488 = (*fresh488).wrapping_add(1);
let fresh489 = addr_of_mut!((*$parser).unread); let fresh489 = addr_of_mut!((*$parser).unread);
*fresh489 = (*fresh489 as libc::c_ulong).wrapping_sub(2_u64) as size_t as size_t; *fresh489 = (*fresh489 as libc::c_ulong).wrapping_sub(2_u64) as size_t as size_t;
} else if *((*$parser).buffer.pointer) as libc::c_int } else if CHECK_AT!((*$parser).buffer, '\r', 0) || CHECK_AT!((*$parser).buffer, '\n', 0)
== '\r' as i32 as yaml_char_t as libc::c_int
|| *((*$parser).buffer.pointer) as libc::c_int
== '\n' as i32 as yaml_char_t as libc::c_int
{ {
let fresh490 = addr_of_mut!($string.pointer); let fresh490 = addr_of_mut!($string.pointer);
let fresh491 = *fresh490; let fresh491 = *fresh490;
@ -125,10 +118,8 @@ macro_rules! READ_LINE {
*fresh494 = (*fresh494).wrapping_add(1); *fresh494 = (*fresh494).wrapping_add(1);
let fresh495 = addr_of_mut!((*$parser).unread); let fresh495 = addr_of_mut!((*$parser).unread);
*fresh495 = (*fresh495).wrapping_sub(1); *fresh495 = (*fresh495).wrapping_sub(1);
} else if *((*$parser).buffer.pointer) as libc::c_int } else if CHECK_AT!((*$parser).buffer, b'\xC2', 0)
== -62i32 as yaml_char_t as libc::c_int && CHECK_AT!((*$parser).buffer, b'\x85', 1)
&& *((*$parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int
== -123i32 as yaml_char_t as libc::c_int
{ {
let fresh496 = addr_of_mut!($string.pointer); let fresh496 = addr_of_mut!($string.pointer);
let fresh497 = *fresh496; let fresh497 = *fresh496;
@ -143,14 +134,10 @@ macro_rules! READ_LINE {
*fresh500 = (*fresh500).wrapping_add(1); *fresh500 = (*fresh500).wrapping_add(1);
let fresh501 = addr_of_mut!((*$parser).unread); let fresh501 = addr_of_mut!((*$parser).unread);
*fresh501 = (*fresh501).wrapping_sub(1); *fresh501 = (*fresh501).wrapping_sub(1);
} else if *((*$parser).buffer.pointer) as libc::c_int } else if CHECK_AT!((*$parser).buffer, b'\xE2', 0)
== -30i32 as yaml_char_t as libc::c_int && CHECK_AT!((*$parser).buffer, b'\x80', 1)
&& *((*$parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int && (CHECK_AT!((*$parser).buffer, b'\xA8', 2)
== -128i32 as yaml_char_t as libc::c_int || CHECK_AT!((*$parser).buffer, b'\xA9', 2))
&& (*((*$parser).buffer.pointer).wrapping_offset(2_isize) as libc::c_int
== -88i32 as yaml_char_t as libc::c_int
|| *((*$parser).buffer.pointer).wrapping_offset(2_isize) as libc::c_int
== -87i32 as yaml_char_t as libc::c_int)
{ {
let fresh502 = addr_of_mut!((*$parser).buffer.pointer); let fresh502 = addr_of_mut!((*$parser).buffer.pointer);
let fresh503 = *fresh502; let fresh503 = *fresh502;
@ -310,21 +297,17 @@ unsafe fn yaml_parser_fetch_next_token(parser: *mut yaml_parser_t) -> libc::c_in
return yaml_parser_fetch_directive(parser); return yaml_parser_fetch_directive(parser);
} }
if (*parser).mark.column == 0_u64 if (*parser).mark.column == 0_u64
&& *((*parser).buffer.pointer) as libc::c_int == '-' as i32 as yaml_char_t as libc::c_int && CHECK_AT!((*parser).buffer, '-', 0)
&& *((*parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int && CHECK_AT!((*parser).buffer, '-', 1)
== '-' as i32 as yaml_char_t as libc::c_int && CHECK_AT!((*parser).buffer, '-', 2)
&& *((*parser).buffer.pointer).wrapping_offset(2_isize) as libc::c_int
== '-' as i32 as yaml_char_t as libc::c_int
&& IS_BLANKZ_AT!((*parser).buffer, 3) && IS_BLANKZ_AT!((*parser).buffer, 3)
{ {
return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_START_TOKEN); return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_START_TOKEN);
} }
if (*parser).mark.column == 0_u64 if (*parser).mark.column == 0_u64
&& *((*parser).buffer.pointer) as libc::c_int == '.' as i32 as yaml_char_t as libc::c_int && CHECK_AT!((*parser).buffer, '.', 0)
&& *((*parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int && CHECK_AT!((*parser).buffer, '.', 1)
== '.' as i32 as yaml_char_t as libc::c_int && CHECK_AT!((*parser).buffer, '.', 2)
&& *((*parser).buffer.pointer).wrapping_offset(2_isize) as libc::c_int
== '.' as i32 as yaml_char_t as libc::c_int
&& IS_BLANKZ_AT!((*parser).buffer, 3) && IS_BLANKZ_AT!((*parser).buffer, 3)
{ {
return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_END_TOKEN); return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_END_TOKEN);
@ -1587,9 +1570,7 @@ unsafe fn yaml_parser_scan_tag(
let end_mark: yaml_mark_t; let end_mark: yaml_mark_t;
let start_mark: yaml_mark_t = (*parser).mark; let start_mark: yaml_mark_t = (*parser).mark;
if !(CACHE!(parser, 2_u64) == 0) { if !(CACHE!(parser, 2_u64) == 0) {
if *((*parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int if CHECK_AT!((*parser).buffer, '<', 1) {
== '<' as i32 as yaml_char_t as libc::c_int
{
handle = yaml_malloc(1_u64) as *mut yaml_char_t; handle = yaml_malloc(1_u64) as *mut yaml_char_t;
if handle.is_null() { if handle.is_null() {
current_block = 17708497480799081542; current_block = 17708497480799081542;
@ -2441,22 +2422,12 @@ unsafe fn yaml_parser_scan_flow_scalar(
break; break;
} }
if (*parser).mark.column == 0_u64 if (*parser).mark.column == 0_u64
&& (*((*parser).buffer.pointer) as libc::c_int && (CHECK_AT!((*parser).buffer, '-', 0)
== '-' as i32 as yaml_char_t as libc::c_int && CHECK_AT!((*parser).buffer, '-', 1)
&& *((*parser).buffer.pointer).wrapping_offset(1_isize) && CHECK_AT!((*parser).buffer, '-', 2)
as libc::c_int || CHECK_AT!((*parser).buffer, '.', 0)
== '-' as i32 as yaml_char_t as libc::c_int && CHECK_AT!((*parser).buffer, '.', 1)
&& *((*parser).buffer.pointer).wrapping_offset(2_isize) && CHECK_AT!((*parser).buffer, '.', 2))
as libc::c_int
== '-' as i32 as yaml_char_t as libc::c_int
|| *((*parser).buffer.pointer) as libc::c_int
== '.' as i32 as yaml_char_t as libc::c_int
&& *((*parser).buffer.pointer).wrapping_offset(1_isize)
as libc::c_int
== '.' as i32 as yaml_char_t as libc::c_int
&& *((*parser).buffer.pointer).wrapping_offset(2_isize)
as libc::c_int
== '.' as i32 as yaml_char_t as libc::c_int)
&& IS_BLANKZ_AT!((*parser).buffer, 3) && IS_BLANKZ_AT!((*parser).buffer, 3)
{ {
yaml_parser_set_scanner_error( yaml_parser_set_scanner_error(
@ -2488,11 +2459,8 @@ unsafe fn yaml_parser_scan_flow_scalar(
leading_blanks = 0_i32; leading_blanks = 0_i32;
while !IS_BLANKZ!((*parser).buffer) { while !IS_BLANKZ!((*parser).buffer) {
if single != 0 if single != 0
&& *((*parser).buffer.pointer) as libc::c_int && CHECK_AT!((*parser).buffer, '\'', 0)
== '\'' as i32 as yaml_char_t as libc::c_int && CHECK_AT!((*parser).buffer, '\'', 1)
&& *((*parser).buffer.pointer).wrapping_offset(1_isize)
as libc::c_int
== '\'' as i32 as yaml_char_t as libc::c_int
{ {
if STRING_EXTEND!(parser, string) == 0 { if STRING_EXTEND!(parser, string) == 0 {
current_block = 8114179180390253173; current_block = 8114179180390253173;
@ -2955,22 +2923,12 @@ unsafe fn yaml_parser_scan_plain_scalar(
break; break;
} }
if (*parser).mark.column == 0_u64 if (*parser).mark.column == 0_u64
&& (*((*parser).buffer.pointer) as libc::c_int && (CHECK_AT!((*parser).buffer, '-', 0)
== '-' as i32 as yaml_char_t as libc::c_int && CHECK_AT!((*parser).buffer, '-', 1)
&& *((*parser).buffer.pointer).wrapping_offset(1_isize) && CHECK_AT!((*parser).buffer, '-', 2)
as libc::c_int || CHECK_AT!((*parser).buffer, '.', 0)
== '-' as i32 as yaml_char_t as libc::c_int && CHECK_AT!((*parser).buffer, '.', 1)
&& *((*parser).buffer.pointer).wrapping_offset(2_isize) && CHECK_AT!((*parser).buffer, '.', 2))
as libc::c_int
== '-' as i32 as yaml_char_t as libc::c_int
|| *((*parser).buffer.pointer) as libc::c_int
== '.' as i32 as yaml_char_t as libc::c_int
&& *((*parser).buffer.pointer).wrapping_offset(1_isize)
as libc::c_int
== '.' as i32 as yaml_char_t as libc::c_int
&& *((*parser).buffer.pointer).wrapping_offset(2_isize)
as libc::c_int
== '.' as i32 as yaml_char_t as libc::c_int)
&& IS_BLANKZ_AT!((*parser).buffer, 3) && IS_BLANKZ_AT!((*parser).buffer, 3)
{ {
current_block = 6281126495347172768; current_block = 6281126495347172768;
@ -2986,24 +2944,12 @@ unsafe fn yaml_parser_scan_plain_scalar(
if (*parser).flow_level != 0 if (*parser).flow_level != 0
&& *((*parser).buffer.pointer) as libc::c_int && *((*parser).buffer.pointer) as libc::c_int
== ':' as i32 as yaml_char_t as libc::c_int == ':' as i32 as yaml_char_t as libc::c_int
&& (*((*parser).buffer.pointer).wrapping_offset(1_isize) && (CHECK_AT!((*parser).buffer, ',', 1)
as libc::c_int || CHECK_AT!((*parser).buffer, '?', 1)
== ',' as i32 as yaml_char_t as libc::c_int || CHECK_AT!((*parser).buffer, '[', 1)
|| *((*parser).buffer.pointer).wrapping_offset(1_isize) || CHECK_AT!((*parser).buffer, ']', 1)
as libc::c_int || CHECK_AT!((*parser).buffer, '{', 1)
== '?' as i32 as yaml_char_t as libc::c_int || CHECK_AT!((*parser).buffer, '}', 1))
|| *((*parser).buffer.pointer).wrapping_offset(1_isize)
as libc::c_int
== '[' as i32 as yaml_char_t as libc::c_int
|| *((*parser).buffer.pointer).wrapping_offset(1_isize)
as libc::c_int
== ']' as i32 as yaml_char_t as libc::c_int
|| *((*parser).buffer.pointer).wrapping_offset(1_isize)
as libc::c_int
== '{' as i32 as yaml_char_t as libc::c_int
|| *((*parser).buffer.pointer).wrapping_offset(1_isize)
as libc::c_int
== '}' as i32 as yaml_char_t as libc::c_int)
{ {
yaml_parser_set_scanner_error( yaml_parser_set_scanner_error(
parser, parser,