diff --git a/src/parser.rs b/src/parser.rs index 6e7ab29..21e8609 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -31,6 +31,16 @@ use crate::{ use core::mem::size_of; use core::ptr::{self, addr_of_mut}; +macro_rules! PEEK_TOKEN { + ($parser:expr) => { + if (*$parser).token_available != 0 || yaml_parser_fetch_more_tokens($parser) != 0 { + (*$parser).tokens.head + } else { + ptr::null_mut::() + } + }; +} + macro_rules! SKIP_TOKEN { ($parser:expr) => { (*$parser).token_available = 0_i32; @@ -163,12 +173,7 @@ unsafe fn yaml_parser_parse_stream_start( mut parser: *mut yaml_parser_t, mut event: *mut yaml_event_t, ) -> libc::c_int { - let token: *mut yaml_token_t = - if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + let token: *mut yaml_token_t = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -209,11 +214,7 @@ unsafe fn yaml_parser_parse_document_start( start: ptr::null_mut::(), end: ptr::null_mut::(), }; - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -222,12 +223,7 @@ unsafe fn yaml_parser_parse_document_start( == YAML_DOCUMENT_END_TOKEN as libc::c_int as libc::c_uint { SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 - { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -299,11 +295,7 @@ unsafe fn yaml_parser_parse_document_start( { return 0_i32; } - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if !token.is_null() { if (*token).type_ as libc::c_uint != YAML_DOCUMENT_START_TOKEN as libc::c_int as libc::c_uint @@ -380,12 +372,7 @@ unsafe fn yaml_parser_parse_document_content( mut parser: *mut yaml_parser_t, event: *mut yaml_event_t, ) -> libc::c_int { - let token: *mut yaml_token_t = - if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + let token: *mut yaml_token_t = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -411,12 +398,7 @@ unsafe fn yaml_parser_parse_document_end( ) -> libc::c_int { let mut end_mark: yaml_mark_t; let mut implicit: libc::c_int = 1_i32; - let token: *mut yaml_token_t = - if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + let token: *mut yaml_token_t = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -467,11 +449,7 @@ unsafe fn yaml_parser_parse_node( column: 0, }; let implicit: libc::c_int; - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -499,12 +477,7 @@ unsafe fn yaml_parser_parse_node( start_mark = (*token).start_mark; end_mark = (*token).end_mark; SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 - { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { current_block = 17786380918591080555; } else if (*token).type_ as libc::c_uint @@ -515,13 +488,7 @@ unsafe fn yaml_parser_parse_node( tag_mark = (*token).start_mark; end_mark = (*token).end_mark; SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 - || yaml_parser_fetch_more_tokens(parser) != 0 - { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { current_block = 17786380918591080555; } else { @@ -537,12 +504,7 @@ unsafe fn yaml_parser_parse_node( start_mark = tag_mark; end_mark = (*token).end_mark; SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 - { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { current_block = 17786380918591080555; } else if (*token).type_ as libc::c_uint @@ -551,13 +513,7 @@ unsafe fn yaml_parser_parse_node( anchor = (*token).data.anchor.value; end_mark = (*token).end_mark; SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 - || yaml_parser_fetch_more_tokens(parser) != 0 - { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { current_block = 17786380918591080555; } else { @@ -864,11 +820,7 @@ unsafe fn yaml_parser_parse_block_sequence_entry( ) -> libc::c_int { let mut token: *mut yaml_token_t; if first != 0 { - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if if (*parser).marks.top != (*parser).marks.end || yaml_stack_extend( addr_of_mut!((*parser).marks.start) as *mut *mut libc::c_void, @@ -890,22 +842,14 @@ unsafe fn yaml_parser_parse_block_sequence_entry( } SKIP_TOKEN!(parser); } - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } if (*token).type_ as libc::c_uint == YAML_BLOCK_ENTRY_TOKEN as libc::c_int as libc::c_uint { let mark: yaml_mark_t = (*token).end_mark; SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -971,22 +915,14 @@ unsafe fn yaml_parser_parse_indentless_sequence_entry( mut event: *mut yaml_event_t, ) -> libc::c_int { let mut token: *mut yaml_token_t; - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } if (*token).type_ as libc::c_uint == YAML_BLOCK_ENTRY_TOKEN as libc::c_int as libc::c_uint { let mark: yaml_mark_t = (*token).end_mark; SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1042,11 +978,7 @@ unsafe fn yaml_parser_parse_block_mapping_key( ) -> libc::c_int { let mut token: *mut yaml_token_t; if first != 0 { - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if if (*parser).marks.top != (*parser).marks.end || yaml_stack_extend( addr_of_mut!((*parser).marks.start) as *mut *mut libc::c_void, @@ -1068,22 +1000,14 @@ unsafe fn yaml_parser_parse_block_mapping_key( } SKIP_TOKEN!(parser); } - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } if (*token).type_ as libc::c_uint == YAML_KEY_TOKEN as libc::c_int as libc::c_uint { let mark: yaml_mark_t = (*token).end_mark; SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1150,22 +1074,14 @@ unsafe fn yaml_parser_parse_block_mapping_value( event: *mut yaml_event_t, ) -> libc::c_int { let mut token: *mut yaml_token_t; - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } if (*token).type_ as libc::c_uint == YAML_VALUE_TOKEN as libc::c_int as libc::c_uint { let mark: yaml_mark_t = (*token).end_mark; SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1210,11 +1126,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry( ) -> libc::c_int { let mut token: *mut yaml_token_t; if first != 0 { - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if if (*parser).marks.top != (*parser).marks.end || yaml_stack_extend( addr_of_mut!((*parser).marks.start) as *mut *mut libc::c_void, @@ -1236,11 +1148,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry( } SKIP_TOKEN!(parser); } - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1251,13 +1159,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry( == YAML_FLOW_ENTRY_TOKEN as libc::c_int as libc::c_uint { SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 - || yaml_parser_fetch_more_tokens(parser) != 0 - { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1337,12 +1239,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_key( mut parser: *mut yaml_parser_t, event: *mut yaml_event_t, ) -> libc::c_int { - let token: *mut yaml_token_t = - if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + let token: *mut yaml_token_t = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1384,21 +1281,13 @@ unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_value( event: *mut yaml_event_t, ) -> libc::c_int { let mut token: *mut yaml_token_t; - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } if (*token).type_ as libc::c_uint == YAML_VALUE_TOKEN as libc::c_int as libc::c_uint { SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1436,12 +1325,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_end( mut parser: *mut yaml_parser_t, mut event: *mut yaml_event_t, ) -> libc::c_int { - let token: *mut yaml_token_t = - if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + let token: *mut yaml_token_t = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1464,11 +1348,7 @@ unsafe fn yaml_parser_parse_flow_mapping_key( ) -> libc::c_int { let mut token: *mut yaml_token_t; if first != 0 { - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if if (*parser).marks.top != (*parser).marks.end || yaml_stack_extend( addr_of_mut!((*parser).marks.start) as *mut *mut libc::c_void, @@ -1490,11 +1370,7 @@ unsafe fn yaml_parser_parse_flow_mapping_key( } SKIP_TOKEN!(parser); } - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1505,13 +1381,7 @@ unsafe fn yaml_parser_parse_flow_mapping_key( == YAML_FLOW_ENTRY_TOKEN as libc::c_int as libc::c_uint { SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 - || yaml_parser_fetch_more_tokens(parser) != 0 - { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1529,12 +1399,7 @@ unsafe fn yaml_parser_parse_flow_mapping_key( } if (*token).type_ as libc::c_uint == YAML_KEY_TOKEN as libc::c_int as libc::c_uint { SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 - { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1616,11 +1481,7 @@ unsafe fn yaml_parser_parse_flow_mapping_value( empty: libc::c_int, ) -> libc::c_int { let mut token: *mut yaml_token_t; - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1630,11 +1491,7 @@ unsafe fn yaml_parser_parse_flow_mapping_value( } if (*token).type_ as libc::c_uint == YAML_VALUE_TOKEN as libc::c_int as libc::c_uint { SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { return 0_i32; } @@ -1747,11 +1604,7 @@ unsafe fn yaml_parser_process_directives( 0_i32 } == 0) { - token = if (*parser).token_available != 0 || yaml_parser_fetch_more_tokens(parser) != 0 { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if !token.is_null() { loop { if !((*token).type_ as libc::c_uint @@ -1833,13 +1686,7 @@ unsafe fn yaml_parser_process_directives( } } SKIP_TOKEN!(parser); - token = if (*parser).token_available != 0 - || yaml_parser_fetch_more_tokens(parser) != 0 - { - (*parser).tokens.head - } else { - ptr::null_mut::() - }; + token = PEEK_TOKEN!(parser); if token.is_null() { current_block = 17143798186130252483; break;