From 2eb2b22c49e6000dcf71865f21ae07e428efe5dc Mon Sep 17 00:00:00 2001 From: Akos Kiss Date: Sun, 7 Aug 2016 00:58:56 +0200 Subject: [PATCH] Rewrite `parser_boolean_t` to `bool` And `PARSER_{TRUE,FALSE}` to `{true,false}`. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu --- jerry-core/parser/js/js-lexer.c | 94 +++++++++++------------ jerry-core/parser/js/js-parser-expr.c | 34 ++++---- jerry-core/parser/js/js-parser-internal.h | 21 ++--- jerry-core/parser/js/js-parser-scanner.c | 90 +++++++++++----------- jerry-core/parser/js/js-parser-statm.c | 46 +++++------ jerry-core/parser/js/js-parser-util.c | 2 +- jerry-core/parser/js/js-parser.c | 20 ++--- 7 files changed, 149 insertions(+), 158 deletions(-) diff --git a/jerry-core/parser/js/js-lexer.c b/jerry-core/parser/js/js-lexer.c index 85ea3bbb5..9fa5bf752 100644 --- a/jerry-core/parser/js/js-lexer.c +++ b/jerry-core/parser/js/js-lexer.c @@ -106,7 +106,7 @@ skip_spaces (parser_context_t *context_p) /**< context */ context_p->token.was_newline = 0; - while (PARSER_TRUE) + while (true) { if (context_p->source_p >= source_end_p) { @@ -419,7 +419,7 @@ static const keyword_string_t * const keyword_string_list[9] = */ static void lexer_parse_identifier (parser_context_t *context_p, /**< context */ - int check_keywords) /**< check keywords */ + bool check_keywords) /**< check keywords */ { /* Only very few identifiers contains \u escape sequences. */ const uint8_t *source_p = context_p->source_p; @@ -430,9 +430,9 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */ size_t length = 0; context_p->token.type = LEXER_LITERAL; - context_p->token.literal_is_reserved = PARSER_FALSE; + context_p->token.literal_is_reserved = false; context_p->token.lit_location.type = LEXER_IDENT_LITERAL; - context_p->token.lit_location.has_escape = PARSER_FALSE; + context_p->token.lit_location.has_escape = false; do { @@ -440,7 +440,7 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */ { uint16_t character; - context_p->token.lit_location.has_escape = PARSER_TRUE; + context_p->token.lit_location.has_escape = true; context_p->source_p = source_p; context_p->token.column = column; @@ -520,7 +520,7 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */ parser_raise_error (context_p, PARSER_ERR_STRICT_IDENT_NOT_ALLOWED); } - context_p->token.literal_is_reserved = PARSER_TRUE; + context_p->token.literal_is_reserved = true; break; } @@ -558,9 +558,9 @@ lexer_parse_string (parser_context_t *context_p) /**< context */ parser_line_counter_t original_line = line; parser_line_counter_t original_column = column; size_t length = 0; - uint8_t has_escape = PARSER_FALSE; + uint8_t has_escape = false; - while (PARSER_TRUE) + while (true) { if (source_p >= source_end_p) { @@ -584,7 +584,7 @@ lexer_parse_string (parser_context_t *context_p) /**< context */ continue; } - has_escape = PARSER_TRUE; + has_escape = true; /* Newline is ignored. */ if (*source_p == LIT_CHAR_CR @@ -697,7 +697,7 @@ lexer_parse_string (parser_context_t *context_p) /**< context */ * after a backslash). Always converted to two 3 byte * long sequence. */ length += 2 * 3; - has_escape = PARSER_TRUE; + has_escape = true; source_p += 4; column++; continue; @@ -755,15 +755,15 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ { const uint8_t *source_p = context_p->source_p; const uint8_t *source_end_p = context_p->source_end_p; - int can_be_float = PARSER_FALSE; + bool can_be_float = false; size_t length; context_p->token.type = LEXER_LITERAL; - context_p->token.literal_is_reserved = PARSER_FALSE; + context_p->token.literal_is_reserved = false; context_p->token.extra_value = LEXER_NUMBER_DECIMAL; context_p->token.lit_location.char_p = source_p; context_p->token.lit_location.type = LEXER_NUMBER_LITERAL; - context_p->token.lit_location.has_escape = PARSER_FALSE; + context_p->token.lit_location.has_escape = false; if (source_p[0] == LIT_CHAR_0 && source_p + 1 < source_end_p) @@ -818,7 +818,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ } else { - can_be_float = PARSER_TRUE; + can_be_float = true; source_p++; } } @@ -832,7 +832,7 @@ lexer_parse_number (parser_context_t *context_p) /**< context */ && source_p[0] >= LIT_CHAR_0 && source_p[0] <= LIT_CHAR_9); - can_be_float = PARSER_TRUE; + can_be_float = true; } if (can_be_float) @@ -987,7 +987,7 @@ lexer_next_token (parser_context_t *context_p) /**< context */ if (lit_char_is_identifier_start (context_p->source_p) || context_p->source_p[0] == LIT_CHAR_BACKSLASH) { - lexer_parse_identifier (context_p, PARSER_TRUE); + lexer_parse_identifier (context_p, true); return; } @@ -1160,7 +1160,7 @@ lexer_process_char_literal (parser_context_t *context_p, /**< context */ const uint8_t *char_p, /**< characters */ size_t length, /**< length of string */ uint8_t literal_type, /**< final literal type */ - uint8_t has_escape) /**< has escape sequences */ + bool has_escape) /**< has escape sequences */ { parser_list_iterator_t literal_iterator; lexer_literal_t *literal_p; @@ -1282,7 +1282,7 @@ lexer_construct_literal_object (parser_context_t *context_p, /**< context */ { uint8_t str_end_character = source_p[-1]; - while (PARSER_TRUE) + while (true) { if (*source_p == str_end_character) { @@ -1514,12 +1514,12 @@ lexer_construct_literal_object (parser_context_t *context_p, /**< context */ /** * Construct a number object. * - * @return PARSER_TRUE if number is small number + * @return true if number is small number */ -int +bool lexer_construct_number_object (parser_context_t *context_p, /**< context */ - int push_number_allowed, /**< push number support is allowed */ - int is_negative_number) /**< sign is negative */ + bool push_number_allowed, /**< push number support is allowed */ + bool is_negative_number) /**< sign is negative */ { parser_list_iterator_t literal_iterator; lexer_literal_t *literal_p; @@ -1556,7 +1556,7 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */ && (int_num != 0 || !is_negative_number)) { context_p->lit_object.index = (uint16_t) int_num; - return PARSER_TRUE; + return true; } } } @@ -1576,7 +1576,7 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */ { context_p->lit_object.literal_p = literal_p; context_p->lit_object.index = (uint16_t) literal_index; - return PARSER_FALSE; + return false; } literal_index++; @@ -1603,7 +1603,7 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */ context_p->lit_object.index = (uint16_t) literal_index; context_p->lit_object.type = LEXER_LITERAL_OBJECT_ANY; - return PARSER_FALSE; + return false; } /* lexer_construct_number_object */ /** @@ -1647,7 +1647,7 @@ lexer_construct_function_object (parser_context_t *context_p, /**< context */ */ void lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ - int parse_only) /**< parse only */ + bool parse_only) /**< parse only */ { #ifndef CONFIG_DISABLE_REGEXP_BUILTIN const uint8_t *source_p = context_p->source_p; @@ -1656,7 +1656,7 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ const uint8_t *source_end_p = context_p->source_end_p; parser_line_counter_t column = context_p->column; lexer_literal_t *literal_p; - int in_class = PARSER_FALSE; + bool in_class = false; uint16_t current_flags; lit_utf8_size_t length; @@ -1668,7 +1668,7 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ regex_start_p--; } - while (PARSER_TRUE) + while (true) { if (source_p >= source_end_p) { @@ -1705,12 +1705,12 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ } case LIT_CHAR_LEFT_SQUARE: { - in_class = PARSER_TRUE; + in_class = true; break; } case LIT_CHAR_RIGHT_SQUARE: { - in_class = PARSER_FALSE; + in_class = false; break; } case LIT_CHAR_BACKSLASH: @@ -1829,7 +1829,7 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ literal_p->u.bytecode_p = (ecma_compiled_code_t *) re_bytecode_p; context_p->token.type = LEXER_LITERAL; - context_p->token.literal_is_reserved = PARSER_FALSE; + context_p->token.literal_is_reserved = false; context_p->token.lit_location.type = LEXER_REGEXP_LITERAL; context_p->lit_object.literal_p = literal_p; @@ -1895,12 +1895,12 @@ lexer_expect_identifier (parser_context_t *context_p, /**< context */ static const lexer_lit_location_t lexer_get_literal = { - (const uint8_t *) "get", 3, LEXER_IDENT_LITERAL, PARSER_FALSE + (const uint8_t *) "get", 3, LEXER_IDENT_LITERAL, false }; static const lexer_lit_location_t lexer_set_literal = { - (const uint8_t *) "set", 3, LEXER_IDENT_LITERAL, PARSER_FALSE + (const uint8_t *) "set", 3, LEXER_IDENT_LITERAL, false }; /** @@ -1908,7 +1908,7 @@ static const lexer_lit_location_t lexer_set_literal = */ void lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ - int must_be_identifier) /**< only identifiers are accepted */ + bool must_be_identifier) /**< only identifiers are accepted */ { skip_spaces (context_p); @@ -1917,11 +1917,11 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ if (context_p->source_p < context_p->source_end_p) { - int create_literal_object = PARSER_FALSE; + bool create_literal_object = false; if (lit_char_is_identifier_start (context_p->source_p) || context_p->source_p[0] == LIT_CHAR_BACKSLASH) { - lexer_parse_identifier (context_p, PARSER_FALSE); + lexer_parse_identifier (context_p, false); if (!must_be_identifier && context_p->token.lit_location.length == 3) @@ -1944,13 +1944,13 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ } } - create_literal_object = PARSER_TRUE; + create_literal_object = true; } else if (context_p->source_p[0] == LIT_CHAR_DOUBLE_QUOTE || context_p->source_p[0] == LIT_CHAR_SINGLE_QUOTE) { lexer_parse_string (context_p); - create_literal_object = PARSER_TRUE; + create_literal_object = true; } else if (!must_be_identifier && context_p->source_p[0] == LIT_CHAR_RIGHT_BRACE) { @@ -1973,7 +1973,7 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ && char_p[0] <= LIT_CHAR_9) { lexer_parse_number (context_p); - lexer_construct_number_object (context_p, PARSER_FALSE, PARSER_FALSE); + lexer_construct_number_object (context_p, false, false); return; } } @@ -1995,7 +1995,7 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ */ void lexer_scan_identifier (parser_context_t *context_p, /**< context */ - int propety_name) /**< property name */ + bool propety_name) /**< property name */ { skip_spaces (context_p); context_p->token.line = context_p->line; @@ -2004,7 +2004,7 @@ lexer_scan_identifier (parser_context_t *context_p, /**< context */ if (context_p->source_p < context_p->source_end_p && (lit_char_is_identifier_start (context_p->source_p) || context_p->source_p[0] == LIT_CHAR_BACKSLASH)) { - lexer_parse_identifier (context_p, PARSER_FALSE); + lexer_parse_identifier (context_p, false); if (propety_name && context_p->token.lit_location.length == 3) { @@ -2044,9 +2044,9 @@ lexer_scan_identifier (parser_context_t *context_p, /**< context */ * Compares the given identifier to that which is the current token * in the parser context. * - * @return non-zero if the input identifiers are the same + * @return true if the input identifiers are the same */ -int +bool lexer_compare_identifier_to_current (parser_context_t *context_p, /**< context */ const lexer_lit_location_t *right) /**< identifier */ { @@ -2081,7 +2081,7 @@ lexer_compare_identifier_to_current (parser_context_t *context_p, /**< co { if (*left_p++ != *right_p++) { - return PARSER_FALSE; + return false; } count--; continue; @@ -2093,7 +2093,7 @@ lexer_compare_identifier_to_current (parser_context_t *context_p, /**< co if (left_chr != lexer_hex_to_character (context_p, right_p, 6)) { - return PARSER_FALSE; + return false; } left_p += 6; @@ -2120,7 +2120,7 @@ lexer_compare_identifier_to_current (parser_context_t *context_p, /**< co { if (utf8_buf[offset] != *right_p++) { - return PARSER_FALSE; + return false; } offset++; } @@ -2130,7 +2130,7 @@ lexer_compare_identifier_to_current (parser_context_t *context_p, /**< co } while (count > 0); - return PARSER_TRUE; + return true; } /* lexer_compare_identifier_to_current */ /** diff --git a/jerry-core/parser/js/js-parser-expr.c b/jerry-core/parser/js/js-parser-expr.c index 97ece27a6..f8763bcb8 100644 --- a/jerry-core/parser/js/js-parser-expr.c +++ b/jerry-core/parser/js/js-parser-expr.c @@ -213,7 +213,7 @@ parser_parse_array_literal (parser_context_t *context_p) /**< context */ parser_emit_cbc (context_p, CBC_CREATE_ARRAY); lexer_next_token (context_p); - while (PARSER_TRUE) + while (true) { if (context_p->token.type == LEXER_RIGHT_SQUARE) { @@ -279,7 +279,7 @@ parser_append_object_literal_item (parser_context_t *context_p, /**< context */ iterator.current_p = context_p->stack.first_p; iterator.current_position = context_p->stack.last_position; - while (PARSER_TRUE) + while (true) { current_item_type_p = iterator.current_p->bytes + iterator.current_position - 1; @@ -362,9 +362,9 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */ parser_stack_push_uint8 (context_p, PARSER_OBJECT_PROPERTY_START); - while (PARSER_TRUE) + while (true) { - lexer_expect_object_literal_id (context_p, PARSER_FALSE); + lexer_expect_object_literal_id (context_p, false); if (context_p->token.type == LEXER_RIGHT_BRACE) { @@ -397,7 +397,7 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */ status_flags |= PARSER_RESOLVE_THIS_FOR_CALLS; } - lexer_expect_object_literal_id (context_p, PARSER_TRUE); + lexer_expect_object_literal_id (context_p, true); literal_index = context_p->lit_object.index; parser_append_object_literal_item (context_p, literal_index, item_type); @@ -463,7 +463,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ int new_was_seen = 0; /* Collect unary operators. */ - while (PARSER_TRUE) + while (true) { /* Convert plus and minus binary operators to unary operators. */ if (context_p->token.type == LEXER_ADD) @@ -513,7 +513,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ } else if (context_p->token.lit_location.type == LEXER_NUMBER_LITERAL) { - int is_negative_number = PARSER_FALSE; + bool is_negative_number = false; while (context_p->stack_top_uint8 == LEXER_PLUS || context_p->stack_top_uint8 == LEXER_NEGATE) @@ -525,7 +525,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ parser_stack_pop_uint8 (context_p); } - if (lexer_construct_number_object (context_p, PARSER_TRUE, is_negative_number)) + if (lexer_construct_number_object (context_p, true, is_negative_number)) { JERRY_ASSERT (context_p->lit_object.index <= CBC_PUSH_NUMBER_BYTE_RANGE_END); @@ -642,7 +642,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ case LEXER_DIVIDE: case LEXER_ASSIGN_DIVIDE: { - lexer_construct_regexp_object (context_p, PARSER_FALSE); + lexer_construct_regexp_object (context_p, false); if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) { @@ -702,7 +702,7 @@ static void parser_process_unary_expression (parser_context_t *context_p) /**< context */ { /* Parse postfix part of a primary expression. */ - while (PARSER_TRUE) + while (true) { /* Since break would only break the switch, we use * continue to continue this loop. Without continue, @@ -772,7 +772,7 @@ parser_process_unary_expression (parser_context_t *context_p) /**< context */ { size_t call_arguments = 0; uint16_t opcode = CBC_CALL; - int is_eval = PARSER_FALSE; + bool is_eval = false; parser_push_result (context_p); @@ -788,7 +788,7 @@ parser_process_unary_expression (parser_context_t *context_p) /**< context */ { JERRY_ASSERT (context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL); context_p->status_flags |= PARSER_ARGUMENTS_NEEDED | PARSER_LEXICAL_ENV_NEEDED | PARSER_NO_REG_STORE; - is_eval = PARSER_TRUE; + is_eval = true; } if (context_p->last_cbc_opcode == CBC_PUSH_PROP) @@ -844,7 +844,7 @@ parser_process_unary_expression (parser_context_t *context_p) /**< context */ if (context_p->token.type != LEXER_RIGHT_PAREN) { - while (PARSER_TRUE) + while (true) { if (++call_arguments > CBC_MAXIMUM_BYTE_VALUE) { @@ -958,7 +958,7 @@ parser_process_unary_expression (parser_context_t *context_p) /**< context */ } /* Generate byte code for the unary operators. */ - while (PARSER_TRUE) + while (true) { uint8_t token = context_p->stack_top_uint8; if (!LEXER_IS_UNARY_OP_TOKEN (token)) @@ -1238,7 +1238,7 @@ static void parser_process_binary_opcodes (parser_context_t *context_p, /**< context */ uint8_t min_prec_treshold) /**< minimal precedence of tokens */ { - while (PARSER_TRUE) + while (true) { uint8_t token = context_p->stack_top_uint8; cbc_opcode_t opcode; @@ -1348,7 +1348,7 @@ parser_parse_expression (parser_context_t *context_p, /**< context */ parser_stack_push_uint8 (context_p, LEXER_EXPRESSION_START); - while (PARSER_TRUE) + while (true) { if (options & PARSE_EXPR_HAS_LITERAL) { @@ -1361,7 +1361,7 @@ parser_parse_expression (parser_context_t *context_p, /**< context */ parser_parse_unary_expression (context_p, &grouping_level); } - while (PARSER_TRUE) + while (true) { parser_process_unary_expression (context_p); diff --git a/jerry-core/parser/js/js-parser-internal.h b/jerry-core/parser/js/js-parser-internal.h index 6c4b64345..90e4fe943 100644 --- a/jerry-core/parser/js/js-parser-internal.h +++ b/jerry-core/parser/js/js-parser-internal.h @@ -72,15 +72,6 @@ #define PARSER_MINUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) - (value)) #define PARSER_PLUS_EQUAL_LC(base, value) (base) = (parser_line_counter_t) ((base) + (value)) -/** - * Parser boolean type. - */ -typedef enum -{ - PARSER_FALSE = 0, /**< false constant */ - PARSER_TRUE = 1 /**< true constant */ -} parser_boolean_t; - /** * Argument for a compact-byte code. */ @@ -327,7 +318,7 @@ void parser_emit_cbc (parser_context_t *, uint16_t); void parser_emit_cbc_literal (parser_context_t *, uint16_t, uint16_t); void parser_emit_cbc_literal_from_token (parser_context_t *, uint16_t); void parser_emit_cbc_call (parser_context_t *, uint16_t, size_t); -void parser_emit_cbc_push_number (parser_context_t *, int); +void parser_emit_cbc_push_number (parser_context_t *, bool); void parser_emit_cbc_forward_branch (parser_context_t *, uint16_t, parser_branch_t *); parser_branch_node_t *parser_emit_cbc_forward_branch_item (parser_context_t *, uint16_t, parser_branch_node_t *); void parser_emit_cbc_backward_branch (parser_context_t *, uint16_t, uint32_t); @@ -351,14 +342,14 @@ void parser_set_continues_to_current_position (parser_context_t *, parser_branch void lexer_next_token (parser_context_t *); void lexer_expect_identifier (parser_context_t *, uint8_t); -void lexer_scan_identifier (parser_context_t *, int); +void lexer_scan_identifier (parser_context_t *, bool); ecma_char_t lexer_hex_to_character (parser_context_t *context_p, const uint8_t *source_p, int length); -void lexer_expect_object_literal_id (parser_context_t *, int); +void lexer_expect_object_literal_id (parser_context_t *, bool); void lexer_construct_literal_object (parser_context_t *, lexer_lit_location_t *, uint8_t); -int lexer_construct_number_object (parser_context_t *, int, int); +bool lexer_construct_number_object (parser_context_t *, bool, bool); void lexer_construct_function_object (parser_context_t *, uint32_t); -void lexer_construct_regexp_object (parser_context_t *, int); -int lexer_compare_identifier_to_current (parser_context_t *, const lexer_lit_location_t *); +void lexer_construct_regexp_object (parser_context_t *, bool); +bool lexer_compare_identifier_to_current (parser_context_t *, const lexer_lit_location_t *); /* Parser functions. */ diff --git a/jerry-core/parser/js/js-parser-scanner.c b/jerry-core/parser/js/js-parser-scanner.c index b183d72a1..674e78266 100644 --- a/jerry-core/parser/js/js-parser-scanner.c +++ b/jerry-core/parser/js/js-parser-scanner.c @@ -60,9 +60,9 @@ typedef enum /** * Scan primary expression. * - * @return PARSER_TRUE for continue, PARSER_FALSE for break + * @return true for continue, false for break */ -static int +static bool parser_scan_primary_expression (parser_context_t *context_p, /**< context */ lexer_token_type_t type, /**< current token type */ scan_stack_modes_t stack_top, /**< current stack top */ @@ -78,7 +78,7 @@ parser_scan_primary_expression (parser_context_t *context_p, /**< context */ case LEXER_DIVIDE: case LEXER_ASSIGN_DIVIDE: { - lexer_construct_regexp_object (context_p, PARSER_TRUE); + lexer_construct_regexp_object (context_p, true); *mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; break; } @@ -104,7 +104,7 @@ parser_scan_primary_expression (parser_context_t *context_p, /**< context */ { parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); *mode = SCAN_MODE_PROPERTY_NAME; - return PARSER_TRUE; + return true; } case LEXER_LITERAL: case LEXER_KEYW_THIS: @@ -164,15 +164,15 @@ parser_scan_primary_expression (parser_context_t *context_p, /**< context */ parser_raise_error (context_p, PARSER_ERR_PRIMARY_EXP_EXPECTED); } } - return PARSER_FALSE; + return false; } /* parser_scan_primary_expression */ /** * Scan the tokens after the primary expression. * - * @return PARSER_TRUE for break, PARSER_FALSE for fall through + * @return true for break, false for fall through */ -static int +static bool parser_scan_post_primary_expression (parser_context_t *context_p, /**< context */ lexer_token_type_t type, /**< current token type */ scan_modes_t *mode) /**< scan mode */ @@ -181,20 +181,20 @@ parser_scan_post_primary_expression (parser_context_t *context_p, /**< context * { case LEXER_DOT: { - lexer_scan_identifier (context_p, PARSER_FALSE); - return PARSER_TRUE; + lexer_scan_identifier (context_p, false); + return true; } case LEXER_LEFT_PAREN: { parser_stack_push_uint8 (context_p, SCAN_STACK_PAREN_EXPRESSION); *mode = SCAN_MODE_PRIMARY_EXPRESSION; - return PARSER_TRUE; + return true; } case LEXER_LEFT_SQUARE: { parser_stack_push_uint8 (context_p, SCAN_STACK_SQUARE_BRACKETED_EXPRESSION); *mode = SCAN_MODE_PRIMARY_EXPRESSION; - return PARSER_TRUE; + return true; } case LEXER_INCREASE: case LEXER_DECREASE: @@ -202,7 +202,7 @@ parser_scan_post_primary_expression (parser_context_t *context_p, /**< context * if (!context_p->token.was_newline) { *mode = SCAN_MODE_PRIMARY_EXPRESSION_END; - return PARSER_TRUE; + return true; } /* FALLTHRU */ } @@ -212,15 +212,15 @@ parser_scan_post_primary_expression (parser_context_t *context_p, /**< context * } } - return PARSER_FALSE; + return false; } /* parser_scan_post_primary_expression */ /** * Scan the tokens after the primary expression. * - * @return PARSER_TRUE for continue, PARSER_FALSE for break + * @return true for continue, false for break */ -static int +static bool parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */ lexer_token_type_t type, /**< current token type */ scan_stack_modes_t stack_top, /**< current stack top */ @@ -233,17 +233,17 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */ { parser_stack_push_uint8 (context_p, SCAN_STACK_COLON_EXPRESSION); *mode = SCAN_MODE_PRIMARY_EXPRESSION; - return PARSER_FALSE; + return false; } case LEXER_COMMA: { if (stack_top == SCAN_STACK_OBJECT_LITERAL) { *mode = SCAN_MODE_PROPERTY_NAME; - return PARSER_TRUE; + return true; } *mode = SCAN_MODE_PRIMARY_EXPRESSION; - return PARSER_FALSE; + return false; } case LEXER_COLON: { @@ -259,7 +259,7 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */ *mode = SCAN_MODE_STATEMENT; } parser_stack_pop_uint8 (context_p); - return PARSER_FALSE; + return false; } /* FALLTHRU */ } @@ -273,7 +273,7 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */ || (type == LEXER_SEMICOLON && stack_top == SCAN_STACK_PAREN_STATEMENT)) { *mode = SCAN_MODE_PRIMARY_EXPRESSION; - return PARSER_FALSE; + return false; } if ((type == LEXER_RIGHT_SQUARE && stack_top == SCAN_STACK_SQUARE_BRACKETED_EXPRESSION) @@ -282,14 +282,14 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */ { parser_stack_pop_uint8 (context_p); *mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; - return PARSER_FALSE; + return false; } *mode = SCAN_MODE_STATEMENT; if (type == LEXER_RIGHT_PAREN && stack_top == SCAN_STACK_PAREN_STATEMENT) { parser_stack_pop_uint8 (context_p); - return PARSER_FALSE; + return false; } /* Check whether we can enter to statement mode. */ @@ -303,7 +303,7 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */ if (type == LEXER_RIGHT_BRACE || context_p->token.was_newline) { - return PARSER_TRUE; + return true; } if (type != LEXER_SEMICOLON) @@ -311,15 +311,15 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */ parser_raise_error (context_p, PARSER_ERR_INVALID_EXPRESSION); } - return PARSER_FALSE; + return false; } /* parser_scan_primary_expression_end */ /** * Scan statements. * - * @return PARSER_TRUE for continue, PARSER_FALSE for break + * @return true for continue, false for break */ -static int +static bool parser_scan_statement (parser_context_t *context_p, /**< context */ lexer_token_type_t type, /**< current token type */ scan_stack_modes_t stack_top, /**< current stack top */ @@ -334,7 +334,7 @@ parser_scan_statement (parser_context_t *context_p, /**< context */ case LEXER_KEYW_FINALLY: case LEXER_KEYW_DEBUGGER: { - return PARSER_FALSE; + return false; } case LEXER_KEYW_IF: case LEXER_KEYW_WHILE: @@ -350,7 +350,7 @@ parser_scan_statement (parser_context_t *context_p, /**< context */ parser_stack_push_uint8 (context_p, SCAN_STACK_PAREN_STATEMENT); *mode = SCAN_MODE_PRIMARY_EXPRESSION; - return PARSER_FALSE; + return false; } case LEXER_KEYW_FOR: { @@ -366,15 +366,15 @@ parser_scan_statement (parser_context_t *context_p, /**< context */ if (context_p->token.type == LEXER_KEYW_VAR) { - return PARSER_FALSE; + return false; } - return PARSER_TRUE; + return true; } case LEXER_KEYW_VAR: case LEXER_KEYW_THROW: { *mode = SCAN_MODE_PRIMARY_EXPRESSION; - return PARSER_FALSE; + return false; } case LEXER_KEYW_RETURN: { @@ -384,7 +384,7 @@ parser_scan_statement (parser_context_t *context_p, /**< context */ { *mode = SCAN_MODE_PRIMARY_EXPRESSION; } - return PARSER_TRUE; + return true; } case LEXER_KEYW_BREAK: case LEXER_KEYW_CONTINUE: @@ -394,9 +394,9 @@ parser_scan_statement (parser_context_t *context_p, /**< context */ && context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { - return PARSER_FALSE; + return false; } - return PARSER_TRUE; + return true; } case LEXER_KEYW_DEFAULT: { @@ -405,13 +405,13 @@ parser_scan_statement (parser_context_t *context_p, /**< context */ { parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); } - return PARSER_FALSE; + return false; } case LEXER_KEYW_CASE: { parser_stack_push_uint8 (context_p, SCAN_STACK_COLON_STATEMENT); *mode = SCAN_MODE_PRIMARY_EXPRESSION; - return PARSER_FALSE; + return false; } case LEXER_RIGHT_BRACE: { @@ -434,22 +434,22 @@ parser_scan_statement (parser_context_t *context_p, /**< context */ { parser_raise_error (context_p, PARSER_ERR_OBJECT_ITEM_SEPARATOR_EXPECTED); } - return PARSER_TRUE; + return true; } - return PARSER_FALSE; + return false; } break; } case LEXER_LEFT_BRACE: { parser_stack_push_uint8 (context_p, SCAN_STACK_BLOCK_STATEMENT); - return PARSER_FALSE; + return false; } case LEXER_KEYW_FUNCTION: { parser_stack_push_uint8 (context_p, SCAN_STACK_BLOCK_STATEMENT); *mode = SCAN_MODE_FUNCTION_ARGUMENTS; - return PARSER_FALSE; + return false; } default: { @@ -466,12 +466,12 @@ parser_scan_statement (parser_context_t *context_p, /**< context */ if (context_p->token.type == LEXER_COLON) { *mode = SCAN_MODE_STATEMENT; - return PARSER_FALSE; + return false; } *mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; } - return PARSER_TRUE; + return true; } /* parser_scan_statement */ /** @@ -514,7 +514,7 @@ parser_scan_until (parser_context_t *context_p, /**< context */ parser_stack_push_uint8 (context_p, SCAN_STACK_HEAD); - while (PARSER_TRUE) + while (true) { lexer_token_type_t type = (lexer_token_type_t) context_p->token.type; scan_stack_modes_t stack_top = (scan_stack_modes_t) context_p->stack_top_uint8; @@ -603,7 +603,7 @@ parser_scan_until (parser_context_t *context_p, /**< context */ if (context_p->token.type != LEXER_RIGHT_PAREN) { - while (PARSER_TRUE) + while (true) { if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) @@ -638,7 +638,7 @@ parser_scan_until (parser_context_t *context_p, /**< context */ { JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL); - lexer_scan_identifier (context_p, PARSER_TRUE); + lexer_scan_identifier (context_p, true); if (context_p->token.type == LEXER_RIGHT_BRACE) { diff --git a/jerry-core/parser/js/js-parser-statm.c b/jerry-core/parser/js/js-parser-statm.c index dd2327a35..1e9d3ac9f 100644 --- a/jerry-core/parser/js/js-parser-statm.c +++ b/jerry-core/parser/js/js-parser-statm.c @@ -303,7 +303,7 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */ { JERRY_ASSERT (context_p->token.type == LEXER_KEYW_VAR); - while (PARSER_TRUE) + while (true) { lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL); JERRY_ASSERT (context_p->token.type == LEXER_LITERAL @@ -442,7 +442,7 @@ parser_parse_if_statement_start (parser_context_t *context_p) /**< context */ /** * Parse if statement (ending part). */ -static int +static bool parser_parse_if_statement_end (parser_context_t *context_p) /**< context */ { parser_if_else_statement_t if_statement; @@ -459,7 +459,7 @@ parser_parse_if_statement_end (parser_context_t *context_p) /**< context */ parser_set_branch_to_current_position (context_p, &if_statement.branch); - return PARSER_FALSE; + return false; } parser_stack_change_last_uint8 (context_p, PARSER_STATEMENT_ELSE); @@ -476,7 +476,7 @@ parser_parse_if_statement_end (parser_context_t *context_p) /**< context */ parser_stack_iterator_write (&iterator, &else_statement, sizeof (parser_if_else_statement_t)); lexer_next_token (context_p); - return PARSER_TRUE; + return true; } /* parser_parse_if_statement_end */ /** @@ -534,7 +534,7 @@ parser_parse_with_statement_end (parser_context_t *context_p) /**< context */ parser_stack_iterator_init (context_p, &iterator); - while (PARSER_TRUE) + while (true) { uint8_t type = parser_stack_iterator_read_uint8 (&iterator); @@ -961,8 +961,8 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context * parser_stack_iterator_t iterator; lexer_range_t switch_body_start; lexer_range_t unused_range; - int switch_case_was_found; - int default_case_was_found; + bool switch_case_was_found; + bool default_case_was_found; parser_branch_node_t *cases_p = NULL; JERRY_ASSERT (context_p->token.type == LEXER_KEYW_SWITCH); @@ -1009,10 +1009,10 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context * parser_stack_push_uint8 (context_p, PARSER_STATEMENT_SWITCH); parser_stack_iterator_init (context_p, &context_p->last_statement); - switch_case_was_found = PARSER_FALSE; - default_case_was_found = PARSER_FALSE; + switch_case_was_found = false; + default_case_was_found = false; - while (PARSER_TRUE) + while (true) { parser_scan_until (context_p, &unused_range, LEXER_KEYW_CASE); @@ -1029,7 +1029,7 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context * parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); } - default_case_was_found = PARSER_TRUE; + default_case_was_found = true; } else if (context_p->token.type == LEXER_KEYW_CASE || context_p->token.type == LEXER_RIGHT_BRACE) @@ -1072,7 +1072,7 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context * { parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); } - switch_case_was_found = PARSER_TRUE; + switch_case_was_found = true; } lexer_next_token (context_p); @@ -1305,7 +1305,7 @@ parser_parse_break_statement (parser_context_t *context_p) /**< context */ && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { /* The label with the same name is searched on the stack. */ - while (PARSER_TRUE) + while (true) { uint8_t type = parser_stack_iterator_read_uint8 (&iterator); if (type == PARSER_STATEMENT_START) @@ -1346,7 +1346,7 @@ parser_parse_break_statement (parser_context_t *context_p) /**< context */ } /* The first switch or loop statement is searched. */ - while (PARSER_TRUE) + while (true) { uint8_t type = parser_stack_iterator_read_uint8 (&iterator); if (type == PARSER_STATEMENT_START) @@ -1400,12 +1400,12 @@ parser_parse_continue_statement (parser_context_t *context_p) /**< context */ && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) { parser_stack_iterator_t loop_iterator; - int for_in_was_seen = PARSER_FALSE; + bool for_in_was_seen = false; loop_iterator.current_p = NULL; /* The label with the same name is searched on the stack. */ - while (PARSER_TRUE) + while (true) { uint8_t type = parser_stack_iterator_read_uint8 (&iterator); @@ -1448,7 +1448,7 @@ parser_parse_continue_statement (parser_context_t *context_p) /**< context */ } else if (type == PARSER_STATEMENT_FOR_IN) { - for_in_was_seen = PARSER_TRUE; + for_in_was_seen = true; } if (type == PARSER_STATEMENT_DO_WHILE @@ -1468,7 +1468,7 @@ parser_parse_continue_statement (parser_context_t *context_p) /**< context */ } /* The first loop statement is searched. */ - while (PARSER_TRUE) + while (true) { uint8_t type = parser_stack_iterator_read_uint8 (&iterator); if (type == PARSER_STATEMENT_START) @@ -1515,7 +1515,7 @@ parser_parse_label (parser_context_t *context_p, /**< context */ parser_stack_iterator_init (context_p, &iterator); - while (PARSER_TRUE) + while (true) { uint8_t type = parser_stack_iterator_read_uint8 (&iterator); if (type == PARSER_STATEMENT_START) @@ -1564,7 +1564,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ lexer_lit_location_t lit_location; uint32_t status_flags = context_p->status_flags; #ifdef PARSER_DUMP_BYTE_CODE - int switch_to_strict_mode = PARSER_FALSE; + bool switch_to_strict_mode = false; #endif /* PARSER_DUMP_BYTE_CODE */ JERRY_ASSERT (context_p->stack_depth == 0); @@ -1578,7 +1578,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ context_p->status_flags |= PARSER_IS_STRICT; #ifdef PARSER_DUMP_BYTE_CODE - switch_to_strict_mode = PARSER_TRUE; + switch_to_strict_mode = true; #endif /* PARSER_DUMP_BYTE_CODE */ } @@ -1942,7 +1942,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED); } - while (PARSER_TRUE) + while (true) { switch (context_p->stack_top_uint8) { @@ -2063,7 +2063,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */ void __attr_noinline___ parser_free_jumps (parser_stack_iterator_t iterator) /**< iterator position */ { - while (PARSER_TRUE) + while (true) { uint8_t type = parser_stack_iterator_read_uint8 (&iterator); parser_branch_node_t *branch_list_p = NULL; diff --git a/jerry-core/parser/js/js-parser-util.c b/jerry-core/parser/js/js-parser-util.c index bb4b662c7..c17ae60e6 100644 --- a/jerry-core/parser/js/js-parser-util.c +++ b/jerry-core/parser/js/js-parser-util.c @@ -301,7 +301,7 @@ parser_emit_cbc_call (parser_context_t *context_p, /**< context */ */ void parser_emit_cbc_push_number (parser_context_t *context_p, /**< context */ - int is_negative_number) /**< sign is negative */ + bool is_negative_number) /**< sign is negative */ { uint16_t value = context_p->lit_object.index; diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c index 3b4945059..fae1cca39 100644 --- a/jerry-core/parser/js/js-parser.c +++ b/jerry-core/parser/js/js-parser.c @@ -20,7 +20,7 @@ #include "js-parser-internal.h" #ifdef PARSER_DUMP_BYTE_CODE -static int parser_show_instrs = PARSER_FALSE; +static bool parser_show_instrs = false; #endif /* PARSER_DUMP_BYTE_CODE */ /** \addtogroup parser Parser @@ -864,7 +864,7 @@ parse_print_literal (ecma_compiled_code_t *compiled_code_p, /**< compiled code * parser_list_iterator_init (literal_pool_p, &literal_iterator); - while (PARSER_TRUE) + while (true) { lexer_literal_t *literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator); @@ -1261,7 +1261,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ size_t initializers_length; uint8_t real_offset; uint8_t *byte_code_p; - int needs_uint16_arguments; + bool needs_uint16_arguments; cbc_opcode_t last_opcode = CBC_EXT_OPCODE; ecma_compiled_code_t *compiled_code_p; jmem_cpointer_t *literal_pool_p; @@ -1394,7 +1394,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ if (flags & CBC_HAS_BRANCH_ARG) { - int prefix_zero = PARSER_TRUE; + bool prefix_zero = true; #if PARSER_MAXIMUM_CODE_SIZE <= 65535 cbc_opcode_t jump_forward = CBC_JUMP_FORWARD_2; #else /* PARSER_MAXIMUM_CODE_SIZE > 65535 */ @@ -1412,7 +1412,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ uint8_t byte = page_p->bytes[offset]; if (byte > 0 || !prefix_zero) { - prefix_zero = PARSER_FALSE; + prefix_zero = false; length++; } else @@ -1451,13 +1451,13 @@ parser_post_processing (parser_context_t *context_p) /**< context */ length++; } - needs_uint16_arguments = PARSER_FALSE; + needs_uint16_arguments = false; total_size = sizeof (cbc_uint8_arguments_t); if ((context_p->register_count + context_p->stack_limit) > CBC_MAXIMUM_BYTE_VALUE || context_p->literal_count > CBC_MAXIMUM_BYTE_VALUE) { - needs_uint16_arguments = PARSER_TRUE; + needs_uint16_arguments = true; total_size = sizeof (cbc_uint16_arguments_t); } @@ -1641,7 +1641,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ if (flags & CBC_HAS_BRANCH_ARG) { - int prefix_zero = PARSER_TRUE; + bool prefix_zero = true; /* The leading zeroes are dropped from the stream. */ JERRY_ASSERT (branch_offset_length > 0 && branch_offset_length <= 3); @@ -1651,7 +1651,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ uint8_t byte = page_p->bytes[offset]; if (byte > 0 || !prefix_zero) { - prefix_zero = PARSER_FALSE; + prefix_zero = false; *dst_p++ = page_p->bytes[offset]; real_offset++; } @@ -2038,7 +2038,7 @@ parser_parse_function (parser_context_t *context_p, /**< context */ /* Argument parsing. */ if (context_p->token.type != LEXER_RIGHT_PAREN) { - while (PARSER_TRUE) + while (true) { uint16_t literal_count = context_p->literal_count;